Skip to content

log4cplus blocks all/many signals #390

@multipond

Description

@multipond
#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:

  • Version: fresh from master (cff5bc2)
  • OS: Linux (custom)
  • CPU: ARMv7 and x86_64
  • log4cplus: build with pthreads

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions