public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Serge E. Hallyn" <serue@us.ibm.com>
To: Roland McGrath <roland@redhat.com>, lkml <linux-kernel@vger.kernel.org>
Subject: Bug in 2b2a1ff64afbadac842bbc58c5166962cf4f7664 ?
Date: Thu, 31 Jul 2008 09:36:02 -0500	[thread overview]
Message-ID: <20080731143602.GA28700@us.ibm.com> (raw)

>From ea5b3ea0dbdb8b9f9ef73e639517cf4805cf2e6f Mon Sep 17 00:00:00 2001
From: Serge E. Hallyn <serue@us.ibm.com>
Date: Thu, 31 Jul 2008 07:29:14 -0700
Subject: [PATCH 1/1] notify parent of death

Commit 2b2a1ff64afbadac842bbc58c5166962cf4f7664
("tracehook: death" by ROland McGrath on Jul 25) included a change
that apparently causes parents not to be notified of child death
in normal circumstances.  In particular the following testcase
fails without this patch.  (I'm sure this patch is wrong, but
hopefully it illustrates where a real problem might hide).

Before commit 2b2a1ff64afbadac842bbc58c5166962cf4f7664, calling
this program testwait.c and running
	# ./testwait /bin/sh
	  # exit
would succeed.  Ever since that commit, exiting the shell makes
it defunct.  With the following patch, it again appears to
properly exit, and my test machine seems to suffer no ill effects
from the patch - though I haven't run ltp since as I say I doubt
the patch is the right solution.

More likely the last line in tracehook_notify_death() isn't
quite right.

thanks,
-serge

 #include <stdio.h>
 #include <stdlib.h>
 #include <sched.h>
 #include <sys/syscall.h>
 #include <unistd.h>
 #include <signal.h>
 #include <string.h>
 #include <errno.h>
 #include <libgen.h>
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/wait.h>

extern pid_t getpgid(pid_t pid);
extern pid_t getsid(pid_t pid);

static const char* procname;

int do_child(void *vargv)
{
        char **argv = (char **)vargv;
        execve(argv[0], argv, __environ);
        perror("execve");
        return 1;
}

int main(int argc, char *argv[])
{
        int c;
        int ret, use_clone = 0;
        int pid;
        int status;

        argv = &argv[optind];
        argc = argc - optind;

        int stacksize = 4*getpagesize();
        void *childstack, *stack = malloc(stacksize);

        if (!stack) {
                perror("malloc");
                return -1;
        }
        childstack = stack + stacksize;

        pid = clone(do_child, childstack, 0, (void *)argv);
        if (pid == -1) {
                perror("clone");
                return -1;
        }
        if ((ret = waitpid(pid, &status, __WALL)) < 0)
                printf("waitpid() returns %d, errno %d\n", ret, errno);

        exit(0);
}

Signed-off-by: Serge E. Hallyn <serue@us.ibm.com>
---
 kernel/exit.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/kernel/exit.c b/kernel/exit.c
index 6cdf607..847fa12 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -924,7 +924,7 @@ static void exit_notify(struct task_struct *tsk, int group_dead)
 		tsk->exit_signal = SIGCHLD;
 
 	signal = tracehook_notify_death(tsk, &cookie, group_dead);
-	if (signal > 0)
+	if (signal >= 0)
 		signal = do_notify_parent(tsk, signal);
 
 	tsk->exit_state = signal < 0 ? EXIT_DEAD : EXIT_ZOMBIE;
-- 
1.5.3.6


             reply	other threads:[~2008-07-31 14:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-31 14:36 Serge E. Hallyn [this message]
2008-07-31 18:53 ` Bug in 2b2a1ff64afbadac842bbc58c5166962cf4f7664 ? Roland McGrath
2008-07-31 19:28   ` Serge E. Hallyn

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=20080731143602.GA28700@us.ibm.com \
    --to=serue@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=roland@redhat.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