From c135d0dded909e2e5780697c4066ad44a3f488c8 Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Fri, 10 Sep 2010 23:41:29 +0200 Subject: [PATCH] io: add io_cloexec to set close-on-exec flag. --- src/ngircd/io.c | 10 ++++++++++ src/ngircd/io.h | 3 +++ 2 files changed, 13 insertions(+) diff --git a/src/ngircd/io.c b/src/ngircd/io.c index cb2b55a9..6843899d 100644 --- a/src/ngircd/io.c +++ b/src/ngircd/io.c @@ -785,6 +785,16 @@ io_setnonblock(int fd) return fcntl(fd, F_SETFL, flags) == 0; } +bool +io_setcloexec(int fd) +{ + int flags = fcntl(fd, F_GETFD); + if (flags == -1) + return false; + flags |= FD_CLOEXEC; + + return fcntl(fd, F_SETFD, flags) == 0; +} bool io_close(int fd) diff --git a/src/ngircd/io.h b/src/ngircd/io.h index a2285de4..2f4c9645 100644 --- a/src/ngircd/io.h +++ b/src/ngircd/io.h @@ -45,6 +45,9 @@ bool io_close PARAMS((int fd)); /* set O_NONBLOCK */ bool io_setnonblock PARAMS((int fd)); +/* set O_CLOEXEC */ +bool io_setcloexec PARAMS((int fd)); + /* watch fds for activity */ int io_dispatch PARAMS((struct timeval *tv));