diff options
author | Max Kellermann <max@duempel.org> | 2008-12-30 16:28:18 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-12-30 16:28:18 +0100 |
commit | cdf1eaeb2c6f65e1fa9bff161764c843b15f5cee (patch) | |
tree | ecfd3af787d388abb3b599c5d11da0fd038e533e /src/daemon.c | |
parent | 6c0f5fc6125a478fd50074880ed7fcac9fd9063e (diff) | |
download | mpd-cdf1eaeb2c6f65e1fa9bff161764c843b15f5cee.tar.gz mpd-cdf1eaeb2c6f65e1fa9bff161764c843b15f5cee.tar.xz mpd-cdf1eaeb2c6f65e1fa9bff161764c843b15f5cee.zip |
daemon: simplified daemonize_close_stdin()
Don't bother to call fstat() or isatty() on STDIN_FILENO.
Diffstat (limited to 'src/daemon.c')
-rw-r--r-- | src/daemon.c | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/src/daemon.c b/src/daemon.c index 569494908..913f06f89 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -31,24 +31,14 @@ void daemonize_close_stdin(void) { - int fd, st; - struct stat ss; + int fd = open("/dev/null", O_RDONLY); - if ((st = fstat(STDIN_FILENO, &ss)) < 0) { - if ((fd = open("/dev/null", O_RDONLY) > 0)) { - g_debug("stdin closed, and could not open /dev/null " - "as fd=0, some external library bugs " - "may be exposed..."); - close(fd); - } - return; + if (fd < 0) + close(STDIN_FILENO); + else if (fd != STDIN_FILENO) { + dup2(fd, STDIN_FILENO); + close(fd); } - if (!isatty(STDIN_FILENO)) - return; - if ((fd = open("/dev/null", O_RDONLY)) < 0) - g_error("failed to open /dev/null %s", strerror(errno)); - if (dup2(fd, STDIN_FILENO) < 0) - g_error("dup2 stdin: %s", strerror(errno)); } void |