From owner-cvs-all Tue Mar 21 20:31:54 2000 Delivered-To: cvs-all@freebsd.org Received: from 1Cust91.tnt1.washington.dc.da.uu.net (localhost [127.0.0.1]) by hub.freebsd.org (Postfix) with ESMTP id 5A7FD37BAC7; Tue, 21 Mar 2000 20:31:40 -0800 (PST) (envelope-from green@FreeBSD.org) Date: Tue, 21 Mar 2000 23:30:14 -0500 (EST) From: Brian Fundakowski Feldman X-Sender: green@green.dyndns.org To: Brian Somers Cc: cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org Subject: Re: cvs commit: src/usr.sbin/ppp exec.c In-Reply-To: <200003220301.TAA86933@freefall.freebsd.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Tue, 21 Mar 2000, Brian Somers wrote: > FWIW: > I tried to implement this by doing a pipe(), setting the > write desciptors close-on-exec flag in the child and writing > errno to the descriptor if the exec() fails. The parent can > then ``if (read()) got errno else exec worked''. > > This didn't work though - the child could write() to fd[1] on > exec failure, but the parent got 0 trying to read() from fd[0] ! > Is this a bug in execve() ? I didn't do anything to change the close-on-exec-ness, but this test case here works fine for me: {"/home/green"}$ ./bar Poppa here, how's it going, son? Hey, dad! Lemme exec something impossible. Oh, so it's "4186" you say? bar.c: #include #include #include int main() { int pipes[2]; int error; char data[sizeof(int)]; char *const impossible[] = { "/", NULL }; error = pipe(pipes); if (error != 0) err(1, "pipe"); switch (fork()) { case 0: printf("Poppa here, how's it going, son?\n"); if (write(pipes[0], "", 1) != 1) err(1, "parent write"); if (read(pipes[0], data, sizeof(data)) != sizeof(data)) err(1, "parent read"); printf("Oh, so it's \"%d\" you say?\n", *(int *)data); exit(0); case -1: err(1, "fork"); default: if (read(pipes[1], data, 1) != 1) err(1, "child read"); printf("Hey, dad! Lemme exec something impossible.\n"); (void)execve(*impossible, impossible, NULL); *(int *)data = 4186; if (write(pipes[1], data, sizeof(data)) != sizeof(data)) err(1, "child write"); exit(0); } } -- Brian Fundakowski Feldman \ FreeBSD: The Power to Serve! / green@FreeBSD.org `------------------------------' To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message