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"); perror("child: setuid()/setgid() failed");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (chdir("/") != 0 || if (chdir("/") != 0) {
(stdin = freopen("/dev/null", "r", stdin)) == NULL || perror("child: chdir('/') failed");
(stdout = freopen("/dev/null", "w", stdout)) == NULL || exit(EXIT_FAILURE);
(stderr = freopen("/dev/null", "w", stderr)) == NULL) { }
perror("child: freopen() failed"); 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); exit(EXIT_FAILURE);
} }
} }

Loading…
Cancel
Save