Skip to content

Commit

Permalink
prov/shm: Fixup signal handling bug
Browse files Browse the repository at this point in the history
Save the old action of different signals separately,
so that they can be recovered correctly.

Signed-off-by: Jie Zhang <[email protected]>
  • Loading branch information
zhngaj committed Feb 7, 2020
1 parent b4f95d4 commit ef3b3e7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions prov/shm/src/smr_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "smr.h"
#include "smr_signal.h"

extern struct sigaction *old_action;

static void smr_resolve_addr(const char *node, const char *service,
char **addr, size_t *addrlen)
Expand Down Expand Up @@ -137,6 +138,7 @@ static int smr_getinfo(uint32_t version, const char *node, const char *service,
static void smr_fini(void)
{
smr_cleanup();
free(old_action);
}

struct fi_provider smr_prov = {
Expand All @@ -157,7 +159,12 @@ struct util_prov smr_util_prov = {
SHM_INI
{

old_action = calloc(SIGRTMIN, sizeof(*old_action));
if (!old_action)
return NULL;
/* Signal handlers to cleanup tmpfs files on an unclean shutdown */
assert(SIGBUS < SIGRTMIN && SIGSEGV < SIGRTMIN
&& SIGTERM < SIGRTMIN && SIGINT < SIGRTMIN);
smr_reg_sig_hander(SIGBUS);
smr_reg_sig_hander(SIGSEGV);
smr_reg_sig_hander(SIGTERM);
Expand Down
6 changes: 3 additions & 3 deletions prov/shm/src/smr_signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include <signal.h>
#include <ofi_shm.h>

struct sigaction old_action;
struct sigaction *old_action;

static void smr_handle_signal(int signum, siginfo_t *info, void *ucontext)
{
Expand All @@ -49,7 +49,7 @@ static void smr_handle_signal(int signum, siginfo_t *info, void *ucontext)
}

/* Register the original signum handler, SIG_DFL or otherwise */
ret = sigaction(signum, &old_action, NULL);
ret = sigaction(signum, &old_action[signum], NULL);
if (ret)
return;

Expand All @@ -66,7 +66,7 @@ static void smr_reg_sig_hander(int signum)
action.sa_sigaction = smr_handle_signal;
action.sa_flags |= SA_SIGINFO;

ret = sigaction(signum, &action, &old_action);
ret = sigaction(signum, &action, &old_action[signum]);
if (ret)
FI_WARN(&smr_prov, FI_LOG_FABRIC,
"Unable to register handler for sig %d\n", signum);
Expand Down

0 comments on commit ef3b3e7

Please sign in to comment.