8000 log4cplus blocks all/many signals · Issue #390 · log4cplus/log4cplus · GitHub
[go: up one dir, main page]

Skip to content

log4cplus blocks all/many signals #390

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

Closed
multipond opened this issue Mar 13, 2019 · 3 comments
Closed

log4cplus blocks all/many signals #390

multipond opened this issue Mar 13, 2019 · 3 comments
Assignees
Labels
Milestone

Comments

@multipond
Copy link
multipond commented Mar 13, 2019
#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
@wilx wilx self-assigned this Mar 13, 2019
@wilx wilx added the bug label Mar 13, 2019
@wilx
Copy link
Contributor
wilx commented Mar 13, 2019

You are completely right.

wilx added a commit that referenced this issue Mar 13, 2019
@wilx wilx closed this as completed in 9fdfe2b Mar 13, 2019
@wilx
Copy link
Contributor
wilx commented Mar 13, 2019

I have hopefully fixed the issue. Please test.

@multipond
Copy link
Author

Works like a charm. 👌

@wilx wilx added this to the v2.0.4 milestone Mar 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants
0