Date: Tue, 21 Mar 2000 23:30:14 -0500 (EST) From: Brian Fundakowski Feldman <green@FreeBSD.org> To: Brian Somers <brian@FreeBSD.org> Cc: cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org Subject: Re: cvs commit: src/usr.sbin/ppp exec.c Message-ID: <Pine.BSF.4.21.0003212327250.11563-100000@green.dyndns.org> In-Reply-To: <200003220301.TAA86933@freefall.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <err.h>
#include <stdio.h>
#include <unistd.h>
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0003212327250.11563-100000>
