diff options
| author | David Lamparter <equinox@opensourcerouting.org> | 2016-11-08 20:46:05 +0100 |
|---|---|---|
| committer | David Lamparter <equinox@opensourcerouting.org> | 2016-11-09 13:40:05 +0100 |
| commit | 2da59394ec858ae5aecf2b26ab8d9fefdae17bb8 (patch) | |
| tree | 720795e72480f81c7f1cbabe1445bbd4ba8acc1c /lib/network.c | |
| parent | 73ea75daa522a43ad0be9bff1f26a98bc2e105b0 (diff) | |
lib: add and use set_cloexec()
watchquagga is already leaking an open file descriptor on its pid file
on fork+exec() invocations; next up is adding vtysh support with even
more fds. Mark things CLOEXEC before going there.
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'lib/network.c')
| -rw-r--r-- | lib/network.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/network.c b/lib/network.c index 5379ecb5a6..506e019136 100644 --- a/lib/network.c +++ b/lib/network.c @@ -94,6 +94,20 @@ set_nonblocking(int fd) return 0; } +int +set_cloexec(int fd) +{ + int flags; + flags = fcntl(fd, F_GETFD, 0); + if (flags == -1) + return -1; + + flags |= FD_CLOEXEC; + if (fcntl(fd, F_SETFD, flags) == -1) + return -1; + return 0; +} + float htonf (float host) { |
