Don't return but _exit after failed exec*() and fork()
Quoting POSIX[0]: "Care should be taken, also, to call _exit() rather than exit() if exec cannot be used, since exit() flushes and closes standard I/O channels, thereby damaging the parent process' standard I/O data structures. (Even with fork(), it is wrong to call exit(), since buffered data would then be flushed twice.)" [0]: http://pubs.opengroup.org/onlinepubs/009695399/functions/vfork.html
This commit is contained in:
6
env.c
6
env.c
@@ -18,6 +18,8 @@ usage(void)
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int savederrno;
|
||||
|
||||
ARGBEGIN {
|
||||
case 'i':
|
||||
if (environ)
|
||||
@@ -35,7 +37,9 @@ main(int argc, char *argv[])
|
||||
|
||||
if (*argv) {
|
||||
execvp(*argv, argv);
|
||||
enprintf(126 + (errno == EEXIST), "execvp: %s:", *argv);
|
||||
savederrno = errno;
|
||||
weprintf("execvp %s:", *argv);
|
||||
_exit(126 + (savederrno == EEXIST));
|
||||
}
|
||||
|
||||
for (; environ && *environ; environ++)
|
||||
|
Reference in New Issue
Block a user