diff options
| author | Peter Maydell <peter.maydell@linaro.org> | 2014-09-26 18:44:25 +0100 |
|---|---|---|
| committer | Peter Maydell <peter.maydell@linaro.org> | 2014-09-26 18:44:25 +0100 |
| commit | e80084d352be64913f28d7b706fec644b85face4 (patch) | |
| tree | 257edf105cc1dc219486e359bc95eb59d2609fcd /os-posix.c | |
| parent | 81ab11a7a524d12412a59ef49c6b270671e62ea0 (diff) | |
| parent | e5048d15ce6addae869f23514b2a1f0d4466418a (diff) | |
| download | focaccia-qemu-e80084d352be64913f28d7b706fec644b85face4.tar.gz focaccia-qemu-e80084d352be64913f28d7b706fec644b85face4.zip | |
Merge remote-tracking branch 'remotes/mjt/tags/trivial-patches-2014-09-26' into staging
trivial patches for 2014-09-26 # gpg: Signature made Fri 26 Sep 2014 18:33:53 BST using RSA key ID A4C3D7DB # gpg: Good signature from "Michael Tokarev <mjt@tls.msk.ru>" # gpg: aka "Michael Tokarev <mjt@corpit.ru>" # gpg: aka "Michael Tokarev <mjt@debian.org>" # gpg: WARNING: This key is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: 6EE1 95D1 886E 8FFB 810D 4324 457C E0A0 8044 65C5 # Subkey fingerprint: 6F67 E18E 7C91 C5B1 5514 66A7 BEE5 9D74 A4C3 D7DB * remotes/mjt/tags/trivial-patches-2014-09-26: os-posix: report error message when lock file failed os-posix: remove confused errno os-posix: change tab to space avoid violating coding style qapi: Update docs given recent event, spacing fixes qapi: Ignore files created during make check qapi: Consistent whitespace in tests/Makefile vmxcap: Update according to SDM of September 2014 .travis.yml: remove "make check" from main matrix .travis.yml: pre-seed sub-modules for speed .travis.yml: make the make slightly more parallel .travis.yml: add more linux-user to the build matrix tests: avoid running duplicate qom-tests Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'os-posix.c')
| -rw-r--r-- | os-posix.c | 83 |
1 files changed, 45 insertions, 38 deletions
diff --git a/os-posix.c b/os-posix.c index cb2a7f7ad7..4898ebf4a2 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)); + fprintf(stderr, "Could not acquire pidfile\n"); 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(); @@ -314,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; } |