event: Move signal handler setup to separate function
Just code movement, no changes. Change-Id: Ie4eba079a6a9eae7632c784985cccb9bd18cd3a6 Signed-off-by: Ben Walker <benjamin.walker@intel.com> Reviewed-on: https://review.gerrithub.io/370757 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
c549377169
commit
30b512c201
107
lib/event/app.c
107
lib/event/app.c
@ -188,14 +188,69 @@ spdk_app_opts_init(struct spdk_app_opts *opts)
|
||||
opts->max_delay_us = 0;
|
||||
}
|
||||
|
||||
static int
|
||||
spdk_app_setup_signal_handlers(struct spdk_app_opts *opts)
|
||||
{
|
||||
struct sigaction sigact;
|
||||
sigset_t sigmask;
|
||||
int rc;
|
||||
|
||||
/* Set up custom shutdown handling if the user requested it. */
|
||||
if (opts->shutdown_cb != NULL) {
|
||||
g_shutdown_event = spdk_event_allocate(spdk_env_get_current_core(),
|
||||
__shutdown_event_cb,
|
||||
NULL, NULL);
|
||||
}
|
||||
|
||||
sigemptyset(&sigmask);
|
||||
memset(&sigact, 0, sizeof(sigact));
|
||||
sigemptyset(&sigact.sa_mask);
|
||||
|
||||
sigact.sa_handler = SIG_IGN;
|
||||
rc = sigaction(SIGPIPE, &sigact, NULL);
|
||||
if (rc < 0) {
|
||||
SPDK_ERRLOG("sigaction(SIGPIPE) failed\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Install the same handler for SIGINT and SIGTERM */
|
||||
sigact.sa_handler = __shutdown_signal;
|
||||
|
||||
rc = sigaction(SIGINT, &sigact, NULL);
|
||||
if (rc < 0) {
|
||||
SPDK_ERRLOG("sigaction(SIGINT) failed\n");
|
||||
return rc;
|
||||
}
|
||||
sigaddset(&sigmask, SIGINT);
|
||||
|
||||
rc = sigaction(SIGTERM, &sigact, NULL);
|
||||
if (rc < 0) {
|
||||
SPDK_ERRLOG("sigaction(SIGTERM) failed\n");
|
||||
return rc;
|
||||
}
|
||||
sigaddset(&sigmask, SIGTERM);
|
||||
|
||||
if (opts->usr1_handler != NULL) {
|
||||
sigact.sa_handler = opts->usr1_handler;
|
||||
rc = sigaction(SIGUSR1, &sigact, NULL);
|
||||
if (rc < 0) {
|
||||
SPDK_ERRLOG("sigaction(SIGUSR1) failed\n");
|
||||
return rc;
|
||||
}
|
||||
sigaddset(&sigmask, SIGUSR1);
|
||||
}
|
||||
|
||||
pthread_sigmask(SIG_UNBLOCK, &sigmask, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
spdk_app_start(struct spdk_app_opts *opts, spdk_event_fn start_fn,
|
||||
void *arg1, void *arg2)
|
||||
{
|
||||
struct spdk_conf *config;
|
||||
struct spdk_conf_section *sp;
|
||||
struct sigaction sigact;
|
||||
sigset_t sigmask;
|
||||
char shm_name[64];
|
||||
int rc;
|
||||
uint64_t tpoint_group_mask;
|
||||
@ -283,57 +338,11 @@ spdk_app_start(struct spdk_app_opts *opts, spdk_event_fn start_fn,
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Set up custom shutdown handling if the user requested it. */
|
||||
if (opts->shutdown_cb != NULL) {
|
||||
g_shutdown_event = spdk_event_allocate(spdk_env_get_current_core(),
|
||||
__shutdown_event_cb,
|
||||
NULL, NULL);
|
||||
}
|
||||
|
||||
sigemptyset(&sigmask);
|
||||
memset(&sigact, 0, sizeof(sigact));
|
||||
sigemptyset(&sigact.sa_mask);
|
||||
|
||||
sigact.sa_handler = SIG_IGN;
|
||||
rc = sigaction(SIGPIPE, &sigact, NULL);
|
||||
if (rc < 0) {
|
||||
SPDK_ERRLOG("sigaction(SIGPIPE) failed\n");
|
||||
if (spdk_app_setup_signal_handlers(opts)) {
|
||||
spdk_conf_free(g_spdk_app.config);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Install the same handler for SIGINT and SIGTERM */
|
||||
sigact.sa_handler = __shutdown_signal;
|
||||
|
||||
rc = sigaction(SIGINT, &sigact, NULL);
|
||||
if (rc < 0) {
|
||||
SPDK_ERRLOG("sigaction(SIGINT) failed\n");
|
||||
spdk_conf_free(g_spdk_app.config);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
sigaddset(&sigmask, SIGINT);
|
||||
|
||||
rc = sigaction(SIGTERM, &sigact, NULL);
|
||||
if (rc < 0) {
|
||||
SPDK_ERRLOG("sigaction(SIGTERM) failed\n");
|
||||
spdk_conf_free(g_spdk_app.config);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
sigaddset(&sigmask, SIGTERM);
|
||||
|
||||
if (opts->usr1_handler != NULL) {
|
||||
sigact.sa_handler = opts->usr1_handler;
|
||||
rc = sigaction(SIGUSR1, &sigact, NULL);
|
||||
if (rc < 0) {
|
||||
SPDK_ERRLOG("sigaction(SIGUSR1) failed\n");
|
||||
spdk_conf_free(g_spdk_app.config);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
sigaddset(&sigmask, SIGUSR1);
|
||||
}
|
||||
|
||||
pthread_sigmask(SIG_UNBLOCK, &sigmask, NULL);
|
||||
|
||||
if (opts->shm_id >= 0) {
|
||||
snprintf(shm_name, sizeof(shm_name), "/%s_trace.%d", opts->name, opts->shm_id);
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user