daemon/shell: refactor redirection of 0/1/2 from /dev/null
Both daemon.c and shell.c contain logic to open FDs 0/1/2 from /dev/null if they are not already open. Move the function in daemon.c to setup.c and use it in shell.c, too. While there, remove a 'not' that inverted the meaning of the comment. The point is indeed to *avoid* messing up. Signed-off-by: Thomas Rast <trast@inf.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
62e91efafd
commit
1d999ddd1d
12
daemon.c
12
daemon.c
@ -1047,18 +1047,6 @@ static int service_loop(struct socketlist *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_errno("open /dev/null or dup failed");
|
||||
if (fd > 2)
|
||||
close(fd);
|
||||
}
|
||||
|
||||
#ifdef NO_POSIX_GOODIES
|
||||
|
||||
struct credentials;
|
||||
|
||||
Reference in New Issue
Block a user