1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +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:
Mikulas Patocka 2009-07-13 21:26:41 +00:00
parent f4b2b84904
commit 3395d72881
4 changed files with 5 additions and 4 deletions

View File

@ -438,7 +438,7 @@ static int _start_daemon(struct dm_event_fifos *fifos)
else if (!pid) {
execvp(DMEVENTD_PATH, NULL);
exit(EXIT_FAILURE);
_exit(EXIT_FAILURE);
} else {
if (waitpid(pid, &status, 0) < 0)
log_error("Unable to start dmeventd: %s",

View File

@ -68,7 +68,7 @@ int exec_cmd(struct cmd_context *cmd, const char *const argv[])
/* FIXME Use execve directly */
execvp(argv[0], (char **const) argv);
log_sys_error("execvp", argv[0]);
exit(errno);
_exit(errno);
}
/* Parent */

View File

@ -90,7 +90,8 @@ void run(int i, char *f) {
dup2(fds[0], 2);
execlp("bash", "bash", f, NULL);
perror("execlp");
exit(202);
fflush(stderr);
_exit(202);
} else {
char buf[128];
snprintf(buf, 128, "%s ...", f);

View File

@ -1055,7 +1055,7 @@ static int _exec_command(const char *name)
if (!(pid = fork())) {
execvp(args[0], args);
exit(127);
_exit(127);
} else if (pid < (pid_t) 0)
return 0;