diff options
author | Matthias Lederhofer <matled@gmx.net> | 2006-07-13 18:32:11 +0200 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2006-07-13 21:50:20 -0700 |
commit | 258e93a155f88fd7385e4d1e26f287044ba973e9 (patch) | |
tree | dd2556a3b1b3d97fb3c9b9ee36324076f1df489e /daemon.c | |
parent | ad8b4f56b5ec1e5385156c20d95649ea8cee6af4 (diff) | |
download | git-258e93a155f88fd7385e4d1e26f287044ba973e9.tar.gz git-258e93a155f88fd7385e4d1e26f287044ba973e9.tar.xz |
daemon: if one of the standard fds is missing open it to /dev/null
Signed-off-by: Matthias Lederhofer <matled@gmx.net>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'daemon.c')
-rw-r--r-- | daemon.c | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -662,6 +662,18 @@ static int service_loop(int socknum, int *socklist) } } +/* if any standard file descriptor is missing open it to /dev/null */ +static void sanitize_stdfds(void) +{ + int fd = open("/dev/null", O_RDWR, 0); + while (fd != -1 && fd < 2) + fd = dup(fd); + if (fd == -1) + die("open /dev/null or dup failed: %s", strerror(errno)); + if (fd > 2) + close(fd); +} + static int serve(int port) { int socknum, *socklist; @@ -773,5 +785,7 @@ int main(int argc, char **argv) return execute(peer); } + sanitize_stdfds(); + return serve(port); } |