public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Daniel Jacobowitz <dan@debian.org>
To: Linus Torvalds <torvalds@osdl.org>
Cc: Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Roland McGrath <roland@redhat.com>, Ingo Molnar <mingo@elte.hu>
Subject: Re: More waitpid issues with CLONE_DETACHED/CLONE_THREAD
Date: Sun, 1 Feb 2004 19:52:12 -0500	[thread overview]
Message-ID: <20040202005212.GA26719@nevyn.them.org> (raw)
In-Reply-To: <Pine.LNX.4.58.0402011333020.2229@home.osdl.org>

On Sun, Feb 01, 2004 at 01:41:48PM -0800, Linus Torvalds wrote:
> 
> 
> On Sun, 1 Feb 2004, Daniel Jacobowitz wrote:
> > 
> > Here you go.  The bug turns out not to be related directly to
> > CLONE_DETACHED.  Compile testcase with -DNOTHREAD to use fork (well,
> > clone, but without the fancy flags), without -DNOTHREAD to use
> > CLONE_DETACHED | CLONE_THREAD.
> 
> I don't think this bug has anything to do with anything else.
> 
> This program seems to show that PTRACE_KILL simply doesn't work.

> and the thing is, it looks like the signal handling changes have totally
> made the child ignore the "exit_code" thing, unless I'm seriously
> misreading something.

That may be (though I don't think so) but it reproduces without
PTRACE_KILL too.  Try the attached, which just replaced PTRACE_KILL
with PTRACE_CONT/tkill(pid, SIGKILL).  Still get zombies.  I haven't
tried reproducing entirely without ptrace yet.

> Roland, you know this code better than I do. Any comments?
> 
> I suspect the PTRACE_KILL logic should also do a
> 
> 	spin_lock_irqsave(child->sighand->siglock, flags);
> 	sigaddset(&child->pending->signal, SIGKILL);
> 	set_tsk_thread_flag(child, TIF_SIGPENDING);
> 	spin_unlock_irqrestore(child->sighand->siglock, flags);
> 
> 	ptrace_detach(child);
> 
> which would set the SIGKILL thing properly, but I suspect we had a good
> reason not to do it that way originally. 
> 
> Daniel?

I doubt there was a good reason.  This code hasn't changed in a hell of
a long time - it probably predates everything up there except sigaddset
:).

/* -DBUG to kill the parent before the child -> hang.  */
/* -DNOTHREAD to us fork instead of clone.  */

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <signal.h>
#include <sys/ptrace.h>
#include <sched.h>
#include <sys/wait.h>
#include <linux/ptrace.h>

int stack_one[8192], stack_two[8192];

int thread_func_two()
{
  write (1, "Thread 2\n", 9);
  while (1)
    sleep (1);
}

int thread_func_one()
{
  int ret;
  char retstr[10];

  write (1, "Thread 1\n", 9);

  ptrace (PTRACE_TRACEME, 0, 0, 0);

  write (1, "Thread 1 signalling\n", 20);

  syscall (SYS_tkill, getpid (), SIGUSR1);

  write (1, "Thread 1 cloning\n", 17);

  ret = clone (thread_func_two, stack_two + 8192,
#ifdef NOTHREAD
	SIGCHLD,
#else
	CLONE_DETACHED | CLONE_THREAD | CLONE_SIGHAND | CLONE_VM | CLONE_FS,
#endif
	NULL);
  sprintf (retstr, "= %d\n", ret);
  write (1, retstr, strlen (retstr));

  write (1, "Thread 1 sleeping\n", 18);

  while (1)
    sleep (1);
}

int main()
{
  int ret, wstat;
  int child = fork(), child2 = 0;

  if (child == 0)
    return thread_func_one();

  ptrace (PTRACE_SETOPTIONS, child, 0, PTRACE_O_TRACECLONE | PTRACE_O_TRACEFORK);
  ret = waitpid (child, &wstat, __WALL);

  ptrace (PTRACE_CONT, child, 0, 0);
  ret = waitpid (child, &wstat, __WALL);
  ptrace (PTRACE_GETEVENTMSG, child, 0, &child2);
  ret = waitpid (child2, &wstat, __WALL);

  ptrace (PTRACE_CONT, child, 0, 0);
  ptrace (PTRACE_CONT, child2, 0, 0);

#ifndef BUG
  ptrace (PTRACE_CONT, child2, 0, 0);
  syscall (SYS_tkill, child2, SIGKILL);
  ret = waitpid (child2, &wstat, __WALL);
#endif

  ptrace (PTRACE_CONT, child, 0, 0);
  syscall (SYS_tkill, child, SIGKILL);
  ret = waitpid (child, &wstat, __WALL);

#ifdef BUG
  ptrace (PTRACE_CONT, child2, 0, 0);
  syscall (SYS_tkill, child2, SIGKILL);
  ret = waitpid (child2, &wstat, __WALL);
#endif

  return 0;
}


-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

  parent reply	other threads:[~2004-02-02  0:52 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-01  3:25 More waitpid issues with CLONE_DETACHED/CLONE_THREAD Daniel Jacobowitz
2004-02-01  4:38 ` Linus Torvalds
2004-02-01  4:43   ` Daniel Jacobowitz
2004-02-01  5:12     ` Daniel Jacobowitz
2004-02-01 21:41       ` Linus Torvalds
2004-02-01 22:25         ` Roland McGrath
2004-02-02  0:55           ` Linus Torvalds
2004-02-02  2:20             ` Andries Brouwer
2004-02-02  2:30               ` Linus Torvalds
2004-02-02  0:52         ` Daniel Jacobowitz [this message]
2004-02-02  2:41           ` Davide Libenzi
2004-02-02  2:55             ` Davide Libenzi
2004-02-04 14:22               ` fs/eventpoll : reduce sizeof(struct epitem) dada1
2004-02-05  4:23                 ` Davide Libenzi
2004-02-01  5:12     ` More waitpid issues with CLONE_DETACHED/CLONE_THREAD Linus Torvalds
2004-02-01  5:14       ` Daniel Jacobowitz
2004-02-01  5:42         ` Roland McGrath
2004-02-01  5:46           ` Daniel Jacobowitz

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=20040202005212.GA26719@nevyn.them.org \
    --to=dan@debian.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=roland@redhat.com \
    --cc=torvalds@osdl.org \
    /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