[SSSD] [PATCH] Set cloexec flag for log files
Jakub Hrozek
jhrozek at redhat.com
Sat Dec 15 19:02:35 UTC 2012
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.
-------------- next part --------------
>From 2b110e3181525117bcbc6609bc149a1c540b0b3f Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Sat, 15 Dec 2012 19:56:33 +0100
Subject: [PATCH] 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(+)
diff --git a/src/util/debug.c b/src/util/debug.c
index cb90d65ac788366cbb732c924f0e7bffd7676ab6..f107f168be6e6dbb9e0bb6718ccec73e7b84ef23 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 {
--
1.8.0.2
More information about the sssd-devel
mailing list