diff options
author | Christian Neukirchen <chneukirchen@gmail.com> | 2014-07-18 23:25:01 +0200 |
---|---|---|
committer | Christian Neukirchen <chneukirchen@gmail.com> | 2014-07-18 23:25:01 +0200 |
commit | b0368aad76ce3b67f6050855f9a43cc7bb2d1dc3 (patch) | |
tree | c4d545445aa4f83440d2a31a9cd4bb347c375765 | |
download | socklog-void-b0368aad76ce3b67f6050855f9a43cc7bb2d1dc3.tar.gz socklog-void-b0368aad76ce3b67f6050855f9a43cc7bb2d1dc3.tar.xz socklog-void-b0368aad76ce3b67f6050855f9a43cc7bb2d1dc3.zip |
Initial import of socklog-void
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | nanoklogd.c | 58 | ||||
-rw-r--r-- | socklog/cron/config | 2 | ||||
-rw-r--r-- | socklog/debug/config | 2 | ||||
-rw-r--r-- | socklog/errors/config | 6 | ||||
-rw-r--r-- | socklog/everything/config | 2 | ||||
-rw-r--r-- | socklog/kernel/config | 2 | ||||
-rw-r--r-- | socklog/lpr/config | 2 | ||||
-rw-r--r-- | socklog/mail/config | 2 | ||||
-rw-r--r-- | socklog/messages/config | 9 | ||||
-rw-r--r-- | socklog/secure/config | 3 | ||||
-rw-r--r-- | socklog/user/config | 2 | ||||
-rw-r--r-- | socklog/xbps/config | 2 | ||||
-rwxr-xr-x | sv/nanoklogd/run | 2 | ||||
l--------- | sv/nanoklogd/supervise | 1 | ||||
-rwxr-xr-x | sv/socklog-unix/check | 2 | ||||
-rwxr-xr-x | sv/socklog-unix/log/run | 2 | ||||
l--------- | sv/socklog-unix/log/supervise | 1 | ||||
-rwxr-xr-x | sv/socklog-unix/run | 2 | ||||
l--------- | sv/socklog-unix/supervise | 1 |
20 files changed, 107 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..22f7ba5 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +all: nanoklogd + +clean: + rm -f nanoklogd diff --git a/nanoklogd.c b/nanoklogd.c new file mode 100644 index 0000000..2dd32a0 --- /dev/null +++ b/nanoklogd.c @@ -0,0 +1,58 @@ +/* nanoklogd - forward kernel messages to /dev/log. */ + +/* Written by Christian Neukirchen <chneukirchen@gmail.com> + To the extent possible under law, the creator of this work has waived + all copyright and related or neighboring rights to this work. */ + +/* This uses /dev/log directly because glibc syslog(3) does + forward LOG_KERN as LOG_USER. */ + +#include <sys/klog.h> +#include <sys/socket.h> +#include <errno.h> +#include <unistd.h> + +static const struct { + short sun_family; + char sun_path[9]; +} log_addr = { + AF_UNIX, + "/dev/log" +}; + +int +main(int argc, char *argv[]) { + char buf[16384]; + int f, l; + + f = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0); + if (f < 0) + return 111; + + if (connect(f, (void *)&log_addr, sizeof log_addr) < 0) + return 112; + + while (1) { + l = klogctl(2, buf, sizeof buf); + if (l < 0) + return 113; + + while (send(f, buf, l, 0) != l) + switch (errno) { + case ECONNREFUSED: + case ECONNRESET: + case ENOTCONN: + /* syslogd went down, retry until up. */ + close(f); + sleep(1); + f = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0); + if (f < 0) + return 111; + connect(f, (void *)&log_addr, sizeof log_addr); + break; + default: + return 114; + } + } + return 0; +} diff --git a/socklog/cron/config b/socklog/cron/config new file mode 100644 index 0000000..edc8653 --- /dev/null +++ b/socklog/cron/config @@ -0,0 +1,2 @@ +-* ++cron.* diff --git a/socklog/debug/config b/socklog/debug/config new file mode 100644 index 0000000..69ca035 --- /dev/null +++ b/socklog/debug/config @@ -0,0 +1,2 @@ +-* ++*.debug:* diff --git a/socklog/errors/config b/socklog/errors/config new file mode 100644 index 0000000..d9b6f34 --- /dev/null +++ b/socklog/errors/config @@ -0,0 +1,6 @@ +-* ++*.err:* ++*.error:* ++*.emerg:* ++*.alert:* ++*.crit:* diff --git a/socklog/everything/config b/socklog/everything/config new file mode 100644 index 0000000..156e253 --- /dev/null +++ b/socklog/everything/config @@ -0,0 +1,2 @@ +-auth.* +-authpriv.* diff --git a/socklog/kernel/config b/socklog/kernel/config new file mode 100644 index 0000000..fcf4d63 --- /dev/null +++ b/socklog/kernel/config @@ -0,0 +1,2 @@ +-* ++kern.* diff --git a/socklog/lpr/config b/socklog/lpr/config new file mode 100644 index 0000000..29d65a4 --- /dev/null +++ b/socklog/lpr/config @@ -0,0 +1,2 @@ +-* ++lpr.* diff --git a/socklog/mail/config b/socklog/mail/config new file mode 100644 index 0000000..f23f79b --- /dev/null +++ b/socklog/mail/config @@ -0,0 +1,2 @@ +-* ++mail.* diff --git a/socklog/messages/config b/socklog/messages/config new file mode 100644 index 0000000..a0be112 --- /dev/null +++ b/socklog/messages/config @@ -0,0 +1,9 @@ +-* ++*.info:* ++*.notice:* ++*.warn:* +-auth.* +-authpriv.* +-mail.* +-news.* +-cron.* diff --git a/socklog/secure/config b/socklog/secure/config new file mode 100644 index 0000000..4b37db2 --- /dev/null +++ b/socklog/secure/config @@ -0,0 +1,3 @@ +-* ++auth.* ++authpriv.* diff --git a/socklog/user/config b/socklog/user/config new file mode 100644 index 0000000..2ffc807 --- /dev/null +++ b/socklog/user/config @@ -0,0 +1,2 @@ +-* ++user.* diff --git a/socklog/xbps/config b/socklog/xbps/config new file mode 100644 index 0000000..800d6ea --- /dev/null +++ b/socklog/xbps/config @@ -0,0 +1,2 @@ +-* ++*.*:*xbps*: * diff --git a/sv/nanoklogd/run b/sv/nanoklogd/run new file mode 100755 index 0000000..a3141ea --- /dev/null +++ b/sv/nanoklogd/run @@ -0,0 +1,2 @@ +#!/bin/sh +exec nanoklogd diff --git a/sv/nanoklogd/supervise b/sv/nanoklogd/supervise new file mode 120000 index 0000000..ed4bc71 --- /dev/null +++ b/sv/nanoklogd/supervise @@ -0,0 +1 @@ +/run/runit/supervise.nanoklogd \ No newline at end of file diff --git a/sv/socklog-unix/check b/sv/socklog-unix/check new file mode 100755 index 0000000..e214585 --- /dev/null +++ b/sv/socklog-unix/check @@ -0,0 +1,2 @@ +#!/bin/sh +exec socklog-check unix /dev/log 2>/dev/null diff --git a/sv/socklog-unix/log/run b/sv/socklog-unix/log/run new file mode 100755 index 0000000..9a27970 --- /dev/null +++ b/sv/socklog-unix/log/run @@ -0,0 +1,2 @@ +#!/bin/sh +exec svlogd -ttt /var/log/socklog/* diff --git a/sv/socklog-unix/log/supervise b/sv/socklog-unix/log/supervise new file mode 120000 index 0000000..34c1ff2 --- /dev/null +++ b/sv/socklog-unix/log/supervise @@ -0,0 +1 @@ +/run/runit/supervise.socklog-unix-log \ No newline at end of file diff --git a/sv/socklog-unix/run b/sv/socklog-unix/run new file mode 100755 index 0000000..8ce56a8 --- /dev/null +++ b/sv/socklog-unix/run @@ -0,0 +1,2 @@ +#!/bin/sh +exec chpst -U nobody:nogroup socklog unix /dev/log 2>&1 diff --git a/sv/socklog-unix/supervise b/sv/socklog-unix/supervise new file mode 120000 index 0000000..f59e021 --- /dev/null +++ b/sv/socklog-unix/supervise @@ -0,0 +1 @@ +/run/runit/supervise.socklog-unix \ No newline at end of file |