1
0
mirror of https://github.com/git/git.git synced 2024-11-20 16:14:02 +01:00

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>
This commit is contained in:
Matthias Lederhofer 2006-07-13 18:32:11 +02:00 committed by Junio C Hamano
parent ad8b4f56b5
commit 258e93a155

@ -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);
}