From owner-freebsd-hackers Sat Sep 29 15: 3:41 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from elvis.mu.org (elvis.mu.org [216.33.66.196]) by hub.freebsd.org (Postfix) with ESMTP id C9C7C37B409 for ; Sat, 29 Sep 2001 15:03:37 -0700 (PDT) Received: by elvis.mu.org (Postfix, from userid 1192) id A8A2281D06; Sat, 29 Sep 2001 17:03:32 -0500 (CDT) Date: Sat, 29 Sep 2001 17:03:32 -0500 From: Alfred Perlstein To: David Taylor Cc: freebsd-hackers@FreeBSD.org Subject: Re: Doubt of system(3) Message-ID: <20010929170332.Y59854@elvis.mu.org> References: <200109291527.f8TFRrU76727.toshi@jp.FreeBSD.org> <20010929153433.U59854@elvis.mu.org> <20010929214338.A57903@gattaca.yadt.co.uk> <20010929221658.B57903@gattaca.yadt.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20010929221658.B57903@gattaca.yadt.co.uk>; from davidt@yadt.co.uk on Sat, Sep 29, 2001 at 10:16:58PM +0100 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG * David Taylor [010929 16:17] wrote: > On Sat, 29 Sep 2001, David Taylor wrote: > > On Sat, 29 Sep 2001, Alfred Perlstein wrote: > > > > > > Why does it need to be corrected? What sort of bad behaviour > > > are you seeing? You do 'a' and you see 'b' when you should > > > see 'c'. > > > > > > What's a, b and c? > > > > > > > Well, hypothetically (I have no time to attempt to set something up to test > > this), it looks to me like: > > > > If you: > > > > 1. Fork, and create a child (say, pid 10) > > 2. Call system, which forks and creates a child (say, pid 11) > > 3. Make the child (pid 10) exit now. > > 3. Interrupt the call to _wait4(pid [=11], ...); > > > > I've now managed to reproduce this... > > Test program at http://www.yadt.demon.co.uk/system-bug.tar.gz > > I'm pretty sure that's incorrect behaviour, and I also beleive the original > patch posted to this list should fix it... I should have realized that, especially since I just spent a week trying to track down the same problem... *smacks head* The posted patch is ok, except for the fact that it returns successful if an rfork thread has reaped the child, another variation is here, which returns an error ECHILD if someone has reaped our spawed child, and also keeps EFAULT propogation although that's not going to happen because of the arguments being on the stack and NULL. What do you think? Should we silently mask ECHILD? what if wait4() returns a different error code in the future? Shouldn't we propogate that? cvs diff: Diffing . Index: system.c =================================================================== RCS file: /home/ncvs/src/lib/libc/stdlib/system.c,v retrieving revision 1.7 diff -u -r1.7 system.c --- system.c 2001/01/24 13:00:59 1.7 +++ system.c 2001/09/29 21:55:41 @@ -53,7 +53,7 @@ __system(command) const char *command; { - pid_t pid; + pid_t pid, savedpid; int pstat; struct sigaction ign, intact, quitact; sigset_t newsigblock, oldsigblock; @@ -86,8 +86,9 @@ execl(_PATH_BSHELL, "sh", "-c", command, (char *)NULL); _exit(127); default: /* parent */ + savedpid = pid; do { - pid = _wait4(pid, &pstat, 0, (struct rusage *)0); + pid = _wait4(savedpid, &pstat, 0, (struct rusage *)0); } while (pid == -1 && errno == EINTR); break; } -- -Alfred Perlstein [alfred@freebsd.org] 'Instead of asking why a piece of software is using "1970s technology," start asking why software is ignoring 30 years of accumulated wisdom.' To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message