Commit Graph

54 Commits

Author SHA1 Message Date
Sami Kerola 2e0fd22d5d logger: improve readablity of pencode() function
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-07-28 21:15:18 +01:00
Sami Kerola 4288f9f12c logger: make --stderr print remote server messages
Users wish to see the message should include also remote messages, not
only the one sent to locally via libc function.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-07-28 21:15:18 +01:00
Sami Kerola aab5b44405 logger: add process --id=parent optional argument
When scripts send several messages they will be easier to group together
when parent process id is printed rather than id of the each logger
process.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-07-28 21:15:18 +01:00
Sami Kerola 4de2e8a038 logger: add rfc5424 support
Add support the more recent syslog protocol and make it default.  The
older BSD syslog protocol can still be used with option --rfc3164.
Protocols are meaningful only when messages are sent to remote syslog
server.

Requested-by: Kodiak Firesmith <ksf@sei.cmu.edu>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-07-28 21:15:17 +01:00
Sami Kerola c68a1cb490 logger: tidy up main() by adding small functions and ctl data
Add logger_open(), logger_command_line(), logger_stdin(), and
logger_close() functions, and move all remaining option argument
assignments to control structure.

Proposed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-07-28 21:15:17 +01:00
Sami Kerola cfa77d2643 logger: add function pointer to choose how logging is done
This change paves way to adding support for both RFC 3164 and RFC 5424
syslog protocols.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-07-28 21:15:17 +01:00
Sami Kerola c462a8caf2 logger: refactor long if clause
When if clause that continues throughout whole function it usually can be
shorten to immediate action, e.g., in this case return on the spot not at
end of the function.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-07-28 21:15:17 +01:00
Sami Kerola 019b97024f logger: do not rely only getlogin(3) telling who ran the command
The getlogin(3) is known not to always work, and when that happens it is
reasonable to try determine user of name by looking process owner and
passwd information.

Reference: http://man7.org/linux/man-pages/man3/getlogin.3.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-07-28 21:15:16 +01:00
Sami Kerola d8b616c216 logger: fix indentation issues
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-07-28 21:15:16 +01:00
Sami Kerola 633493beaf logger: ensure program writes everything to syslog file descriptor
It is fair assumption messages an user is asking to be wrote will be
attempted to be wrote as hard as possible.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-07-28 21:15:16 +01:00
Benno Schulenberg 09af3db48e textual: fix some typos and inconsistencies in various messages
Fixing plain typos, miswordings, inconsistent periods, some missing
angular brackets, and a proper pluralization (even when it involves
a constant, because for some languages the precise value matters).

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2014-07-23 08:56:00 +02:00
Sami Kerola 89dda67868 build-sys: remove unnecessary void casts
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-05-12 13:07:12 +02:00
Sami Kerola 4d7d1af674 logger: check numeric priority and facility input values
Earlier use of unknown facility or priority number was accepted, and
resulted in unexpected result.  For example when looking journalctl
--priority=7.8 was converted to priotity 0 and facility 1.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-05-12 13:07:09 +02:00
Sami Kerola 047e2888a3 logger: fail when io vector number exceeds maximum
Earlier version silently failed without logging anything.

$ logger --journald=/etc/services ; echo $?
1

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-05-12 13:07:06 +02:00
Karel Zak ebff016a19 build-sys: consolidate systemd support
* systemd (since v209) uses only one library (when compiled
   without --enable-compat-libs)

 * all systemd build-sys stuff is merged into HAVE_SYSTEMD
  (automake) and HAVE_LIBSYSTEMD (C macro) now

 * all is controlled by --with-systemd, default is to automatically
   check for systemd libs

 * no more --enable-socket-activation and --enable-journald

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-09 12:23:30 +02:00
Sami Kerola 4b670c01df logger: allow user to send structured journald messages
This feature is hopefully mostly used to give MESSAGE_ID labels for
messages coming from scripts, making search of messages easy.  The
logger(1) manual page update should give enough information how to use
--journald option.

[kzak@redhat.com: - add missing #ifdefs
                  - use xalloc.h]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-04 13:44:21 +01:00
Benno Schulenberg 4ce393f4d8 textual: fix several typos and angular brackets in messages
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-06-07 12:11:14 +02:00
Karel Zak 195c36032a logger: small coding style changes
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-05-29 10:56:05 +02:00
Karel Zak 925aa9e85d logger: cleanup usage()
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-05-29 10:54:51 +02:00
Dennis H Jensen 98920f8059 logger: add support for --prio-prefix when logging stdin
This patch adds a new option to logger that will make it look for a
priority prefix <n> at the beginning of every line. The priority is
a single decimal number formed as explained in syslog(3).

If a prefix is found logger will log the message using the found
facility and level in that prefix, if the prefix doesn't contain a
facility the default facility specified by the -p option will be used.
If no prefix is found, logger will use the priority specified by -p.

[kzak@redhat.com: - add --prio-prefix to usage() output]

Signed-off-by: Dennis H Jensen <dennis.h.jensen@siemens.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-05-29 10:47:16 +02:00
Karel Zak 2885c533fd logger: make socket initialization in main() more readable
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-04-08 16:39:59 +02:00
Sami Kerola 68265d070d logger: allow to log using tcp transport protocol
This commit fixes error in usage() text, which claimed TCP is default
transport protocol.  That was not true, and neither it should be.  The
syslog messages has traditionally sent using UDP.

For the logger remains using UDP as first transport, but if it fails a
TCP connection is attempted.  If an user wishes remote logging can be
forced to use either UDP or TCP.  The service port for UDP is familiar
'syslog', for TCP the port 'syslog-conn' seems like reasonable default.

[kzak@redhat.com: - rename myopenlog to unix_socket(),
                  - always reset st to -1]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-04-08 16:31:28 +02:00
Sami Kerola fe6999da0a logger: make local sockets to try both stream and datagram
When journald, from systemd, is in use logger gave following error.

$ logger --socket /dev/log test logger: connect /dev/log: Protocol wrong
type for socket

The journald supports only AF_DGRAM, and nothing else.  Support for
AF_STREAM sockets was dropped because it messed up message ordering.

From an users point of view necessity to add --udp (UNIX(TM) Datagram
Protocol?) option when talking to syslog via unix socket felt confusing
and wrong.  The command should know what is the socket type, and silently
use the correct one, unless the type is explicitely defined.

CC: Karel Zak <kzak@redhat.com>
Adviced-by: Lennart Poettering <lennart@poettering.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-04-05 14:05:24 +02:00
Benno Schulenberg b50945d4ac textual: spell and encode the name of Arkadiusz Miśkiewicz correctly
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-02-06 11:15:02 +01:00
Karel Zak e421313dc2 textual: use UTIL_LINUX_VERSION everywhere
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-01-25 12:05:26 +01:00
Sami Kerola 24f4db6972 logger: replace gethostbyname() with getaddrinfo()
The gethostbyname() is legacy function which may be withdrawn in a
future.

Reference: http://pubs.opengroup.org/onlinepubs/009695399/functions/gethostbyname.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-10-22 10:14:24 +02:00
Dave Reisner 283d626b36 logger: use memcpy instead of bcopy
bcopy is marked legacy in POSIX.1-2001 and should not be used.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-05-29 09:33:14 +02:00
Dave Reisner 82054b1d99 logger: mark decode/pencode as static
Move these functions to the top of the file where they can be marked
static and the prototypes can be removed.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-05-29 09:32:13 +02:00
Dave Reisner 652add4c2c logger: avoid explicit fclose(stdout)
This is done for us via an atexit hook since c05a80ca63. Avoids a
useless 'Write error' on exit whenever invoking the tool.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-05-29 09:32:10 +02:00
maximilian attems adddfd37a1 misc-utils: cleanup unused strings.h includes
Noticed on klibc building.

Signed-off-by: maximilian attems <max@stro.at>
2012-05-23 10:31:12 +02:00
Karel Zak 495b13983e Merge branch 'master' of https://github.com/jhuntwork/util-linux 2012-05-23 09:39:40 +02:00
Karel Zak db41a4298f misc-utils: cleanup strtoxx_or_err()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-05-15 17:44:37 +02:00
Jeremy Huntwork 1c935e725e Remove use of __P. Its intended usage was to support pre-ANSI C compilers, but that is not even possible with the modern-day codebase. Moreover, it breaks compiling on libcs that do not define this legacy implementation-internal macro. 2012-05-13 16:32:51 +00:00
Sami Kerola c05a80ca63 misc-utils: verify writing to streams was successful
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-04-04 19:56:48 +02:00
Karel Zak 86248cd28a logger: fix remote logging
Reported-by: Hervé Quillévéré <herve_quillevere@herveq.tk>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-12-08 10:20:22 +01:00
Karel Zak f3970c99b7 logger: non-ANSI definition [smatch scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-09-12 16:13:58 +02:00
Karel Zak 2da4918695 logger: indent usage()
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-08-16 12:23:15 +02:00
Benno Schulenberg 0050c52917 logger: improve, sort and slice up usage() help text
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2011-08-16 10:16:38 +02:00
Sami Kerola 49999d6aef logger: use libc error printing facilities
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-03-08 12:04:06 +01:00
Sami Kerola b363e86d76 logger: support long options
Use getopt_long and usage output changed to match long options.
This patch will also scrutiny argument of formerly undocumented
-P option.

[kzak@redhat.com: - include c.h]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-03-08 11:55:28 +01:00
Sami Kerola dd49983ad9 logger: fix variable type compiler warning
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-03-08 11:49:57 +01:00
WUEBBELS, Josef \(Extern\) 912d6b9892 logger: support for logging to UDP socket / remote syslog server
It adds the ability to logger to log a message to a udp socket.  The -n option
followed by the hostname of the remote host is mandatory to do this.  The
optional -P option can be used to change the UDP destination port (default
514).  The function udpopenlog is used to open the udp socket. After that
everything works in almost the same way like it does when logging to a UNIX
socket.

Signed-off-by: Josef Wuebbels <josef.wuebbels@mtu.de>
2011-02-14 17:59:28 +01:00
Daniel Mierswa c0f19ccff7 replace bcopy,bzero,index and rindex
Those 4 functions are marked as LEGACY in POSIX.1-2001 and removed in
POSIX.1-2008.

Replaced with memmove,memset,strchr and strrchr.

Signed-off-by: Daniel Mierswa <impulze@impulze.org>
2009-08-17 11:15:59 +02:00
Pedro Ribeiro 331b704481 logger: several strings without gettext calls
Signed-off-by: Pedro Ribeiro <p.m42.ribeiro@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2008-10-03 09:17:07 +02:00
LaMont Jones dd0d165479 logger: use snprintf instead of sprintf in logger.c
Signed-off-by: LaMont Jones <lamont@mmjgroup.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2007-07-24 00:22:20 +02:00
Karel Zak 2cccd0ff2b Imported from util-linux-2.12d tarball. 2006-12-07 00:26:18 +01:00
Karel Zak ffc4374869 Imported from util-linux-2.11o tarball. 2006-12-07 00:25:53 +01:00
Karel Zak c07ebfa1e0 Imported from util-linux-2.11b tarball. 2006-12-07 00:25:46 +01:00
Karel Zak 66ee8158b6 Imported from util-linux-2.10s tarball. 2006-12-07 00:25:44 +01:00
Karel Zak 22853e4a82 Imported from util-linux-2.10m tarball. 2006-12-07 00:25:43 +01:00