summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--nanoklogd.c58
-rw-r--r--socklog/cron/config2
-rw-r--r--socklog/debug/config2
-rw-r--r--socklog/errors/config6
-rw-r--r--socklog/everything/config2
-rw-r--r--socklog/kernel/config2
-rw-r--r--socklog/lpr/config2
-rw-r--r--socklog/mail/config2
-rw-r--r--socklog/messages/config9
-rw-r--r--socklog/secure/config3
-rw-r--r--socklog/user/config2
-rw-r--r--socklog/xbps/config2
-rwxr-xr-xsv/nanoklogd/run2
l---------sv/nanoklogd/supervise1
-rwxr-xr-xsv/socklog-unix/check2
-rwxr-xr-xsv/socklog-unix/log/run2
l---------sv/socklog-unix/log/supervise1
-rwxr-xr-xsv/socklog-unix/run2
l---------sv/socklog-unix/supervise1
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