run-command: dup_devnull(): guard against syscalls failing

dup_devnull() did not check the return values of open() and dup2().
Fix this omission.

Signed-off-by: Thomas Rast <trast@inf.ethz.ch>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Thomas Rast 2013-07-12 10:58:36 +02:00 committed by Junio C Hamano
parent a2cb86c152
commit a77f106c78

View File

@ -76,7 +76,10 @@ static inline void close_pair(int fd[2])
static inline void dup_devnull(int to) static inline void dup_devnull(int to)
{ {
int fd = open("/dev/null", O_RDWR); int fd = open("/dev/null", O_RDWR);
dup2(fd, to); if (fd < 0)
die_errno(_("open /dev/null failed"));
if (dup2(fd, to) < 0)
die_errno(_("dup2(%d,%d) failed"), fd, to);
close(fd); close(fd);
} }
#endif #endif