Skip to content

Commit fdfca35

Browse files
committed
dhcpcd: warn on dup2 failures when daemonising
1 parent 3f44ca2 commit fdfca35

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎src/dhcpcd.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,10 @@ dhcpcd_daemonised(struct dhcpcd_ctx *ctx)
340340
* We know that stdin is already mapped to /dev/null.
341341
* TODO: Capture script output and log it to the logfile and/or syslog.
342342
*/
343-
dup2(STDIN_FILENO, STDOUT_FILENO);
344-
dup2(STDIN_FILENO, STDERR_FILENO);
343+
if (dup2(STDIN_FILENO, STDOUT_FILENO) == -1)
344+
logwarn("%s: dup2 %d", __func__, STDOUT_FILENO);
345+
if (dup2(STDIN_FILENO, STDERR_FILENO) == -1)
346+
logwarn("%s: dup2 %d", __func__, STDERR_FILENO);
345347

346348
ctx->options |= DHCPCD_DAEMONISED;
347349
}
@@ -2040,7 +2042,7 @@ dup_null(int fd)
20402042
}
20412043

20422044
if ((err = dup2(fd_null, fd)) == -1)
2043-
logwarn("dup2 %d", fd);
2045+
logwarn("%s: dup2 %d", __func__, fd);
20442046
close(fd_null);
20452047
return err;
20462048
}

0 commit comments

Comments
 (0)