Commit Graph

116 Commits

Author SHA1 Message Date
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
Karel Zak a9f789e518 last: use xalloc.h, err.h, nls.h and EXIT_ macros
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-12 14:10:42 +02:00
Karel Zak 4c7dfea7a4 last: consolidate btmp/wtmp file paths
.. so share the paths with another utils.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-12 13:42:25 +02:00
Karel Zak 293e0c90e4 last: add long options, improve usage()
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-12 13:39:11 +02:00
Karel Zak 4d1d1233f4 last: clean up the begin of the file
.. and improve last(1) stuff in configure script.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-12 12:26:03 +02:00
Ondrej Oprala ce60272039 last: merge sysvinit last/lastb
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-12 12:07:52 +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 7ff8163815 last: stop usig MAXHOSTNAMELEN
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-10-19 16:56:57 +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
Karel Zak 69c9e8387b last: use min() from c.h
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-05-23 10:07:57 +02:00
Sami Kerola 439cdf1e24 login-utils: verify writing to streams was successful
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-04-04 19:58:34 +02:00
Sami Kerola ba0c903004 docs: add deprecation comments
Markup deprecation to command header to avoid people wasting time in
fixing these utilities.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-18 14:28:03 +01:00
Sami Kerola 5818a4aa9e last: fix few compiler warnings
Calling abort() as default seems appropriate as the default should be
impossible to reach.

last.c:355:3: warning: switch missing default case [-Wswitch-default]

And simple line removals.

last.c:110:13: warning: redundant redeclaration of 'optind' [-Wredundant-decls]
last.c:111:15: warning: redundant redeclaration of 'optarg' [-Wredundant-decls]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-11-29 17:58:00 +01:00
Sami Kerola 889df821e3 last: possible buffer overflow fixed [smatch scan]
last.c +447 ttyconv(11) error: buffer overflow '(arg)' 3 <= 3

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-11-29 17:58:00 +01:00
Sami Kerola 889f1215f6 last: fix smatch warning
login-utils/last.c +447 ttyconv(11) error: buffer overflow '(arg)' 3 <= 3

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-09-10 16:49:58 +02:00
Karel Zak 696b5ca45b last: fix compiler warnings [-Wsign-compare]
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-08-01 15:39:55 +02:00
Fabian Groffen eb76ca98b0 build-sys: provide alternatives for err, errx, warn and warnx
Solaris lacks err, errx, warn and warnx.  This also means the err.h header
doesn't exist.  Removed err.h include from all files, and included err.h from
c.h instead if it exists, otherwise alternatives are provided.

Signed-off-by: Fabian Groffen <grobian@gentoo.org>
2011-02-14 17:45:24 +01:00
Marek Polacek db797f24f1 last: Use EXIT_* and err()
Signed-off-by: Marek Polacek <mmpolacek@gmail.com>
2010-12-10 13:18:12 +01:00
Davidlohr Bueso eecb3c83ce last: use xalloc lib
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2010-11-30 13:18:18 +01:00
Marek Polacek 50644ff4de use _exit() instead of exit() in sighandlers
Signed-off-by: Marek Polacek <mmpolacek@gmail.com>
2010-10-29 13:26:25 +02:00
Karel Zak 8e5cf69f9e last: fix utmp.ut_time usage
The utmp.ut_time is timeval.tv_sec (time_t) or int32_t. It's more
robust not to use ctime() or time() directly.

Signed-off-by: Karel Zak <kzak@redhat.com>
2009-11-20 14:46:32 +01:00
Karel Zak 48d7b13a1e Imported from util-linux-2.13-pre1 tarball. 2006-12-07 00:26:54 +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 7eda085c41 Imported from util-linux-2.9v tarball. 2006-12-07 00:25:39 +01:00
Karel Zak 5c36a0eb7c Imported from util-linux-2.9i tarball. 2006-12-07 00:25:37 +01:00
Karel Zak 2b6fc908bc Imported from util-linux-2.8 tarball. 2006-12-07 00:25:35 +01:00
Karel Zak fd6b7a7ffc Imported from util-linux-2.7.1 tarball. 2006-12-07 00:25:34 +01:00
Karel Zak 726f69e29c Imported from util-linux-2.5 tarball. 2006-12-07 00:25:33 +01:00
Karel Zak 6dbe3af945 Imported from util-linux-2.2 tarball. 2006-12-07 00:25:32 +01:00