diff options
author | Karel Zak | 2012-09-07 13:29:55 +0200 |
---|---|---|
committer | Karel Zak | 2012-09-07 13:29:55 +0200 |
commit | 9d48340d44a83fdfc24ce70a69fd84b6dd0ca3fd (patch) | |
tree | 4bc444161c53bfd8a8aa6536cb9b077429e36377 /lib/pager.c | |
parent | sulogin: cleanup file descriptors usage (diff) | |
download | kernel-qcow2-util-linux-9d48340d44a83fdfc24ce70a69fd84b6dd0ca3fd.tar.gz kernel-qcow2-util-linux-9d48340d44a83fdfc24ce70a69fd84b6dd0ca3fd.tar.xz kernel-qcow2-util-linux-9d48340d44a83fdfc24ce70a69fd84b6dd0ca3fd.zip |
lib/pager: robust work with file descriptors [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib/pager.c')
-rw-r--r-- | lib/pager.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/pager.c b/lib/pager.c index 1fce5bf20..5cf8c03b5 100644 --- a/lib/pager.c +++ b/lib/pager.c @@ -17,6 +17,8 @@ #include "xalloc.h" #include "nls.h" +#define NULL_DEVICE "/dev/null" + void setup_pager(void); static const char *pager_argv[] = { "sh", "-c", NULL, NULL }; @@ -40,7 +42,10 @@ static inline void close_pair(int fd[2]) static inline void dup_devnull(int to) { - int fd = open("/dev/null", O_RDWR); + int fd = open(NULL_DEVICE, O_RDWR); + + if (fd < 0) + err(EXIT_FAILURE, _("cannot open %s"), NULL_DEVICE); dup2(fd, to); close(fd); } @@ -70,7 +75,7 @@ static int start_command(struct child_process *cmd) if (need_in) { dup2(fdin[0], 0); close_pair(fdin); - } else if (cmd->in) { + } else if (cmd->in > 0) { dup2(cmd->in, 0); close(cmd->in); } |