summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2012-07-24 13:52:40 +0200
committerMiloslav Trmač <mitr@redhat.com>2012-07-30 07:29:14 +0200
commitc66605420d513d259040a16ba13e5597c15e7769 (patch)
tree8c0ac0755af04a3c15f36ad4a7546b6e2f2bd625
parent4751e93b9d621ab32d01380c55d886b38f4cfe44 (diff)
downloadlibumberlog-c66605420d513d259040a16ba13e5597c15e7769.tar.gz
libumberlog-c66605420d513d259040a16ba13e5597c15e7769.tar.xz
libumberlog-c66605420d513d259040a16ba13e5597c15e7769.zip
Mark missing PID cache data separately from flags.
This simplifies the syslog() path a little, and allows us to express "PID should be cached but no value is set.". Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-rw-r--r--lib/umberlog.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/umberlog.c b/lib/umberlog.c
index 8396ad7..67ea63b 100644
--- a/lib/umberlog.c
+++ b/lib/umberlog.c
@@ -69,7 +69,8 @@ static struct
int facility;
const char *ident;
- pid_t pid;
+ /* Cached data */
+ pid_t pid; /* -1 = no value cached */
uid_t uid;
gid_t gid;
char hostname[_POSIX_HOST_NAME_MAX + 1];
@@ -106,7 +107,10 @@ ul_openlog (const char *ident, int option, int facility)
ul_process_data.facility = facility;
ul_process_data.ident = ident;
- ul_process_data.pid = getpid ();
+ if ((ul_process_data.flags & LOG_UL_NOCACHE) != 0)
+ ul_process_data.pid = -1;
+ else
+ ul_process_data.pid = getpid ();
ul_process_data.gid = getgid ();
ul_process_data.uid = getuid ();
gethostname (ul_process_data.hostname, _POSIX_HOST_NAME_MAX);
@@ -164,10 +168,12 @@ _find_prio (int prio)
static inline pid_t
_find_pid (void)
{
- if (ul_process_data.flags & LOG_UL_NOCACHE)
- return getpid ();
- else
- return ul_process_data.pid;
+ pid_t pid;
+
+ pid = ul_process_data.pid;
+ if (pid == -1)
+ pid = getpid ();
+ return pid;
}
static inline uid_t