Skip to content

Commit

Permalink
Unblock signals after setting the handler
Browse files Browse the repository at this point in the history
For safer execution, unblocking the signal after
setting the handler instead of before ensures all
signals get received by the correct handler.

Signed-off-by: Abdulrahman Alattas <rmnattas@gmail.com>
  • Loading branch information
rmnattas committed Jan 8, 2021
1 parent 217933c commit 96937d1
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions port/unix/omrsignal.c
Expand Up @@ -1269,16 +1269,6 @@ registerSignalHandlerWithOS(OMRPortLibrary *portLibrary, uint32_t portLibrarySig
return OMRPORT_SIG_ERROR;
}

/* If a process has blocked a signal, then the signal stays blocked
* in the sub-processes across fork(s) and exec(s). A blocked
* signal prevents its OS signal handler to be invoked. A signal is
* unblocked as an OS signal handler is installed for it in case a
* parent process has blocked it.
*/
if (0 != unblockSignal(unixSignalNo)) {
return OMRPORT_SIG_ERROR;
}

memset(&newAction, 0, sizeof(struct sigaction));

/* Do not block any signals. */
Expand Down Expand Up @@ -1380,6 +1370,17 @@ registerSignalHandlerWithOS(OMRPortLibrary *portLibrary, uint32_t portLibrarySig
unsetBitMaskSignalsWithMainHandlers(portLibrarySignalNo);
}


/* If a process has blocked a signal, then the signal stays blocked
* in the sub-processes across fork(s) and exec(s). A blocked
* signal prevents its OS signal handler to be invoked. A signal is
* unblocked as an OS signal handler is installed for it in case a
* parent process has blocked it.
*/
if (0 != unblockSignal(unixSignalNo)) {
return OMRPORT_SIG_ERROR;
}

return 0;
}

Expand Down

0 comments on commit 96937d1

Please sign in to comment.