summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2012-07-24 12:29:04 +0200
committerMiloslav Trmač <mitr@redhat.com>2012-07-30 07:10:15 +0200
commitafcb5c504f7302165f34931864389cbc115b7b16 (patch)
tree73a75121ab24334e9310805d8e9455d6fea2a82e
parentcc5ef77263fcbf980c18381ae02a73f0d1ad66e1 (diff)
downloadlibumberlog-afcb5c504f7302165f34931864389cbc115b7b16.tar.gz
libumberlog-afcb5c504f7302165f34931864389cbc115b7b16.tar.xz
libumberlog-afcb5c504f7302165f34931864389cbc115b7b16.zip
Make "facility" set by ul_openlog() per-process
... to match openlog(3). Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-rw-r--r--lib/Makefile.am1
-rw-r--r--lib/umberlog.c19
2 files changed, 17 insertions, 3 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index b6b60b3..8c1bf3c 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -7,6 +7,7 @@ libumberlog_la_LDFLAGS = -Wl,--version-script,${srcdir}/libumberlog.ld \
-version-info ${LUL_CURRENT}:${LUL_REVISION}:${LUL_AGE}
libumberlog_la_SOURCES = umberlog.c umberlog.h buffer.c buffer.h
+libumberlog_la_LIBADD = -lpthread
libumberlog_includedir = $(includedir)
libumberlog_include_HEADERS = umberlog.h
diff --git a/lib/umberlog.c b/lib/umberlog.c
index a04b628..58f6bb0 100644
--- a/lib/umberlog.c
+++ b/lib/umberlog.c
@@ -34,6 +34,7 @@
#include <unistd.h>
#include <stdio.h>
#include <dlfcn.h>
+#include <pthread.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
@@ -62,13 +63,20 @@ static __thread struct
{
int flags;
- int facility;
pid_t pid;
uid_t uid;
gid_t gid;
const char *ident;
char hostname[_POSIX_HOST_NAME_MAX + 1];
} ul_thread_data;
+static struct
+{
+ /* The lock is used only to serialize writes; we assume that reads are safe
+ even when racing with writes, note that POSIX does not guarantee this (but
+ the BSD syslog does the same thing). */
+ pthread_mutex_t lock;
+ int facility;
+} ul_process_data = { PTHREAD_MUTEX_INITIALIZER, 0 };
static __thread ul_buffer_t ul_buffer;
static __thread int ul_recurse;
@@ -93,7 +101,9 @@ ul_openlog (const char *ident, int option, int facility)
{
old_openlog (ident, option, facility);
ul_thread_data.flags = option;
- ul_thread_data.facility = facility;
+ pthread_mutex_lock (&ul_process_data.lock);
+ ul_process_data.facility = facility;
+ pthread_mutex_unlock (&ul_process_data.lock);
ul_thread_data.pid = getpid ();
ul_thread_data.gid = getgid ();
ul_thread_data.uid = getuid ();
@@ -107,6 +117,9 @@ ul_closelog (void)
{
old_closelog ();
memset (&ul_thread_data, 0, sizeof (ul_thread_data));
+ pthread_mutex_lock (&ul_process_data.lock);
+ ul_process_data.facility = 0;
+ pthread_mutex_unlock (&ul_process_data.lock);
}
/** HELPERS **/
@@ -117,7 +130,7 @@ _find_facility (int prio)
int fac = prio & LOG_FACMASK;
if (fac == 0)
- fac = ul_thread_data.facility;
+ fac = ul_process_data.facility;
while (facilitynames[i].c_name != NULL &&
facilitynames[i].c_val != fac)