Commit Graph

268 Commits

Author SHA1 Message Date
Joachim Wiberg
eed3335caa logger: fix \m -> \n, found on Slackware current
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-06-30 22:27:58 +02:00
Joachim Wiberg
fc5096f1c2 syslogd: support for extracting user level messages from /dev/kmsg
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>
2021-06-21 23:15:10 +02:00
Joachim Wiberg
7ce44f5b9e syslogd: ignore EINVAL from kernel, silently restart polling
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-06-21 23:14:57 +02:00
Joachim Wiberg
36778bee4a logger: support for -k, early log to /dev/kmsg
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>
2021-06-21 23:11:54 +02:00
Joachim Wiberg
10ccdc3da1 logger: only attempt logrotate if target is file
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-06-20 09:10:26 +02:00
Joachim Wiberg
e3d6ff8737 Check boundary in every step of parse_rfc5424()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-06 11:59:33 +02:00
Joachim Wiberg
d1f1702277 Check boundary first in parse_rfc5424()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-06 10:09:34 +02:00
Joachim Wiberg
ebced817a7 Ensure argument to printsys() is always nul terminated
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-06 10:03:01 +02:00
Joachim Wiberg
52fc3f7176 Ensure received data is nul terminated, found by Coverity Scan
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>
2021-05-06 09:42:45 +02:00
Joachim Wiberg
65ceec1171 Fix GCC warning: integer constant is so large that it is unsigned
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-06 08:55:26 +02:00
Joachim Wiberg
e5ee2446a0 Follow-up to 92a4fb3: allow kernel log dupes around edge of seqno
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>
2021-05-06 08:47:30 +02:00
Joachim Wiberg
92a4fb3318 Fix #29: prevent repeating kernel messages when syslogd is restarted
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>
2021-05-05 05:17:15 +02:00
Joachim Wiberg
1de66a04c0 logger: minor, staticify
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-05 04:52:48 +02:00
Joachim Wiberg
eb454d7d37 Fix #28: log messages stuck in 1969
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>
2021-05-05 03:25:22 +02:00
Joachim Wiberg
4ab8bc7b40 Fix #31: invalid time for kernel log messages on 32-bit machines
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-05 03:04:52 +02:00
Joachim Wiberg
d722584191 Fix #32: fix logging of remote kernel messages being mapped to uucp
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-04 10:45:13 +02:00
Joachim Wiberg
2731591709 syslogd: Fix spelling error found by lintian
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-21 15:50:13 +01:00
Joachim Wiberg
d00c9dac74 Minor, refactor in preparation for checking kmesg seqno
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-21 13:05:26 +01:00
Joachim Wiberg
0901310226 Load or reload timezone data on init/SIGHUP
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>
2021-02-21 11:47:42 +01:00
Joachim Wiberg
f54c1d1f30 Fix issue with parsing /dev/kmsg time, off by one error
Problem and proposed fix reported by opty on #troglobit at freenode.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-21 11:46:09 +01:00
Joachim Wiberg
d2444c720f Fix #27: bug in /dev/kmsg priority parser, intrdocued in v2.2.0
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>
2021-01-26 22:04:49 +01:00
Joachim Wiberg
406e4299a1 logger: No need for appending error message, err() already does this
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-01-25 00:13:06 +01:00
Joachim Wiberg
ea2565ce4e Drop %m gnuism from internal log macro
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-01-25 00:13:06 +01:00
Joachim Wiberg
3e4000b25a Fix #26: handle Linux EPIPE on /dev/kmsg
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>
2021-01-25 00:12:29 +01:00
Joachim Wiberg
45085709e8 Update copyright years
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-01-15 11:16:04 +01:00
Joachim Wiberg
680c622efb Fix GCC init warning on ArmV5, use memset() instead
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-01-14 15:21:11 +01:00
Joachim Wiberg
883b351351 Allow loop initial declarations, explicitly enable C99
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>
2021-01-14 12:50:51 +01:00
Joachim Wiberg
30842595d5 Update copyright years and author last name
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2020-08-31 21:28:45 +02:00
Joachim Wiberg
5aa7372f4c Fix #19: Prefer /dev/kmsg over /proc/kmsg on Linux
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>
2020-08-31 21:28:45 +02:00
Joachim Wiberg
93117e5801 Define _GNU_SOURCE, required for O_CLOEXEC on uClibc
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>
2020-08-30 11:43:53 +02:00
Changqing Li
e684939559 Makefile.am: fixup issue #17
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>
2020-08-27 11:40:44 +08:00
Joachim Nilsson
5eec48df9d Minor, wording and formatting of comment
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-22 09:47:01 +01:00
Changqing Li
b88e21d177 fix one rarely reproduced parallel build problem
fix for this issue:
https://github.com/troglobit/sysklogd/issues/17

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Signed-off-by: Changqing Li <changqing.li@windriver.com>
2020-03-20 16:52:41 +08:00
Joachim Nilsson
6da50d15f7 syslogd: Minor, reduce scope of local variables
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-19 19:59:37 +01:00
Joachim Nilsson
f35aa0760e syslogd: Minor, reduce code duplication
Found by clang-tidy

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-19 19:59:21 +01:00
Joachim Nilsson
d22f7168e0 Revert "syslogd: cfopts(): reinit strtok() so both OPT1,OPT2 are found"
This reverts commit d758581 since it breaks unit tests by missing the
first option after ;

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-19 10:30:25 +01:00
Steffen Nurpmeso
d75858100c syslogd: cfopts(): reinit strtok() so both OPT1,OPT2 are found
Signed-off-by: Steffen Nurpmeso <steffen@sdaoden.eu>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-19 09:32:30 +01:00
Joachim Nilsson
ee47b88cd2 Follow-up to 84d70e6, fix spelling
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-19 09:11:15 +01:00
Joachim Nilsson
64257d689d Minor, cleanup/coding-style
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-19 09:10:58 +01:00
Joachim Nilsson
5fce3001ed Simplify handling of replacement functions; strlcpy() & C:o
- 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>
2020-01-19 09:08:48 +01:00
Johan Askerin
5bfe15f767 syslogd: Fix startup issue with remote sinks
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>
2020-01-17 13:20:52 +01:00
Joachim Nilsson
773e69ea2e syslogd: Ignore temporary network problems when sending remote
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>
2020-01-17 13:01:29 +01:00
Joachim Nilsson
84d70e63fc Drop libcompat to simplify build deps and really fix #11
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>
2020-01-16 22:17:23 +01:00
Joachim Nilsson
e0411a3a56 Fix invalid format specifier for f_prevcount, found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-03 09:51:48 +01:00
Joachim Nilsson
39ea566d45 Fix minor descriptor leak, found by Coverity Scan
It is safe to always close() the fd here.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-03 09:46:11 +01:00
Joachim Nilsson
0f7ee8d430 syslogd: Fix variable names shadowing other global or local defs.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-12-16 22:06:26 +01:00
Joachim Nilsson
ff03287d5a syslogd: Use snprintf() rather than sprintf()
Protects against buffer overruns.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-12-16 22:06:26 +01:00
Joachim Nilsson
0afdfb4911 syslogd: Handle multiple invocations of SIGHUP
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-12-16 13:25:48 +01:00
Joachim Nilsson
b3f016aaf1 syslogd: Minor, fix size_t format specifier %zd vs %zu
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-12-14 10:13:48 +01:00
Joachim Nilsson
48bfe6edf4 syslogd: Refactor, use sigaction() instead of deprecated signal()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-12-14 08:46:36 +01:00