-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
* ADD [broker] Add signal handler in broker #1530
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,10 +10,6 @@ | |
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#if !defined(NANO_PLATFORM_WINDOWS) | ||
#include <signal.h> | ||
#endif | ||
|
||
#include "nng/mqtt/mqtt_client.h" | ||
#include "nng/protocol/mqtt/nmq_mqtt.h" | ||
#include "nng/supplemental/tls/tls.h" | ||
|
@@ -64,6 +60,41 @@ | |
// be set in the thousands, each context consumes a couple of KB.) Recommend to | ||
// set as the same as your CPU cores. | ||
|
||
#if !defined(NANO_PLATFORM_WINDOWS) | ||
#include <signal.h> | ||
#include <errno.h> | ||
static const all_signals[] = { | ||
#ifdef SIGHUP | ||
SIGHUP, | ||
#endif | ||
#ifdef SIGQUIT | ||
SIGQUIT, | ||
#endif | ||
#ifdef SIGTRAP | ||
SIGTRAP, | ||
#endif | ||
#ifdef SIGIO | ||
SIGIO, | ||
#endif | ||
SIGABRT, | ||
SIGFPE, | ||
SIGILL, | ||
SIGINT, | ||
SIGSEGV, | ||
SIGTERM | ||
}; | ||
|
||
int sig_handler(int signum) | ||
{ | ||
log_error("signal caught!!!! signumber: %d\n", signum); | ||
|
||
if (signum == SIGINT) { | ||
exit(EXIT_FAILURE); | ||
} | ||
} | ||
JaylinYu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#endif | ||
|
||
|
||
enum options { | ||
OPT_HELP = 1, | ||
OPT_HOCONFILE = 2, /* Do not change this value, it is used beyond this file. */ | ||
|
@@ -147,22 +178,8 @@ | |
|
||
#if (defined DEBUG) && (defined ASAN) | ||
int keepRunning = 1; | ||
void | ||
intHandler(int dummy) | ||
{ | ||
keepRunning = 0; | ||
fprintf(stderr, "\nBroker exit(0).\n"); | ||
} | ||
#endif | ||
|
||
void | ||
termHandler(int dummy) | ||
{ | ||
fprintf(stderr, "\nReceive SIGTERM signal."); | ||
fprintf(stderr, "\nBroker exit(0).\n"); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
static inline bool | ||
bridge_handler(nano_work *work) | ||
{ | ||
|
@@ -1114,8 +1131,19 @@ | |
|
||
#if (defined DEBUG) && (defined ASAN) | ||
#if !(defined NANO_PLATFORM_WINDOWS) | ||
signal(SIGTERM, termHandler); | ||
signal(SIGINT, intHandler); | ||
struct sigaction act; | ||
i = 0; | ||
|
||
memset(&act, 0, sizeof act); | ||
sigemptyset(&act.sa_mask); | ||
act.sa_handler = sig_handler; | ||
act.sa_flags = 0; | ||
|
||
do { | ||
if (sigaction(all_signals[i], &act, NULL)) { | ||
fprintf(stderr, "Cannot install signal %d handler: %s.\n", all_signals[i], strerror(errno)); | ||
} | ||
} while (all_signals[i++] != SIGTERM); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @wanghaEMQ want broker exit while receving SIGINT |
||
#endif | ||
|
||
if (is_testing == true) { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / CodeQL
Unused static variable Note