diff options
| author | Gergely Nagy <algernon@balabit.hu> | 2012-03-20 11:56:30 +0100 |
|---|---|---|
| committer | Gergely Nagy <algernon@balabit.hu> | 2012-03-20 11:56:30 +0100 |
| commit | 4b1861e787693113e759c44519dd4396ee3dc0cd (patch) | |
| tree | 47ece5b5b69ca3476a342000b18b5921b9c4c6dd /lib/cee-syslog.c | |
| parent | 1e062b1f74e499e39564da1485063e149c883df3 (diff) | |
| download | libumberlog-4b1861e787693113e759c44519dd4396ee3dc0cd.tar.gz libumberlog-4b1861e787693113e759c44519dd4396ee3dc0cd.tar.xz libumberlog-4b1861e787693113e759c44519dd4396ee3dc0cd.zip | |
Implement UID/GID discovery.
We now cache the uid and gid upon openlog(), and add it to the
automatic fields unless discovery is disabled.
The caching can be turned off by passing either the LOG_CEE_NOCACHE or
the LOG_CEE_NOCACHE_UID flag to openlog(). The latter also disables
caching the gid.
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
Diffstat (limited to 'lib/cee-syslog.c')
| -rw-r--r-- | lib/cee-syslog.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/lib/cee-syslog.c b/lib/cee-syslog.c index 60d8517..0256164 100644 --- a/lib/cee-syslog.c +++ b/lib/cee-syslog.c @@ -53,6 +53,8 @@ static __thread struct int facility; pid_t pid; + uid_t uid; + gid_t gid; const char *ident; } cee_sys_settings; @@ -72,6 +74,8 @@ cee_openlog (const char *ident, int option, int facility) cee_sys_settings.flags = option; cee_sys_settings.facility = facility; cee_sys_settings.pid = getpid (); + cee_sys_settings.gid = getgid (); + cee_sys_settings.uid = getuid (); cee_sys_settings.ident = ident; } @@ -104,7 +108,7 @@ _find_prio (int prio) return "<unknown>"; } -static inline const pid_t +static inline pid_t _find_pid (void) { if (cee_sys_settings.flags & LOG_CEE_NOCACHE) @@ -113,6 +117,26 @@ _find_pid (void) return cee_sys_settings.pid; } +static inline uid_t +_get_uid (void) +{ + if (cee_sys_settings.flags & LOG_CEE_NOCACHE || + cee_sys_settings.flags & LOG_CEE_NOCACHE_UID) + return getuid (); + else + return cee_sys_settings.uid; +} + +static inline uid_t +_get_gid (void) +{ + if (cee_sys_settings.flags & LOG_CEE_NOCACHE || + cee_sys_settings.flags & LOG_CEE_NOCACHE_UID) + return getgid (); + else + return cee_sys_settings.gid; +} + static struct json_object * _cee_json_vappend (struct json_object *json, va_list ap) { @@ -153,6 +177,8 @@ _cee_discover (struct json_object *jo, int priority) "facility", "%s", _find_facility (), "priority", "%s", _find_prio (priority), "program", "%s", cee_sys_settings.ident, + "uid", "%d", _get_uid (), + "gid", "%d", _get_gid (), NULL); } |
