Commit Graph

73 Commits

Author SHA1 Message Date
Karel Zak c580b554c9 Merge branch 'timex' of https://github.com/kerolasa/lelux-utiliteetit
* 'timex' of https://github.com/kerolasa/lelux-utiliteetit:
  logger: check availability of ntp_gettime()
2015-01-26 11:59:10 +01:00
Karel Zak d0e875ffd4 logger: improve usage()
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-26 11:26:40 +01:00
Benno Schulenberg d45867162c textual: put option and its description into a single translatable string
Also improve the description: notime, notq, and nohost are literals,
not things to be replaced by something else -- so no angular brackets.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-01-26 11:22:13 +01:00
Benno Schulenberg 54fefa078e textual: fix spellos and inconsistencies in several program messages
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-01-26 11:17:55 +01:00
Samuel Thibault 87ee265835 logger: check availability of ntp_gettime()
Make compilation to work in systems which don't have sys/timex.h and its
ntp_gettime().

Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Samuel Thibault <sthibault@debian.org>
2015-01-23 19:57:22 +00:00
Benno Schulenberg 451dbcfae1 textual: add a docstring to most of the utilities
This adds a concise description of a tool to its usage text.

A first form of this patch was proposed by Steven Honeyman
(see http://www.spinics.net/lists/util-linux-ng/msg09994.html).

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-01-06 11:27:38 +01:00
Andreas Henriksson 5ec85227ad logger: gettimeofday needs <sys/time.h>
Either works on linux, but kfreebsd build fails
if we don't use the <sys/time.h> include.

According to man gettimeofday the correct include is <sys/time.h>

Signed-off-by: Andreas Henriksson <andreas@fatal.se>
2014-09-22 12:54:11 +02:00
Karel Zak 59c6ac0b92 logger: use generic --id=<id>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-20 12:24:40 +02:00
Sami Kerola 46ee14df66 logger: set function arguments read-only when possible
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-08-15 21:52:12 +01:00
Sami Kerola 77c3bd5bf6 logger: optimize string initializations
Setting whole array to be completely full of nulls cannot be as quick as
making the only significant member of the array when needed.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-08-15 21:52:12 +01:00
Sami Kerola 35d3619793 logger: remove openlog(3) options
One variable less, and more importantly bit operations become unnecessary
in if statements.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-08-15 21:52:12 +01:00
Sami Kerola 1d57503378 logger: allow use of --id=ppid when logging locally
There is no obvious way to make syslog(3) to print both pid or ppid, so
duplicate the libc syslog() to logger.  Making the ppid printing work
using unix socket has side effect of local becoming capable to use both
rfc format output, which is hopefully seen as good thing.  The
syslog_local() is format wise one-to-one copy with glibc syslog(3)
format.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-08-15 21:52:12 +01:00
Benno Schulenberg 1d23119072 textual: remove some inconsistent periods from error messages
While doing so, also improve translatability and some wordings.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2014-08-11 14:51:54 +02:00
Karel Zak 7eec45f2d8 logger: fix untranslated message
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-07-29 12:13:24 +02:00
Karel Zak 1042ce18df logger: require --{server,socket} to remote rfc542/rfc3164 log
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-07-29 12:08:47 +02:00
Karel Zak e598686d3c logger: fix -i=ppid
For short options (-i) the optional argument contains '='.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-07-29 11:49:00 +02:00
Karel Zak 852feb7299 logger: clean up strings usage
- use allocated buffers to compose the final messages

 - initialize static buffers to zero

 - remove strlen-after-sprintf

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-07-29 11:43:01 +02:00
Sami Kerola 133bf77bc2 logger: add hostname to rfc3164 message
This makes the obsolete protocol a little bit more compliant with the
internet standard, but few should care now when we have rfc5424 support,
and rfc3164 feels broken.  For example it requires hostname to be not
fully qualified, which is hard to understand, and should make users to
prefer the new protocol.

Reported-by: Frank Thilo <thilo@unix-ag.org>
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=705217
CC: Andreas Henriksson <andreas@fatal.se>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-07-28 21:15:18 +01:00
Sami Kerola 3d9f4b1d23 logger: warn when --file and command line message are combined
When --file is combined with command line arguments the later has
silently been ignored.  This commit makes user to be aware the logger
will not use command line arguments when --file is specified.

Reported-by: "Daniel 'DaB.' Baur" <debian@daniel.baur4.info>
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=467244
CC: Andreas Henriksson <andreas@fatal.se>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-07-28 21:15:18 +01:00
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