Commit Graph

48 Commits

Author SHA1 Message Date
Karel Zak 9ee95fa26a utmpdump: do not use atoi()
Addresses: https://github.com/karelzak/util-linux/issues/1358
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-07-20 11:49:57 +02:00
Andrew Shapiro f3a7b057ac utmpdup: Ensure flushing when using follow flag
The following usages of utmpdump result in no output being flushed to the specified file because the default output buffering is fully buffered:

$ utmpdump --follow --output myOutputFile /var/log/utmp
$ utmpdump --follow /var/log/utmp > myOutputFile

This change configures line buffering for these scenarios so that output will be flushed after each log event.

Signed-off-by: Andrew Shapiro <anshapiro@gmail.com>
2021-03-02 10:49:53 +01:00
Rosen Penev 042f62dfc5
[clang-tidy] do not use else after return
Found with readability-else-after-return

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-20 13:20:59 -07:00
Karel Zak e868cfb0a6 utmpdump: check ftello() return value
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-16 13:46:03 +02:00
Karel Zak 2c308875a7 misc: consolidate version printing and close_stdout()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-16 15:14:13 +02:00
J William Piggott 4111bb3ab5 lib/timeutils: add common ISO timestamp masks
* Start the ISO format flags at bit 0 instead of bit 1.

* Remove unnecessary _8601 from ISO format flag names to
  avoid line wrapping and to ease readability.

* ISO timestamps have date-time-timzone in common, so move
  the TIMEZONE flag to bit 2 causing all timestamp masks
  to have the first three bits set and the last four bits
  as timestamp 'options'.

* Change the 'SPACE' flag to a 'T' flag, because it makes
  the code and comments more concise.

* Add common ISO timestamp masks.

* Implement the ISO timestamp masks in all applicable code
  using the strxxx_iso() functions.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2017-11-10 16:34:55 -05:00
Ruediger Meier f45f3ec34a misc: consolidate macro style USAGE_HELP_OPTIONS
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>
2017-06-29 16:54:33 +02:00
Ruediger Meier b1a294c448 misc: introduce print_usage_help_options()
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>
2017-06-27 12:26:19 +02:00
Ruediger Meier 86be6a32d3 misc: cosmetics, remove argument from usage(FILE*)
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>
2017-06-26 14:38:24 +02:00
Karel Zak b8af37d767 build-sys: remove duplicate includes
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-12 11:17:02 +02:00
Sami Kerola 34a9766b0e utmpdump: remove unnecessary variable
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-03-31 12:58:13 +02:00
Sami Kerola 8791804065 misc: do not use plain 0 as NULL [smatch scan]
text-utils/tailf.c:69:21: warning: Using plain integer as NULL pointer

Since many 'struct option' has used zero as NULL make them more readable in
same go by reindenting, and using named argument requirements.

Reference: https://lwn.net/Articles/93577/
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Sami Kerola b72a75e993
lib: add timegm() portability function to lib/timeutils.c
Local timegm() is a replacement function in cases it is missing from libc
implementation.  Hopefully the replacement is never, or very rarely, used.

CC: Ruediger Meier <ruediger.meier@ga-group.nl>
Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-03 22:31:18 +00:00
Karel Zak 677ec86cef Use --help suggestion on invalid option
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>
2016-12-19 13:13:34 +01:00
Ruediger Meier b4b919fe5e login-utils: switch to utmpx.h
Now the build will fail on many non-Linux systems because
utmpx.h is available everywhere but we still use non-POSIX
features. We'll fix this next commit.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-12-07 12:35:24 +01:00
Ruediger Meier f718c2fc7f utmpdump: code formatting for readability
BTW avoid using the defined sizes.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-12-07 12:35:24 +01:00
Ruediger Meier 55771f5409 login-utils: remove _HAVE_UT_TV fallback
_HAVE_UT_TV is glibc only. Moreover we want to move to utmpx where
timeval is standard.

Now utmp/subsecond (1173d0a6) should work on all supported systems.

CC: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-12-07 12:35:24 +01:00
Sami Kerola 74ce680a3e
misc: simplify if clauses [oclint]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-21 21:14:33 +01:00
Sami Kerola 1173d0a6bf
utmpdump: use iso-8601 timestamp format with subsecond accuracy
Newer 'struct utmp' is using 'struct timeval' to represent login and logout
times, so include the maximum accuracy to textual utmp format.  Notice that
this change does not remove support of converting earlier textual formats
back to binary.  But conversions from binary to former format will no longer
be available.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-06-26 21:58:18 +01:00
Sami Kerola 3749bdcecf
utmpdump: use always UTC-0 timezone in textual output
Converting a time structure from text format that has timezone markup is
practically impossible.  See reference links for more information.  This
leads to situation where multiple utmpdump(1) conversions from binary to
text and back make timestamps to shift amount of timezone offset to UTC-0.

The easiest way to make multiple conversions to work without timeshifts is
to always use UTC-0 timezone.  Downside of this approach is that the textual
format is less human readable than local timestamps would be.

Reference: http://www.catb.org/esr/time-programming/#_strptime_3_and_getdate_3
Reference: http://man7.org/linux/man-pages/man3/strptime.3.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-06-26 21:58:18 +01:00
Benno Schulenberg fc14ceba5e textual: grammarize and harmonize the stat error message
The message "stat failed %s" seems to say that stat() failed to
do something, or failed to pass a test, but of course it means
that the statting of something failed.  So say so.  Also make
two very similar messages equal to this one.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-02-02 11:27:10 +01:00
Karel Zak 912a7077b2 utmpdump: don't pass parameter of type "struct utmp" by value [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-29 11:40:47 +01: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
Ruediger Meier 18df1cc77c utmpdump: fix localtime() error handling
If current TZ has no representation of a given time_t then localtime()
would return NULL and break the next strftime().

In practice this happens very likely on systems with 64bit time_t when
parsing broken binary data. Seen on aarch64 (and probably s390) using
our (incompatible) test wtmp data.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2014-06-11 23:06:32 +02:00
Karel Zak 85dd024d84 utmpdump: make analyzers happy
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-10-01 17:11:25 +02:00
Sami Kerola ee508c153f utmpdump: make IPv6 addresses work
(unless bug[s]) This change is backwards compatibile.  Earlier binary to
text dumps can be converted back to binary, or otherway around.

The only thing that will not work are IPv6 addresses that possible
earlier conversion had broke.  Such conversions resulted with random IPv4
in place of IPv6 address in text format, and original information is gone
forever.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:10 +01:00
Sami Kerola cfa7fe890b last, utmpdump, agetty, wall, write: avoid compatibility hacks
In include/bits/utmp.h the ut_user and ut_time macros are marked with
comment they are backwards compatibility hacks.  It is probably best to
avoid use of these macros where ever possible.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:10 +01:00
Sami Kerola ad20f0d883 utmpdump: assigned values are never read [clang-analyzer]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-07-09 14:25:07 +02:00
Sami Kerola 930954d87a utmpdump: add option to write to a file
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-04-26 13:25:58 +02:00
Karel Zak 48f2fdbf89 utmpdump: fix compiler warning [-Wunused-result]
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-07-26 09:46:49 +02:00
Sami Kerola 289dcc9023 translation: unify file open error messages
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-07-16 18:18:22 +02:00
Sami Kerola 400bc941fc utmpdump: use help and version output macros
Done to reduce translation project work.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-07-16 18:18:22 +02:00
Sami Kerola 4e7e68ca6f utmpdump: remove unused variable
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-07-16 18:18:21 +02:00
Karel Zak faebdd91ba utmpdump: cleanup file descriptor usage
- don't support --follow for stdin at all
 - inotify based implementation closes the file, so don't close it in
   main() again

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-07-10 11:25:11 +02:00
Sami Kerola 5ec1ad1348 utmpdump: encourage users not to follow stdin
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-07-10 11:01:29 +02:00
Sami Kerola 7346f2b61c utmpdump: use inotify to when following file
Co-Author: Karel Zak <kzak@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-07-10 10:59:58 +02:00
Sami Kerola e31926b443 utmpdump: fixes based on static analysis [cppcheck]
[utmpdump.c:82]: (style) The function 'unspace' is never used
[utmpdump.c:131]: (style) The scope of the variable 't' can be reduced
[utmpdump.c:167]: (warning) scanf without field width limits can crash with huge input data

[kzak@redhat.com: - don't use scanf field width limits for integers]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-07-10 08:56:22 +02:00
Sami Kerola cd903a0eba utmpdump: white space fix
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-07-09 18:04:37 +02:00
Bernhard Voelker 4810de912a utmpdump: document optional filename argument
Signed-off-by: Bernhard Voelker <mail@bernhard-voelker.de>
2012-07-09 17:11:00 +02:00
Karel Zak 34f4d96163 utmpdump: use xalloc.h, minor coding style changes
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-29 17:34:12 +02:00
Karel Zak c8a6af07e7 utmpdump: cleanup usage()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-29 17:27:40 +02:00
Karel Zak 9e15c93d76 utmpdump: add long options
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-29 17:22:42 +02:00
Karel Zak 704bd903ec utmpdump: use err.h stuff
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-29 17:09:51 +02:00
Karel Zak 23031b9904 utmpdump: add NLS and closestream support
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-29 16:59:32 +02:00
Karel Zak a9eee87090 utmpdump: remove dead code
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-29 16:56:04 +02:00
Karel Zak b89fc9151f utmpdump: remove libc5 support
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-29 16:52:30 +02:00
Karel Zak fa9baa80e8 utmpdump: cleanup comments, funcs definition lines
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-29 16:43:37 +02:00
Karel Zak 78d5ceacb1 utmpdump: new command, merge from sysvinit
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-29 16:34:46 +02:00