Browse Source

* fix freopen() calls : std{in,out,err} may be read-only

master
Alex 'AdUser' Z 7 years ago
parent
commit
4a56895165
  1. 13
      src/daemon.c

13
src/daemon.c

@ -232,11 +232,14 @@ int main(int argc, char *argv[]) {
perror("child: setuid()/setgid() failed");
exit(EXIT_FAILURE);
}
if (chdir("/") != 0 ||
(stdin = freopen("/dev/null", "r", stdin)) == NULL ||
(stdout = freopen("/dev/null", "w", stdout)) == NULL ||
(stderr = freopen("/dev/null", "w", stderr)) == NULL) {
perror("child: freopen() failed");
if (chdir("/") != 0) {
perror("child: chdir('/') failed");
exit(EXIT_FAILURE);
}
if (freopen("/dev/null", "r", stdin) == NULL ||
freopen("/dev/null", "w", stdout) == NULL ||
freopen("/dev/null", "w", stderr) == NULL) {
perror("child: freopen() on std streams failed");
exit(EXIT_FAILURE);
}
}

Loading…
Cancel
Save