This is an archive of the discontinued Mercurial Phabricator instance.

osutil: add a function to unblock signals
ClosedPublic

Authored by quark on Dec 20 2017, 5:12 AM.

Details

Summary

Signals could be blocked by something like:

#include <unistd.h>
#include <signal.h>
int main(int argc, char * const argv[]) {
  sigset_t set;
  sigfillset(&set);
  sigprocmask(SIG_BLOCK, &set, NULL);
  execv("/bin/hg", argv);
  return 0;
}

One of the problems is if SIGCHLD is blocked, chgserver would not reap
zombie workers since it depends on SIGCHLD handler entirely.

While it's the parent process to blame but it seems a good idea to just
unblock the signal from hg. FWIW git does that for SIGPIPE already [1].

Unfortunately Python 2 does not reset or provide APIs to change signal
masks. Therefore let's add one in osutil. Note: Python 3.3 introduced
signal.pthread_sigmask which solves the problem.

sigprocmask is part of POSIX [2] so there is no feature testing in
setup.py.

[1]: https://github.com/git/git/commit/7559a1be8a0afb10df41d25e4cf4c5285a5faef1
[2]: http://pubs.opengroup.org/onlinepubs/7908799/xsh/sigprocmask.html

Diff Detail

Repository
rHG Mercurial
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

quark created this revision.Dec 20 2017, 5:12 AM
quark edited the summary of this revision. (Show Details)
yuja requested changes to this revision.Dec 20 2017, 8:25 AM
yuja added a subscriber: yuja.
yuja added inline comments.
mercurial/cext/osutil.c
1123

Nit: sigaddset() may raise EINVAL if the given signum is invalid.
Maybe it's also better to check the result of sigemptyset() for clarity.

This revision now requires changes to proceed.Dec 20 2017, 8:25 AM
quark updated this revision to Diff 4561.Dec 20 2017, 2:38 PM
yuja accepted this revision.Dec 21 2017, 9:34 AM
This revision is now accepted and ready to land.Dec 21 2017, 9:34 AM
This revision was automatically updated to reflect the committed changes.