diff options
author | Miloslav Trmač <mitr@redhat.com> | 2012-07-24 12:44:32 +0200 |
---|---|---|
committer | Miloslav Trmač <mitr@redhat.com> | 2012-07-30 07:19:58 +0200 |
commit | 29fd70816db8d7b492734dadfd375362b7695876 (patch) | |
tree | 6d8ea410aecce7c3ddc85eb759482b3ae0fb5986 | |
parent | 58bc54dc373c4f2f710531b379c32f15e25d41eb (diff) | |
download | libumberlog-29fd70816db8d7b492734dadfd375362b7695876.tar.gz libumberlog-29fd70816db8d7b492734dadfd375362b7695876.tar.xz libumberlog-29fd70816db8d7b492734dadfd375362b7695876.zip |
Make "ident" (log tag) a per-process variable
... to comply with openlog(3p).
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-rw-r--r-- | lib/umberlog.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/umberlog.c b/lib/umberlog.c index 5fb9710..d0fe6b6 100644 --- a/lib/umberlog.c +++ b/lib/umberlog.c @@ -66,7 +66,6 @@ static __thread struct pid_t pid; uid_t uid; gid_t gid; - const char *ident; char hostname[_POSIX_HOST_NAME_MAX + 1]; } ul_thread_data; static struct @@ -76,7 +75,8 @@ static struct the BSD syslog does the same thing). */ pthread_mutex_t lock; int facility; -} ul_process_data = { PTHREAD_MUTEX_INITIALIZER, LOG_USER }; + const char *ident; +} ul_process_data = { PTHREAD_MUTEX_INITIALIZER, LOG_USER, NULL }; static __thread ul_buffer_t ul_buffer; static __thread int ul_recurse; @@ -103,11 +103,11 @@ ul_openlog (const char *ident, int option, int facility) ul_thread_data.flags = option; pthread_mutex_lock (&ul_process_data.lock); ul_process_data.facility = facility; + ul_process_data.ident = ident; pthread_mutex_unlock (&ul_process_data.lock); ul_thread_data.pid = getpid (); ul_thread_data.gid = getgid (); ul_thread_data.uid = getuid (); - ul_thread_data.ident = ident; gethostname (ul_thread_data.hostname, _POSIX_HOST_NAME_MAX); } @@ -117,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.ident = NULL; + pthread_mutex_unlock (&ul_process_data.lock); } /** HELPERS **/ @@ -489,7 +492,7 @@ _ul_discover (ul_buffer_t *buffer, int priority) "pid", "%d", _find_pid (), "facility", "%s", _find_facility (priority), "priority", "%s", _find_prio (priority), - "program", "%s", ul_thread_data.ident, + "program", "%s", ul_process_data.ident, "uid", "%d", _get_uid (), "gid", "%d", _get_gid (), "host", "%s", _get_hostname (), |