]> granicus.if.org Git - postgresql/commitdiff
Check dup2() results in syslogger
authorStephen Frost <sfrost@snowman.net>
Sun, 26 Jan 2014 21:26:18 +0000 (16:26 -0500)
committerStephen Frost <sfrost@snowman.net>
Sun, 26 Jan 2014 21:26:18 +0000 (16:26 -0500)
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.

src/backend/postmaster/syslogger.c

index 54a2b3bd339c6351d147a264b5f745e07a89d83e..3c54956e70f3b669545121eaf7c5933cfefcb5da 100644 (file)
@@ -210,8 +210,14 @@ SysLoggerMain(int argc, char *argv[])
                close(fileno(stderr));
                if (fd != -1)
                {
-                       dup2(fd, fileno(stdout));
-                       dup2(fd, fileno(stderr));
+                       if (dup2(fd, fileno(stdout)) < 0)
+                                       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);
                }
        }