Skip to content

Commit

Permalink
util: fix possible wrong error message in debug builds
Browse files Browse the repository at this point in the history
Signed-off-by: He Xian <hexian000@outlook.com>
  • Loading branch information
hexian000 committed Jan 17, 2025
1 parent ee475a4 commit 81a897a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ void init(int argc, char **argv)
.sa_handler = SIG_IGN,
};
if (sigaction(SIGPIPE, &ignore, NULL) != 0) {
FAILMSGF("sigaction: %s", strerror(errno));
const int err = errno;
FAILMSGF("sigaction: %s", strerror(err));
}
#if WITH_CRASH_HANDLER
set_crash_handler();
Expand Down Expand Up @@ -298,13 +299,15 @@ void daemonize(
/* Create an anonymous pipe for communicating with daemon process. */
int fd[2];
if (pipe(fd) == -1) {
FAILMSGF("pipe: %s", strerror(errno));
const int err = errno;
FAILMSGF("pipe: %s", strerror(err));
}
/* First fork(). */
{
const pid_t pid = fork();
if (pid < 0) {
FAILMSGF("fork: %s", strerror(errno));
const int err = errno;
FAILMSGF("fork: %s", strerror(err));
} else if (pid > 0) {
CLOSE_FD(fd[1]);
char buf[256];
Expand All @@ -326,7 +329,8 @@ void daemonize(
{
const pid_t pid = fork();
if (pid < 0) {
FAILMSGF("fork: %s", strerror(errno));
const int err = errno;
FAILMSGF("fork: %s", strerror(err));
} else if (pid > 0) {
/* Call exit() in the first child. */
exit(EXIT_SUCCESS);
Expand Down

0 comments on commit 81a897a

Please sign in to comment.