2 #include <sys/socket.h>
13 static const char *log_ident;
15 static int log_facility = LOG_USER;
16 static int log_mask = 0xff;
17 static int log_fd = -1;
19 int setlogmask(int maskpri)
22 if (maskpri) log_mask = maskpri;
42 static void __openlog(const char *ident, int opt, int facility)
46 log_facility = facility;
48 if (!(opt & LOG_NDELAY) || log_fd>=0) return;
50 log_fd = socket(AF_UNIX, SOCK_DGRAM, 0);
51 fcntl(log_fd, F_SETFD, FD_CLOEXEC);
54 void openlog(const char *ident, int opt, int facility)
57 __openlog(ident, opt, facility);
61 void __vsyslog(int priority, const char *message, va_list ap)
70 if (!(log_mask & LOG_MASK(priority&7)) || (priority&~0x3ff)) return;
75 __openlog(log_ident, log_opt | LOG_NDELAY, log_facility);
84 strftime(timebuf, sizeof timebuf, "%b %e %T", &tm);
86 pid = (log_opt & LOG_PID) ? getpid() : 0;
87 l = snprintf(buf, sizeof buf, "<%d>%s %s%s%.0d%s: ",
89 log_ident ? log_ident : "",
90 "["+!pid, pid, "]"+!pid);
91 l2 = vsnprintf(buf+l, sizeof buf - l, message, ap);
94 if (buf[l-1] != '\n') buf[l++] = '\n';
95 sendto(log_fd, buf, l, 0, (void *)&log_addr, 11);
101 void syslog(int priority, const char *message, ...)
104 va_start(ap, message);
105 __vsyslog(priority, message, ap);
109 weak_alias(__vsyslog, vsyslog);