summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGergely Nagy <algernon@madhouse-project.org>2012-04-28 18:18:32 +0200
committerGergely Nagy <algernon@madhouse-project.org>2012-04-28 18:18:32 +0200
commit8cfef10830350c565e8ee917f83b9e97016a0a62 (patch)
tree32406caa5a85df767940c2d9b1fc1c94a8c617dd
parent0a00d2b837d186c261d5bc31c08737e60cf4172b (diff)
downloadlibumberlog-8cfef10830350c565e8ee917f83b9e97016a0a62.tar.gz
libumberlog-8cfef10830350c565e8ee917f83b9e97016a0a62.tar.xz
libumberlog-8cfef10830350c565e8ee917f83b9e97016a0a62.zip
Add a closelog() wrapper to clear the environment
Our openlog() wrapper fills in a couple of variables, and those were kept around even after a closelog(), and thus, affected ul_format() calls even after a closelog(). This in turn, made one of the test cases fail, as that was relying on the default behaviour, which was modified due to an openlog() in an earlier test case. We now wrap closelog() aswell, and NULL out our settings to get a clean state, and add a test case to verify this behaviour aswell. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
-rw-r--r--lib/libumberlog.ld5
-rw-r--r--lib/umberlog.c12
-rw-r--r--lib/umberlog.h1
-rw-r--r--lib/umberlog.rst8
-rw-r--r--t/test_umberlog.c19
5 files changed, 44 insertions, 1 deletions
diff --git a/lib/libumberlog.ld b/lib/libumberlog.ld
index 8cd48e7..225d51c 100644
--- a/lib/libumberlog.ld
+++ b/lib/libumberlog.ld
@@ -15,3 +15,8 @@ LIBUMBERLOG_0.1.0 {
facilitynames;
prioritynames;
};
+
+LIBUMBERLOG_0.2.1 {
+ global:
+ ul_closelog;
+} LIBUMBERLOG_0.1.0;
diff --git a/lib/umberlog.c b/lib/umberlog.c
index ad25709..e4eb5d3 100644
--- a/lib/umberlog.c
+++ b/lib/umberlog.c
@@ -48,6 +48,7 @@
static void (*old_syslog) ();
static void (*old_vsyslog) ();
static void (*old_openlog) ();
+static void (*old_closelog) ();
static int (*old_setlogmask) ();
static void ul_init (void) __attribute__((constructor));
@@ -75,6 +76,7 @@ ul_init (void)
old_syslog = dlsym (RTLD_NEXT, "syslog");
old_vsyslog = dlsym (RTLD_NEXT, "vsyslog");
old_openlog = dlsym (RTLD_NEXT, "openlog");
+ old_closelog = dlsym (RTLD_NEXT, "closelog");
old_setlogmask = dlsym (RTLD_NEXT, "setlogmask");
}
@@ -99,6 +101,13 @@ ul_openlog (const char *ident, int option, int facility)
gethostname (ul_sys_settings.hostname, _POSIX_HOST_NAME_MAX);
}
+void
+ul_closelog (void)
+{
+ old_closelog ();
+ memset (&ul_sys_settings, 0, sizeof (ul_sys_settings));
+}
+
/** HELPERS **/
static inline const char *
_find_facility (int prio)
@@ -512,6 +521,9 @@ __vsyslog_chk (int __pri, int __flag, __const char *__fmt, va_list ap)
void openlog (const char *ident, int option, int facility)
__attribute__((alias ("ul_openlog")));
+void closelog (void)
+ __attribute__((alias ("ul_closelog")));
+
#undef syslog
void syslog (int priority, const char *msg_format, ...)
__attribute__((alias ("ul_legacy_syslog")));
diff --git a/lib/umberlog.h b/lib/umberlog.h
index 4245dae..51ed7be 100644
--- a/lib/umberlog.h
+++ b/lib/umberlog.h
@@ -41,6 +41,7 @@ char *ul_format (int priority, const char *msg_format, ...)
char *ul_vformat (int priority, const char *msg_format, va_list ap);
void ul_openlog (const char *ident, int option, int facility);
+void ul_closelog (void);
int ul_setlogmask (int mask);
int ul_syslog (int priority, const char *msg_format, ...)
diff --git a/lib/umberlog.rst b/lib/umberlog.rst
index c655263..d2cd354 100644
--- a/lib/umberlog.rst
+++ b/lib/umberlog.rst
@@ -7,7 +7,7 @@ CEE-enhanced syslog message generation
--------------------------------------
:Author: Gergely Nagy <algernon@balabit.hu>
-:Date: 2012-03-23
+:Date: 2012-04-28
:Manual section: 3
:Manual group: CEE-enhanced syslog Manual
@@ -19,6 +19,7 @@ SYNOPSIS
#include <umberlog.h>
void ul_openlog (const char *ident, int option, int facility);
+ void ul_closelog (void);
int ul_syslog (int priority, const char *format, ....);
int ul_vsyslog (int priority, const char *format, va_list ap);
@@ -37,6 +38,11 @@ the original **openlog()** function, which opens a connection to the
system logger for a program. The updated version adds support for a
number of new option flags, described below.
+**ul_closelog()** (also aliased to **closelog()**) is similar to
+**ul_openlog()** in that it is a wrapper around the original
+**closelog()**. It clears any settings set so far, to get back to a
+clean state.
+
**ul_legacy_syslog()** and **ul_legacy_vsyslog()** are both thin
layers over the original **syslog()** and **vsyslog()** functions, and
the library overrides the original functions with this two. The only
diff --git a/t/test_umberlog.c b/t/test_umberlog.c
index 33ed8bf..b0085c6 100644
--- a/t/test_umberlog.c
+++ b/t/test_umberlog.c
@@ -236,6 +236,24 @@ test_facprio (void)
json_object_put (jo);
}
+static void
+test_closelog (void)
+{
+ char *msg;
+ struct json_object *jo;
+
+ openlog ("umberlog/test_closelog", LOG_UL_NODISCOVER, LOG_LOCAL0);
+ closelog ();
+
+ msg = ul_format (LOG_LOCAL1 | LOG_DEBUG, "%s", __FUNCTION__, NULL);
+ jo = parse_msg (msg);
+ free (msg);
+
+ verify_value (jo, "facility", "local1");
+
+ json_object_put (jo);
+}
+
int
main (void)
{
@@ -246,6 +264,7 @@ main (void)
test_no_timestamp ();
test_json_escape ();
test_facprio ();
+ test_closelog ();
return 0;
}