summaryrefslogtreecommitdiff
path: root/src/logging.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2018-12-05 18:29:15 +0100
committerWerner Koch <wk@gnupg.org>2018-12-05 18:29:55 +0100
commitf4d139b399e1e5044fe6bb0ceecd4c72e63dac94 (patch)
tree8f3102cf86a770ec9331db399fb99dda729b3e71 /src/logging.c
parent793838fd859afd837df070ee2e75c100e932b220 (diff)
downloadlibgpg-error-f4d139b399e1e5044fe6bb0ceecd4c72e63dac94.tar.gz
core: Allow logging to an estream.
* src/logging.c (set_file_fd): Add and use new arg 'stream'. (_gpgrt_log_set_sink): Implement setting an estream sink. * tests/t-logging.c: New test. * tests/Makefile.am (TESTS): Add test. Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'src/logging.c')
-rw-r--r--src/logging.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/logging.c b/src/logging.c
index 51e1362..42e7180 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -455,10 +455,10 @@ fun_closer (void *cookie_arg)
/* Common function to either set the logging to a file or a file
descriptor. */
static void
-set_file_fd (const char *name, int fd)
+set_file_fd (const char *name, int fd, estream_t stream)
{
estream_t fp;
- int want_socket;
+ int want_socket = 0;
#ifdef HAVE_W32CE_SYSTEM
int use_writefile = 0;
#endif
@@ -472,6 +472,13 @@ set_file_fd (const char *name, int fd)
logstream = NULL;
}
+ if (stream)
+ {
+ /* We don't use a cookie to log directly to a stream. */
+ fp = stream;
+ goto leave;
+ }
+
/* Figure out what kind of logging we want. */
if (name && !strcmp (name, "-"))
{
@@ -479,7 +486,6 @@ set_file_fd (const char *name, int fd)
fd = _gpgrt_fileno (es_stderr);
}
- want_socket = 0;
if (name && !strncmp (name, "tcp://", 6) && name[6])
want_socket = 1;
#ifndef HAVE_W32_SYSTEM
@@ -541,6 +547,7 @@ set_file_fd (const char *name, int fd)
if (!fp)
fp = es_stderr;
+ leave:
_gpgrt_setvbuf (fp, NULL, _IOLBF, 0);
logstream = fp;
@@ -567,20 +574,20 @@ void
_gpgrt_log_set_sink (const char *name, estream_t stream, int fd)
{
if (name && !stream && fd == -1)
- set_file_fd (name, -1);
+ set_file_fd (name, -1, NULL);
else if (!name && !stream && fd != -1)
{
if (!_gpgrt_fd_valid_p (fd))
_gpgrt_log_fatal ("gpgrt_log_set_sink: fd is invalid: %s\n",
strerror (errno));
- set_file_fd (NULL, fd);
+ set_file_fd (NULL, fd, NULL);
}
else if (!name && stream && fd == -1)
{
- _gpgrt_log_fatal ("gpgrt_log_set_sink: stream arg not yet supported\n");
+ set_file_fd (NULL, -1, stream);
}
else /* default */
- set_file_fd ("-", -1);
+ set_file_fd ("-", -1, NULL);
}