summaryrefslogtreecommitdiffstats
path: root/lib/umberlog.c
diff options
context:
space:
mode:
authorGergely Nagy <algernon@balabit.hu>2012-05-02 16:25:04 +0200
committerGergely Nagy <algernon@balabit.hu>2012-05-02 16:25:04 +0200
commitac2a1fdb38057e032b22c4e2ea43d5ab741222b8 (patch)
tree52f91b7c65314760932543b8825303e1122954fe /lib/umberlog.c
parentb9751e1ca5f96ffdf49e38646709a3de9e25a208 (diff)
parente5faea1d639252017cc8321e9c2cb5d17b061e97 (diff)
Merge tag 'libumberlog-0.2.1' into debian
libumberlog 0.2.1 release
Diffstat (limited to 'lib/umberlog.c')
-rw-r--r--lib/umberlog.c40
1 files changed, 32 insertions, 8 deletions
diff --git a/lib/umberlog.c b/lib/umberlog.c
index fe0a6b7..e4eb5d3 100644
--- a/lib/umberlog.c
+++ b/lib/umberlog.c
@@ -48,9 +48,11 @@
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));
+static void ul_finish (void) __attribute__((destructor));
static __thread struct
{
@@ -74,9 +76,16 @@ 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");
}
+static void
+ul_finish (void)
+{
+ free (ul_buffer.msg);
+}
+
void
ul_openlog (const char *ident, int option, int facility)
{
@@ -92,17 +101,28 @@ 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 (void)
+_find_facility (int prio)
{
int i = 0;
+ int fac = prio & LOG_FACMASK;
+
+ if (fac == 0)
+ fac = ul_sys_settings.facility;
while (facilitynames[i].c_name != NULL &&
- facilitynames[i].c_val != ul_sys_settings.facility)
+ facilitynames[i].c_val != fac)
i++;
- if (facilitynames[i].c_val == ul_sys_settings.facility)
+ if (facilitynames[i].c_val == fac)
return facilitynames[i].c_name;
return "<unknown>";
}
@@ -111,12 +131,13 @@ static inline const char *
_find_prio (int prio)
{
int i = 0;
+ int pri = LOG_PRI (prio);
while (prioritynames[i].c_name != NULL &&
- prioritynames[i].c_val != prio)
+ prioritynames[i].c_val != pri)
i++;
- if (prioritynames[i].c_val == prio)
+ if (prioritynames[i].c_val == pri)
return prioritynames[i].c_name;
return "<unknown>";
}
@@ -309,7 +330,7 @@ _ul_discover (ul_buffer_t *buffer, int priority)
buffer = _ul_json_append (buffer,
"pid", "%d", _find_pid (),
- "facility", "%s", _find_facility (),
+ "facility", "%s", _find_facility (priority),
"priority", "%s", _find_prio (priority),
"program", "%s", ul_sys_settings.ident,
"uid", "%d", _get_uid (),
@@ -341,6 +362,8 @@ _ul_vformat (ul_buffer_t *buffer, int format_version,
if (!value)
return NULL;
+ ul_buffer_reset (buffer);
+
buffer = ul_buffer_append (buffer, "msg", value);
if (buffer == NULL)
{
@@ -395,8 +418,6 @@ ul_vformat (int priority, const char *msg_format, va_list ap)
const char *msg;
ul_buffer_t *buffer = &ul_buffer;
- ul_buffer_reset (buffer);
-
msg = _ul_vformat_str (buffer, 1, priority, msg_format, ap);
if (!msg)
{
@@ -500,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")));