Skip to content

Commit

Permalink
Refactor: introduce sigqueue_zero
Browse files Browse the repository at this point in the history
and use it throughout the code to consistently clear
argument passed to sigqueue
  • Loading branch information
wenningerk committed Sep 26, 2023
1 parent 5ec38cf commit bb352ea
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
17 changes: 12 additions & 5 deletions src/sbd-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1257,13 +1257,20 @@ sbd_set_format_string(int method, const char *daemon)
}
}

int sigqueue_zero(pid_t pid, int sig)
{
union sigval signal_value;

memset(&signal_value, 0, sizeof(signal_value));

return sigqueue(pid, sig, signal_value);
}

void
notify_parent(void)
{
pid_t ppid;
union sigval signal_value;

memset(&signal_value, 0, sizeof(signal_value));
ppid = getppid();

if (ppid == 1) {
Expand All @@ -1284,17 +1291,17 @@ notify_parent(void)
case pcmk_health_unclean:
case pcmk_health_noquorum:
DBGLOG(LOG_WARNING, "Notifying parent: UNHEALTHY (%d)", servant_health);
sigqueue(ppid, SIG_PCMK_UNHEALTHY, signal_value);
sigqueue_zero(ppid, SIG_PCMK_UNHEALTHY);
break;

case pcmk_health_online:
DBGLOG(LOG_DEBUG, "Notifying parent: healthy");
sigqueue(ppid, SIG_LIVENESS, signal_value);
sigqueue_zero(ppid, SIG_LIVENESS);
break;

default:
DBGLOG(LOG_WARNING, "Notifying parent: UNHEALTHY %d", servant_health);
sigqueue(ppid, SIG_PCMK_UNHEALTHY, signal_value);
sigqueue_zero(ppid, SIG_PCMK_UNHEALTHY);
break;
}
}
Expand Down
15 changes: 6 additions & 9 deletions src/sbd-inquisitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,10 @@ int check_all_dead(void)
{
struct servants_list_item *s;
int r = 0;
union sigval svalue;

for (s = servants_leader; s; s = s->next) {
if (s->pid != 0) {
r = sigqueue(s->pid, 0, svalue);
r = sigqueue_zero(s->pid, 0);
if (r == -1 && errno == ESRCH)
continue;
return 0;
Expand All @@ -206,10 +205,9 @@ int check_all_dead(void)
void servant_start(struct servants_list_item *s)
{
int r = 0;
union sigval svalue;

if (s->pid != 0) {
r = sigqueue(s->pid, 0, svalue);
r = sigqueue_zero(s->pid, 0);
if ((r != -1 || errno != ESRCH))
return;
}
Expand Down Expand Up @@ -251,11 +249,11 @@ void servants_start(void)
void servants_kill(void)
{
struct servants_list_item *s;
union sigval svalue;

for (s = servants_leader; s; s = s->next) {
if (s->pid != 0)
sigqueue(s->pid, SIGKILL, svalue);
if (s->pid != 0) {
sigqueue_zero(s->pid, SIGKILL);
}
}
}

Expand All @@ -280,7 +278,6 @@ static inline void cleanup_servant_by_pid(pid_t pid)
int inquisitor_decouple(void)
{
pid_t ppid = getppid();
union sigval signal_value;

/* During start-up, we only arm the watchdog once we've got
* quorum at least once. */
Expand All @@ -291,7 +288,7 @@ int inquisitor_decouple(void)
}

if (ppid > 1) {
sigqueue(ppid, SIG_LIVENESS, signal_value);
sigqueue_zero(ppid, SIG_LIVENESS);
}
return 0;
}
Expand Down
11 changes: 4 additions & 7 deletions src/sbd-md.c
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,6 @@ int servant_md(const char *diskname, int mode, const void* argp)
int mbox;
int rc = 0;
time_t t0, t1, latency;
union sigval signal_value;
sigset_t servant_masks;
struct sbd_context *st;
pid_t ppid;
Expand Down Expand Up @@ -1159,7 +1158,7 @@ int servant_md(const char *diskname, int mode, const void* argp)
/* Not a clean stop. Abort start-up */
cl_log(LOG_WARNING, "Found fencing message - aborting start-up. Manual intervention required!");
ppid = getppid();
sigqueue(ppid, SIG_EXITREQ, signal_value);
sigqueue_zero(ppid, SIG_EXITREQ);
rc = 0;
goto out;
}
Expand All @@ -1172,8 +1171,6 @@ int servant_md(const char *diskname, int mode, const void* argp)
}
}

memset(&signal_value, 0, sizeof(signal_value));

while (1) {
struct sector_header_s *s_header_retry = NULL;
struct sector_node_s *s_node_retry = NULL;
Expand Down Expand Up @@ -1237,7 +1234,7 @@ int servant_md(const char *diskname, int mode, const void* argp)
case SBD_MSG_TEST:
memset(s_mbox, 0, sizeof(*s_mbox));
mbox_write(st, mbox, s_mbox);
sigqueue(ppid, SIG_TEST, signal_value);
sigqueue_zero(ppid, SIG_TEST);
break;
case SBD_MSG_RESET:
rc = EXIT_MD_SERVANT_REQUEST_RESET;
Expand All @@ -1246,7 +1243,7 @@ int servant_md(const char *diskname, int mode, const void* argp)
rc = EXIT_MD_SERVANT_REQUEST_SHUTOFF;
goto out;
case SBD_MSG_EXIT:
sigqueue(ppid, SIG_EXITREQ, signal_value);
sigqueue_zero(ppid, SIG_EXITREQ);
break;
case SBD_MSG_CRASHDUMP:
rc = EXIT_MD_SERVANT_REQUEST_CRASHDUMP;
Expand All @@ -1264,7 +1261,7 @@ int servant_md(const char *diskname, int mode, const void* argp)
break;
}
}
sigqueue(ppid, SIG_LIVENESS, signal_value);
sigqueue_zero(ppid, SIG_LIVENESS);

t1 = time(NULL);
latency = t1 - t0;
Expand Down
1 change: 1 addition & 0 deletions src/sbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ pid_t make_daemon(void);
void maximize_priority(void);
void sbd_get_uname(void);
void sbd_set_format_string(int method, const char *daemon);
int sigqueue_zero(pid_t pid, int sig);
void notify_parent(void);

/* Tunable defaults: */
Expand Down

0 comments on commit bb352ea

Please sign in to comment.