diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2024-04-28 12:24:57 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2024-05-06 17:47:11 -0700 |
commit | e6ac911fdff233507f1eff950886c5d23a1e8ff5 (patch) | |
tree | fda2e0bce6153fa895dbd534ca71a5126c0f95c0 | |
parent | 3bbb10cf0fde28647edf996c7b92d89f299fdb76 (diff) |
DetachStdio: check that open & dup2 functions succeed
This was originally an attempt to fix -Wanalyzer-fd-use-without-check
warnings from gcc 13.2 with -fanalyzer, but it still gives false positives
reported to gcc in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113329
and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114880 .
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/app/xfs/-/merge_requests/7>
-rw-r--r-- | os/daemon.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/os/daemon.c b/os/daemon.c index 45a8e3e..d4ae673 100644 --- a/os/daemon.c +++ b/os/daemon.c @@ -91,15 +91,27 @@ DetachStdio (void) * Set up the standard file descriptors. */ nullfd = open ("/dev/null", O_RDWR); + if (nullfd == -1) { + FatalError("opening /dev/null failed: %s\n", strerror(errno)); + } if (nullfd != 0) { - dup2(nullfd, 0); + if (dup2(nullfd, 0) == -1) { + FatalError("dup2 of /dev/null to fd 0 failed: %s\n", + strerror(errno)); + } close(nullfd); } - dup2 (0, 1); + if (dup2 (0, 1) == -1) { + FatalError("dup2 of /dev/null to fd 1 failed: %s\n", + strerror(errno)); + } #ifdef USE_SYSLOG if (UseSyslog) { - dup2 (0, 2); + if (dup2 (0, 2) == -1) { + FatalError("dup2 of /dev/null to fd 2 failed: %s\n", + strerror(errno)); + } return; } #endif |