Commit 790eaa69 authored by Stephen Frost's avatar Stephen Frost

Check dup2() results in syslogger

Consistently check the dup2() call results throughout syslogger.c.
It's pretty unlikely that they'll error out, but if they do,
ereport(FATAL) instead of blissfully continuing on.

Spotted by the Coverity scanner.
parent f2795f8b
...@@ -210,8 +210,14 @@ SysLoggerMain(int argc, char *argv[]) ...@@ -210,8 +210,14 @@ SysLoggerMain(int argc, char *argv[])
close(fileno(stderr)); close(fileno(stderr));
if (fd != -1) if (fd != -1)
{ {
dup2(fd, fileno(stdout)); if (dup2(fd, fileno(stdout)) < 0)
dup2(fd, fileno(stderr)); ereport(FATAL,
(errcode_for_file_access(),
errmsg("could not redirect stdout: %m")));
if (dup2(fd, fileno(stderr)) < 0)
ereport(FATAL,
(errcode_for_file_access(),
errmsg("could not redirect stderr: %m")));
close(fd); close(fd);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment