Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1653554
| From | Thomas Gleixner <tglx@linutronix.de> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: signals: Bug or manpage inconsistency? |
| Date | 2017-05-30 23:00 +0200 |
| Message-ID | <tMWpc-3Hl-27@gated-at.bofh.it> (permalink) |
| References | <tMPnI-7TL-13@gated-at.bofh.it> <tMS2d-1ag-15@gated-at.bofh.it> <tMSOC-1GK-25@gated-at.bofh.it> <tMSYi-1K4-5@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Tue, 30 May 2017, Linus Torvalds wrote:
> On Tue, May 30, 2017 at 10:04 AM, Oleg Nesterov <oleg@redhat.com> wrote:
> > Obviously this is a user-visible change and it can break something. Say, an
> > application does sigwaitinfo(SIGCHLD) and SIGCHLD is ignored (SIG_IGN), this
> > will no longer work.
>
> That's an interesting special case. Yes, SIG_IGN actually has magical
> properties wrt SIGCHLD. It basically means the opposite of ignoring
> it, it's an "implicit signal handler". So I could imagine people
> using SIG_IGN to avoid the signal handler, but then block SIG_CHLD and
> using sigwait() for it.
>
> That sounds nonportable as hell, but I could imagine people doing it
> because it happens to work.
Just that it does not work. See do_notify_parent()
if (!tsk->ptrace && sig == SIGCHLD &&
(psig->action[SIGCHLD-1].sa.sa_handler == SIG_IGN ||
(psig->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDWAIT))) {
/*
* We are exiting and our parent doesn't care. POSIX.1
* defines special semantics for setting SIGCHLD to SIG_IGN
* or setting the SA_NOCLDWAIT flag: we should be reaped
* automatically and not left for our parent's wait4 call.
* Rather than having the parent do it as a magic kind of
* signal handler, we just set this to tell do_exit that we
* can be cleaned up without becoming a zombie. Note that
* we still call __wake_up_parent in this case, because a
* blocked sys_wait4 might now return -ECHILD.
*
* Whether we send SIGCHLD or not for SA_NOCLDWAIT
* is implementation-defined: we do (if you don't want
* it, just use SIG_IGN instead).
*/
autoreap = true;
if (psig->action[SIGCHLD-1].sa.sa_handler == SIG_IGN)
sig = 0;
}
if (valid_signal(sig) && sig)
__group_send_sig_info(sig, &info, tsk->parent);
So if the oarent has SIG_IGN we do not send a signal at all. So it's not a
really interesting special case and the magic properties are not that magic
either. Test case below. The parent waits forever.
Thanks,
tglx
---
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
int main(void)
{
struct sigaction action;
sigset_t set;
int signum;
sigemptyset(&set);
sigaddset (&set, SIGCHLD);
memset(&action, 0, sizeof(action));
action.sa_handler = SIG_IGN;
sigaction(SIGCHLD, &action, NULL);
sigprocmask(SIG_BLOCK, &set, NULL);
if (fork() == 0) {
sleep(1);
printf("Child exiting\n");
exit(0);
}
sigwait(&set, &signum);
printf("Parent exiting\n");
return 0;
}
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
signals: Bug or manpage inconsistency? Thomas Gleixner <tglx@linutronix.de> - 2017-05-30 15:30 +0200
Re: signals: Bug or manpage inconsistency? Thomas Gleixner <tglx@linutronix.de> - 2017-05-30 18:20 +0200
Re: signals: Bug or manpage inconsistency? Oleg Nesterov <oleg@redhat.com> - 2017-05-30 19:10 +0200
Re: signals: Bug or manpage inconsistency? Linus Torvalds <torvalds@linux-foundation.org> - 2017-05-30 19:20 +0200
Re: signals: Bug or manpage inconsistency? Oleg Nesterov <oleg@redhat.com> - 2017-05-30 21:20 +0200
Re: signals: Bug or manpage inconsistency? Thomas Gleixner <tglx@linutronix.de> - 2017-05-30 23:00 +0200
Re: signals: Bug or manpage inconsistency? ebiederm@xmission.com (Eric W. Biederman) - 2017-05-31 03:00 +0200
Re: signals: Bug or manpage inconsistency? ebiederm@xmission.com (Eric W. Biederman) - 2017-05-31 03:20 +0200
Re: signals: Bug or manpage inconsistency? Linus Torvalds <torvalds@linux-foundation.org> - 2017-05-30 19:10 +0200
Re: signals: Bug or manpage inconsistency? Thomas Gleixner <tglx@linutronix.de> - 2017-05-30 21:40 +0200
Re: signals: Bug or manpage inconsistency? Linus Torvalds <torvalds@linux-foundation.org> - 2017-05-30 22:00 +0200
Re: signals: Bug or manpage inconsistency? Thomas Gleixner <tglx@linutronix.de> - 2017-05-30 23:10 +0200
Re: signals: Bug or manpage inconsistency? "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> - 2017-05-31 09:00 +0200
Re: signals: Bug or manpage inconsistency? ebiederm@xmission.com (Eric W. Biederman) - 2017-06-01 09:10 +0200
csiph-web