From 7800c9da75ad0dc3b4a530b15adce86d6c4f26e5 Mon Sep 17 00:00:00 2001 From: Lukas Slebodnik Date: Fri, 8 Mar 2013 15:27:14 +0100 Subject: More generalized function open_debug_file_ex() Function open_debug_file_ex() set flag FD_CLOEXEC to opened file according to the value of third parameter. Removed duplicity of unsetting FD_CLOEXEC after calling function open_debug_file_ex() --- src/util/debug.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/util/debug.c') diff --git a/src/util/debug.c b/src/util/debug.c index 54fb8011..3bf5e75a 100644 --- a/src/util/debug.c +++ b/src/util/debug.c @@ -173,7 +173,7 @@ void ldb_debug_messages(void *context, enum ldb_debug_level level, free(message); } -int open_debug_file_ex(const char *filename, FILE **filep) +int open_debug_file_ex(const char *filename, FILE **filep, bool want_cloexec) { FILE *f = NULL; char *logpath; @@ -214,8 +214,10 @@ int open_debug_file_ex(const char *filename, FILE **filep) return EIO; } - flags = fcntl(debug_fd, F_GETFD, 0); - (void) fcntl(debug_fd, F_SETFD, flags | FD_CLOEXEC); + if(want_cloexec) { + flags = fcntl(debug_fd, F_GETFD, 0); + (void) fcntl(debug_fd, F_SETFD, flags | FD_CLOEXEC); + } if (filep == NULL) { debug_file = f; @@ -228,7 +230,7 @@ int open_debug_file_ex(const char *filename, FILE **filep) int open_debug_file(void) { - return open_debug_file_ex(NULL, NULL); + return open_debug_file_ex(NULL, NULL, true); } int rotate_debug_files(void) -- cgit