It is well established practise on Linux to use /dev/kmsg (old or
new API) before syslogd is up (and /dev/log exists). This patch
enables support for extracting non-kernel log messages and logging
them with their proper facility and priority.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This patch adds support for logging to /dev/kmsg, which can be highly
useful for early scripts that run long before syslogd has started and
/dev/log is available.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
Coverity found two possible untrusted loop bounds, in unix_cb() and
inet_cb(), that were indeed possibly unterminated strings. These
were classified as medium. A third finding, marked high, was found
in kernel_cb(), which upon further investigation seems bogus.
This patch terminates the buffers received in unix_cb() and inet_cb()
but only changes to 0 from \0 termination in kernel_cb().
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
Although hihgly unlikely, if the kernel log sequence number (seqno)
reaches the end of its MAX value (18446744073709551615) we allow for
dupes to handle the wrap-around back to zero (0) in the counter.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This patch fixes the problem with kernel messages being repeated when
syslogd is restarted at runtime. This is achieved by caching the last
seqno read from /dev/kmsg to /run/syslogd.cache. The latter is usually
a ram disk these days so it should be a fairly quick op.
Excessive updates are prevented by only caching after handling all
callbacks in the socket_poll() loop, and only updating the cache
if there has been any new kernel messages since last update.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
The timer_now() API, introduced in 2019, returns time relative to boot.
Useful for relative time comparisons, but when used for absolute time,
e.g. for log messages, it must be offset with boot_time.
This patch fixes issue #28, but also wall messages, which exhibits the
same problem.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This should fix any lingering issues with logging with the wrong
timezone at boot. As long as syslogd gets HUP'ed after setting
the new timezone.
Improvements to this welcome, of course.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This patch fixes a bug in the kernel log priority parser introduced in
v2.2.0 with the new support for /dev/kmsg, replacing /proc/kmsg which
has another format for the log priority.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
When Linux CONFIG_LOG_BUF_SHIFT is set too low, or too many messages are
generated by the kernel, /dev/kmsg will overflow. This is signaled with
EPIPE to userspace. We can use the seqnos to figure out how many we've
lost, but seqnos are currently ignored.
> In case records get overwritten while /dev/kmsg is held open, or
> records get faster overwritten than they are read, the next read()
> will return -EPIPE and the current reading position gets updated to
> the next available record. The passed sequence numbers allow the log
> consumer to calculate the amount of lost messages.
-- https://lwn.net/Articles/490690/
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
Fixes the following error on certain buildroot toolchains:
syslogd.c: In function 'fmt5424':
syslogd.c:1583:2: error: 'for' loop initial declarations are only allowed in C99 mode
for (int j = 25; j >= 20; --j) {
^
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This patch migrates the sysklogd project to use the modern /dev/kmsg
interface on Linux. There are many advantages over the older /proc
interface; 1) no need to wait for /proc to be mounted, 2) it provides
multiple simultaneous access. For more information, see:
https://www.kernel.org/doc/Documentation/ABI/testing/dev-kmsg
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
When building sysklogd on a uClibc system we must define _GNU_SOURCE to
get O_CLOEXEC.
Since _GNU_SOURCE is also required for asprintf() with GLIBC, as used by
the pidfile() replacement function, we drop it from there and rely on
AM_CPPFLAGS for all sources.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
only make $(LIBOBJS) depend on $(LTLIBOBJS) still have race condition,
library like pidfile.o may be changed when compile or link for target
libsyslog_la_LIBADD, which will cause problem like below:
ERROR: dwarfsrcfiles failed with exit code 1 (cmd was ['dwarfsrcfiles', /tmp/work/ppc7400-oe-linux/sysklogd/2.1.2-r0/package/usr/lib/libsyslog.a']):
dwarfsrcfiles: tmp/work/ppc7400-oe-linux/sysklogd/2.1.2-r0/package/usr/lib/libsyslog.a: not a valid ELF file
arm-oe-linux-gnueabi-libtool: link: arm-oe-linux-gnueabi-gcc -march=armv7ve -mthumb -mfpu=neon -mfloat-abi=hard --sysroot=TOPDIR/tmp-glibc/work/armv7vet2hf-neon-oe-linux-gnueabi/sysklogd/2.1.2-r0/recipe-sysroot -shared -fPIC -DPIC .libs/libsyslog_la-syslog.o ../lib/.libs/pidfile.o ../lib/.libs/strlcpy.o ../lib/.libs/strlcat.o -march=armv7ve -mthumb -mfpu=neon -mfloat-abi=hard --sysroot=TOPDIR/tmp-glibc/work/armv7vet2hf-neon-oe-linux-gnueabi/sysklogd/2.1.2-r0/recipe-sysroot -O2 -g -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -Wl,-soname -Wl,libsyslog.so.0 -o .libs/libsyslog.so.0.0.0
arm-oe-linux-gnueabi-libtool: link: (cd ".libs" && rm -f "libsyslog.so.0" && ln -s "libsyslog.so.0.0.0" "libsyslog.so.0")
arm-oe-linux-gnueabi-libtool: link: (cd ".libs" && rm -f "libsyslog.so" && ln -s "libsyslog.so.0.0.0" "libsyslog.so")
arm-oe-linux-gnueabi-libtool: link: arm-oe-linux-gnueabi-gcc-ar cru .libs/libsyslog.a libsyslog_la-syslog.o ../lib/pidfile.o ../lib/strlcpy.o ../lib/strlcat.o
TOPDIR/tmp-glibc/work/armv7vet2hf-neon-oe-linux-gnueabi/sysklogd/2.1.2-r0/recipe-sysroot-native/usr/bin/arm-oe-linux-gnueabi/../../libexec/arm-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/10.1.0/ar: `u' modifier ignored since `D' is the default (see `U')
TOPDIR/tmp-glibc/work/armv7vet2hf-neon-oe-linux-gnueabi/sysklogd/2.1.2-r0/recipe-sysroot-native/usr/bin/arm-oe-linux-gnueabi/../../libexec/arm-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/10.1.0/ar: ../lib/strlcat.o: No such file or directory
Signed-off-by: Changqing Li <changqing.li@windriver.com>
- Drop weak bindings, use simple #define in compat.h instead
- No need to #ifdef sources with HAVE_foo, configure handles this for us
- Move utimensat() declaration to compat.h from pidfile.c to be consistent
With these changes we can let libsyslog link with the replacement objs,
just like syslogd and logger does. Because even if the C-library does
*not* have strlcpy() & C:o *and* an application has a local copy of any
of these APIs, our versions are prefixed with __ in the symbol table.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
Only reset f_fime when the filed is in normal operation, not suspended,
otherwise the INET_SUSPEND_TIME handling is broken.
Signed-off-by: Johan Askerin <johan.askerin@gmail.com>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
When sending to a remote syslog server, configured as an IP address or
when the DNS name has already been resolved, we may get temporary error
messages like ENETUNREACH and similar from sendmsg().
Before this patch the whole filed was placed in F_FORW_SUSP, like failed
DNS resolve, which introduces a 180 sec delay before even trying again.
A better approach is to just try again with the next syslog message.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
The original idea with libcompat was to keep as few objects as
possible for linking with libsyslog. That in turn to prevent
a user of libsyslog from suddenly also getting strong binding
to symbols like strlcpy() from libsyslog, rather than their C
library of choice.
However, this caused strlcpy.c to be built as both .o and .lo
files, which in turn caused really bizarre build problems due
to bad DAG dependency.
This patch drops libcompat and instead marks all replacement APIs
as weak symbols, which a C library can override.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>