diff options
| author | Donald Sharp <sharpd@cumulusnetworks.com> | 2017-10-06 09:12:09 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-10-06 09:12:09 -0400 |
| commit | bdef880d9c8cf41333ec43d9bbe7ffc42aefd0db (patch) | |
| tree | b989162af36e086f498f00a9dc181ea40feddd02 /lib/libfrr.c | |
| parent | 76ae8092db11aa40198f71424103b484675d4d62 (diff) | |
| parent | 8526b84200a7e733fa507e2805cae4755423d09e (diff) | |
Merge pull request #1299 from opensourcerouting/small_fixes
Small fixes
Diffstat (limited to 'lib/libfrr.c')
| -rw-r--r-- | lib/libfrr.c | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/lib/libfrr.c b/lib/libfrr.c index 2859f062c1..6cb8711edf 100644 --- a/lib/libfrr.c +++ b/lib/libfrr.c @@ -768,6 +768,8 @@ void frr_vty_serv(void) static void frr_terminal_close(int isexit) { + int nullfd; + if (daemon_ctl_sock != -1) { close(daemon_ctl_sock); daemon_ctl_sock = -1; @@ -783,11 +785,16 @@ static void frr_terminal_close(int isexit) 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; @@ -849,10 +856,15 @@ void frr_run(struct thread_master *master) } } 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); |
