mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Davide Libenzi <davidel@xmailserver.org>
To: Scott James Remnant <scott@canonical.com>
Cc: Oleg Nesterov <oleg@redhat.com>,
	Roland McGrath <roland@redhat.com>, Ingo Molnar <mingo@elte.hu>,
	Casey Dahlin <cdahlin@redhat.com>,
	Linux Kernel <linux-kernel@vger.kernel.org>,
	Randy Dunlap <randy.dunlap@oracle.com>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>
Subject: Re: [RESEND][RFC PATCH v2] waitfd
Date: Sat, 10 Jan 2009 15:11:28 -0800 (PST)	[thread overview]
Message-ID: <alpine.DEB.1.10.0901101454110.22208@alien.or.mcafeemobile.com> (raw)
In-Reply-To: <1231607252.11642.103.camel@quest>

On Sat, 10 Jan 2009, Scott James Remnant wrote:

> First, what we have today:
> 
> 	sigemptyset (&mask);
> 	sigaddset (&mask, SIGCHLD);
> 
> 	/* Block normal delivery and receive by sigfd instead */
> 	sigprocmask (SIG_BLOCK, &mask, NULL);
> 	sigfd = signalfd (-1, &mask, 0);
> 
> 	for (;;) {
> 		read (sigfd, &fd_siginfo, sizeof siginfo);
> 
> 		/* throw away fd_siginfo, we're reading SIGCHLD and
> 		 * can't use it :-(
> 		 */
> 
> 		/* SIGCHLD means _at_least_one_ child is pending, there
> 		 * may be more; so we have to loop AND expect to find
> 		 * nothing
> 		 */
> 		for (;;) {
> 			/* ARGH! waitid returns 0 with WNOHANG if there
> 			 * are no children.
> 			 *
> 			 * AND the structure, despite being logically
> 			 * the same, isn't the same as the signalfd
> 			 * one :-/
> 			 */
> 			memset (&w_siginfo, 0, sizeof w_siginfo);
> 
> 			waitid (P_ALL, 0, &w_siginfo,
> 				WEXITED | WNOHANG);
> 
> 			/* Did we find anything? */
> 			if (! w_siginfo.si_pid)
> 				break;
> 
> 			/* NOW we have the siginfo_t for a recently
> 			 * deceased process
> 			 */
> 
> 			mourn (&w_siginfo);
> 		}
> 

That, once all the glamorous comments are removed, can be solved pretty 
much with this much userspace code:

int waitfd(int flags) {
	sigemptyset(&mask);
	sigaddset(&mask, SIGCHLD);
	sigprocmask(SIG_BLOCK, &mask, NULL);

	return signalfd(-1, &mask, flags);
}

int waitfd_read(int fd, siginfo_t *si) {
	for (;;) {
		if (read(sigfd, &fd_siginfo,
		    sizeof fd_siginfo) != sizeof(fd_siginfo)
			retrun 0;
		memset(si, 0, sizeof *si);
		waitid(P_ALL, 0, si, WEXITED | WNOHANG);
		if (si->si_pid)
			break;
	}
	return sizeof *si;
}


About the exit_signal, that would have made probably more sense for 
it to be a parent property, instead of childs one. And be:

	do_notify_parent(p, p->parent->exit_signal);

instead of:

	do_notify_parent(p, p->exit_signal);

After all, is the parent that is going to make use of the notification, 
not the child.



- Davide



  parent reply	other threads:[~2009-01-10 23:11 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-06 18:11 [RFC " Casey Dahlin
2009-01-06 18:27 ` Alan Cox
2009-01-06 18:31 ` Randy Dunlap
2009-01-06 18:45   ` Casey Dahlin
2009-01-06 18:50     ` Randy Dunlap
2009-01-06 18:48 ` Andi Kleen
2009-01-06 19:07 ` [RESEND][RFC " Casey Dahlin
2009-01-07 12:34   ` Ingo Molnar
2009-01-07 13:05     ` Casey Dahlin
2009-01-07 15:00       ` Ingo Molnar
2009-01-07 17:19     ` Oleg Nesterov
2009-01-07 17:24       ` Ingo Molnar
2009-01-07 17:52       ` Davide Libenzi
2009-01-07 20:38         ` Casey Dahlin
2009-01-10 14:47       ` Scott James Remnant
2009-01-10 21:14         ` Casey Dahlin
2009-01-10 21:20           ` Scott James Remnant
2009-01-10 22:08             ` Casey Dahlin
2009-01-10 22:31           ` Oleg Nesterov
2009-01-10 22:37             ` Casey Dahlin
2009-01-10 22:46               ` Oleg Nesterov
2009-01-07 20:53     ` Roland McGrath
2009-01-07 20:58       ` Ingo Molnar
2009-01-07 21:05         ` Davide Libenzi
2009-01-07 21:50           ` Ingo Molnar
2009-01-07 21:02       ` Ulrich Drepper
2009-01-08 14:32         ` Oleg Nesterov
2009-01-08 19:35           ` Roland McGrath
2009-01-08 20:36             ` Casey Dahlin
2009-01-08 21:39               ` Oleg Nesterov
2009-01-10 14:52                 ` Scott James Remnant
2009-01-10 16:19                   ` Oleg Nesterov
2009-01-10 17:09                     ` Scott James Remnant
2009-01-10 18:21                       ` Oleg Nesterov
2009-01-10 18:46                         ` Scott James Remnant
2009-01-10 14:50               ` Scott James Remnant
2009-01-10 21:20                 ` Casey Dahlin
2009-01-08 22:04       ` Michael Kerrisk
2009-01-10 14:09       ` Scott James Remnant
2009-01-10 14:45       ` Scott James Remnant
2009-01-10 15:57         ` Oleg Nesterov
2009-01-10 17:07           ` Scott James Remnant
2009-01-10 18:13             ` Oleg Nesterov
2009-01-10 20:13               ` Scott James Remnant
2009-01-10 22:24                 ` Oleg Nesterov
2009-01-10 23:14                   ` Davide Libenzi
2009-01-10 22:25             ` Casey Dahlin
2009-01-10 23:11             ` Davide Libenzi [this message]
2011-03-02  1:37           ` Denys Vlasenko
2011-03-02 13:55             ` Oleg Nesterov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.1.10.0901101454110.22208@alien.or.mcafeemobile.com \
    --to=davidel@xmailserver.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=cdahlin@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=oleg@redhat.com \
    --cc=randy.dunlap@oracle.com \
    --cc=roland@redhat.com \
    --cc=scott@canonical.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®