(log_set_file): Do not close an old logstream if it

used to be stderr or stdout.
This commit is contained in:
Werner Koch 2004-06-21 09:50:22 +00:00
parent 8b3cf19e24
commit 3571968f04
2 changed files with 12 additions and 6 deletions

View File

@ -1,3 +1,8 @@
2004-06-21 Werner Koch <wk@g10code.com>
* logging.c (log_set_file): Do not close an old logstream if it
used to be stderr or stdout.
2004-05-05 Werner Koch <wk@gnupg.org>
* logging.c (log_set_file): Oops, don't close if LOGSTREAM is NULL.

View File

@ -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;
}
}