Skip to content

Commit

Permalink
Refactor: use int for timeouts & latency instead of wild mix and casts
Browse files Browse the repository at this point in the history
correct format strings where a sign doesn't make sense in the
context but the variables are still of signed type.
  • Loading branch information
wenningerk committed Sep 26, 2023
1 parent 1e3a2e1 commit 56e17ac
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 31 deletions.
8 changes: 4 additions & 4 deletions src/sbd-cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ sbd_cpg_membership_health_update()
set_servant_health(pcmk_health_noquorum, LOG_WARNING,
"Connected to %s but quorum using qdevice is distrusted "
"for SBD as qdevice-sync_timeout (%ds) > watchdog-timeout "
"(%lus).",
"(%us).",
name_for_cluster_type(get_cluster_type()),
qdevice_sync_timeout, timeout_watchdog
);
break;
}
#endif
set_servant_health(pcmk_health_online, LOG_INFO,
"Connected to %s (%u members)%s",
"Connected to %s (%d members)%s",
name_for_cluster_type(get_cluster_type()),
cpg_membership_entries,
#if CHECK_QDEVICE_SYNC_TIMEOUT
Expand Down Expand Up @@ -710,9 +710,9 @@ find_pacemaker_remote(void)
}

/* entry_name is truncated to 16 characters including the nul terminator */
cl_log(LOG_DEBUG, "Found %s at %u", entry_name, pid);
cl_log(LOG_DEBUG, "Found %s at %d", entry_name, pid);
if (strncmp(entry_name, PACEMAKER_REMOTE_BINARY, 15) == 0) {
cl_log(LOG_NOTICE, "Found Pacemaker Remote at PID %u", pid);
cl_log(LOG_NOTICE, "Found Pacemaker Remote at PID %d", pid);
remoted_pid = pid;
remote_node = true;
break;
Expand Down
18 changes: 9 additions & 9 deletions src/sbd-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@
#endif

/* Tunable defaults: */
unsigned long timeout_watchdog = SBD_WATCHDOG_TIMEOUT_DEFAULT;
int timeout_msgwait = 2 * SBD_WATCHDOG_TIMEOUT_DEFAULT;
unsigned long timeout_watchdog_warn = calculate_timeout_watchdog_warn(SBD_WATCHDOG_TIMEOUT_DEFAULT);
bool do_calculate_timeout_watchdog_warn = true;
int timeout_watchdog = SBD_WATCHDOG_TIMEOUT_DEFAULT;
int timeout_msgwait = 2 * SBD_WATCHDOG_TIMEOUT_DEFAULT;
int timeout_watchdog_warn = calculate_timeout_watchdog_warn(SBD_WATCHDOG_TIMEOUT_DEFAULT);
bool do_calculate_timeout_watchdog_warn = true;
int timeout_allocate = 2;
int timeout_loop = 1;
int timeout_io = 3;
int timeout_startup = 120;

int watchdog_use = 1;
int watchdog_set_timeout = 1;
unsigned long timeout_watchdog_crashdump = 0;
int timeout_watchdog_crashdump = 0;
int skip_rt = 0;
int debug = 0;
int debug_mode = 0;
Expand Down Expand Up @@ -179,7 +179,7 @@ watchdog_init_interval_fd(int wdfd, int timeout)
{
if (ioctl(wdfd, WDIOC_SETTIMEOUT, &timeout) < 0) {
cl_perror( "WDIOC_SETTIMEOUT"
": Failed to set watchdog timer to %u seconds.",
": Failed to set watchdog timer to %d seconds.",
timeout);
cl_log(LOG_CRIT, "Please validate your watchdog configuration!");
cl_log(LOG_CRIT, "Choose a different watchdog driver or specify -T to skip this if you are completely sure.");
Expand All @@ -203,7 +203,7 @@ watchdog_init_interval(void)
if (watchdog_init_interval_fd(watchdogfd, timeout_watchdog) < 0) {
return -1;
}
cl_log(LOG_INFO, "Set watchdog timeout to %u seconds.", (int) timeout_watchdog);
cl_log(LOG_INFO, "Set watchdog timeout to %d seconds.", timeout_watchdog);
return 0;
}

Expand Down Expand Up @@ -266,7 +266,7 @@ watchdog_init(void)
if (watchdogfd >= 0) {
cl_log(LOG_NOTICE, "Using watchdog device '%s'", watchdogdev);
if (watchdog_set_timeout) {
cl_log(LOG_INFO, "Set watchdog timeout to %u seconds.", (int) timeout_watchdog);
cl_log(LOG_INFO, "Set watchdog timeout to %d seconds.", timeout_watchdog);
}
} else {
return -1;
Expand Down Expand Up @@ -651,7 +651,7 @@ int watchdog_test(void)
printf("\n");
printf("NOTICE: The watchdog device is expected to reset the system\n"
" in %d seconds. If system remains active beyond that time,\n"
" watchdog may not be functional.\n\n", (int) timeout_watchdog);
" watchdog may not be functional.\n\n", timeout_watchdog);
for (i=timeout_watchdog; i>1; i--) {
printf("Reset countdown ... %d seconds\n", i);
sleep(1);
Expand Down
14 changes: 7 additions & 7 deletions src/sbd-inquisitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ void inquisitor_child(void)
int decoupled = 0;
int cluster_appeared = 0;
int pcmk_override = 0;
time_t latency;
int latency;
struct timespec t_last_tickle, t_now;
struct servants_list_item* s;

Expand Down Expand Up @@ -725,8 +725,8 @@ void inquisitor_child(void)

/* Note that this can actually be negative, since we set
* last_tickle after we set now. */
latency = t_now.tv_sec - t_last_tickle.tv_sec;
if (timeout_watchdog && (latency > (int)timeout_watchdog)) {
latency = (int) (t_now.tv_sec - t_last_tickle.tv_sec);
if (timeout_watchdog && (latency > timeout_watchdog)) {
if (!decoupled) {
/* We're still being watched by our
* parent. We don't fence, but exit. */
Expand All @@ -745,10 +745,10 @@ void inquisitor_child(void)
}
}

if (timeout_watchdog_warn && (latency > (int)timeout_watchdog_warn)) {
if (timeout_watchdog_warn && (latency > timeout_watchdog_warn)) {
cl_log(LOG_WARNING,
"Latency: No liveness for %ds exceeds watchdog warning timeout of %ds (healthy servants: %d)",
(int)latency, (int)timeout_watchdog_warn, good_servants);
latency, timeout_watchdog_warn, good_servants);

if (debug_mode && watchdog_use) {
/* In debug mode, trigger a reset before the watchdog can panic the machine */
Expand Down Expand Up @@ -1110,7 +1110,7 @@ int main(int argc, char **argv, char **envp)
case 'C':
timeout_watchdog_crashdump = sanitized_num_optarg;
cl_log(LOG_INFO, "Setting crashdump watchdog timeout to %d",
(int)timeout_watchdog_crashdump);
timeout_watchdog_crashdump);
break;
case '1':
timeout_watchdog = sanitized_num_optarg;
Expand All @@ -1128,7 +1128,7 @@ int main(int argc, char **argv, char **envp)
timeout_watchdog_warn = sanitized_num_optarg;
do_calculate_timeout_watchdog_warn = false;
cl_log(LOG_INFO, "Setting latency warning to %d",
(int)timeout_watchdog_warn);
timeout_watchdog_warn);
break;
case 't':
servant_restart_interval = sanitized_num_optarg;
Expand Down
11 changes: 6 additions & 5 deletions src/sbd-md.c
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ static int servant_check_timeout_inconsistent(struct sector_header_s *hdr)
{
if (timeout_watchdog != hdr->timeout_watchdog) {
cl_log(LOG_WARNING, "watchdog timeout: %d versus %d on this device",
(int)timeout_watchdog, (int)hdr->timeout_watchdog);
timeout_watchdog, (int)hdr->timeout_watchdog);
return -1;
}
if (timeout_allocate != hdr->timeout_allocate) {
Expand Down Expand Up @@ -1077,7 +1077,8 @@ int servant_md(const char *diskname, int mode, const void* argp)
struct sector_header_s *s_header = NULL;
int mbox;
int rc = 0;
time_t t0, t1, latency;
time_t t0, t1;
int latency;
sigset_t servant_masks;
struct sbd_context *st;
pid_t ppid;
Expand Down Expand Up @@ -1264,14 +1265,14 @@ int servant_md(const char *diskname, int mode, const void* argp)
sigqueue_zero(ppid, SIG_LIVENESS);

t1 = time(NULL);
latency = t1 - t0;
latency = (int) (t1 - t0);
if (timeout_watchdog_warn && (latency > timeout_watchdog_warn)) {
cl_log(LOG_WARNING,
"Latency: %ds exceeded watchdog warning timeout %ds on disk %s",
(int)latency, (int)timeout_watchdog_warn,
latency, timeout_watchdog_warn,
diskname);
} else if (debug) {
DBGLOG(LOG_DEBUG, "Latency: %ds on disk %s", (int)latency,
DBGLOG(LOG_DEBUG, "Latency: %ds on disk %s", latency,
diskname);
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/sbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ int sigqueue_zero(pid_t pid, int sig);
void notify_parent(void);

/* Tunable defaults: */
extern unsigned long timeout_watchdog;
extern unsigned long timeout_watchdog_warn;
extern bool do_calculate_timeout_watchdog_warn;
extern unsigned long timeout_watchdog_crashdump;
extern int timeout_watchdog;
extern int timeout_watchdog_warn;
extern bool do_calculate_timeout_watchdog_warn;
extern int timeout_watchdog_crashdump;
extern int timeout_allocate;
extern int timeout_loop;
extern int timeout_msgwait;
Expand Down Expand Up @@ -216,5 +216,5 @@ bool sbd_is_cluster(struct servants_list_item *servant);

#define calculate_timeout_watchdog_warn(timeout) \
(timeout < 5 ? 2 : \
(timeout < (ULONG_MAX / 3) ? \
(((unsigned long) timeout) * 3 / 5) : (((unsigned long) timeout) / 5 * 3)))
(timeout < (INT_MAX / 3) ? \
(((int) timeout) * 3 / 5) : (((int) timeout) / 5 * 3)))

0 comments on commit 56e17ac

Please sign in to comment.