From 63ce8e150c2c3178c56b3969ec16ec702ced7abd Mon Sep 17 00:00:00 2001 From: Gonglei Date: Fri, 26 Sep 2014 16:14:30 +0800 Subject: os-posix: change tab to space avoid violating coding style Cc: Eric Blake Signed-off-by: Gonglei Reviewed-by: Paolo Bonzini Signed-off-by: Michael Tokarev --- os-posix.c | 79 +++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 42 insertions(+), 37 deletions(-) (limited to 'os-posix.c') diff --git a/os-posix.c b/os-posix.c index cb2a7f7ad7..f0564ef9d9 100644 --- a/os-posix.c +++ b/os-posix.c @@ -204,45 +204,49 @@ static void change_root(void) void os_daemonize(void) { if (daemonize) { - pid_t pid; + pid_t pid; - if (pipe(fds) == -1) - exit(1); + if (pipe(fds) == -1) { + exit(1); + } - pid = fork(); - if (pid > 0) { - uint8_t status; - ssize_t len; + pid = fork(); + if (pid > 0) { + uint8_t status; + ssize_t len; - close(fds[1]); + close(fds[1]); - again: + again: len = read(fds[0], &status, 1); - if (len == -1 && (errno == EINTR)) + if (len == -1 && (errno == EINTR)) { goto again; - - if (len != 1) + } + if (len != 1) { exit(1); + } else if (status == 1) { fprintf(stderr, "Could not acquire pidfile: %s\n", strerror(errno)); exit(1); - } else + } else { exit(0); - } else if (pid < 0) - exit(1); - - close(fds[0]); - qemu_set_cloexec(fds[1]); + } + } else if (pid < 0) { + exit(1); + } - setsid(); + close(fds[0]); + qemu_set_cloexec(fds[1]); - pid = fork(); - if (pid > 0) - exit(0); - else if (pid < 0) - exit(1); + setsid(); - umask(027); + pid = fork(); + if (pid > 0) { + exit(0); + } else if (pid < 0) { + exit(1); + } + umask(027); signal(SIGTSTP, SIG_IGN); signal(SIGTTOU, SIG_IGN); @@ -255,24 +259,25 @@ void os_setup_post(void) int fd = 0; if (daemonize) { - uint8_t status = 0; - ssize_t len; + uint8_t status = 0; + ssize_t len; again1: - len = write(fds[1], &status, 1); - if (len == -1 && (errno == EINTR)) - goto again1; - - if (len != 1) - exit(1); - + len = write(fds[1], &status, 1); + if (len == -1 && (errno == EINTR)) { + goto again1; + } + if (len != 1) { + exit(1); + } if (chdir("/")) { perror("not able to chdir to /"); exit(1); } - TFR(fd = qemu_open("/dev/null", O_RDWR)); - if (fd == -1) - exit(1); + TFR(fd = qemu_open("/dev/null", O_RDWR)); + if (fd == -1) { + exit(1); + } } change_root(); -- cgit 1.4.1 From 97699eff3afc9c0dda865882415f81584b926727 Mon Sep 17 00:00:00 2001 From: Gonglei Date: Fri, 26 Sep 2014 16:14:31 +0800 Subject: os-posix: remove confused errno If we get inside the 'else if (status == 1)' conditional, then we know that read() succeeded, and therefore errno is unspecified. Printing strerror(errno) on a random value is not helpful. Cc: Eric Blake Signed-off-by: Gonglei Reviewed-by: Paolo Bonzini Signed-off-by: Michael Tokarev --- os-posix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os-posix.c') diff --git a/os-posix.c b/os-posix.c index f0564ef9d9..e31a099a2b 100644 --- a/os-posix.c +++ b/os-posix.c @@ -226,7 +226,7 @@ void os_daemonize(void) exit(1); } else if (status == 1) { - fprintf(stderr, "Could not acquire pidfile: %s\n", strerror(errno)); + fprintf(stderr, "Could not acquire pidfile\n"); exit(1); } else { exit(0); -- cgit 1.4.1 From e5048d15ce6addae869f23514b2a1f0d4466418a Mon Sep 17 00:00:00 2001 From: Gonglei Date: Fri, 26 Sep 2014 16:14:32 +0800 Subject: os-posix: report error message when lock file failed It will cause that create vm failed When manager tool is killed forcibly (kill -9 libvirtd_pid), the file not was unlink, and unlock. It's better that report the error message for users. Signed-off-by: Huangweidong Signed-off-by: Gonglei Reviewed-by: Paolo Bonzini Signed-off-by: Michael Tokarev --- os-posix.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'os-posix.c') diff --git a/os-posix.c b/os-posix.c index e31a099a2b..4898ebf4a2 100644 --- a/os-posix.c +++ b/os-posix.c @@ -319,6 +319,8 @@ int qemu_create_pidfile(const char *filename) return -1; } if (lockf(fd, F_TLOCK, 0) == -1) { + fprintf(stderr, "lock file '%s' failed: %s\n", + filename, strerror(errno)); close(fd); return -1; } -- cgit 1.4.1