From 449fd66aa70c284dd91d51c49363ef9e941dba8d Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Sat, 15 Dec 2012 19:56:33 +0100 Subject: Set cloexec flag for log files https://fedorahosted.org/sssd/ticket/1708 The services kept the fd to /var/log/sssd/sssd.log open. I don't think there's any point in keeping the logfiles open after exec-ing for the child, so I set the CLOEXEC flag. --- src/util/debug.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/util/debug.c') diff --git a/src/util/debug.c b/src/util/debug.c index cb90d65ac..f107f168b 100644 --- a/src/util/debug.c +++ b/src/util/debug.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -179,6 +180,8 @@ int open_debug_file_ex(const char *filename, FILE **filep) const char *log_file; mode_t old_umask; int ret; + int debug_fd; + int flags; if (filename == NULL) { log_file = debug_log_file; @@ -204,6 +207,14 @@ int open_debug_file_ex(const char *filename, FILE **filep) } umask(old_umask); + debug_fd = fileno(f); + if (debug_fd == -1) { + return EIO; + } + + flags = fcntl(debug_fd, F_GETFD, 0); + (void) fcntl(debug_fd, F_SETFD, flags | FD_CLOEXEC); + if (filep == NULL) { debug_file = f; } else { -- cgit