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:
14
tar.c
14
tar.c
@@ -55,7 +55,8 @@ decomp(FILE *fp)
|
||||
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
eprintf("fork:");
|
||||
weprintf("fork:");
|
||||
_exit(1);
|
||||
} else if (!pid) {
|
||||
dup2(fileno(fp), 0);
|
||||
dup2(fds[1], 1);
|
||||
@@ -64,12 +65,13 @@ decomp(FILE *fp)
|
||||
|
||||
switch (filtermode) {
|
||||
case 'j':
|
||||
execlp("bzip2", "bzip2", "-cd", (char *)0);
|
||||
eprintf("execlp bzip2:");
|
||||
execlp("bzip2", "bzip2", "-cd", NULL);
|
||||
weprintf("execlp bzip2:");
|
||||
_exit(1);
|
||||
case 'z':
|
||||
execlp("gzip", "gzip", "-cd", (char *)0);
|
||||
eprintf("execlp gzip:");
|
||||
break;
|
||||
execlp("gzip", "gzip", "-cd", NULL);
|
||||
weprintf("execlp gzip:");
|
||||
_exit(1);
|
||||
}
|
||||
}
|
||||
close(fds[1]);
|
||||
|
Reference in New Issue
Block a user