Commit Graph

331 Commits

Author SHA1 Message Date
Joachim Wiberg
9e9c1c884a Fix #57: garbled tag name in std log file output
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-08-12 14:30:19 +02:00
Joachim Wiberg
6bc8525a8d Ensure both logger and syslogd output the same version string
Slight differences in output when called with `-v` flag:

  - Should output to stdout, that's what people expect (not an error)
  - Should output *project* name and version, for syslogd this is not
    so obvious since it *logs* 'syslogd vx.y.z' while the version is
    'sysklogd vx.y.z'

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-08-01 13:17:01 +02:00
Joachim Wiberg
7bd017be0a logger: fix default log severity info -> notice, like other loggers
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-08-01 12:48:31 +02:00
Joachim Wiberg
a2ff3a93f6 libsyslog: drop extra leading space in message
When logging to a file we want a space to separate proc[pid]: from the
message, but for regular logging local/remote we don't want to inject
an extra space.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-08-01 12:37:19 +02:00
Joachim Wiberg
22ee326192 logger: drop trailing space when reading message from command line
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-08-01 12:28:59 +02:00
Joachim Wiberg
a06639bd0e libsyslog: bump ABI version, changes/additions to interface
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-08-01 11:45:33 +02:00
Joachim Wiberg
4fdbb64c51 libsyslog: honor LIB_PTRIM when logging to stderr
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-08-01 11:34:55 +02:00
Joachim Wiberg
221ae0abe0 libsyslog: avoid opening+connecting to syslogd when LOG_NLOG
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-08-01 11:34:55 +02:00
Joachim Wiberg
43d8640aac libsyslog: enforce 32 char limit on RFC3164 output to remote syslogd
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-07-31 18:48:39 +02:00
Joachim Wiberg
50f6ad74cb syslogd: ensure tag is <= 32 chars for RFC3164 output
This may cause a bit of a regression for some users, but the RFC is
crystal clear on this point, the tag MUST NOT exceed 32 characters.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-07-31 18:48:26 +02:00
Joachim Wiberg
5662afe2c0 Adjust log file output format in BSD mode to output proc[PID] too
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-07-31 17:17:25 +02:00
Joachim Wiberg
8b513ade8e Fix log option flag: LOG_RFC3154 -> LOG_RFC3164
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-07-31 12:54:25 +02:00
Joachim Wiberg
f0b7b6fdf8 Merge branch 'master' into dev 2022-07-31 12:29:29 +02:00
Joachim Wiberg
70bfb8ed98 Handle gettimeofday() errors the same way everywhere
Problem found by Coverity Scan.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-07-31 12:21:23 +02:00
Joachim Wiberg
4f94756bf2 logger: add support for -I PID to log, e.g., $$ from a shell script
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-07-31 12:03:57 +02:00
Joachim Wiberg
f32ca837c1 logger: add support for -H NAME to override system hostname
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-07-31 11:48:58 +02:00
Joachim Wiberg
c7f65e11c9 logger: minor, coding style (reverse Christmas tree)
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-07-31 11:44:29 +02:00
Joachim Wiberg
1fc5c174f1 logger: update usage text with new options
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-07-31 10:41:25 +02:00
Joachim Wiberg
c8fe229cfc logger: add support for RFC3164 style (for remote) logging
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-07-31 10:16:01 +02:00
Joachim Wiberg
5d98f06718 logger: drop debug logs
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-07-31 10:14:57 +02:00
Joachim Wiberg
dfb654688a logger: initial support for logging to a remote host
This is the first RFC5424 (only) support for for logging to a remote
host.  The syntax continues to follow the FreeBSD logger.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-07-29 14:53:23 +02:00
Joachim Wiberg
3086637768 libsyslog: fix loss of logger messages on failed connect()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-07-29 14:37:46 +02:00
Joachim Wiberg
daba6cce09 Fix #5&: failure to reset socket count on SIGHUP
As reported on GitHub. When logging to a remote host, after a few
SIGHUP's we get the following log message:

     Only 16 IP addresses per socket supported.

When closing all currently open sockets, the socket count must be reset
to allow for opening new ones, otherwise we'll run out of "counts".
Yes, this should be refactored to use the FreeBSD model implementation.

Problem introduced in v2.4.0, commit 075815e.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-07-26 07:47:09 +02:00
Joachim Wiberg
34c812415d
Merge pull request #53 from meta-ed/hexencoding
Prevent logfile corruption by control codes

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-06-17 18:17:53 +02:00
Edward K. McGuire
bcc3c7c1fb Prevent logfile corruption by control codes
Do not corrupt logfiles when kernel messages contain control codes,
notably \n. Instead, preserve the kernel's protective C-style hex
encoding. For example, \n embedded in a message by a kernel-level
facility is received as "\x0a". Kernel-level facilities cannot be
trusted to use only syslog-safe codes in kernel messages. See:
<https://kernel.org/doc/Documentation/ABI/testing/dev-kmsg>
2022-06-16 15:52:04 -05:00
Edward K. McGuire
9427734546 Prevent overread when scanning the message buffer
This change avoids the possibility of advancing past the null
terminator, by always testing the value at the pointer before
advancing the pointer.

While repairing this, I reconciled the code sections that read the
priority, sequence, and timestamp, so that they handle the pointer in
exactly the same way. This makes the source easier to maintain.
2022-06-16 14:33:34 -05:00
Joachim Wiberg
8f83328850 Fake usec timestamp for RFC3164 messages
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-06-05 16:43:20 +02:00
Joachim Wiberg
1e9f164198 Fake usec timestamp for untrusted kernel log messages
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-06-04 18:55:14 +02:00
Joachim Wiberg
dfc32d7843 Fix memory leak on exit
Only to clean up, possibly relevant for no-MMU systems, but
they have other issues as well (e.g. fork) that prevent them
from using the sysklogd project.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-05-29 16:59:50 +02:00
Joachim Wiberg
62dea3aecf Minor, fix missing \n in calls to logit()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-05-22 22:10:12 +02:00
Joachim Wiberg
075815eeb8 Add support for setting secure_mode=[0,1,2] in .conf file
Logic for secure mode setting in .conf file

 - Command line always wins
 - SIGHUP activates changes

Note, if -s is given on command line it always wins, regardless.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-05-22 22:10:12 +02:00
Joachim Wiberg
a453eca4be Minor, rename local variable for consistency
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-05-22 22:10:11 +02:00
Joachim Wiberg
4e70aff619 Refactor: add cfkey_match() with new struct cfkey for file options
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-05-22 22:10:11 +02:00
Joachim Wiberg
619422b7ed Minor, whitespace fixup
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-05-22 22:10:11 +02:00
Edward K. McGuire
4f24bce339 Don't skip the <PRI> field in the call to wallmsg()
This is redundant and causes message truncation.  The <PRI> field is
skipped within wallmsg() itself.

Signed-off-by: Edward K. McGuire <metaed@gmail.com>
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-05-14 11:58:33 +02:00
Joachim Wiberg
6798fe76d5 Document reason for stat() in opensys()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-03-14 06:59:51 +01:00
Steffen Nurpmeso
45554a54e6 syslogd.c: rotate_file(): do not loose file mode due to rotation 2022-03-14 05:55:27 +01:00
Steffen Nurpmeso
949e80f150 Implement forced log file rotation upon SIGUSR2 2022-03-14 05:52:46 +01:00
Steffen Nurpmeso
7038e51a0f "notify": address Joachim Wiberg's comments (pull/45) 2022-03-12 17:22:18 +01:00
Steffen Nurpmeso
72f2faef6e Add "notify" keyword 2022-03-12 15:28:02 +01:00
Joachim Wiberg
6022d3c7d0 Fix #49: add support for -8 command line option to allow 8-bit data
This patch allows the user to disable the 8-bit data check in the log
message validator.  If you have experienced problems with logging any
unicode (utf-8) messages after v1.6, this option is for you.

The correct way to handle this is to add proper parser support for the
Unicode BOM, defined in RFC5424[1], as NetBSD syslogd does[2], search
for IS_BOM().

[1]: https://datatracker.ietf.org/doc/html/rfc5424#appendix-A.8
[2]: http://cvsweb.netbsd.org/bsdweb.cgi/src/usr.sbin/syslogd/syslogd.c?rev=1.138

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-03-07 20:57:00 +01:00
Joachim Wiberg
aceb4cddcf Add missing -H option to usage text, issue #41
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-03-05 18:37:49 +01:00
Joachim Wiberg
e4330515e8 Disable KernLog in container
No need to save seqno when we've detected being in container and have
disabled kernel logging.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-03-05 15:31:46 +01:00
Joachim Wiberg
40622ef6c7 Fix build error introduced when fixing issue #48
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-03-05 15:31:46 +01:00
Joachim Wiberg
c534556790 Auto-detect if we're running in a container and disable klogd
This patch adds a very rudimentary container check.  When one, of a
select few containers, are detected, sysklogd disables the kernel
logging -- since there's no point in logging kernel messages other
than from the host system.

Issue #48

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-02-14 00:28:28 +01:00
Joachim Wiberg
29e932008d Fix #48: add option ('-K') to disable kernel logging
This patch adds support for disabling kernel logging, opensys().  This
is in addition to the character device validation check, and primarily
for use in container use-cases -- where logging kernel is not needed.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-02-13 23:40:06 +01:00
Joachim Wiberg
49b99584a4 Verify the kernel log fifo is a proper character device
Issue #48 describes a problem with 100% CPU load in a container
use-case.  Turns out one of the issues was that /dev/kmsg was
not a proper character device.  This patch adds a very basic
check to ensure /dev/kmsg is usable.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-02-13 23:03:30 +01:00
Joachim Wiberg
e61e5abb88 Follow-up to 9856e07, rename '-K' option to '-t'
We need the '-K' option to disable kernel logging, so this option needs
to be renamed, unfortunately.  Fortunately it's not been released yet.

Issue #42

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-02-13 22:53:02 +01:00
Joachim Wiberg
f4f2ad365e Redo DNS lookup on failure to send to remote server
When entering the forwarding suspend timer, free any previous address
info and do a new DNS lookup when the timer elapses.  The failure to
send may be because we're using a stale IP address.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-11-27 20:21:45 +01:00
Joachim Wiberg
f516ff6023 Fix #36: retry DNS lookup of remote syslog servers with res_init()
This patch replaces the INET_SUSPEND_TIME for DNS lookup with a 5 sec
back-off to prevent DNS lookup on each message.

Also, reorder WARN() and NOTE() so they are called *after* setting the
f_type, otherwise we unleash endless recursive loops.

To avoid filling up the log with "Failed resolving ..." messages every
time we retry, we set a flag to remember we've already logged warning.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-11-27 20:18:21 +01:00