public inbox for linux-ia64@vger.kernel.org
 help / color / mirror / Atom feed
* wait4 causes segfault in i386 chroot
@ 2004-06-10  5:16 Ian Wienand
  2004-06-10 19:08 ` Arun Sharma
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ian Wienand @ 2004-06-10  5:16 UTC (permalink / raw)
  To: linux-ia64

[-- Attachment #1: Type: text/plain, Size: 1954 bytes --]

Hi,

We just upgraded a box from 2.4 -> 2.6.7-rc3 and now we are seeing a
strange wait problem in a 386 chroot environment.  The initial problem
was that I could chroot into the directory where the 386 install is
kept, but as soon as whatever I ran from the shell prompt completed
the shell got a segv.  This happened with both bash and csh, but not
when you directed bash to exec something directly with a -c flag.

I've tracked it down to doing a wait/waitpid/wait4 (they all end up in
wait4) in a sigchld signal handler.  If I do a minimal test case where
I catch the sigchld and wait, once the call returns it segfaults as in
this trace (gdb can't seem to give a good backtrace).

[pid  8192] exit_group(1)               = ?  <-- child exits
Process 8192 detached
<... nanosleep resumed> 0xbffffbe4)     = ? ERESTART_RESTARTBLOCK (To be restarted)
--- SIGCHLD (Child exited) @ 0 (0) ---
wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 1}], WNOHANG, NULL) = 8192
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV +++

However, if you do the wait in the parent directly it works fine!

Anyone have any ideas?

-i

--- minimal test program ---
#include <stdio.h>
#include <wait.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/wait.h>

int pid;

void sigchld_handler (int signum)
{
	int pid, status;
	while (!(pid = wait4(WAIT_ANY, &status, WNOHANG, NULL))) {
		if (pid < 0) {
			perror ("waitpid");
			break;
		}
		if (pid == 0)
			break;
	}
}

int main(int argc, char *argv[]) {

  int pid, status;

  signal(SIGCHLD, sigchld_handler);
  
  if ((pid = fork()) == -1)
	  exit(1);
  
  //child
  else if (pid == 0) {  
	  sleep(2);
	  exit(1);
  }
  
  //parent
  else {
	  //remove the sigchld handler and 
          //replace this with wait/waitpid/wait4() 
	  //and everything is fine
	  sleep(10);
  }
  
return 0;

}

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-06-11 20:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-06-10  5:16 wait4 causes segfault in i386 chroot Ian Wienand
2004-06-10 19:08 ` Arun Sharma
2004-06-11  2:02 ` Ian Wienand
2004-06-11 20:13 ` Arun Sharma

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox