}
nullfd = open("/dev/null", O_RDONLY | O_NOCTTY);
- dup2(nullfd, 0);
- dup2(nullfd, 1);
- dup2(nullfd, 2);
- close(nullfd);
+ if (nullfd == -1) {
+ zlog_err("%s: failed to open /dev/null: %s", __func__,
+ safe_strerror(errno));
+ } else {
+ dup2(nullfd, 0);
+ dup2(nullfd, 1);
+ dup2(nullfd, 2);
+ close(nullfd);
+ }
if (dup2(fd_async, LDPD_FD_ASYNC) == -1)
fatal("cannot setup imsg async fd");
static void frr_terminal_close(int isexit)
{
+ int nullfd;
+
if (daemon_ctl_sock != -1) {
close(daemon_ctl_sock);
daemon_ctl_sock = -1;
fflush(stdout);
}
- int nullfd = open("/dev/null", O_RDONLY | O_NOCTTY);
- dup2(nullfd, 0);
- dup2(nullfd, 1);
- dup2(nullfd, 2);
- close(nullfd);
+ nullfd = open("/dev/null", O_RDONLY | O_NOCTTY);
+ if (nullfd == -1) {
+ zlog_err("%s: failed to open /dev/null: %s", __func__,
+ safe_strerror(errno));
+ } else {
+ dup2(nullfd, 0);
+ dup2(nullfd, 1);
+ dup2(nullfd, 2);
+ close(nullfd);
+ }
}
static struct thread *daemon_ctl_thread = NULL;
}
} else if (di->daemon_mode) {
int nullfd = open("/dev/null", O_RDONLY | O_NOCTTY);
- dup2(nullfd, 0);
- dup2(nullfd, 1);
- dup2(nullfd, 2);
- close(nullfd);
+ if (nullfd == -1) {
+ zlog_err("%s: failed to open /dev/null: %s", __func__,
+ safe_strerror(errno));
+ } else {
+ dup2(nullfd, 0);
+ dup2(nullfd, 1);
+ dup2(nullfd, 2);
+ close(nullfd);
+ }
if (daemon_ctl_sock != -1)
close(daemon_ctl_sock);