summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2012-12-15 19:56:33 +0100
committerJakub Hrozek <jhrozek@redhat.com>2012-12-18 11:38:02 +0100
commitba4f38e4e377e0b1d9c6217e415fb6e1fb5591cd (patch)
tree527809bbbaffba049062a343482e0168fa93f9a8
parente57a115f671183154248ec908b218de912a62700 (diff)
downloadsssd-ba4f38e4e377e0b1d9c6217e415fb6e1fb5591cd.tar.gz
sssd-ba4f38e4e377e0b1d9c6217e415fb6e1fb5591cd.tar.xz
sssd-ba4f38e4e377e0b1d9c6217e415fb6e1fb5591cd.zip
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.
-rw-r--r--src/util/debug.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/util/debug.c b/src/util/debug.c
index e57656d7f..a027e701b 100644
--- a/src/util/debug.c
+++ b/src/util/debug.c
@@ -24,6 +24,7 @@
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
+#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -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 {