diff options
author | Miloslav Trmač <mitr@redhat.com> | 2012-07-24 13:55:21 +0200 |
---|---|---|
committer | Miloslav Trmač <mitr@redhat.com> | 2012-07-30 07:37:19 +0200 |
commit | 576705a6d8b7f46018d6522e8684ca147ab9c45f (patch) | |
tree | a944b0b610ff4a5e6389818da5e18e1eb0d42621 | |
parent | c66605420d513d259040a16ba13e5597c15e7769 (diff) | |
download | libumberlog-576705a6d8b7f46018d6522e8684ca147ab9c45f.tar.gz libumberlog-576705a6d8b7f46018d6522e8684ca147ab9c45f.tar.xz libumberlog-576705a6d8b7f46018d6522e8684ca147ab9c45f.zip |
Initialize PID to "no value cached"
Now syslog () without openlog () will include a correct PID value instead
of 0. Also reset the cache on closelog ().
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-rw-r--r-- | lib/umberlog.c | 4 | ||||
-rw-r--r-- | t/test_umberlog.c | 18 |
2 files changed, 20 insertions, 2 deletions
diff --git a/lib/umberlog.c b/lib/umberlog.c index 67ea63b..78f5510 100644 --- a/lib/umberlog.c +++ b/lib/umberlog.c @@ -77,7 +77,7 @@ static struct } ul_process_data = { PTHREAD_MUTEX_INITIALIZER, 0, LOG_USER, NULL, - 0, 0, 0, { 0, } + -1, 0, 0, { 0, } }; static __thread ul_buffer_t ul_buffer; @@ -124,7 +124,7 @@ ul_closelog (void) pthread_mutex_lock (&ul_process_data.lock); ul_process_data.ident = NULL; - ul_process_data.pid = 0; + ul_process_data.pid = -1; ul_process_data.gid = 0; ul_process_data.uid = 0; ul_process_data.hostname[0] = '\0'; diff --git a/t/test_umberlog.c b/t/test_umberlog.c index fdc48dc..aa50484 100644 --- a/t/test_umberlog.c +++ b/t/test_umberlog.c @@ -30,6 +30,22 @@ verify_value (struct json_object *jo, const char *key, } static void +verify_value_differs (struct json_object *jo, const char *key, + const char *unexpected_value) +{ + struct json_object *o; + const char *value; + + o = json_object_object_get (jo, key); + + ck_assert (o != NULL); + + value = json_object_get_string (o); + + ck_assert_str_ne (value, unexpected_value); +} + +static void verify_value_exists (struct json_object *jo, const char *key) { struct json_object *o; @@ -274,6 +290,7 @@ START_TEST (test_closelog) #else verify_value_missing (jo, "program"); #endif + verify_value_differs (jo, "pid", "0"); json_object_put (jo); } @@ -328,6 +345,7 @@ START_TEST (test_openlog_defaults) #else verify_value_missing (jo, "program"); #endif + verify_value_differs (jo, "pid", "0"); json_object_put (jo); closelog (); |