From 3eaa6748f0f57eff6b85e3e4a249ccaeccd09bed Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 11 Jul 2016 16:40:53 +0200 Subject: Close file descriptors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/gammad.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gammad.c b/src/gammad.c index 9534f9f..5450399 100644 --- a/src/gammad.c +++ b/src/gammad.c @@ -17,6 +17,7 @@ */ #include +#include #include #include #include @@ -430,7 +431,16 @@ int main(int argc, char** argv) if (argc > 0) usage(); - /* TODO Close all file descriptors above stderr */ + /* Close all file descriptors above stderr */ + { + struct rlimit rlimit; + if (getrlimit(RLIMIT_NOFILE, &rlimit) || (rlimit.rlim_cur == RLIM_INFINITY)) + n = 4 << 10; + else + n = (size_t)(rlimit.rlim_cur); + for (i = STDERR_FILENO + 1; i < n; i++) + close((int)i); + } /* Set umask, reset signal handlers, and reset signal mask */ umask(0); -- cgit v1.2.3-70-g09d2