Skip to content
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

CFE-4401: Added MaskTerminationSignalsInThread() for re-use in CFEngine core for Termux platform #228

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libutils/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ libutils_la_SOURCES = \
sequence.c sequence.h \
string_sequence.c string_sequence.h \
set.c set.h \
signal_lib.h \
stack.c stack.h \
threaded_stack.c threaded_stack.h \
statistics.c statistics.h \
Expand Down
2 changes: 1 addition & 1 deletion libutils/file_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1945,7 +1945,7 @@ static int LockFD(int fd, short int lock_type, bool wait)
{
if (errno != EINTR)
{
Log(LOG_LEVEL_DEBUG, "Failed to acquire file lock for FD %d: %s",
Log(LOG_LEVEL_DEBUG, "Failed to acquire file lock wait for FD %d: %s",
fd, GetErrorStr());
return -1;
}
Expand Down
15 changes: 15 additions & 0 deletions libutils/signal_lib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
static inline void MaskTerminationSignalsInThread()
{
/* Mask termination signals in a thread so that they always end up in the
* main thread. The function calls below should just always succeed and even
* if they didn't, there's nothing to do. */
sigset_t th_sigset;
NDEBUG_UNUSED int ret = sigemptyset(&th_sigset);
assert(ret == 0);
ret = sigaddset(&th_sigset, SIGINT);
assert(ret == 0);
ret = sigaddset(&th_sigset, SIGTERM);
assert(ret == 0);
ret = pthread_sigmask(SIG_BLOCK, &th_sigset, NULL);
assert(ret == 0);
}
Loading