-
Notifications
You must be signed in to change notification settings - Fork 30
restore original procmask for child process #50
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -475,38 +475,44 @@ int main(int argc,char * argv[]) | |
| memset(&sig, 0, sizeof(sig)); | ||
|
|
||
| PRINTF("Installing signal handlers\n"); | ||
|
|
||
| // SIGPIPE, SIGTERM and SIGHUP will be handled in the main loop | ||
| // with the assistance of pselect. This means that we have them | ||
| // blocked outside of pselect call, but unblocked atomically | ||
| // within pselect. Each time pselect returns, we safely check if | ||
| // any of the signals were received. | ||
|
|
||
| // Block the signals that we bill be handling in the main loop. | ||
|
|
||
| // Block the signals that we will be handling in the main loop | ||
| // and re-enable them during pselect. | ||
| // At the same time, retrieve the original signal mask before | ||
| // blocking, to be passed to pselect. | ||
| // blocking, to be passed to the child processes. | ||
|
|
||
| sigset_t sigset_block; | ||
| sigset_t sigset_child; | ||
| sigset_t sigset_pselect; | ||
| sigemptyset(&sigset_block); | ||
| sigaddset(&sigset_block, SIGPIPE); | ||
| sigaddset(&sigset_block, SIGTERM); | ||
| sigaddset(&sigset_block, SIGHUP); | ||
| sigprocmask(SIG_BLOCK, &sigset_block, &sigset_pselect); | ||
|
|
||
| sigaddset(&sigset_block, SIGXFSZ); | ||
| if (inFgMode) { | ||
| sigaddset(&sigset_block, SIGINT); | ||
| sigaddset(&sigset_block, SIGQUIT); | ||
| } | ||
| sigprocmask(SIG_BLOCK, &sigset_block, &sigset_child); | ||
|
|
||
| // enable SIGPIPE, SIGTERM and SIGHUP during pselect | ||
| sigprocmask(0, NULL, &sigset_pselect); | ||
| sigdelset(&sigset_pselect, SIGTERM); | ||
| sigdelset(&sigset_pselect, SIGHUP); | ||
| sigdelset(&sigset_pselect, SIGPIPE); | ||
|
|
||
| sig.sa_handler = &OnSigPipe; // sigaction() needed for Solaris | ||
| sigaction(SIGPIPE, &sig, NULL); | ||
| sig.sa_handler = &OnSigTerm; | ||
| sigaction(SIGTERM, &sig, NULL); | ||
| sig.sa_handler = &OnSigHup; | ||
| sigaction(SIGHUP, &sig, NULL); | ||
| sig.sa_handler = SIG_IGN; | ||
| sigaction(SIGXFSZ, &sig, NULL); | ||
| if (inFgMode) { | ||
| sig.sa_handler = SIG_IGN; | ||
| sigaction(SIGINT, &sig, NULL); | ||
| sig.sa_handler = SIG_IGN; | ||
| sigaction(SIGQUIT, &sig, NULL); | ||
| } | ||
|
Contributor
Author
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. Is this correct? Ignore CTRL-C when running in the foreground? |
||
|
|
||
| // Make an accept item to listen for control connections | ||
| PRINTF("Creating control listener\n"); | ||
|
|
@@ -657,7 +663,7 @@ int main(int argc,char * argv[]) | |
| PRINTF("Option oneshot is set... exiting\n"); | ||
| shutdownServer = true; | ||
| } else { | ||
| npi= processFactory(childExec, childArgv); | ||
| npi= processFactory(childExec, childArgv, &sigset_child); | ||
| if (npi) AddConnection(npi); | ||
| if (firstRun) { | ||
| firstRun = false; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,7 +87,7 @@ void DeleteConnection(connectionItem *ci); | |
| // constructors are public: | ||
|
|
||
| // processFactory creates the process that we are managing | ||
| connectionItem * processFactory(char *exe, char *argv[]); | ||
| connectionItem * processFactory(char *exe, char *argv[], sigset_t *sigset); | ||
|
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. This could be |
||
| bool processFactoryNeedsRestart(); // Call to test status of the server process | ||
| void processFactorySendSignal(int signal); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,11 +15,11 @@ | |
|
|
||
| class processClass : public connectionItem | ||
| { | ||
| friend connectionItem * processFactory(char *exe, char *argv[]); | ||
| friend connectionItem * processFactory(char *exe, char *argv[], sigset_t *sigset); | ||
| friend bool processFactoryNeedsRestart(); | ||
| friend void processFactorySendSignal(int signal); | ||
| public: | ||
| processClass(char *exe, char *argv[]); | ||
| processClass(char *exe, char *argv[], sigset_t *sigset); | ||
|
Comment on lines
+18
to
+22
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. Same for these |
||
| void readFromFd(void); | ||
| int Send(const char *,int); | ||
| void markDeadIfChildIs(pid_t pid) { if (pid==_pid) _markedForDeletion=true; } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This unblocks some more signals from the child, because the
SIG_IGNdisposition used insigactionpreviously would still apply to the child processes, even if the sigmask was restored.Would be nice if the commit message called out that nuance.