summaryrefslogtreecommitdiffstats
path: root/misc-utils/logger.c
Commit message (Collapse)AuthorAgeFilesLines
* logger: make code more robust for static analyzer [clang scan]Karel Zak2019-05-231-0/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: consolidate version printing and close_stdout()Karel Zak2019-04-161-6/+6
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* docs: fix typos [codespell]Sami Kerola2019-02-181-1/+1
| | | | | Reference: https://github.com/codespell-project/codespell Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* various: fix 'uninitialized when used' warnings [clang]Sami Kerola2019-02-181-1/+1
| | | | | | | This change fixes "warning: variable 'var' may be uninitialized when used here [-Wconditional-uninitialized]" warnings reported in various files. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* logger: concatenate multiple lines of MESSAGE into a single field.Karel Zak2019-01-231-2/+22
| | | | | | | | | | | | this is deemed a useful special case since journalctl will only show either the first or last element of the message array if the field appears multiple times. Based on patch from: Kjetil Torgrim Homme <kjetil.homme@redpill-linpro.com> https://github.com/karelzak/util-linux/pull/743 Addresses: https://github.com/karelzak/util-linux/issues/742 Signed-off-by: Karel Zak <kzak@redhat.com>
* logger: Define SD_JOURNAL_SUPPRESS_LOCATION.YmrDtnJu2018-07-071-0/+1
| | | | | | | | | | | | The normal journald functions add the location in the C source code files to the log messages. This is nice for a big C based project, but logger is used in scripts so it would be more useful to let users specify the location in the script by adding the CODE_FUNC, CODE_FILE and CODE_FILE fields to the log message. It is already possible to do this, but it will result in two versions of these fields: one for the location in logger.c and one for the location in the script.
* misc: fix typos using codespellRuediger Meier2018-02-161-1/+1
| | | | | | Some more funny typos, please review carefully. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* logger: keep header generators independent on connectionKarel Zak2017-10-121-5/+1Star
| | | | | | | * avoid memory leaks * don't use incomplete or header after free() Signed-off-by: Karel Zak <kzak@redhat.com>
* logger: allow to reconnect on initial failed connect tooKarel Zak2017-10-111-4/+7
| | | | | | | The current code sets noact flag if unix socked connection failed. This is ugly. We want to reconnect always in all cases (well, except --socket-error=on). Signed-off-by: Karel Zak <kzak@redhat.com>
* logger: add dummy fallback for OSXKarel Zak2017-10-101-1/+6
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* logger: reconnect on failed send()Karel Zak2017-10-101-9/+38
| | | | | | | | | | | | | | | | | | | The libc syslog() reconnects on failed send(). We need the same thing as logger(1) is expected as long time running tool. For example recommended Apache configuration is: ErrorLog "| /usr/bin/logger -t apache_error -p local6.debug" The issue is that connection endpoint (e.g. syslogd) maybe restarted. The simple way how to test is: for i in $(seq 0 3600); do echo "This is message number $i"; sleep 1; done | logger --tcp --server 127.0.0.1 --port 514 and restart your syslog. The current implementation gets SIGPIPE or write warning message, but it never reconnect. Addresses: https://github.com/karelzak/util-linux/issues/363 Signed-off-by: Karel Zak <kzak@redhat.com>
* logger: make stdin parsing more friendly to static analyzersKarel Zak2017-09-151-0/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: consolidate macro style USAGE_HELP_OPTIONSRuediger Meier2017-06-291-2/+2
| | | | | | | | | changed in include/c.h and applied via sed: sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c") sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c") Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: introduce print_usage_help_options()Ruediger Meier2017-06-271-2/+1Star
| | | | | | | | | | | | Consolidate --help and --version descriptions. We are now able to align them to the other options. We changed include/c.h. The rest of this patch was generated by sed, plus manually setting the right alignment numbers. We do not change anything but white spaces in the --help output. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: cosmetics, remove argument from usage(FILE*)Ruediger Meier2017-06-261-3/+4
| | | | | | | | | | | | | | This patch is trivial and changes nothing, because we were always using usage(stdout) Now all our usage() functions look very similar. If wanted we could auto-generate another big cosmetical patch to remove all the useless "FILE *out" constants and use printf and puts rather than their f* friends. Such patch could be automatically synchronized with the translation project (newlines!) to not make the translators sick. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* logger: make month names, login name, and tag read-only objectsSami Kerola2017-05-031-6/+6
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* logger: support sub-trees in the ID for RFC5424Karel Zak2017-01-281-2/+13
| | | | | | | | | | | | | | | | | The current code supports <name>@<digit> only, but we also need <name>@<digit>.<digit>[. ...] RFC5424: 7.2.2 enterpriseId: In general, only the IANA-assigned private enterprise number is needed (a single number). An enterprise might decide to use sub-identifiers below its private enterprise number. If sub- identifiers are used, they MUST be separated by periods and be represented as decimal numbers. An example for that would be "32473.1.2". Addresses: https://github.com/karelzak/util-linux/issues/406 Signed-off-by: Karel Zak <kzak@redhat.com>
* Use --help suggestion on invalid optionKarel Zak2016-12-191-2/+1Star
| | | | | | | | The current default is to print all usage() output. This is overkill in many case. Addresses: https://github.com/karelzak/util-linux/issues/338 Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: fix unsigned int usage for ctype.h functionsKarel Zak2016-10-261-1/+1
| | | | | Reported-by: "Yuriy M. Kaminskiy" <yumkam@gmail.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* Fix minor typosYuri Chornoivan2016-10-201-1/+1
|
* misc: fix declarations shadowing variables in the global scope [oclint]Sami Kerola2016-07-211-7/+7
| | | | | | Fixes multiple occurences of 'optarg' overwrites. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* logger: simplify if clause [oclint]Sami Kerola2016-07-211-24/+24
| | | | | | | This has effect of collapsing rather long indentation block, so commit separately. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* logger: remove trailing spaces when outputing to journalSami Kerola2016-07-191-5/+2Star
| | | | | | | | | | | | | | Issues: 1. Whitespace-ish \r is not stripped, while it should be. 2. In journal \r is considered unprintable. Lennart: "it is the duty of the client side to drop the trailing whitespace, which "logger" doesn't do". Reported-by: Ivan Babrou <ibobrik@gmail.com> Explained-by: Lennart Poettering <lennart@poettering.net> Reference: https://github.com/systemd/systemd/issues/3416 Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* logger: be more precise about --port descriptionKarel Zak2016-06-211-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: Fix various typosSebastian Rasmussen2016-05-311-2/+2
| | | | | | | Fix various typos in error messages, warnings, debug strings, comments and names of static functions. Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
* logger: correct the grammar of an error messageBenno Schulenberg2016-03-161-1/+1
| | | | Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* logger: fix memory leak [ASAN and valgrind]Sami Kerola2016-03-141-1/+3
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* misc: remove duplicate includesKarel Zak2016-03-101-1/+0Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* logger: fix compiler warning, const facilitynamesRuediger Meier2016-03-081-2/+2
| | | | | | | | | | | | This was the warning on FreeBSD: misc-utils/logger.c:221:24: warning: passing 'const CODE [25]' to parameter of type 'CODE *' (aka 'struct _code *') discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers] facility = decode(s, facilitynames); ^~~~~~~~~~~~~ misc-utils/logger.c:187:43: note: passing argument to parameter 'codetab' here static int decode(const char *name, CODE *codetab) Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: fix some includesRuediger Meier2016-02-291-0/+1
| | | | | | | | | features.h: any glibc header includes this already libgen.h: was unused there sys/uio.h: for writev(3p) sys/queue.h seems like it was never used Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* logger: use SCM_CREDENTIALS on LINUX onlyRuediger Meier2016-02-261-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | This is a build fix of FreeBSD and OSX. Basically we revert the following commit for non-linux systems: 27a9eb53 "use --id as local socket credentials" Note I could also compile it like this: #ifdef HAVE_SYS_UCRED_H # define _WANT_UCRED # include <sys/param.h> # include <sys/ucred.h> # define SCM_CREDENTIALS SCM_CREDS #endif [...] #ifdef _linux_ cred->pid = ctl->pid; #endif [...] ... but don't know how to test whether it does what it should. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* Merge branch 'ldadd-cflags-warnings' of https://github.com/rudimeier/util-linuxKarel Zak2016-02-241-1/+1
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 'ldadd-cflags-warnings' of https://github.com/rudimeier/util-linux: build-sys: disable unused parameter warnings for some test progs misc: fix compiler warnungs (unsigned/signed) misc: fix warnings "unused parameter" [-Wunused-parameter] libfdisk: fix warnings, "redundant redeclaration" [-Wredundant-decls] tests: fix compiler warnings [-Wmissing-prototypes] libfdisk: fix compiler warnings [-Wmissing-prototypes] libfdisk: fix missing symbol libblkid: fix compiler warnings [-Wmissing-prototypes] libmount: add mnt_fs_set_priority() build-sys: always add AM_CFLAGS build-sys: always use global LDADD
| * misc: fix compiler warnungs (unsigned/signed)Ruediger Meier2016-02-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These ones should be fixed: libblkid/src/probe.c:393:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libblkid/src/probe.c:907:25: warning: signed and unsigned type in conditional expression [-Wsign-compare] libblkid/src/probe.c:1221:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libblkid/src/partitions/partitions.c:540:47: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libblkid/src/partitions/partitions.c:1043:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libblkid/src/partitions/partitions.c:1056:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libblkid/src/partitions/partitions.c:1057:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libblkid/src/partitions/partitions.c:1061:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libblkid/src/partitions/partitions.c:1199:27: warning: signed and unsigned type in conditional expression [-Wsign-compare] libblkid/src/partitions/partitions.c:1410:26: warning: signed and unsigned type in conditional expression [-Wsign-compare] libblkid/src/partitions/partitions.c:1431:25: warning: signed and unsigned type in conditional expression [-Wsign-compare] libblkid/src/superblocks/linux_raid.c:151:8: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits] libblkid/src/superblocks/linux_raid.c:155:2: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits] libblkid/src/superblocks/superblocks.c:375:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libblkid/src/superblocks/xfs.c:141:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libsmartcols/src/table.c:333:24: warning: signed and unsigned type in conditional expression [-Wsign-compare] libsmartcols/src/table.c:344:25: warning: signed and unsigned type in conditional expression [-Wsign-compare] libsmartcols/src/table_print.c:753:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libfdisk/src/ask.c:364:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libfdisk/src/utils.c:33:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libfdisk/src/context.c:435:56: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libfdisk/src/context.c:730:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libfdisk/src/script.c:557:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libfdisk/src/dos.c:1791:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] libfdisk/src/gpt.c:813:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] misc-utils/logger.c:408:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] misc-utils/logger.c:408:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] misc-utils/logger.c:408:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] misc-utils/logger.c:408:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] misc-utils/logger.c:408:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] disk-utils/partx.c:140:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] disk-utils/partx.c:551:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] disk-utils/partx.c:640:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* | logger: always update header when writing stdin lineKarel Zak2016-02-241-2/+11
|/ | | | | | Addresses: http://bugs.debian.org/798239 Reported-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Karel Zak <kzak@redhat.com>
* logger: shadow declarationSami Kerola2015-11-061-7/+7
| | | | | | | | misc-utils/logger.c:448:17: warning: declaration of 'msg' shadows a parameter [-Wshadow] misc-utils/logger.c:429:74: note: shadowed declaration is here Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* logger: remove unnecessary commentKarel Zak2015-10-291-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* logger: use --id as local socket credentialsKarel Zak2015-10-291-0/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | If you have really paranoid syslog (or systemd who listens on /dev/log) then it replaces in the message PID with a real PID from socket header credentials: # echo $PPID 1550 # logger -p info --stderr --id=$PPID "This is message baby!" <14>Oct 29 11:22:13 kzak[1550]: This is message baby! # journald -n 1 Oct 29 11:22:13 ws kzak[22100]: This is message baby! ^^^^^ This patch forces kernel to accept another *valid* PID if logger(1) executed with root permissions; improved version: # logger -p info --stderr --id=$PPID "This is message baby!" <14>Oct 29 11:26:00 kzak[1550]: This is message baby! # journald -n 1 Oct 29 11:26:00 ws kzak[1550]: This is message baby! Signed-off-by: Karel Zak <kzak@redhat.com>
* logger: use iovec for all messageKarel Zak2015-10-271-20/+45
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* logger: use iovec and sendmsg() to send messageKarel Zak2015-10-271-11/+19
| | | | | | | | | The iovec based solutions allow to send multiple strings by one syscall (for example additional \n messages separator). We can also use it to send additional socket header metadata (e.g. SCM_CREDENTIALS) later. Signed-off-by: Karel Zak <kzak@redhat.com>
* logger: fix messages separation on UNIX socketKarel Zak2015-10-061-11/+23
| | | | | | | | | | | | | | | | | | | | The function write_output() add additional \n after each message on TYPE_TPC. This is required by syslog daemons, otherwise you will see multiple log messages merged together in your log file, for example: Oct 6 09:01:40 ws kzak: AAA<14>Oct 6 09:01:40 kzak: BBB for printf "AAA\nBBB\n" | logger -p info -u <any-socket> Unfortunately, the connection initialization functions keep the default ALL_TYPES as connection type and nowhere in the control struct is info about the final real connection type. The problem is invisible when you specify --tpc or --udp on logger command line. Addresses: https://github.com/karelzak/util-linux/issues/225 Signed-off-by: Karel Zak <kzak@redhat.com>
* logger: add --sd-id and -sd-paramKarel Zak2015-10-011-14/+232
| | | | | | | | | | | | | | | | | | This patch add support for RFC 5424 structured data elements. For example: logger --rfc5424 --sd-id zoo@123 \ --sd-param tiger=\"hungry\" \ --sd-param zebra=\"running\" \ --sd-id manager@123 \ --sd-param onMeeting=\"yes\" \ "this is message" produces: <13>1 2015-10-01T14:07:59.168662+02:00 ws kzak - - [timeQuality tzKnown="1" isSynced="1" syncAccuracy="218616"][zoo@123 tiger="hungry" zebra="running"][manager@123 onMeeting="yes"] this is message Signed-off-by: Karel Zak <kzak@redhat.com>
* logger: improve readability [smatch scan]Karel Zak2015-08-051-5/+5
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* logger: Add support to logger for RFC6587 octet countingAlex Bligh2015-07-291-7/+17
| | | | | | | | | | | | | | | | | | | | | | | | This patch adds support to logger for RFC6587 octet counting. RFC6587 provides support for two sorts of framing: 1. Octet counting (at RFC6587 s3.4.1) In essence each frame is preceded by a decimal length and a space. 2. Non-transparent framing (at RFC6587 s3.4.2), also called 'octet stuffing' In essence each frame is terminated by a `\n` Prior to this patch, logger used option 2 (non-transparent framing) on TCP, and used no framing on UDP. After this patch, the default behaviour is unchanged, but if the '--octet-count' option is supplied, option 1 is used for both TCP and UDP. Arguably octet count framing makes little sense on UDP, but some servers provide it and this allows testing of those servers. Signed-off-by: Alex Bligh <alex@alex.org.uk>
* logger: do not exit when socket errors are not enforcedSami Kerola2015-07-201-4/+5
| | | | | | | | | | | | | | | The libc openlog(3) does not have error detection whether unix socket could be opened. As a side effect that made it possible to use logger even if syslogd was not running. Of course user message in these cases were lost. This change makes the logger do behave similar way again, so that sysvinit scripts can successfully pipe messages to logger when ever. Addresses: https://bugs.debian.org/787864 Addresses: https://bugs.debian.org/790875 Reported-by: Andreas Beckmann <anbe@debian.org> Reported-by: Andreas Henriksson <andreas@fatal.se> Tested-by: Robie Basak <robie.basak@ubuntu.com> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* logger: --stderr and --no-act turn "auto-errors" onRuediger Meier2015-04-091-3/+2Star
| | | | Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* logger: fix memory leaksSami Kerola2015-04-071-1/+2
| | | | | Reported-by: Patrick Plagwitz <patrick.plagwitz@fau.de> Signed-off-by: Sami Kerola <sami.kerola@lastminute.com>
* logger: generate header when reading message from stdinPatrick Plagwitz2015-04-071-7/+7
| | | | | | | | | | | | | | | This change fixes crashing error, that ought not to be simply avoided. $ echo foo | logger -n localhost Segmentation fault (core dumped) If the ctl->hdr is just checked not to be NULL syslog message will not have valid header, so generating such is not optional when reading message from stdin and writing it to remote destination. Reviewed-by: Bernhard Voelker <mail@bernhard-voelker.de> Signed-off-by: Patrick Plagwitz <patrick.plagwitz@fau.de> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* logger: fix LOGGER_TEST_TIMEOFDAY checkKarel Zak2015-03-231-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* logger: add -DTEST_LOGGERKarel Zak2015-03-161-6/+50
| | | | | | | | | | | | | | | | | | | | | | "make test_logger" now compiles logger(1) test program to overwrite system datetime stuff, hostname and PID, for example: export TZ=GMT export LOGGER_TEST_TIMEOFDAY=1234567890.123456 export LOGGER_TEST_HOSTNAME=foo export LOGGER_TEST_GETPID=123 ./test_logger --rfc5424 --no-act --stderr -i --tag MyTag mesg <13>1 2009-02-13T23:31:30.123456+00:00 foo MyTag 123 - [timeQuality tzKnown="1" isSynced="0"] mesg if the LOGGER_TEST_* variables are not specified then default to standard logger(1) behavior. Note that it would be possible to use for example "unshare --utc" to make hostname stable and portable, but LOGGER_TEST_* variables allow to keep the tests less complex. Signed-off-by: Karel Zak <kzak@redhat.com>
* logger: add --no-act for testingKarel Zak2015-03-161-14/+32
| | | | | | | | | | * force --journal mode to also output to stderr when the option --stderr specified on command line * add --no-act to avoid all write() operations to make it possible to write tests without "spam" system logs Signed-off-by: Karel Zak <kzak@redhat.com>