A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/log4cplus/log4cplus/issues/390 below:

log4cplus blocks all/many signals · Issue #390 · log4cplus/log4cplus · GitHub

#include <signal.h>
#include <iostream>

void signalHandler(int signum) {
	std::cout << "Received: " << signum<< '\n';
}

int main(int argc, char *argv[]) {
	signal(SIGTERM, signalHandler);
	signal(SIGABRT, signalHandler);
	signal(SIGKILL, signalHandler);

	while(1){
	
	}

	return 0;
}

When the above program is linked against a log4cplus (with pthreads enabled), it will not
receive any signals.

By looking at the code it seems to be related to the recent change prompted by issue #385.

SignalsBlocker::SignalsBlocker ()
    : impl (new SignalsBlocker::SignalsBlockerImpl)
{
#if defined (LOG4CPLUS_USE_PTHREADS)
    sigset_t block_all_set;
    sigfillset (&block_all_set);
    (void) pthread_sigmask (SIG_BLOCK, &block_all_set, &impl->signal_set);
#endif
}


SignalsBlocker::~SignalsBlocker()
{
#if defined (LOG4CPLUS_USE_PTHREADS)
    (void) pthread_sigmask (SIG_BLOCK, &impl->signal_set, nullptr);
#endif
}

I looked at man 3 pthread_sigmask it just forwards to man 2 sigprocmask which states:

       sigprocmask()  is  used  to  fetch and/or change the signal mask of the
       calling thread.  The signal mask is the set of signals  whose  delivery
       is  currently  blocked  for  the  caller  (see  also signal(7) for more
       details).

       The behavior of the call is dependent on the value of how, as follows.

       SIG_BLOCK
              The set of blocked signals is the union of the current  set  and
              the set argument.

       SIG_UNBLOCK
              The  signals  in set are removed from the current set of blocked
              signals.  It is permissible to attempt to unblock a signal which
              is not blocked.

       SIG_SETMASK
              The set of blocked signals is set to the argument set.

So to fix it, I believe in ~SignalsBlocker it should use SIG_SETMASK rather than SIG_BLOCK.

Info:


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4