mirror of
git://sourceware.org/git/lvm2.git
synced 2025-02-28 05:57:49 +03:00
Change exit() to _exit() in the child process. exit flushes stdio file buffers,
_exit doesn't. If there were some open files, an error in exec and subsequent exit() would cause the buffers to be flushed twice. Example: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/wait.h> int main() { printf("buu"); if (!fork()) { execl("/bin/true-not-exists", "/bin/true", NULL); exit(1); } wait(NULL); return 0; } Signed-off-by: Mikulas Patocka <mpatocka@redhat.com --- daemons/dmeventd/libdevmapper-event.c | 2 +- lib/misc/lvm-exec.c | 2 +- test/harness.c | 3 ++- tools/dmsetup.c | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-)
This commit is contained in:
parent
ee373a2721
commit
31b3571d31
@ -438,7 +438,7 @@ static int _start_daemon(struct dm_event_fifos *fifos)
|
|||||||
|
|
||||||
else if (!pid) {
|
else if (!pid) {
|
||||||
execvp(DMEVENTD_PATH, NULL);
|
execvp(DMEVENTD_PATH, NULL);
|
||||||
exit(EXIT_FAILURE);
|
_exit(EXIT_FAILURE);
|
||||||
} else {
|
} else {
|
||||||
if (waitpid(pid, &status, 0) < 0)
|
if (waitpid(pid, &status, 0) < 0)
|
||||||
log_error("Unable to start dmeventd: %s",
|
log_error("Unable to start dmeventd: %s",
|
||||||
|
@ -68,7 +68,7 @@ int exec_cmd(struct cmd_context *cmd, const char *const argv[])
|
|||||||
/* FIXME Use execve directly */
|
/* FIXME Use execve directly */
|
||||||
execvp(argv[0], (char **const) argv);
|
execvp(argv[0], (char **const) argv);
|
||||||
log_sys_error("execvp", argv[0]);
|
log_sys_error("execvp", argv[0]);
|
||||||
exit(errno);
|
_exit(errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parent */
|
/* Parent */
|
||||||
|
@ -90,7 +90,8 @@ void run(int i, char *f) {
|
|||||||
dup2(fds[0], 2);
|
dup2(fds[0], 2);
|
||||||
execlp("bash", "bash", f, NULL);
|
execlp("bash", "bash", f, NULL);
|
||||||
perror("execlp");
|
perror("execlp");
|
||||||
exit(202);
|
fflush(stderr);
|
||||||
|
_exit(202);
|
||||||
} else {
|
} else {
|
||||||
char buf[128];
|
char buf[128];
|
||||||
snprintf(buf, 128, "%s ...", f);
|
snprintf(buf, 128, "%s ...", f);
|
||||||
|
@ -1055,7 +1055,7 @@ static int _exec_command(const char *name)
|
|||||||
|
|
||||||
if (!(pid = fork())) {
|
if (!(pid = fork())) {
|
||||||
execvp(args[0], args);
|
execvp(args[0], args);
|
||||||
exit(127);
|
_exit(127);
|
||||||
} else if (pid < (pid_t) 0)
|
} else if (pid < (pid_t) 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user