From c49a66e6dc9a7ba97e43a8b0f7d175c2a9e25fbf Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 6 Dec 2011 18:06:13 +0000 Subject: [PATCH] LRN: Ensure that GTK can then do the internal call write(2, message, strlen (message)); successfully by default. --- src/util/common_logging.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/util/common_logging.c b/src/util/common_logging.c index 22901bf26..ba51e550c 100644 --- a/src/util/common_logging.c +++ b/src/util/common_logging.c @@ -546,6 +546,7 @@ GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile) int dirwarn; char *fn; const char *env_logfile = NULL; + int altlog_fd; min_level = get_type (loglevel); #if !defined(GNUNET_CULL_LOGGING) @@ -569,8 +570,33 @@ GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile) if (NULL == fn) return GNUNET_SYSERR; dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn)); - altlog = FOPEN (fn, "a"); - if (altlog == NULL) + altlog_fd = OPEN (fn, O_APPEND | +#if WINDOWS + O_BINARY | +#endif + O_WRONLY); + if (altlog_fd != -1) + { + int dup_return; + if (GNUNET_stderr != NULL) + fclose (GNUNET_stderr); + dup_return = dup2 (altlog_fd, 2); + close (altlog_fd); + if (dup_return != -1) + { + altlog = fdopen (2, "ab"); + if (altlog == NULL) + { + close (2); + altlog_fd = -1; + } + } + else + { + altlog_fd = -1; + } + } + if (altlog_fd == -1) { GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", fn); if (dirwarn) @@ -581,8 +607,6 @@ GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile) return GNUNET_SYSERR; } GNUNET_free (fn); - if (GNUNET_stderr != NULL) - fclose (GNUNET_stderr); GNUNET_stderr = altlog; return GNUNET_OK; } -- 2.25.1