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:
7
chroot.c
7
chroot.c
@@ -36,15 +36,14 @@ main(int argc, char *argv[])
|
||||
|
||||
if (argc == 1) {
|
||||
cmd = *shell;
|
||||
execvp(*shell, shell);
|
||||
execvp(cmd, shell);
|
||||
} else {
|
||||
cmd = argv[1];
|
||||
execvp(argv[1], argv + 1);
|
||||
execvp(cmd, argv + 1);
|
||||
}
|
||||
|
||||
savederrno = errno;
|
||||
weprintf("execvp %s:", cmd);
|
||||
_exit(126 + (savederrno == ENOENT));
|
||||
|
||||
return 0; /* not reached */
|
||||
_exit(126 + (savederrno == ENOENT));
|
||||
}
|
||||
|
Reference in New Issue
Block a user