Commit Graph

80 Commits

Author SHA1 Message Date
Sami Kerola f06abd22be
last: display input file in usage() according to command name
Default depends on whether the executable is called 'lastb' or something
else.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-10-18 18:03:34 +01:00
Ruediger Meier 2e81d99870 last, fix race when comparing time stamps
It is just luck if two time() calls happen within the same
second. Introduced in 31d28e09.

Actually I don't like adding another global variable but this
way we avoid bigger refactoring. IMO it's questionable why
lastdate, lastdown, etc. are initialized with current time() at
all. It looks unsafe to print "still running" always when
logout_time = now.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2015-03-25 10:36:52 +01:00
Ruediger Meier 568f460ca3 last: fix first (current) runlevel line
Since 744c7fec lastrch was not set to current time anymore, but we need it.

 # broken:
 $ ./last -x | grep -m 2 runlevel
 runlevel (to lvl 5)   3.11.10-25-deskt Wed Feb 18 13:11 - 01:00 (-16484+-12:-11)
 runlevel (to lvl 5)   3.11.10-25-deskt Thu Jan 22 16:50 - 13:11 (26+20:21)

 # fixed:
 $ ./last -x | grep -m 2 runlevel
 runlevel (to lvl 5)   3.11.10-25-deskt Wed Feb 18 13:11   still running
 runlevel (to lvl 5)   3.11.10-25-deskt Thu Jan 22 16:50 - 13:11 (26+20:21)

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2015-03-25 10:36:49 +01:00
Karel Zak 744c7fecd3 last: keep array of files in main()
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-03-13 11:47:00 +01:00
Karel Zak da1a8ed0b0 last: fix utmplist usage
last(1) uses a global list of entries, this is unnecessary and it's
also mistake because the pointer to the list is not set to NULL when
last(1) opens another utmp file. For example:

 last -f /var/log/wtmp -f /var/log/wtmp-20150220

ends with unexpected free() call or sometimes with never ending loop.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1201033
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-03-13 11:30:16 +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
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
Karel Zak cd2876d252 build-sys: move all around clock_gettime() to monotonic.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-19 11:54:47 +01:00
Sami Kerola d4ce90d47c last: improve code readability by renaming variable names
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-09-19 19:31:01 +01:00
Sami Kerola 8813da1ea2 last: make is_phantom() when kernel config does not include audit support
When kernel CONFIG_AUDIT is not set the /proc/<pid>/loginuid information
is not present resulting live sessions to be marked 'gone - no logout' in
last(1) print out.  To go-around this change makes last(1) to look
/dev/<tty> device ownership as a substitute of loginuid.

The go-around seems to work fairly well, but it has it short comings.
For example after closing a X window session the /dev/ttyN file seems to
be owned by root, not the user who had it before entering to the X
session.  While that is suboptimal it is still better than an attmempt to
determine uid_t by looking owner of the /proc/<struct utmp ut_pid>, that
is a login(1) process running as root.

The issue was found using Archlinux installation.

$ pacman -Qi linux
Name           : linux
Version        : 3.16-2
[...]
Build Date     : Mon Aug 4 18:06:51 2014

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-09-19 19:31:01 +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
Karel Zak 2e118e709b last: fix is_phantom() logic [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-07-17 14:39:11 +02:00
Sami Kerola 0e65dcde88 textual: fix some typos
Found with misspell-check version 2.0d.

Reference: https://github.com/lyda/misspell-check
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-07-13 17:21:02 +01:00
Ruediger Meier 6e69f1ee0f last: avoid leading "-" before "no logout"
This affects option --time-format=notime.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2014-05-10 15:17:42 +02:00
Ruediger Meier 4fcbfaa81d last: minor cleanup if statements
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2014-05-08 22:14:27 +02:00
Ruediger Meier f16d5044e1 last: --time-format=full should do the same like -F
For no reason "full" did something else than "iso" or -F as you
see here:
$ ./last  -f ../tests/ts/last/wtmp.LE  --time-format=full  | grep -A2 "no logout"
torvalds linux        hobby            Mon Aug 26 02:57:08 1991    gone                    - no logout
reboot   system boot  system-name      Wed Aug 28 20:00:00 2013   still                    running
reboot   system boot  system-name      Wed Aug 28 18:00:00 2013 - Wed Aug 28 19:00:00 2013  (01:00)
$ ./last  -f ../tests/ts/last/wtmp.LE  --time-format=iso  | grep -A2 "no logout"
torvalds linux        hobby            1991-08-26T02:57:08+0200   gone - no logout
reboot   system boot  system-name      2013-08-28T20:00:00+0200   still running
reboot   system boot  system-name      2013-08-28T18:00:00+0200 - 2013-08-28T19:00:00+0200  (01:00)
$ ./last  -f ../tests/ts/last/wtmp.LE  -F  | grep -A2 "no logout"
torvalds linux        hobby            Mon Aug 26 02:57:08 1991   gone - no logout
reboot   system boot  system-name      Wed Aug 28 20:00:00 2013   still running
reboot   system boot  system-name      Wed Aug 28 18:00:00 2013 - Wed Aug 28 19:00:00 2013  (01:00)

Also note the useless leading space before "gone"

The only thing which matters is fmt->out width when printing these
strings like "still running". Now ctl->fulltime flag is unsused and
removed.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2014-05-08 22:14:06 +02:00
Ruediger Meier d3108db19e last: fix uninitialized length
length was unset when using "last --time-format=iso"

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2014-05-07 14:42:36 +02:00
Karel Zak 08ca3e26a8 lib/timeutils: remove get_boot_time from libcommon
clock_gettime() needs -lrt, so let's keep this stuff
outside libcommon.la

Reported-by: Ruediger Meier <sweet_f_a@gmx.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-05-06 13:16:05 +02:00
Sami Kerola 0e5218acd9 last: fix is_phantom() detection
The /proc/<pid>/loginuid is not always available, and when so a running
session should not be determined to be gone.  This is a regression from
commit mentioned in reference.

Sessions that have started before previous system boot, and did not log
out meanwhile, will be marked as gone.  It is fair to say that these
sessions are most likely result of a wtmp corruption.

Reference: 404fa3f93c
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-05-04 11:42:03 +01:00
Karel Zak 78a3b0af30 include/carefulputc: cleanup and add fputs_{quoted,nonblank}()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-03 12:29:16 +02:00
Sami Kerola 404fa3f93c last: make session gone determination more robust
Earlier determination that used kill with signal zero to pid was prone to
false positive reports, due reuse of pid space and unrelated processes.
New function is_phantom() tries do a little bit better job, but fails to
be perfect.  It seems linking to gether utmp session start time or
terminal id with /proc/<pid>/ information is not as simple as one might
hope.

Reported-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-02-10 18:25:31 +01:00
Benno Schulenberg 47481cbd01 textual: standardize some "cannot read" and "seek failed" error messages
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-10-09 11:37:38 +02:00
Karel Zak d879e0529c last: check fstat() return [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-10-01 16:59:43 +02:00
Karel Zak 60f25deae7 lib: rename time-util.c to timeutils.c, fix headers
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-10 13:11:02 +02:00
Sami Kerola bce5163b68 last: fix memory leak
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-09-10 12:57:31 +02:00
Karel Zak 2ea747ebf1 last: --fulltime and --time-format are mutually exclusive
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-02 11:42:44 +02:00
Karel Zak c87e4fbbf4 last: consolidate time formatting to one struct
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-02 11:28:43 +02:00
Karel Zak ee24e58f86 last: use bit array
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-09-02 11:11:38 +02: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 31d28e0951 last: tell verbally system is still running
Use of uptime time stamp as previous boot login time makes the output not
constant, which is rather difficult to test.  Verbal message 'system is
still running' makes testing easy, and noticing which boot is still
running clear to a person.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:10 +01:00
Sami Kerola 97bbb5e41c last: trim trailing white spaces
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:10 +01:00
Sami Kerola 438269dca9 last: never restrict session time
When a session time will reach whopping 10000 days the last round bracket
is unnecessarily removed from output.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:09 +01:00
Sami Kerola 45f11b6bf7 last: add --time-format with iso-8601 format
The ISO-8601 format makes consuming time stamps easy with various
parsers.  The format includes time zone information which is crucial when
an investigator is trying to make sense outputs collected from systems
all a across planet.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:09 +01:00
Sami Kerola 83484375f2 last: use configuration struct
This allows reducing global variables and will minimize number of
arguments for functions making code a little bit easier to read, and
maintain.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:09 +01:00
Sami Kerola 4e01db8842 last: fix --present option logic error
Printing of sessions 'still logged in' was skipped because an error in
logic.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:09 +01:00
Sami Kerola dd50168b91 last: add --since time spec option
The --since and --until options are companions often needed together.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:08 +01:00
Sami Kerola 75ab9bf1eb lib/time-util: move YYYYMMDDHHMMSS to common parser
Even while the YYYYMMDDHHMMSS time format it not magnificent it is best
to make it to be part of the one, and only, time format parser.

Proposed-by: Karel Zak <kzak@redhat.com>
References: http://markmail.org/message/6baqt4ttkopu7ra6
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:08 +01:00
Sami Kerola 3a4ae395a4 last: parse easy to use time formats
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:08 +01:00
Sami Kerola 30faa20244 last: fix typo
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-29 18:14:06 +01:00
Karel Zak b86727542f last: mention optional arguments in usage
Reported-by: Bernhard Voelker <mail@bernhard-voelker.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-23 12:01:01 +02:00
Sami Kerola 37f534a667 last: add --present option
The --present option will allow user to easily determine who where logged
in at a given time.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-23 11:45:42 +02:00
Sami Kerola 7ec7822965 last: allow --file to be defined multiple times
This is useful when an admin is trying to find something, and has to
process all available data.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-23 11:31:34 +02:00
Sami Kerola 751947b6fc last: global variables are initialize automatically to zero
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-23 10:59:03 +02:00
Sami Kerola 328734c048 last: use as narrow variable scoping as possible
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-23 10:59:02 +02:00
Sami Kerola f65833b930 last: remove broken code
Comment in the deletion tells everything necessary.

"This doesn't work on modern systems, where only a DNS lookup of the
result from hostname() will get you the domainname.  Remember that
domainname() is the NIS domainname, not DNS.  So basically this whole
piece of code is bullshit."

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-23 10:59:00 +02:00
Sami Kerola e843d04753 last: prefer enum rather than #definition list
Incremental number lists are more hard to get wrong with enum, and they
are nicer to debug as for example gdb is aware of these symbolic names.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-23 10:58:59 +02:00
Sami Kerola 5cae90f9d1 last: make switch cases complete, and inform if impossible occurs
Some of the ut_type numbers does not seem to be recognized by last(1) so
they are, at least for now, silently ignored.  See glibc documentation
for information what the ignored EMPTY, INIT_PROCESS, LOGIN_PROCESS, and
ACCOUNTING mean.

Reference: FIXME
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-23 10:58:57 +02:00
Sami Kerola 1bd68aab3b last: check expected numeric user input is number
This commit also changes the line count to use unsigned integers, as
negative numbers in this context does not make sense.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-23 10:58:55 +02:00
Sami Kerola 2e58cd407e last: use carefulput() for printable character output
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-23 10:58:51 +02:00
Karel Zak 77079432d7 last: coding style clean up
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-13 10:22:50 +02:00