chiark / gitweb /
util: add is_main_thread() call
[elogind.git] / src / logger.c
index 710dfed33bc9b12a0e0a6bfef38e41aef6507ff8..81196dbe00cd0e0734989d22149439bd5e040d14 100644 (file)
 #include "list.h"
 #include "sd-daemon.h"
 #include "tcpwrap.h"
+#include "def.h"
 
 #define STREAMS_MAX 4096
 #define SERVER_FD_MAX 16
-#define TIMEOUT ((int) (5*60*MSEC_PER_SEC))
+#define TIMEOUT_MSEC ((int) (DEFAULT_EXIT_USEC/USEC_PER_MSEC))
 
 typedef struct Stream Stream;
 
@@ -93,42 +94,6 @@ struct Stream {
         LIST_FIELDS(Stream, stream);
 };
 
-static void parse_priority(char **p, int *priority) {
-        int a = 0, b = 0, c = 0;
-        int k;
-
-        assert(p);
-        assert(*p);
-        assert(priority);
-
-        if ((*p)[0] != '<')
-                return;
-
-        if (!strchr(*p, '>'))
-                return;
-
-        if ((*p)[2] == '>') {
-                c = undecchar((*p)[1]);
-                k = 3;
-        } else if ((*p)[3] == '>') {
-                b = undecchar((*p)[1]);
-                c = undecchar((*p)[2]);
-                k = 4;
-        } else if ((*p)[4] == '>') {
-                a = undecchar((*p)[1]);
-                b = undecchar((*p)[2]);
-                c = undecchar((*p)[3]);
-                k = 5;
-        } else
-                return;
-
-        if (a < 0 || b < 0 || c < 0)
-                return;
-
-        *priority = a*100+b*10+c;
-        *p += k;
-}
-
 static int stream_log(Stream *s, char *p, usec_t ts) {
 
         char header_priority[16], header_time[64], header_pid[16];
@@ -141,25 +106,14 @@ static int stream_log(Stream *s, char *p, usec_t ts) {
         priority = s->priority;
 
         if (s->prefix)
-                parse_priority(&p, &priority);
-
-        if (s->prefix &&
-            p[0] == '<' &&
-            p[1] >= '0' && p[1] <= '7' &&
-            p[2] == '>') {
-
-                /* Detected priority prefix */
-                priority = LOG_MAKEPRI(LOG_FAC(priority), (p[1] - '0'));
-
-                p += 3;
-        }
+                parse_syslog_priority(&p, &priority);
 
         if (*p == 0)
                 return 0;
 
         /* Patch in LOG_USER facility if necessary */
-        if (LOG_FAC(priority) == 0)
-                priority = LOG_MAKEPRI(LOG_USER, LOG_PRI(priority));
+        if ((priority & LOG_FACMASK) == 0)
+                priority = LOG_USER | LOG_PRI(priority);
 
         /*
          * The format glibc uses to talk to the syslog daemon is:
@@ -708,7 +662,7 @@ int main(int argc, char *argv[]) {
 
                 if ((k = epoll_wait(server.epoll_fd,
                                     &event, 1,
-                                    server.n_streams <= 0 ? TIMEOUT : -1)) < 0) {
+                                    server.n_streams <= 0 ? TIMEOUT_MSEC : -1)) < 0) {
 
                         if (errno == EINTR)
                                 continue;