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:
8
xargs.c
8
xargs.c
@@ -168,13 +168,15 @@ spawn(void)
|
||||
int savederrno;
|
||||
|
||||
pid = fork();
|
||||
if (pid < 0)
|
||||
eprintf("fork:");
|
||||
if (pid < 0) {
|
||||
weprintf("fork:");
|
||||
_exit(1);
|
||||
}
|
||||
if (pid == 0) {
|
||||
execvp(*cmd, cmd);
|
||||
savederrno = errno;
|
||||
weprintf("execvp %s:", *cmd);
|
||||
_exit(savederrno == ENOENT ? 127 : 126);
|
||||
_exit(126 + (savederrno == ENOENT));
|
||||
}
|
||||
waitchld();
|
||||
}
|
||||
|
Reference in New Issue
Block a user