From 3571968f04ac5bbbbc2702478d1478330d2e2973 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Mon, 21 Jun 2004 09:50:22 +0000 Subject: (log_set_file): Do not close an old logstream if it used to be stderr or stdout. --- jnlib/ChangeLog | 5 +++++ jnlib/logging.c | 13 +++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/jnlib/ChangeLog b/jnlib/ChangeLog index e9f643774..e4df12a7f 100644 --- a/jnlib/ChangeLog +++ b/jnlib/ChangeLog @@ -1,3 +1,8 @@ +2004-06-21 Werner Koch + + * logging.c (log_set_file): Do not close an old logstream if it + used to be stderr or stdout. + 2004-05-05 Werner Koch * logging.c (log_set_file): Oops, don't close if LOGSTREAM is NULL. diff --git a/jnlib/logging.c b/jnlib/logging.c index c75efaf85..f91339687 100644 --- a/jnlib/logging.c +++ b/jnlib/logging.c @@ -129,15 +129,15 @@ fun_writer (void *cookie_arg, const char *buffer, size_t size) struct fun_cookie_s *cookie = cookie_arg; /* Note that we always try to reconnect to the socket but print - error messages only the first time an error occured. IF + error messages only the first time an error occured. If RUNNING_DETACHED is set we don't fall back to stderr and even do - not print any error messages. This is needed becuase detached - processes often close stderr and my printing to fiel descriptor 2 + not print any error messages. This is needed because detached + processes often close stderr and by writing to file descriptor 2 we might send the log message to a file not intended for logging (e.g. a pipe or network connection). */ if (cookie->fd == -1) { - /* Note yet open or meanwhile closed due to an error. */ + /* Not yet open or meanwhile closed due to an error. */ struct sockaddr_un addr; size_t addrlen; @@ -256,13 +256,14 @@ log_set_file (const char *name) #endif /* Neither fopencookie nor funopen. */ /* We always need to print the prefix and the pid, so that the - server reading the socket can do something meanigful. */ + server reading the socket can do something meaningful. */ force_prefixes = 1; /* On success close the old logstream right now, so that we are really sure it has been closed. */ if (fp && logstream) { - fclose (logstream); + if (logstream != stderr && logstream != stdout) + fclose (logstream); logstream = NULL; } } -- cgit v1.2.3