4 * Issue syslog messages via the kernel printk queue.
14 /* Maximum size for a kernel message */
18 #define LOGDEV "/dev/kmsg"
20 /* Max length of ID string */
21 #define MAXID 31 /* MAXID+5 must be < BUFLEN */
24 static char id[MAXID+1];
25 static int syslog_flags = 0;
27 void openlog(const char *ident, int option, int facility)
31 (void)option; (void)facility; /* Unused */
33 if ( __syslog_fd == -1 ) {
34 __syslog_fd = fd = open(LOGDEV, O_WRONLY);
37 fcntl(fd, F_SETFD, (long)FD_CLOEXEC);
40 syslog_flags = option;
42 strncpy(id, ident?ident:"", MAXID);
45 void vsyslog(int prio, const char *format, va_list ap)
51 if ( __syslog_fd == -1 )
55 buf[1] = LOG_PRI(prio)+'0';
59 if ( syslog_flags & LOG_PID )
60 len += sprintf(buf+3, "%s[%u]: ", id, getpid());
62 len += sprintf(buf+3, "%s: ", id);
64 len += vsnprintf(buf+len, BUFLEN-len, format, ap);
66 if ( len > BUFLEN-1 ) len = BUFLEN-1;
67 if (buf[len-1] != '\n')
72 fd = 2; /* Failed to open log, write to stderr */
76 if ( syslog_flags & LOG_PERROR )
77 _fwrite(buf+3, len-3, stderr);
80 void syslog(int prio, const char *format, ...)
85 vsyslog(prio, format, ap);