Commit Graph

341 Commits

Author SHA1 Message Date
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
Joachim Nilsson
dec90a25ab syslogd: Set pipe fd non-blocking in timer backend
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-12-14 08:00:00 +01:00
Joachim Nilsson
2179d5a862 syslogd: Minor coding style cleanups
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-12-14 07:59:39 +01:00
Joachim Nilsson
2bbafcbd16 syslogd: Audit usage text, slim down, fix -R to -r conversion
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-12-10 08:34:49 +01:00
Joachim Nilsson
91c54466fd Minor, let logger use local version of syslog.h
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-12-09 16:56:46 +01:00
Joachim Nilsson
e0c2d3ad0d syslogd: Only log INTERNAL_MARK every MarkInterval
Internal log messages of INTERNAL_MARK time were created every 30
seconds (TIMERINTVL) instead of every MarkInterval (default 20 min).

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-12-09 15:10:30 +01:00
Joachim Nilsson
7ee7df058b syslogd: Only default to log rotation on actual files
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-12-09 13:42:05 +01:00
Joachim Nilsson
d6b7cd6134 syslogd: Minor, factor out O_CREATE
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-12-09 13:41:52 +01:00
Joachim Nilsson
9262229cc8 syslogd: Add log format and remote port to debug listing of sinks
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-12-09 13:22:46 +01:00
Joachim Nilsson
e15d789c84 Fix #9: Open kernel log pipe after daemonizing
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-12-07 20:58:16 +01:00
Joachim Nilsson
3462e2ba19 syslogd: Remove debug fprintf() from 6e6c0dd
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-12-07 20:58:16 +01:00
Joachim Nilsson
f46850b000 syslogd: Refactor backgrounding/daemonization w/ code from FreeBSD
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-12-07 20:58:16 +01:00
Khem Raj
d3d18505d0 include sys/types.h for off_t
Fixes
error: unknown type name 'off_t'

Signed-off-by: Khem Raj <raj.khem@gmail.com>
2019-12-07 10:33:14 -08:00
Khem Raj
095052c601 Remove __BEGIN_DECLS/__END_DECLS
The __BEGIN_DECLS and __END_DECLS are internal identifiers in glibc and
are not defined in any standard. Using them fails build on musl
libc, its better to avoid them

Signed-off-by: Khem Raj <raj.khem@gmail.com>
2019-12-07 10:33:14 -08:00
Joachim Nilsson
899d0d28be Relicense configure.ac and Makefile.am's under 3-clause BSD
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-12-07 10:57:47 +01:00
Joachim Nilsson
6bb6672ebf Remove klogd from the sysklogd project
This patch removes one of the traditionally key pieces of the sysklogd
project, klogd.  Now that syslogd performs logging of kernel messages
we no longer require a separate daemon for that.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-12-07 10:31:06 +01:00
Joachim Nilsson
8aa2060312 Fix #8: kernel messages duplicated to console
When building the sysklogd project --without-klogd we must disable the
kernel logging to console on Linux.  This fix depends on how the sysctl
setting `kernel.printk` is configured.  The patch only calls the kernel
to set console_loglevel to minimum_console_loglevel.

See the kernel docs for details:

  https://www.kernel.org/doc/Documentation/sysctl/kernel.txt

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-12-07 10:30:42 +01:00
Joachim Nilsson
a7fe2ef700 Use correct define in #ifdef, __linux__ not linux
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-12-06 18:26:39 +01:00
Joachim Nilsson
6e6c0ddfaa syslogd: Integrate new timer API
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-12-06 18:13:15 +01:00
Joachim Nilsson
5ac6c39687 syslogd: Add generic timer API to replace exising buggy one
This patch adds a alarm()/SIGALRM based generic timer API to syslogd.
The API takes care to wrap SIGALRM and serialize all timer events to
a standard UNIX pipe(2) which syslogd can poll() for like any other
incoming event.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-12-05 20:38:43 +01:00
Joachim Nilsson
163aa84cc4 klogd: Add '-F' as alias for '-n', for compat with syslogd
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-12-01 21:17:02 +01:00
Joachim Nilsson
f6713bdb84 syslogd: Increase granularity of background flush/mark timer
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-12-01 21:12:54 +01:00
Joachim Nilsson
4556901a2b syslogd: Update documentation, -m interval is in minutes
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-12-01 15:59:35 +01:00
Joachim Nilsson
f4c01a3ba3 syslogd: Refactor domark() timer handling, always run at TIMERINTVL
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-30 17:55:58 +01:00
Joachim Nilsson
c3acff5fae syslogd: Only Initialize syslogd once
This bug caused syslogd to fall back to logging to /dev/console for
internal log messages/errors during reconfiguration at runtime.

syslogd has the FreeBSD style of keeping already open log files ready
for logging until re:init() has completed, when new log files are rolled
in and any old ones not to be used anymore are closed.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-29 11:23:05 +01:00
Joachim Nilsson
a9758d1559 syslogd: Record time of first occurrence of a message
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-29 11:23:05 +01:00
Joachim Nilsson
0a8cecfa84 syslogd: Handle DNS lookup of unknown remote hosts in domark()
Refactor of nslookup of unknown remote syslog servers, both when
(re)reading the .conf file and at runtime.  This means we retry
DNS lookup every 30 sec, or INET_SUSPEND_TIME +/- 30 sec.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-29 11:23:05 +01:00
Joachim Nilsson
90dd1b1c37 syslogd: Always domark() timer, regardless of -mfoo value
The domark() timer handles a lot of the critical maintenance action in
syslogd, it must always be guaranteed to run.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-29 11:23:05 +01:00
Joachim Nilsson
280b5fd3ec syslogd: Fix blocking of SIGHUP/ALRM during logmsg()
Only block signals *after* all sanity checking of log message has been
completed, otherwise we will end up with blocked SIGHUP and SIGALRM.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-29 11:23:05 +01:00
Joachim Nilsson
05c5b6752d syslogd: Always create PID file, even in debug mode
We definitely want to be able to run syslogd in debug mode for extended
periods of time and still run under finit/systemd or similar, letting
users know we run as 'PID'.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-29 11:23:05 +01:00
Joachim Nilsson
8e255b7f9d syslogd: Only set debugging_on in Debug (-d) mode
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-28 15:27:52 +01:00
Joachim Nilsson
b7d4225ef1 syslogd: Retry address lookup forever, never give up
When logging to a remote server, using @fqdn syntax in syslog.conf,
syslogd calls getaddrinfo() to resolve the IP address.  Older versions
of syslogd gave up after 10 retries.  We want to retry forever since we
may be running in a setup with bad network connection to the DNS server
for longer periods of time.

This patch only removes the 'give up' mechanism, which unfortunately
reused the f_prevcount value, which in turn could cause that value to
become -1 and thus trigger an assert().  With this code out of the way,
and the type change in the previous commit, the counter can never again
be negative.

Note: The configurable suspend time before trying again remains at its
default of 3 minutes.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-28 14:53:07 +01:00
Joachim Nilsson
49e168601e syslogd: Change f_prevcount type; int --> size_t
If it wraps around to zero we want to log the message anyway.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-28 14:39:12 +01:00
Joachim Nilsson
1d8fe4944d syslogd: Reset prevcount in fprintlog_first() to prevent assert()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-28 10:00:34 +01:00
Joachim Nilsson
3d4b8cb84d syslogd: Improve log messages on error, eg. INET sendto()
When we fail sending to a remote host, help admin debug the issue by
stating which remote we failed to send to.

Also minor changes to other similar error messages, use same form.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-28 09:38:22 +01:00
Joachim Nilsson
7793fcbd14 Fix #3: Don't guess PID file location, use configure --runstatedir
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-24 18:52:31 +01:00
Joachim Nilsson
4396004fba Add missing '-k' and '-T' command line flags to getopt()
Fixes GitHub issue #2

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-24 18:38:26 +01:00
Joachim Nilsson
b80a225f73 Minor, simplify previous commit and add logger on/off to summary
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-18 17:54:35 +01:00
Lars Wendler
227008ec0f
build: make logger and its man page optional
There are other packages that provide a logger program like util-linux
We should respekt that

Signed-off-by: Lars Wendler <polynomial-c@gentoo.org>
2019-11-18 12:36:25 +01:00
Joachim Nilsson
f44a026d86 syslogd: Fix broken wallmsg(), off-by one iov
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-15 08:31:46 +01:00
Joachim Nilsson
bd5903509d syslogd: Fix RFC3164 formatting, no space after <PRI> field
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-15 08:26:21 +01:00
Joachim Nilsson
09f6b7bf6c syslogd: Minor, don't log to console when exiting ...
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-13 19:13:49 +01:00
Joachim Nilsson
54edca09d9 syslogd: Close open UNIX and inet sockets on SIGTERM
When creating Inet sockets we may get multiple struct addrinfo records.
With this patch we support up to 16 records per Internet peer.  When
closing we iterate over all peers and all records.

Refactor socket_close() to clean up any lingering socket path when
closing UNIX socket.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-13 19:11:34 +01:00
Joachim Nilsson
4192e543a5 syslogd: Use common nomenclature for next pointer
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-13 18:44:01 +01:00
Joachim Nilsson
6350bf2474 syslogd: Fix invalid free(), found by Valgrind
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-13 18:44:01 +01:00
Joachim Nilsson
0f0f8f845d syslogd: Add FreeBSD and NetBSD -n flag to disable DNS query
This patch re-adds the -n flag, but now to disable DNS reverse-query for
all incoming messages.  This can potentially speed up logging a lot for
small/embedded systems that act as log sink.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-13 17:16:51 +01:00
Joachim Nilsson
cf9d281e5b syslogd: Adopt FreeBSD -F instead of -n to run in foreground
This change will probably break most installations.  We do this to free
up '-n' for use as disabling DNS lookups, from FreeBSD *and* NetBSD.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-13 17:08:47 +01:00
Joachim Nilsson
9d415f313f syslogd: Add FreeBSD -k option to allow LOG_KERNEL facility messages
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-13 16:44:51 +01:00
Joachim Nilsson
c465f340bc syslogd: NetBSD/FreeBSD -T option, log remote msgs with local time
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-13 16:16:23 +01:00
Joachim Nilsson
12fa1f6682 syslogd: Accept pre-RFC3164 formatted messages from remote hosts
This patch makes us wire-compatible with older versions of ourself, and
current versions set up to use default remote format.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-13 16:09:20 +01:00
Joachim Nilsson
06b26aae7b syslogd: Reformat usage text a bit for readability, hopefully
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-13 15:16:05 +01:00
Joachim Nilsson
0c61fe73f2 logger: Sort options in usage text alphabetically
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-13 14:49:05 +01:00
Joachim Nilsson
62137926ec syslogd: Add support for FreeBSD -a allowed_peer filtering
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-13 14:48:49 +01:00
Joachim Nilsson
3b6199aaef Drop --with-syslogd-pidfile from configure, use -P option to syslogd
This patch drops the configure flag --with-syslogd-pidfile=foo since
syslogd now natively supports custom PID file using -P foo.

Also, the default PID file and syslog.conf paths have been changed from
the hard-coded /var/run (_PATH_VARRUN) and /etc to use configure paths.
This may not be appreciated by everyone but allows the project to have
support for all use-cases in a de facto standard fashion.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-13 11:52:15 +01:00
Joachim Nilsson
4b175653cb syslogd: Fix formatting of usage text, and spell check
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-13 10:27:39 +01:00
Joachim Nilsson
c2d9f80859 syslogd: Drop -h flag, does not do anything since 353cd10
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-13 10:22:15 +01:00
Joachim Nilsson
45c7dcc6df syslogd: Only warn when opening /proc/kmsg fails, continue anyway
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-13 09:55:33 +01:00
Joachim Nilsson
353cd10a06 Refactor, graft in FreeBSD fprintlog_first() & fprintlog_successive()
This patch looks big, but it's really just fprintlog() being split up
into three new functions: fprintlog_first() & fprintlog_successive() and
fprintlog_write().  Similar to how the FreeBSD syslogd is structured.

In the refactoring process Joey's proxy-prevention was removed.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-13 09:43:57 +01:00
Joachim Nilsson
97dfe638b4 Fix uninitialized variable, found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-13 08:16:14 +01:00
Joachim Nilsson
0555e0989f Fix suspicius code for allocating a sockaddr_un to a sockaddr ptr
Remarked on by Coverity Scan.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-13 08:14:48 +01:00
Joachim Nilsson
69608f7158 syslogd: Fix RFC3164 TAG formatting when no PID is included
This patch fixes the omission of final ':' following a content TAG when
an app-name without a process ID is included.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-12 16:42:44 +01:00
Joachim Nilsson
d92f8466f8 syslogd: Minor refactor, move init code from main() to init()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-12 16:42:44 +01:00
Joachim Nilsson
823bb4cf2a Support for building the project w/o separate klogd (default)
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-12 16:42:44 +01:00
Joachim Nilsson
0455da805f syslogd: Rename -R flag to -r, same as logger tool
Now that we've dropped the previous -r flag we can rename the rotation
flag so it's the same between both logger and syslogd.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-12 13:30:25 +01:00
Joachim Nilsson
2f72a17b8e syslogd: If system has SO_REUSEPORT, use it
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-12 13:28:02 +01:00
Joachim Nilsson
095aa56996 Minor, don't touch PID file on SIGHUP in debug mode
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-12 13:28:02 +01:00
Joachim Nilsson
f606667038 syslogd: Add support for FreeBSD -s, secure mode
- Update man page
- Enable -s in default systemd service settings
- Add support for SecureMode, with shutdown()

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-12 13:28:02 +01:00
Joachim Nilsson
d607d6b845 syslogd: Update usage text and man page for new -b flag, drop -r
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-12 13:28:02 +01:00
Joachim Nilsson
762e09d7e8 syslogd: Drop -l HOST flag, the RFCs are very clear on this point
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-12 13:28:02 +01:00
Joachim Nilsson
d1035377cc syslogd: Drop -s HOST flag in favor of future BSD SecureMode
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-12 13:28:02 +01:00
Joachim Nilsson
4ee6211277 syslogd: Refactor internals to use new socket API
This patch is inspired, in part, by FreeBSD syslogd but now diverges
onto its own path.  Special handling for AF_UNIX sockets are required
on Linux, which unlike BSD cannot use getaddrinfo() on UNIX sockets.

- Rip out old funix[] and finet support
- Add new concept of peers
- Linked list of peers can be > 20
- Temporarily open up to accept all remote conns
- Remove old logerror(), replaced with new log macros

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-12 13:28:01 +01:00
Joachim Nilsson
07677c78a5 Graft struct addrinfo support on top of new socket API
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-12 13:28:01 +01:00
Joachim Nilsson
a4c1acbca8 syslogd: Drop -r flag, to be replaced with BSD -s (secure) flag
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-12 09:19:54 +01:00
Joachim Nilsson
c66411e8c2 Use new log macros and err.h fns
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-12 08:56:06 +01:00
Joachim Nilsson
53c2d0e3d9 Export flog() function and define new log macros ERR(), WARN(), etc.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-11 18:52:00 +01:00
Joachim Nilsson
90fb520c06 Add socket helper functions from SMCRoute, licesened as 3-clause BSD
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-10 11:22:14 +01:00
Joachim Nilsson
c31a7d1031 Minor refactor/cleanup
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-10 09:35:01 +01:00
Joachim Nilsson
a2feba69e2 Allow klogd to send LOG_KERN messages to syslogd
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-09 11:46:56 +01:00
Joachim Nilsson
b15420fdc5 syslogd: Inherit parsed PRI value in RFC3164 front-end
The RFC5424 front-end already does this.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-09 11:23:03 +01:00
Joachim Nilsson
9aaa7ec8c4 syslogd: Install SIGHUP handler earlier
When a heavily loaded system starts up syslogd may not in time reach its
original installation of the SIGHUP handler before receiving the signal.
It will then die and have to be restarted by PID 1.

This patch installs the SIGHUP handler early, with all the other signals
right after command line parsing.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-08 16:15:29 +01:00
Joachim Nilsson
dd5b470342 Fix assert when buffer->hostname == NULL at startup
Default to use 'from' in RFC3164 parser, just like the RFC5424 parser
already does.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-08 15:50:09 +01:00
Joachim Nilsson
0a3c5e1544 syslogd: Update usage text, drop -a add -b and simplify
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-08 08:50:17 +01:00
Joachim Nilsson
3377f07a5a klogd: Update usage text, no more -i or -I
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-08 08:50:17 +01:00
Joachim Nilsson
cc96379252 syslogd: Fix RFC5424 structured-data parser
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-07 23:21:33 +01:00
Joachim Nilsson
22c3fa9fa3 syslogd: Increase debug logging of raw incoming and parsed messages
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-07 23:21:33 +01:00
Joachim Nilsson
3f68d765db logger: Change usage text slightly for readability
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-07 23:21:33 +01:00
Joachim Nilsson
31815d6143 logger: Add NetBSD -d SD for RFC5424 structured data
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-07 23:21:31 +01:00
Joachim Nilsson
e25f835a5a logger: Add NetBSD -m MSGID support for logging RFC5424 style
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-07 23:20:11 +01:00
Joachim Nilsson
f2e1793cda logger: Add NetBSD -n option for LOG_NDELAY
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-07 22:03:11 +01:00
Joachim Nilsson
0aa57978ee logger: Add NetBSD -i option for LOG_PID
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-07 21:54:47 +01:00
Joachim Nilsson
d3461fd6a3 logger: Add NetBSD -c option for LOG_CONS
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-07 21:08:01 +01:00
Joachim Nilsson
fff4368e80 RFC5424 sec 6.1 states that we *should* support 2048 byte long msgs
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-07 20:56:02 +01:00
Joachim Nilsson
07033382ee Minor, type cast logit() argument for Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-07 20:35:54 +01:00
Joachim Nilsson
11819e5b7f Type cast arguments to logit(), fixes warnings from Coverity
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-07 19:37:12 +01:00
Joachim Nilsson
884a0a180b Use correct format specifier for ssize_t, found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-07 19:37:04 +01:00
Joachim Nilsson
774523f6e2 Fix missing argument to logit() and clean up unreadable code
Found by Coverity Scan

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-07 19:36:49 +01:00
Joachim Nilsson
7533f96ca9 Fix invalid/missing/extra argument to logit(), found by Coverity
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-07 19:24:38 +01:00
Joachim Nilsson
64c6866667 Minor, drop debug log message for normal case
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-07 19:08:29 +01:00
Joachim Nilsson
f8e87f143d syslogd: Drop -a SOCK support, replaced with multiple -p SOCK args
The -p SOCK syntax is what NetBSD syslogd use, so this is more of an
alignment with upstream.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-07 19:08:29 +01:00
Joachim Nilsson
d723574eee logger: Update usage text with missing -u SOCK info
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-07 06:47:53 +01:00
Joachim Nilsson
1544cddd5a Drop unnecessary (and buggy) debug logs
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-06 16:53:48 +01:00
Joachim Nilsson
533ca61faa Support for sending messages to a custom port on remote server
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-06 14:23:03 +01:00
Joachim Nilsson
ff4b9e0499 Minor, code formatting
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-06 13:55:05 +01:00
Joachim Nilsson
d3abc7aa16 Minor, whitespace formatting
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-06 13:45:38 +01:00
Joachim Nilsson
fc4b804a6d Add LOG_WARN alias
Along with syslogp(), this is ia killer vendor lock-in feature.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-06 13:45:21 +01:00
Joachim Nilsson
31d7298516 Refactor, factor out getaddrinfo() code duplication to a sep. func.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-06 13:35:06 +01:00
Joachim Nilsson
65ac085a97 Add backwards compatibility handling with sysklogd v1.6
This patch adds compatibility with sysklgd v1.6 and also adds the new
action flag "RFC3164" to explicitly be able to set old format.  This
format is the default, except for remote syslog.  Also, the rotation
support added in v1.6 has chnaged syntax which this patch addresses.

- Remote syslog defaults to BSD format, w/o timestamp and hostname
- Support reading log rotation without ';rotate=' prefix

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-06 12:26:54 +01:00
Joachim Nilsson
02a67ef273 Refactor, move daemon defines to header file
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-06 12:08:09 +01:00
Joachim Nilsson
3ced4508b4 Add missing globfree(), found using -fsanitize=address
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-06 08:48:50 +01:00
Joachim Nilsson
ec06b220e4 If available, use O_TMPFILE, fix insecure tempfile found by Coverity
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-06 07:04:06 +01:00
Joachim Nilsson
3cff584621 Refactor wallmsg() slightly, fixes "unused value" found by Coverity
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-06 07:03:57 +01:00
Joachim Nilsson
e8674a8fd7 Check return value from setsockopt(), found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-05 15:56:47 +01:00
Joachim Nilsson
3c2c353c37 Handle open() errors during log rotation, found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-05 11:04:44 +01:00
Joachim Nilsson
0bf36c59a6 Refactor, close() may try to close -1, found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-05 10:28:26 +01:00
Joachim Nilsson
2e8dffe893 If fstat() failes logrotate() cannot run, found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-05 10:23:17 +01:00
Joachim Nilsson
1fe3c311ca Ignore return value from rename() to silence Coverity Scan
If we cannot rename our own files we're in a bit of a pickle.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-05 10:21:58 +01:00
Joachim Nilsson
58b243ea55 Replace unsafe strncpy() and strcpy() with safe strlcpy(),
C.f. Coverity CID 1076404

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-05 10:10:06 +01:00
Joachim Nilsson
f6ecb8b47b Fix Coverity CID 1406626, avoid strncat() in favor of snprintf()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-05 09:37:07 +01:00
Joachim Nilsson
a4b09cc15b Clarify comment, _PATH_LOG applies to *sysklogd project*
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-05 08:57:15 +01:00
Joachim Nilsson
2fcfc0ad81 Drop #include "config.h" from syslog.h
Should not be in an exported header, obviously.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-05 08:42:29 +01:00
Joachim Nilsson
e202196152 Add missing files to distribution, found by make distcheck
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-04 20:09:15 +01:00
Joachim Nilsson
58da3b6bd2 Mark strlcat() and strlcpy() as weak functions, for libsyslog
The strlcat() and strlcpy() functions are only intended to be used
by syslog.c internally (and syslogd), when building libsyslog.

A user linking with libsyslog may have another library that provides
strlcat() or strlcpy() replacements.  We must therefore mark ours as
weak functions so they can be overridden.

This patch also add a convenience library for libsyslog, to control
the build deps. for libsyslog.  This is where external dependencies
should be addded (explicitly) when syslog.c is updated from NetBSD.
If you add new deps you likely want to mark them too as weak refs.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-04 11:04:13 +01:00
Joachim Nilsson
8f66822b2a Check for getprogname() et al, and use config.h for #ifndefs
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-04 10:55:52 +01:00
Joachim Nilsson
ad70b49790 Minor, whitspace alignment
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-04 06:21:50 +01:00
Joachim Nilsson
024dde00c2 Remove unused files
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-03 21:14:45 +01:00
Joachim Nilsson
11a16e16b8 syslogd: Strip whitespace in rule between action and option
Terminate action filename/pipe/host so we don't get any trailing tab or
space character in file or host names.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-03 19:48:22 +01:00
Joachim Nilsson
ff27d39cca syslogd: Fix double free() warning after SIGHUP
This cleanup section has moved to *after* cfparse()

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-03 19:47:54 +01:00
Joachim Nilsson
b2940cade1 Remove old Makefile, not needed anymore
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-03 17:30:12 +01:00