diff options
| author | Gergely Nagy <algernon@balabit.hu> | 2012-04-20 13:14:29 +0200 |
|---|---|---|
| committer | Gergely Nagy <algernon@balabit.hu> | 2012-04-20 13:14:29 +0200 |
| commit | 5509ee80130cb781d0c88d411021a98b5fab4556 (patch) | |
| tree | 6300f9ca839c39e0deb952cc7e5c95d31d84a108 /lib | |
| parent | 32887a13759b27f5b29f585d2b278c225be1fa0d (diff) | |
| download | libumberlog-5509ee80130cb781d0c88d411021a98b5fab4556.tar.gz libumberlog-5509ee80130cb781d0c88d411021a98b5fab4556.tar.xz libumberlog-5509ee80130cb781d0c88d411021a98b5fab4556.zip | |
Resolve facility & priority properly
The priority passed to the syslog() call can contain a facility
embedded, so we need to extract it to find both the facility and the
priority.
This also means that the facility set at openlog()-time can be
overridden later, so _find_facility() has to take the priority value
into account.
This patch makes libumberlog do just the above: extract both priority
and facility from the priority passed to syslog(), and if facility is
0, use the default set at openlog()-time, if any.
Added a test case to test this expected behaviour.
Reported-by: Peter Czanik <czanik@balabit.hu>
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/umberlog.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/umberlog.c b/lib/umberlog.c index d07a24a..ad25709 100644 --- a/lib/umberlog.c +++ b/lib/umberlog.c @@ -101,15 +101,19 @@ ul_openlog (const char *ident, int option, int facility) /** HELPERS **/ static inline const char * -_find_facility (void) +_find_facility (int prio) { int i = 0; + int fac = prio & LOG_FACMASK; + + if (fac == 0) + fac = ul_sys_settings.facility; while (facilitynames[i].c_name != NULL && - facilitynames[i].c_val != ul_sys_settings.facility) + facilitynames[i].c_val != fac) i++; - if (facilitynames[i].c_val == ul_sys_settings.facility) + if (facilitynames[i].c_val == fac) return facilitynames[i].c_name; return "<unknown>"; } @@ -118,12 +122,13 @@ static inline const char * _find_prio (int prio) { int i = 0; + int pri = LOG_PRI (prio); while (prioritynames[i].c_name != NULL && - prioritynames[i].c_val != prio) + prioritynames[i].c_val != pri) i++; - if (prioritynames[i].c_val == prio) + if (prioritynames[i].c_val == pri) return prioritynames[i].c_name; return "<unknown>"; } @@ -316,7 +321,7 @@ _ul_discover (ul_buffer_t *buffer, int priority) buffer = _ul_json_append (buffer, "pid", "%d", _find_pid (), - "facility", "%s", _find_facility (), + "facility", "%s", _find_facility (priority), "priority", "%s", _find_prio (priority), "program", "%s", ul_sys_settings.ident, "uid", "%d", _get_uid (), |
