[PATCH 2/2] run-command: dup_devnull(): guard against syscalls failing
- From
Thomas Rast <trast@inf.ethz.ch>
- Date
- Jul 12, 2013, 08:58 UTC
- Message-ID
- <0f1e919ab5886d00d6956499cf5ed3e064033f11.1373618940.git.trast@inf.ethz.ch>
- In-Reply-To
- <cover.1373618940.git.trast@inf.ethz.ch>
dup_devnull() did not check the return values of open() and dup2(). Fix this omission.
Signed-off-by: Thomas Rast <trast@inf.ethz.ch> --- run-command.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/run-command.c b/run-command.c index aece872..1b7f88e 100644 --- a/run-command.c +++ b/run-command.c @@ -76,7 +76,10 @@ static inline void close_pair(int fd[2]) static inline void dup_devnull(int to) { 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); } #endif
-- 1.8.3.2.998.g1d087bc