diff --git a/libc/nt/advapi32/DeregisterEventSource.s b/libc/nt/advapi32/DeregisterEventSource.s index d1c3d2643..f8ec53bd1 100644 --- a/libc/nt/advapi32/DeregisterEventSource.s +++ b/libc/nt/advapi32/DeregisterEventSource.s @@ -1,2 +1,15 @@ .include "o/libc/nt/codegen.inc" .imp advapi32,__imp_DeregisterEventSource,DeregisterEventSource,1239 + + .text.windows +DeregisterEventSource: + push %rbp + mov %rsp,%rbp + .profilable + mov %rdi,%rcx + sub $32,%rsp + call *__imp_DeregisterEventSource(%rip) + leave + ret + .endfn DeregisterEventSource,globl + .previous diff --git a/libc/nt/advapi32/RegisterEventSourceA.s b/libc/nt/advapi32/RegisterEventSourceA.s index 2830af98b..e742c3632 100644 --- a/libc/nt/advapi32/RegisterEventSourceA.s +++ b/libc/nt/advapi32/RegisterEventSourceA.s @@ -1,2 +1,12 @@ .include "o/libc/nt/codegen.inc" .imp advapi32,__imp_RegisterEventSourceA,RegisterEventSourceA,1686 + + .text.windows +RegisterEventSourceA: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_RegisterEventSourceA(%rip),%rax + jmp __sysv2nt + .endfn RegisterEventSourceA,globl + .previous diff --git a/libc/nt/advapi32/RegisterEventSourceW.s b/libc/nt/advapi32/RegisterEventSourceW.s index 21b73b787..02816012d 100644 --- a/libc/nt/advapi32/RegisterEventSourceW.s +++ b/libc/nt/advapi32/RegisterEventSourceW.s @@ -1,2 +1,12 @@ .include "o/libc/nt/codegen.inc" .imp advapi32,__imp_RegisterEventSourceW,RegisterEventSourceW,1687 + + .text.windows +RegisterEventSource: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_RegisterEventSourceW(%rip),%rax + jmp __sysv2nt + .endfn RegisterEventSource,globl + .previous diff --git a/libc/nt/advapi32/ReportEventA.s b/libc/nt/advapi32/ReportEventA.s index e9d133b36..fb61edaef 100644 --- a/libc/nt/advapi32/ReportEventA.s +++ b/libc/nt/advapi32/ReportEventA.s @@ -1,2 +1,12 @@ .include "o/libc/nt/codegen.inc" .imp advapi32,__imp_ReportEventA,ReportEventA,1704 + + .text.windows +ReportEventA: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_ReportEventA(%rip),%rax + jmp __sysv2nt10 + .endfn ReportEventA,globl + .previous diff --git a/libc/nt/advapi32/ReportEventW.s b/libc/nt/advapi32/ReportEventW.s index 294ac6261..683e07733 100644 --- a/libc/nt/advapi32/ReportEventW.s +++ b/libc/nt/advapi32/ReportEventW.s @@ -1,2 +1,12 @@ .include "o/libc/nt/codegen.inc" .imp advapi32,__imp_ReportEventW,ReportEventW,1705 + + .text.windows +ReportEvent: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_ReportEventW(%rip),%rax + jmp __sysv2nt10 + .endfn ReportEvent,globl + .previous diff --git a/libc/nt/events.h b/libc/nt/events.h index f6a2eee09..8530bc22b 100644 --- a/libc/nt/events.h +++ b/libc/nt/events.h @@ -39,6 +39,19 @@ bool32 GetCursorPos(struct NtPoint *lpPoint); int64_t SendMessage(int64_t hWnd, uint32_t Msg, uint64_t wParam, int64_t lParam); +#define EVENTLOG_SUCCESS 0x00000000 +#define EVENTLOG_ERROR_TYPE 0x00000001 +#define EVENTLOG_WARNING_TYPE 0x00000002 +#define EVENTLOG_INFORMATION_TYPE 0x00000004 +#define EVENTLOG_AUDIT_SUCCESS 0x00000008 +#define EVENTLOG_AUDIT_FAILURE 0x00000010 + +int32_t ReportEventA(int64_t handle, uint16_t wType, uint16_t wCategory, + uint32_t dwEventID, const char *lpUserId, uint16_t wNumStrings, + uint32_t dwDataSize, const char **lpStrings, void **lpRawData); +int64_t RegisterEventSourceA(const char *lpUNCServerName, const char *lpSourceName); +int32_t DeregisterEventSource(uint64_t handle); + COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_EVENTS_H_ */ diff --git a/libc/nt/master.sh b/libc/nt/master.sh index 31f681421..d4257064b 100755 --- a/libc/nt/master.sh +++ b/libc/nt/master.sh @@ -1214,7 +1214,7 @@ imp 'DeleteUmsThreadContext' DeleteUmsThreadContext kernel32 284 imp 'DeleteVolumeMountPointA' DeleteVolumeMountPointA kernel32 285 imp 'DeleteVolumeMountPoint' DeleteVolumeMountPointW kernel32 0 # KernelBase imp 'DequeueUmsCompletionListItems' DequeueUmsCompletionListItems kernel32 287 -imp 'DeregisterEventSource' DeregisterEventSource advapi32 1239 +imp 'DeregisterEventSource' DeregisterEventSource advapi32 1239 1 imp 'DeregisterShellHookWindow' DeregisterShellHookWindow user32 1682 imp 'DeriveCapabilitySidsFromName' DeriveCapabilitySidsFromName KernelBase 263 imp 'DescribePixelFormat' DescribePixelFormat gdi32 1388 @@ -4652,8 +4652,8 @@ imp 'RegisterDManipHook' RegisterDManipHook user32 2254 imp 'RegisterDeviceNotificationA' RegisterDeviceNotificationA user32 2255 imp 'RegisterDeviceNotification' RegisterDeviceNotificationW user32 2256 imp 'RegisterErrorReportingDialog' RegisterErrorReportingDialog user32 2257 -imp 'RegisterEventSourceA' RegisterEventSourceA advapi32 1686 -imp 'RegisterEventSource' RegisterEventSourceW advapi32 1687 +imp 'RegisterEventSourceA' RegisterEventSourceA advapi32 1686 2 +imp 'RegisterEventSource' RegisterEventSourceW advapi32 1687 2 imp 'RegisterFrostWindow' RegisterFrostWindow user32 2258 imp 'RegisterGPNotificationInternal' RegisterGPNotificationInternal KernelBase 1385 imp 'RegisterGhostWindow' RegisterGhostWindow user32 2259 @@ -4737,8 +4737,8 @@ imp 'ReplacePartitionUnit' ReplacePartitionUnit kernel32 1217 imp 'ReplaceTextA' ReplaceTextA comdlg32 124 1 imp 'ReplaceText' ReplaceTextW comdlg32 125 1 imp 'ReplyMessage' ReplyMessage user32 2288 -imp 'ReportEventA' ReportEventA advapi32 1704 -imp 'ReportEvent' ReportEventW advapi32 1705 +imp 'ReportEventA' ReportEventA advapi32 1704 9 +imp 'ReportEvent' ReportEventW advapi32 1705 9 imp 'ReportInertia' ReportInertia user32 2551 imp 'RequestDeviceWakeup' RequestDeviceWakeup kernel32 1218 imp 'RequestWakeupLatency' RequestWakeupLatency kernel32 1219 diff --git a/libc/sock/bind.c b/libc/sock/bind.c index a01cba665..d9b28a4a3 100644 --- a/libc/sock/bind.c +++ b/libc/sock/bind.c @@ -41,10 +41,10 @@ int bind(int fd, const void *addr, uint32_t addrsize) { if (!IsBsd()) { return sys_bind(fd, addr, addrsize); } else { - struct sockaddr_in_bsd addr2; - assert(sizeof(struct sockaddr_in) == sizeof(struct sockaddr_in_bsd)); - memcpy(&addr2, addr, sizeof(struct sockaddr_in)); - sockaddr2bsd(&addr2); + char addr2[sizeof(struct sockaddr_un_bsd)]; /* sockaddr_un_bsd is the largest */ + assert(addrsize <= sizeof(addr2)); + memcpy(&addr2, addr, addrsize); + sockaddr2bsd(&addr2[0]); return sys_bind(fd, &addr2, addrsize); } } else if (__isfdkind(fd, kFdSocket)) { diff --git a/libc/sock/connect-sysv.c b/libc/sock/connect-sysv.c index 94455d035..cc8de8e72 100644 --- a/libc/sock/connect-sysv.c +++ b/libc/sock/connect-sysv.c @@ -23,14 +23,13 @@ #include "libc/sysv/errfuns.h" int sys_connect(int fd, const void *addr, uint32_t addrsize) { - if (addrsize != sizeof(struct sockaddr_in)) return einval(); if (!IsBsd()) { return __sys_connect(fd, addr, addrsize); } else { - struct sockaddr_in_bsd addr2; - assert(sizeof(struct sockaddr_in) == sizeof(struct sockaddr_in_bsd)); - memcpy(&addr2, addr, sizeof(struct sockaddr_in)); - sockaddr2bsd(&addr2); - return sys_connect(fd, &addr2, addrsize); + char addr2[sizeof(struct sockaddr_un_bsd)]; /* sockaddr_un_bsd is the largest */ + assert(addrsize <= sizeof(addr2)); + memcpy(&addr2, addr, addrsize); + sockaddr2bsd(&addr2[0]); + return __sys_connect(fd, &addr2, addrsize); } } diff --git a/libc/sock/internal.h b/libc/sock/internal.h index 1a9c38838..2ea9b0aa0 100644 --- a/libc/sock/internal.h +++ b/libc/sock/internal.h @@ -46,6 +46,12 @@ struct msghdr_bsd { uint32_t msg_flags; /* « different type */ }; +struct sockaddr_un_bsd { + uint8_t sun_len; /* sockaddr len including NUL on freebsd but excluding it on openbsd/xnu */ + uint8_t sun_family; + char sun_path[108]; +}; + struct SockFd { int family; int type; diff --git a/libc/sock/sendto.c b/libc/sock/sendto.c index 7b30d6675..44b40140f 100644 --- a/libc/sock/sendto.c +++ b/libc/sock/sendto.c @@ -47,16 +47,15 @@ */ ssize_t sendto(int fd, const void *buf, size_t size, uint32_t flags, const void *opt_addr, uint32_t addrsize) { - assert(sizeof(struct sockaddr_in) == sizeof(struct sockaddr_in_bsd)); if (!IsWindows()) { if (!IsBsd() || !opt_addr) { return sys_sendto(fd, buf, size, flags, opt_addr, addrsize); } else { - struct sockaddr_in_bsd addr2; - if (addrsize != sizeof(addr2)) return einval(); - memcpy(&addr2, opt_addr, sizeof(struct sockaddr_in)); - sockaddr2bsd(&addr2); - return sys_sendto(fd, buf, size, flags, &addr2, addrsize); + char addr2[sizeof(struct sockaddr_un_bsd)]; /* sockaddr_un_bsd is the largest */ + if (addrsize > sizeof(addr2)) return einval(); + memcpy(&addr2, opt_addr, addrsize); + sockaddr2bsd(&addr2[0]); + return sys_sendto(fd, buf, size, flags, &addr2[0], addrsize); } } else if (__isfdkind(fd, kFdSocket)) { return sys_sendto_nt(&g_fds.p[fd], (struct iovec[]){{buf, size}}, 1, flags, diff --git a/libc/sock/sock.h b/libc/sock/sock.h index b40bc2955..71ca50fe1 100644 --- a/libc/sock/sock.h +++ b/libc/sock/sock.h @@ -40,6 +40,11 @@ struct sockaddr_in { /* Linux+NT ABI */ uint8_t sin_zero[8]; }; +struct sockaddr_un { + uint16_t sun_family; /* AF_UNIX */ + char sun_path[108];/* path */ +}; + struct sockaddr_storage { union { uint16_t ss_family; diff --git a/libc/sock/sock.mk b/libc/sock/sock.mk index 217c2c88a..6c533a50b 100644 --- a/libc/sock/sock.mk +++ b/libc/sock/sock.mk @@ -24,8 +24,11 @@ LIBC_SOCK_A_DIRECTDEPS = \ LIBC_FMT \ LIBC_INTRIN \ LIBC_MEM \ + LIBC_TIME \ + LIBC_STR \ + LIBC_UNICODE \ LIBC_NEXGEN32E \ - LIBC_NT_KERNEL32 \ + LIBC_NT_ADVAPI32 \ LIBC_NT_KERNEL32 \ LIBC_NT_MSWSOCK \ LIBC_NT_NTDLL \ diff --git a/libc/sock/syslog.c b/libc/sock/syslog.c new file mode 100644 index 000000000..b07d35e2b --- /dev/null +++ b/libc/sock/syslog.c @@ -0,0 +1,343 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2020 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/dce.h" +#include "libc/errno.h" +#include "libc/fmt/fmt.h" +#include "libc/log/internal.h" +#include "libc/sysv/consts/log.h" +#include "libc/sysv/consts/o.h" +#include "libc/sysv/consts/af.h" +#include "libc/sysv/consts/sock.h" +#include "libc/runtime/valist.h" +#include "libc/stdio/stdio.h" +#include "libc/calls/calls.h" +#include "libc/str/str.h" +#include "libc/time/struct/tm.h" +#include "libc/time/time.h" +#include "libc/calls/weirdtypes.h" +#include "libc/sock/sock.h" +#include "libc/sock/syslog.h" +#include "libc/nt/runtime.h" +#include "libc/nt/events.h" + +/* Note: log_facility should be initialized with LOG_USER by default, + * but since LOG_USER is not a constant value, we cannot initialize it + * here. Set it to -1 to force the public functions to call __initlog() + * for the first time. + */ +static int log_facility = -1; +static char log_ident[32]; +static int log_opt; +static int log_mask; +static uint16_t log_id; /* Used for Windows EvtID */ +static int64_t log_fd = -1; + + +static const struct sockaddr_un log_addr = { + AF_UNIX, + "/dev/log" +}; + + +static void __initlog() { + log_ident[0] = '\0'; + log_opt = LOG_ODELAY; + log_facility = LOG_USER; + log_mask = LOG_PRI(0xff); // Initially use max verbosity + log_fd = -1; +} + +forceinline int is_lost_conn(int e) { + return (e==ECONNREFUSED) || + (e==ECONNRESET) || + (e==ENOTCONN) || + (e==EPIPE); +} + +static void __openlog() { + if (IsWindows()) { + log_fd = RegisterEventSourceA(NULL, log_ident); + } else { + log_fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0); + if (log_fd >= 0) { + int rc = connect(log_fd, (void *)&log_addr, sizeof(log_addr)); + if (rc < 0) { + printf("ERR: connect(openlog) failed: %s (errno=%d)\n", strerror(errno), errno); + } + } + } +} + + +/** + * Generates a log message which will be distributed by syslogd + * + * Note: no errors are reported if an error occurred while logging + * the message. + * + * @param priority is a bitmask containing the facility value and + * the level value. If no facility value is ORed into priority, + * then the default value set by openlog() is used. + * it set to NULL, the program name is used. + * Level is one of LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, + * LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG + * @param message the format of the message to be processed by vprintf() + * @param ap the va_list of arguments to be applied to the message + * @asyncsignalsafe + */ +void vsyslog(int priority, const char *message, va_list ap) { + char timebuf[16]; /* Store formatted time */ + time_t now; + struct tm tm; + char buf[1024]; + int errno_save = errno; /* Save current errno */ + int pid; + int l, l2; + int hlen; /* If LOG_CONS is specified, use to store the point in + * the header message after the timestamp */ + + if (log_fd < 0) __openlog(); + + if (!(priority & LOG_FACMASK)) priority |= log_facility; + + /* Build the time string */ + now = time(NULL); + gmtime_r(&now, &tm); + strftime(timebuf, sizeof(timebuf), "%b %e %T", &tm); + + pid = (log_opt & LOG_PID) ? getpid() : 0; + /* This is a clever trick to optionally include "[]" + * only if pid != 0. When pid==0, the while "[%.0d]" is skipped: + * %s%.0d%s -> String, pidValue, String + * Each of those %s: + * - if pid == 0 -> !pid is true (1), so "[" + 1 points to the + * NULL terminator after the "[". + * - if pid != 0 -> !pid is false (0), so the string printed is + * the "[". + */ + l = snprintf(buf, sizeof(buf), "<%d>%s ", priority, timebuf); + hlen = l; + l += snprintf(buf+l, sizeof(buf)-l, "%s%s%.0d%s: ", log_ident, "["+!pid, pid, "]"+!pid); + errno = errno_save; + + /* Append user message */ + l2 = vsnprintf(buf+l, sizeof(buf)-l, message, ap); + if (l2 >= 0) { + if (l2 >= sizeof(buf) - l) { + l = sizeof(buf) - 1; + } else { + l += l2; + } + if (buf[l-1] != '\n') { + buf[l++] = '\n'; + } + if (!IsWindows()) { + /* Unix: + * - First try to send it to syslogd + * - If fails and LOG_CONS is provided, writes to /dev/console + */ + +#if 0 + if (send(log_fd, buf, l, 0) < 0 && (!is_lost_conn(errno) + || connect(log_fd, (void *)&log_addr, sizeof(log_addr)) < 0 + || send(log_fd, buf, l, 0) < 0) + && (log_opt & LOG_CONS)) { + int fd = open("/dev/console", O_WRONLY|O_NOCTTY); + if (fd >= 0) { + dprintf(fd, "%.*s", l-hlen, buf+hlen); + close(fd); + } + } +#else + int rc = send(log_fd, buf, l, 0); + if (rc < 0) { + printf("ERR: send(1) failed: %s (errno=%d)\n", strerror(errno), errno); + if (!is_lost_conn(errno)) { + rc = connect(log_fd, (void *)&log_addr, sizeof(log_addr)); + if (rc < 0) { + printf("ERR: connect(syslog) failed: %s (errno=%d)\n", strerror(errno), errno); + } else { + rc = send(log_fd, buf, l, 0); + if (rc < 0) { + printf("ERR: send(2) failed: %s (errno=%d)\n", strerror(errno), errno); + } + } + } + } +#endif + } else { + uint16_t evtType; + uint32_t evtID; + const char *bufArr[] = { &buf[hlen] }; /* Only print the message without time*/ + /* Windows only have 3 usable event types + * Event ID are not supported + * For more information on message types and event IDs, see: + * https://docs.microsoft.com/en-us/windows/win32/eventlog/event-identifiers + */ + priority &= LOG_PRIMASK; // Remove facility from the priority field + if (priority == LOG_EMERG || + priority == LOG_ALERT || + priority == LOG_CRIT) { + evtType = EVENTLOG_ERROR_TYPE; + evtID = 0xe << 28 | (LOG_USER) << 16; + } else if (priority == LOG_WARNING) { + evtType = EVENTLOG_WARNING_TYPE; + evtID = 0xa << 28 | (LOG_USER) << 16; + } else { + /* LOG_NOTICE, LOG_INFO, LOG_DEBUG */ + evtType = EVENTLOG_INFORMATION_TYPE; + evtID = 0x6 << 28 | (LOG_USER) << 16; + } + ReportEventA(log_fd, + evtType, /* Derived from priority */ + 0 /* Category unsupported */, + evtID, /* Unsupported */ + NULL, /* User SID */ + 1, /* Number of strings */ + 0, /* Raw data size */ + bufArr, /* String(s) */ + NULL /* Arguments */ ); + ++log_id; + } + + if (log_opt & LOG_PERROR) dprintf(2, "%.*s", l-hlen, buf+hlen); + } +} + + +/** + * Sets log priority mask + * + * Modifies the log priority mask that determines which calls to + * syslog() may be logged. + * Log priority values are LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, + * LOG_WARNING, LOG_NOTICE, LOG_INFO, and LOG_DEBUG. + * + * @param mask the new priority mask to use by syslog() + * @return the previous log priority mask + * @asyncsignalsafe + */ +int setlogmask(int maskpri) { + int ret; + if (log_facility == -1) { + __initlog(); + } + ret = log_mask; + if (maskpri) log_mask = LOG_PRI(maskpri); + return ret; +} + + +/** + * Opens a connection to the system logger + * + * Calling this function before calling syslog() is optional and + * only allow customizing the identity, options and facility of + * the messages logged. + * + * @param ident a string that prepends every logged message. If + * it set to NULL, the program name is used. + * @param opt specifies flags which control the operation of openlog(). + * Only the following flags are supported: + * LOG_CONS = Write directly to the system console if there is + * an error while sending to the system logger. + * LOG_NDELAY = Open the connection with the system logger + * immediately instead of waiting for the first + * message to be logged. + * LOG_ODELAY = The converse of LOG_NDELAY. + * LOG_PERROR = Also log the message to stderr. + * LOG_PID = Include the caller's PID with each message + * @param facility specifies the default facitlity value that defines + * what kind of program is logging the message. + * Possible values are: LOG_AUTH, LOG_AUTHPRIV, + * LOG_CRON, LOG_DAEMON, LOG_FTP, LOG_LOCAL0 through LOG_LOCAL7, + * LOG_LPR, LOG_MAIL, LOG_NEWS, LOG_SYSLOG, LOG_USER (default), + * LOG_UUCP. + * @asyncsignalsafe + */ +void openlog(const char *ident, int opt, int facility) { + size_t n; + + if (log_facility == -1) { + __initlog(); + } + if (!ident) { + ident = program_invocation_short_name; + } + n = strnlen(ident, sizeof(log_ident) - 1); + memcpy(log_ident, ident, n); + log_ident[n] = 0; + log_opt = opt; + log_facility = facility; + log_id = 0; + + if ((opt & LOG_NDELAY) && log_fd<0) __openlog(); +} + + +/** + * Generates a log message which will be distributed by syslogd + * + * Note: no errors are reported if an error occurred while logging + * the message. + * + * @param priority is a bitmask containing the facility value and + * the level value. If no facility value is ORed into priority, + * then the default value set by openlog() is used. + * it set to NULL, the program name is used. + * Level is one of LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, + * LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG + * @param message the message formatted using the same rules as printf() + * @asyncsignalsafe + */ +void syslog(int priority, const char *message, ...) { + va_list ap; + if (log_facility == -1) { + __initlog(); + } + if (LOG_PRI(priority) <= log_mask) { + va_start(ap, message); + vsyslog(priority, message, ap); + va_end(ap); + } +} + + +/** + * Closes the file descriptor being used to write to the system logger + * + * Use of closelog is optional + * @asyncsignalsafe + */ +void closelog(void) { + if (log_facility == -1) { + __initlog(); + } + if (log_fd == -1) { + return; + } + if (IsWindows()) { + DeregisterEventSource(log_fd); + } else { + close(log_fd); + } + log_fd = -1; +} + + diff --git a/libc/sock/syslog.h b/libc/sock/syslog.h new file mode 100644 index 000000000..5342509bb --- /dev/null +++ b/libc/sock/syslog.h @@ -0,0 +1,18 @@ +#ifndef COSMOPOLITAN_LIBC_SOCK_SYSLOG_H_ +#define COSMOPOLITAN_LIBC_SOCK_SYSLOG_H_ + + +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +#define LOG_PRI(p) ((p) & LOG_PRIMASK) + +int setlogmask(int); +void openlog(const char *, int, int); +void syslog(int, const char *, ...); +void closelog(void); +void vsyslog(int, const char *, va_list); + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_SOCK_SYSLOG_H_ */ diff --git a/libc/sysv/consts.sh b/libc/sysv/consts.sh index 59c3a5538..acedc624a 100755 --- a/libc/sysv/consts.sh +++ b/libc/sysv/consts.sh @@ -22,7 +22,7 @@ dir=libc/sysv/consts # The Fifth Bell System, Community Edition # » catalogue of carnage # -# group name GNU/Systemd XNU's Not UNIX FreeBSD OpenBSD NetBSD XENIX Commentary +# group name GNU/Systemd XNU's Not UNIX FreeBSD OpenBSD NetBSD Windows Commentary syscon errno ENOSYS 38 78 78 78 78 1 # bsd consensus & kNtErrorInvalidFunction syscon errno EPERM 1 1 1 1 1 12 # unix consensus & kNtErrorInvalidAccess (should be kNtErrorNotOwner but is that mutex only??) syscon errno ENOENT 2 2 2 2 2 2 # unix consensus & kNtErrorFileNotFound @@ -842,41 +842,41 @@ syscon pr PR_SET_PTRACER 0x59616d61 0 0 0 0 0 syscon log LOG_EMERG 0 0 0 0 0 0 # consensus syscon log LOG_KERN 0 0 0 0 0 0 # consensus -syscon log LOG_ALERT 1 1 1 1 1 0 # unix consensus -syscon log LOG_PID 1 1 1 1 1 0 # unix consensus -syscon log LOG_CONS 2 2 2 2 2 0 # unix consensus -syscon log LOG_CRIT 2 2 2 2 2 0 # unix consensus -syscon log LOG_ERR 3 3 3 3 3 0 # unix consensus -syscon log LOG_ODELAY 4 4 4 4 4 0 # unix consensus -syscon log LOG_WARNING 4 4 4 4 4 0 # unix consensus -syscon log LOG_NOTICE 5 5 5 5 5 0 # unix consensus -syscon log LOG_INFO 6 6 6 6 6 0 # unix consensus -syscon log LOG_DEBUG 7 7 7 7 7 0 # unix consensus -syscon log LOG_PRIMASK 7 7 7 7 7 0 # unix consensus -syscon log LOG_NDELAY 8 8 8 8 8 0 # unix consensus -syscon log LOG_USER 8 8 8 8 8 0 # unix consensus -syscon log LOG_MAIL 0x10 0x10 0x10 0x10 0x10 0 # unix consensus -syscon log LOG_NOWAIT 0x10 0x10 0x10 0x10 0x10 0 # unix consensus -syscon log LOG_DAEMON 24 24 24 24 24 0 # unix consensus -syscon log LOG_NFACILITIES 24 25 24 24 24 0 -syscon log LOG_AUTH 0x20 0x20 0x20 0x20 0x20 0 # unix consensus -syscon log LOG_PERROR 0x20 0x20 0x20 0x20 0x20 0 # unix consensus -syscon log LOG_SYSLOG 40 40 40 40 40 0 # unix consensus -syscon log LOG_LPR 48 48 48 48 48 0 # unix consensus -syscon log LOG_NEWS 56 56 56 56 56 0 # unix consensus -syscon log LOG_UUCP 0x40 0x40 0x40 0x40 0x40 0 # unix consensus -syscon log LOG_CRON 72 72 72 72 72 0 # unix consensus +syscon log LOG_ALERT 1 1 1 1 1 1 # unix consensus +syscon log LOG_PID 1 1 1 1 1 1 # unix consensus +syscon log LOG_CONS 2 2 2 2 2 2 # unix consensus +syscon log LOG_CRIT 2 2 2 2 2 2 # unix consensus +syscon log LOG_ERR 3 3 3 3 3 3 # unix consensus +syscon log LOG_ODELAY 4 4 4 4 4 4 # unix consensus +syscon log LOG_WARNING 4 4 4 4 4 4 # unix consensus +syscon log LOG_NOTICE 5 5 5 5 5 5 # unix consensus +syscon log LOG_INFO 6 6 6 6 6 6 # unix consensus +syscon log LOG_DEBUG 7 7 7 7 7 7 # unix consensus +syscon log LOG_PRIMASK 7 7 7 7 7 7 # unix consensus +syscon log LOG_NDELAY 8 8 8 8 8 8 # unix consensus +syscon log LOG_USER 8 8 8 8 8 8 # unix consensus +syscon log LOG_MAIL 0x10 0x10 0x10 0x10 0x10 0x10 # unix consensus +syscon log LOG_NOWAIT 0x10 0x10 0x10 0x10 0x10 0x10 # unix consensus +syscon log LOG_DAEMON 24 24 24 24 24 24 # unix consensus +syscon log LOG_NFACILITIES 24 25 24 24 24 24 +syscon log LOG_AUTH 0x20 0x20 0x20 0x20 0x20 0x20 # unix consensus +syscon log LOG_PERROR 0x20 0x20 0x20 0x20 0x20 0x20 # unix consensus +syscon log LOG_SYSLOG 40 40 40 40 40 40 # unix consensus +syscon log LOG_LPR 48 48 48 48 48 48 # unix consensus +syscon log LOG_NEWS 56 56 56 56 56 56 # unix consensus +syscon log LOG_UUCP 0x40 0x40 0x40 0x40 0x40 40 # unix consensus +syscon log LOG_CRON 72 72 72 72 72 72 # unix consensus syscon log LOG_SELECT 76 0 0 0 0 0 syscon log LOG_SENSE 77 0 0 0 0 0 -syscon log LOG_LOCAL0 0x80 0x80 0x80 0x80 0x80 0 # unix consensus -syscon log LOG_LOCAL1 136 136 136 136 136 0 # unix consensus -syscon log LOG_LOCAL2 144 144 144 144 144 0 # unix consensus -syscon log LOG_LOCAL3 152 152 152 152 152 0 # unix consensus -syscon log LOG_LOCAL4 160 160 160 160 160 0 # unix consensus -syscon log LOG_LOCAL5 168 168 168 168 168 0 # unix consensus -syscon log LOG_LOCAL6 176 176 176 176 176 0 # unix consensus -syscon log LOG_LOCAL7 184 184 184 184 184 0 # unix consensus -syscon log LOG_FACMASK 0x03f8 0x03f8 0x03f8 0x03f8 0x03f8 0 # unix consensus +syscon log LOG_LOCAL0 0x80 0x80 0x80 0x80 0x80 0x80 # unix consensus +syscon log LOG_LOCAL1 136 136 136 136 136 136 # unix consensus +syscon log LOG_LOCAL2 144 144 144 144 144 144 # unix consensus +syscon log LOG_LOCAL3 152 152 152 152 152 152 # unix consensus +syscon log LOG_LOCAL4 160 160 160 160 160 160 # unix consensus +syscon log LOG_LOCAL5 168 168 168 168 168 168 # unix consensus +syscon log LOG_LOCAL6 176 176 176 176 176 176 # unix consensus +syscon log LOG_LOCAL7 184 184 184 184 184 184 # unix consensus +syscon log LOG_FACMASK 0x03f8 0x03f8 0x03f8 0x03f8 0x03f8 0x03f8 # unix consensus syscon sg SG_DXFER_TO_FROM_DEV -4 0 0 0 0 0 syscon sg SG_DXFER_FROM_DEV -3 0 0 0 0 0 diff --git a/libc/sysv/consts/LOG_ALERT.S b/libc/sysv/consts/LOG_ALERT.S index a4a4a3733..e06f8d0fa 100644 --- a/libc/sysv/consts/LOG_ALERT.S +++ b/libc/sysv/consts/LOG_ALERT.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_ALERT,1,1,1,1,1,0 +.syscon log,LOG_ALERT,1,1,1,1,1,1 diff --git a/libc/sysv/consts/LOG_AUTH.S b/libc/sysv/consts/LOG_AUTH.S index e49b1c348..f810118f8 100644 --- a/libc/sysv/consts/LOG_AUTH.S +++ b/libc/sysv/consts/LOG_AUTH.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_AUTH,0x20,0x20,0x20,0x20,0x20,0 +.syscon log,LOG_AUTH,0x20,0x20,0x20,0x20,0x20,0x20 diff --git a/libc/sysv/consts/LOG_CONS.S b/libc/sysv/consts/LOG_CONS.S index 9c18366e5..ece48311f 100644 --- a/libc/sysv/consts/LOG_CONS.S +++ b/libc/sysv/consts/LOG_CONS.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_CONS,2,2,2,2,2,0 +.syscon log,LOG_CONS,2,2,2,2,2,2 diff --git a/libc/sysv/consts/LOG_CRIT.S b/libc/sysv/consts/LOG_CRIT.S index f788b32b0..d623e5551 100644 --- a/libc/sysv/consts/LOG_CRIT.S +++ b/libc/sysv/consts/LOG_CRIT.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_CRIT,2,2,2,2,2,0 +.syscon log,LOG_CRIT,2,2,2,2,2,2 diff --git a/libc/sysv/consts/LOG_CRON.S b/libc/sysv/consts/LOG_CRON.S index a7811f5c6..f392b84ca 100644 --- a/libc/sysv/consts/LOG_CRON.S +++ b/libc/sysv/consts/LOG_CRON.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_CRON,72,72,72,72,72,0 +.syscon log,LOG_CRON,72,72,72,72,72,72 diff --git a/libc/sysv/consts/LOG_DAEMON.S b/libc/sysv/consts/LOG_DAEMON.S index d6455e6ba..10f3772dd 100644 --- a/libc/sysv/consts/LOG_DAEMON.S +++ b/libc/sysv/consts/LOG_DAEMON.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_DAEMON,24,24,24,24,24,0 +.syscon log,LOG_DAEMON,24,24,24,24,24,24 diff --git a/libc/sysv/consts/LOG_DEBUG.S b/libc/sysv/consts/LOG_DEBUG.S index e7be4c545..3e39ee2b6 100644 --- a/libc/sysv/consts/LOG_DEBUG.S +++ b/libc/sysv/consts/LOG_DEBUG.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_DEBUG,7,7,7,7,7,0 +.syscon log,LOG_DEBUG,7,7,7,7,7,7 diff --git a/libc/sysv/consts/LOG_ERR.S b/libc/sysv/consts/LOG_ERR.S index cf04dcfd6..bf9507d94 100644 --- a/libc/sysv/consts/LOG_ERR.S +++ b/libc/sysv/consts/LOG_ERR.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_ERR,3,3,3,3,3,0 +.syscon log,LOG_ERR,3,3,3,3,3,3 diff --git a/libc/sysv/consts/LOG_FACMASK.S b/libc/sysv/consts/LOG_FACMASK.S index 93e626784..25d730624 100644 --- a/libc/sysv/consts/LOG_FACMASK.S +++ b/libc/sysv/consts/LOG_FACMASK.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_FACMASK,0x03f8,0x03f8,0x03f8,0x03f8,0x03f8,0 +.syscon log,LOG_FACMASK,0x03f8,0x03f8,0x03f8,0x03f8,0x03f8,0x03f8 diff --git a/libc/sysv/consts/LOG_INFO.S b/libc/sysv/consts/LOG_INFO.S index 01e728777..1eb6985af 100644 --- a/libc/sysv/consts/LOG_INFO.S +++ b/libc/sysv/consts/LOG_INFO.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_INFO,6,6,6,6,6,0 +.syscon log,LOG_INFO,6,6,6,6,6,6 diff --git a/libc/sysv/consts/LOG_LOCAL0.S b/libc/sysv/consts/LOG_LOCAL0.S index 55234ca24..fcd14530b 100644 --- a/libc/sysv/consts/LOG_LOCAL0.S +++ b/libc/sysv/consts/LOG_LOCAL0.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_LOCAL0,0x80,0x80,0x80,0x80,0x80,0 +.syscon log,LOG_LOCAL0,0x80,0x80,0x80,0x80,0x80,0x80 diff --git a/libc/sysv/consts/LOG_LOCAL1.S b/libc/sysv/consts/LOG_LOCAL1.S index 85a14fe64..36ffdde59 100644 --- a/libc/sysv/consts/LOG_LOCAL1.S +++ b/libc/sysv/consts/LOG_LOCAL1.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_LOCAL1,136,136,136,136,136,0 +.syscon log,LOG_LOCAL1,136,136,136,136,136,136 diff --git a/libc/sysv/consts/LOG_LOCAL2.S b/libc/sysv/consts/LOG_LOCAL2.S index 217f08023..1ddfe950c 100644 --- a/libc/sysv/consts/LOG_LOCAL2.S +++ b/libc/sysv/consts/LOG_LOCAL2.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_LOCAL2,144,144,144,144,144,0 +.syscon log,LOG_LOCAL2,144,144,144,144,144,144 diff --git a/libc/sysv/consts/LOG_LOCAL3.S b/libc/sysv/consts/LOG_LOCAL3.S index ed6b8cea9..d8af1d662 100644 --- a/libc/sysv/consts/LOG_LOCAL3.S +++ b/libc/sysv/consts/LOG_LOCAL3.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_LOCAL3,152,152,152,152,152,0 +.syscon log,LOG_LOCAL3,152,152,152,152,152,152 diff --git a/libc/sysv/consts/LOG_LOCAL4.S b/libc/sysv/consts/LOG_LOCAL4.S index dcd671a8d..6abccdf09 100644 --- a/libc/sysv/consts/LOG_LOCAL4.S +++ b/libc/sysv/consts/LOG_LOCAL4.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_LOCAL4,160,160,160,160,160,0 +.syscon log,LOG_LOCAL4,160,160,160,160,160,160 diff --git a/libc/sysv/consts/LOG_LOCAL5.S b/libc/sysv/consts/LOG_LOCAL5.S index 92be42478..6062a680f 100644 --- a/libc/sysv/consts/LOG_LOCAL5.S +++ b/libc/sysv/consts/LOG_LOCAL5.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_LOCAL5,168,168,168,168,168,0 +.syscon log,LOG_LOCAL5,168,168,168,168,168,168 diff --git a/libc/sysv/consts/LOG_LOCAL6.S b/libc/sysv/consts/LOG_LOCAL6.S index 5ce637a54..53c16ccac 100644 --- a/libc/sysv/consts/LOG_LOCAL6.S +++ b/libc/sysv/consts/LOG_LOCAL6.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_LOCAL6,176,176,176,176,176,0 +.syscon log,LOG_LOCAL6,176,176,176,176,176,176 diff --git a/libc/sysv/consts/LOG_LOCAL7.S b/libc/sysv/consts/LOG_LOCAL7.S index 873c32177..8b0d73e2a 100644 --- a/libc/sysv/consts/LOG_LOCAL7.S +++ b/libc/sysv/consts/LOG_LOCAL7.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_LOCAL7,184,184,184,184,184,0 +.syscon log,LOG_LOCAL7,184,184,184,184,184,184 diff --git a/libc/sysv/consts/LOG_LPR.S b/libc/sysv/consts/LOG_LPR.S index d0bc3c5da..0be5f536c 100644 --- a/libc/sysv/consts/LOG_LPR.S +++ b/libc/sysv/consts/LOG_LPR.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_LPR,48,48,48,48,48,0 +.syscon log,LOG_LPR,48,48,48,48,48,48 diff --git a/libc/sysv/consts/LOG_MAIL.S b/libc/sysv/consts/LOG_MAIL.S index a3ab000f9..e534e178f 100644 --- a/libc/sysv/consts/LOG_MAIL.S +++ b/libc/sysv/consts/LOG_MAIL.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_MAIL,0x10,0x10,0x10,0x10,0x10,0 +.syscon log,LOG_MAIL,0x10,0x10,0x10,0x10,0x10,0x10 diff --git a/libc/sysv/consts/LOG_NDELAY.S b/libc/sysv/consts/LOG_NDELAY.S index 36505a8bc..af158f72c 100644 --- a/libc/sysv/consts/LOG_NDELAY.S +++ b/libc/sysv/consts/LOG_NDELAY.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_NDELAY,8,8,8,8,8,0 +.syscon log,LOG_NDELAY,8,8,8,8,8,8 diff --git a/libc/sysv/consts/LOG_NEWS.S b/libc/sysv/consts/LOG_NEWS.S index 7d72d8e96..af6bc33e1 100644 --- a/libc/sysv/consts/LOG_NEWS.S +++ b/libc/sysv/consts/LOG_NEWS.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_NEWS,56,56,56,56,56,0 +.syscon log,LOG_NEWS,56,56,56,56,56,56 diff --git a/libc/sysv/consts/LOG_NFACILITIES.S b/libc/sysv/consts/LOG_NFACILITIES.S index 0d69a603a..924f57b8d 100644 --- a/libc/sysv/consts/LOG_NFACILITIES.S +++ b/libc/sysv/consts/LOG_NFACILITIES.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_NFACILITIES,24,25,24,24,24,0 +.syscon log,LOG_NFACILITIES,24,25,24,24,24,24 diff --git a/libc/sysv/consts/LOG_NOTICE.S b/libc/sysv/consts/LOG_NOTICE.S index de0fd3153..7164aa399 100644 --- a/libc/sysv/consts/LOG_NOTICE.S +++ b/libc/sysv/consts/LOG_NOTICE.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_NOTICE,5,5,5,5,5,0 +.syscon log,LOG_NOTICE,5,5,5,5,5,5 diff --git a/libc/sysv/consts/LOG_NOWAIT.S b/libc/sysv/consts/LOG_NOWAIT.S index cfe22f1fe..415b564d8 100644 --- a/libc/sysv/consts/LOG_NOWAIT.S +++ b/libc/sysv/consts/LOG_NOWAIT.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_NOWAIT,0x10,0x10,0x10,0x10,0x10,0 +.syscon log,LOG_NOWAIT,0x10,0x10,0x10,0x10,0x10,0x10 diff --git a/libc/sysv/consts/LOG_ODELAY.S b/libc/sysv/consts/LOG_ODELAY.S index acec796f7..5b97aa3b3 100644 --- a/libc/sysv/consts/LOG_ODELAY.S +++ b/libc/sysv/consts/LOG_ODELAY.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_ODELAY,4,4,4,4,4,0 +.syscon log,LOG_ODELAY,4,4,4,4,4,4 diff --git a/libc/sysv/consts/LOG_PERROR.S b/libc/sysv/consts/LOG_PERROR.S index 03229c0c6..a80b7f8df 100644 --- a/libc/sysv/consts/LOG_PERROR.S +++ b/libc/sysv/consts/LOG_PERROR.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_PERROR,0x20,0x20,0x20,0x20,0x20,0 +.syscon log,LOG_PERROR,0x20,0x20,0x20,0x20,0x20,0x20 diff --git a/libc/sysv/consts/LOG_PID.S b/libc/sysv/consts/LOG_PID.S index 54f06008d..7fff6d6b4 100644 --- a/libc/sysv/consts/LOG_PID.S +++ b/libc/sysv/consts/LOG_PID.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_PID,1,1,1,1,1,0 +.syscon log,LOG_PID,1,1,1,1,1,1 diff --git a/libc/sysv/consts/LOG_PRIMASK.S b/libc/sysv/consts/LOG_PRIMASK.S index 2ec561fba..bd140bfbe 100644 --- a/libc/sysv/consts/LOG_PRIMASK.S +++ b/libc/sysv/consts/LOG_PRIMASK.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_PRIMASK,7,7,7,7,7,0 +.syscon log,LOG_PRIMASK,7,7,7,7,7,7 diff --git a/libc/sysv/consts/LOG_SYSLOG.S b/libc/sysv/consts/LOG_SYSLOG.S index 35943f5b0..42420d291 100644 --- a/libc/sysv/consts/LOG_SYSLOG.S +++ b/libc/sysv/consts/LOG_SYSLOG.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_SYSLOG,40,40,40,40,40,0 +.syscon log,LOG_SYSLOG,40,40,40,40,40,40 diff --git a/libc/sysv/consts/LOG_USER.S b/libc/sysv/consts/LOG_USER.S index aaa208107..71538bc39 100644 --- a/libc/sysv/consts/LOG_USER.S +++ b/libc/sysv/consts/LOG_USER.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_USER,8,8,8,8,8,0 +.syscon log,LOG_USER,8,8,8,8,8,8 diff --git a/libc/sysv/consts/LOG_UUCP.S b/libc/sysv/consts/LOG_UUCP.S index 458a242d8..daa7b2fbe 100644 --- a/libc/sysv/consts/LOG_UUCP.S +++ b/libc/sysv/consts/LOG_UUCP.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_UUCP,0x40,0x40,0x40,0x40,0x40,0 +.syscon log,LOG_UUCP,0x40,0x40,0x40,0x40,0x40,40 diff --git a/libc/sysv/consts/LOG_WARNING.S b/libc/sysv/consts/LOG_WARNING.S index de8d3c15e..805b9731a 100644 --- a/libc/sysv/consts/LOG_WARNING.S +++ b/libc/sysv/consts/LOG_WARNING.S @@ -1,2 +1,2 @@ #include "libc/sysv/consts/syscon.internal.h" -.syscon log,LOG_WARNING,4,4,4,4,4,0 +.syscon log,LOG_WARNING,4,4,4,4,4,4 diff --git a/libc/sysv/consts/log.h b/libc/sysv/consts/log.h index 8a7d93ee5..838bfd293 100644 --- a/libc/sysv/consts/log.h +++ b/libc/sysv/consts/log.h @@ -40,6 +40,13 @@ #define LOG_UUCP SYMBOLIC(LOG_UUCP) #define LOG_WARNING SYMBOLIC(LOG_WARNING) +/* + * arguments to setlogmask. + */ +#define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */ +#define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */ + + #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_