diff --git a/doc/man/man8/keepalived.8.in b/doc/man/man8/keepalived.8.in index f56d6bf07c..9f00ad2ddd 100644 --- a/doc/man/man8/keepalived.8.in +++ b/doc/man/man8/keepalived.8.in @@ -44,6 +44,7 @@ keepalived \- load\-balancing and high\-availability service [\fB\-\-perf\fP[={all|run|end}]] [\fB\-\-debug\fP[=debug-options]] [\fB\-\-no-mem-check\fP] +[\fB\-\-ignore-sigint\fP] [\fB\-v\fP|\fB\-\-version\fP] [\fB\-h\fP|\fB\-\-help\fP] @@ -216,6 +217,10 @@ The data recorded is for use with the perf tool. \fB --no-mem-check\fP Disable malloc() etc mem-checks if they have been compiled into keepalived. .TP +\fB --ignore-sigint\fP +Disable SIGINT handling (defaults to terminating keepalived). This is needed +for running keepalived under GDB. +.TP \fB --debug\fP[=debug-options]] Enables debug options if they have been compiled into keepalived. \fIdebug-options\fP is made up of a sequence of strings of the form Ulll. diff --git a/keepalived/bfd/bfd_daemon.c b/keepalived/bfd/bfd_daemon.c index a9d4cc68fb..4d20f159ea 100644 --- a/keepalived/bfd/bfd_daemon.c +++ b/keepalived/bfd/bfd_daemon.c @@ -240,7 +240,10 @@ static void bfd_signal_init(void) { signal_set(SIGHUP, sigreload_bfd, NULL); - signal_set(SIGINT, sigend_bfd, NULL); + if (ignore_sigint) + signal_ignore(SIGINT); + else + signal_set(SIGINT, sigend_bfd, NULL); signal_set(SIGTERM, sigend_bfd, NULL); signal_set(SIGUSR1, sigdump_bfd, NULL); #ifdef THREAD_DUMP diff --git a/keepalived/check/check_daemon.c b/keepalived/check/check_daemon.c index 8e4184e641..887b00d5f9 100644 --- a/keepalived/check/check_daemon.c +++ b/keepalived/check/check_daemon.c @@ -565,7 +565,10 @@ static void check_signal_init(void) { signal_set(SIGHUP, sigreload_check, NULL); - signal_set(SIGINT, sigend_check, NULL); + if (ignore_sigint) + signal_ignore(SIGINT); + else + signal_set(SIGINT, sigend_check, NULL); signal_set(SIGTERM, sigend_check, NULL); signal_set(SIGUSR1, sigusr1_check, NULL); #ifdef THREAD_DUMP diff --git a/keepalived/core/main.c b/keepalived/core/main.c index 0316e8450c..a52b781f1f 100644 --- a/keepalived/core/main.c +++ b/keepalived/core/main.c @@ -211,6 +211,9 @@ static bool create_core_dump = false; static const char *core_dump_pattern = "core"; static char *orig_core_dump_pattern = NULL; +/* Signal handling */ +bool ignore_sigint = false; + /* debug flags */ #if defined _TIMER_CHECK_ || \ defined _SMTP_ALERT_DEBUG_ || \ @@ -1289,7 +1292,10 @@ signal_init(void) #ifdef _WITH_JSON_ signal_set(SIGJSON, propagate_signal, NULL); #endif - signal_set(SIGINT, sigend, NULL); + if (ignore_sigint) + signal_ignore(SIGINT); + else + signal_set(SIGINT, sigend, NULL); signal_set(SIGTERM, sigend, NULL); #ifdef THREAD_DUMP signal_set(SIGTDUMP, thread_dump_signal, NULL); @@ -1886,6 +1892,7 @@ usage(const char *prog) fprintf(stderr, " -i, --config-id id Skip any configuration lines beginning '@' that don't match id\n" " or any lines beginning @^ that do match.\n" " The config-id defaults to the node name if option not used\n"); + fprintf(stderr, " --ignore-sigint ignore SIGINT (default means terminate) - used for debugging with GDB\n"); fprintf(stderr, " --signum=SIGFUNC Return signal number for STOP, RELOAD, DATA, STATS, STATS_CLEAR" #ifdef _WITH_JSON_ ", JSON" @@ -2051,6 +2058,7 @@ parse_cmdline(int argc, char **argv) {"signum", required_argument, NULL, 4 }, {"config-test", optional_argument, NULL, 't'}, {"config-fd", required_argument, NULL, 8 }, + {"ignore-sigint", no_argument, NULL, 9 }, #ifdef _WITH_PERF_ {"perf", optional_argument, NULL, 5 }, #endif @@ -2356,6 +2364,9 @@ parse_cmdline(int argc, char **argv) case 8: set_config_fd(atoi(optarg)); break; + case 9: + ignore_sigint = true; + break; case '?': if (optopt && argv[curind][1] != '-') fprintf(stderr, "Unknown option -%c\n", optopt); diff --git a/keepalived/include/main.h b/keepalived/include/main.h index 814a02157b..90809ac138 100644 --- a/keepalived/include/main.h +++ b/keepalived/include/main.h @@ -82,6 +82,8 @@ extern unsigned os_major; /* Kernel version */ extern unsigned os_minor; extern unsigned os_release; +extern bool ignore_sigint; + extern void free_parent_mallocs_startup(bool); extern void free_parent_mallocs_exit(void); extern const char *make_syslog_ident(const char*); diff --git a/keepalived/vrrp/vrrp_daemon.c b/keepalived/vrrp/vrrp_daemon.c index d16b192dc6..4a483d40c4 100644 --- a/keepalived/vrrp/vrrp_daemon.c +++ b/keepalived/vrrp/vrrp_daemon.c @@ -789,7 +789,10 @@ static void vrrp_signal_init(void) { signal_set(SIGHUP, sigreload_vrrp, NULL); - signal_set(SIGINT, sigend_vrrp, NULL); + if (ignore_sigint) + signal_ignore(SIGINT); + else + signal_set(SIGINT, sigend_vrrp, NULL); signal_set(SIGTERM, sigend_vrrp, NULL); signal_set(SIGUSR1, sigusr1_vrrp, NULL); signal_set(SIGUSR2, sigusr2_vrrp, NULL);