Commit cdf1eaeb authored by Max Kellermann's avatar Max Kellermann

daemon: simplified daemonize_close_stdin()

Don't bother to call fstat() or isatty() on STDIN_FILENO.
parent 6c0f5fc6
...@@ -31,24 +31,14 @@ ...@@ -31,24 +31,14 @@
void void
daemonize_close_stdin(void) daemonize_close_stdin(void)
{ {
int fd, st; int fd = open("/dev/null", O_RDONLY);
struct stat ss;
if ((st = fstat(STDIN_FILENO, &ss)) < 0) { if (fd < 0)
if ((fd = open("/dev/null", O_RDONLY) > 0)) { close(STDIN_FILENO);
g_debug("stdin closed, and could not open /dev/null " else if (fd != STDIN_FILENO) {
"as fd=0, some external library bugs " dup2(fd, STDIN_FILENO);
"may be exposed..."); close(fd);
close(fd);
}
return;
} }
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 void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment