X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flog.c;h=5c5b734f2f83c96a9bf7cb18cfdf89e630dbea0e;hb=66ccd0387e528567dff92239e85c962d2f140ef1;hp=b6d4bf9c1b80a4f47eb592b2dfb0e4d5011da83f;hpb=35b8ca3aaf8cb044ad76675dfcad89e000dd4a5c;p=elogind.git diff --git a/src/log.c b/src/log.c index b6d4bf9c1..5c5b734f2 100644 --- a/src/log.c +++ b/src/log.c @@ -231,6 +231,16 @@ void log_set_target(LogTarget target) { log_target = target; } +void log_close(void) { + log_close_console(); + log_close_kmsg(); + log_close_syslog(); +} + +void log_forget_fds(void) { + console_fd = kmsg_fd = syslog_fd = -1; +} + void log_set_max_level(int level) { assert((level & LOG_PRIMASK) == level); @@ -238,11 +248,11 @@ void log_set_max_level(int level) { } static int write_to_console( - int level, - const char*file, - int line, - const char *func, - const char *buffer) { + int level, + const char*file, + int line, + const char *func, + const char *buffer) { char location[64]; struct iovec iovec[5]; @@ -289,7 +299,7 @@ static int write_to_syslog( if (syslog_fd < 0) return 0; - snprintf(header_priority, sizeof(header_priority), "<%i>", LOG_MAKEPRI(LOG_DAEMON, LOG_PRI(level))); + snprintf(header_priority, sizeof(header_priority), "<%i>", level); char_array_0(header_priority); t = (time_t) (now(CLOCK_REALTIME) / USEC_PER_SEC); @@ -346,7 +356,7 @@ static int write_to_kmsg( if (kmsg_fd < 0) return 0; - snprintf(header_priority, sizeof(header_priority), "<%i>", LOG_PRI(level)); + snprintf(header_priority, sizeof(header_priority), "<%i>", level); char_array_0(header_priority); snprintf(header_pid, sizeof(header_pid), "[%lu]: ", (unsigned long) getpid()); @@ -377,6 +387,10 @@ static int log_dispatch( if (log_target == LOG_TARGET_NULL) return 0; + /* Patch in LOG_DAEMON facility if necessary */ + if ((level & LOG_FACMASK) == 0) + level = LOG_DAEMON | LOG_PRI(level); + do { char *e; int k = 0;