* [PATCH 00/16] pull: additions recent to last(1) work, plus few small changes
@ 2013-08-17 18:15 Sami Kerola
2013-08-17 18:15 ` [PATCH 01/16] build-sys: remove unnecessary environment variable Sami Kerola
` (16 more replies)
0 siblings, 17 replies; 21+ messages in thread
From: Sami Kerola @ 2013-08-17 18:15 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Hi Karel and others,
This patch set is mostly about last(1), which was recently undeprecated.
Many of the following patches are direct reactions to that change, while,
especially at the end of the patch set, others are more of a enhancements
of the last(1). With that I mean mostly about patches 0013, 0015, and
0016, which may or may not be how this command should behave. IMHO the
--present option from 0016 is most useful of these feature like changes.
Any/everyone; comments, proposal, etc feedback is welcome, as usual.
The following changes since commit 7f1fe74248290c50f5447c2c09fcf0f0575a7666:
build-sys: remove deprecated elvtune command (2013-08-13 15:55:52 +0200)
are available in the git repository at:
git://github.com/kerolasa/lelux-utiliteetit.git 2013wk32
for you to fetch changes up to 7c3160f91491d5edc793f03077fa4ba3db5ff440:
last: add --present option (2013-08-17 16:43:45 +0100)
----------------------------------------------------------------
Sami Kerola (16):
build-sys: remove unnecessary environment variable
docs: update TODO
build-sys: complete elvtune removal
docs: be clear which last(1) is deprecated
docs: add long options to last.1 manual page
include: carefulput: print determined char when unprintable char is found
last: use carefulput() for printable character output
last: check expected numeric user input is number
last: make switch cases complete, and inform if impossible occurs
last: prefer enum rather than #definition list
last: remove broken code
last: use as narrow variable scoping as possible
last: use ISO 8601 time format for --fulltimes
last: global variables are initialize automatically to zero
last: allow --file to be defined multiple times
last: add --present option
.gitignore | 1 -
Documentation/TODO | 5 -
Documentation/deprecated.txt | 7 +-
autogen.sh | 1 -
include/carefulputc.h | 4 +-
login-utils/Makemodule.am | 2 +-
login-utils/last.1 | 184 +++++++++++++----------
login-utils/last.c | 340 +++++++++++++++++++++++--------------------
term-utils/wall.c | 2 +-
term-utils/write.c | 2 +-
10 files changed, 292 insertions(+), 256 deletions(-)
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 01/16] build-sys: remove unnecessary environment variable
2013-08-17 18:15 [PATCH 00/16] pull: additions recent to last(1) work, plus few small changes Sami Kerola
@ 2013-08-17 18:15 ` Sami Kerola
2013-08-17 18:15 ` [PATCH 02/16] docs: update TODO Sami Kerola
` (15 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Sami Kerola @ 2013-08-17 18:15 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
The addition to original removal done in commit 952f1d79.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
autogen.sh | 1 -
1 file changed, 1 deletion(-)
diff --git a/autogen.sh b/autogen.sh
index 2bcbda7..48e26ad 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -12,7 +12,6 @@ test -z "$srcdir" && srcdir=.
THEDIR=`pwd`
cd $srcdir
DIE=0
-HAS_GTKDOC=1
test -f sys-utils/mount.c || {
echo
--
1.8.3.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 02/16] docs: update TODO
2013-08-17 18:15 [PATCH 00/16] pull: additions recent to last(1) work, plus few small changes Sami Kerola
2013-08-17 18:15 ` [PATCH 01/16] build-sys: remove unnecessary environment variable Sami Kerola
@ 2013-08-17 18:15 ` Sami Kerola
2013-08-17 18:15 ` [PATCH 03/16] build-sys: complete elvtune removal Sami Kerola
` (14 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Sami Kerola @ 2013-08-17 18:15 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
The minix type fixes took place December 2012.
Commit: a180dc6c54f90896d6491f9bdf704523236dd99c
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
Documentation/TODO | 5 -----
1 file changed, 5 deletions(-)
diff --git a/Documentation/TODO b/Documentation/TODO
index fe67f12..89b147b 100644
--- a/Documentation/TODO
+++ b/Documentation/TODO
@@ -25,11 +25,6 @@ lscpu
- detect more hypervisors, see 'virt-what' shell script
http://people.redhat.com/~rjones/virt-what/
-minix (fsck, mkfs)
-------------------
-
- - clean up types -- use ino_t, size_t and ssize_t
-
libmount (mount/umount)
-----------------------
--
1.8.3.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 03/16] build-sys: complete elvtune removal
2013-08-17 18:15 [PATCH 00/16] pull: additions recent to last(1) work, plus few small changes Sami Kerola
2013-08-17 18:15 ` [PATCH 01/16] build-sys: remove unnecessary environment variable Sami Kerola
2013-08-17 18:15 ` [PATCH 02/16] docs: update TODO Sami Kerola
@ 2013-08-17 18:15 ` Sami Kerola
2013-08-17 18:15 ` [PATCH 04/16] docs: be clear which last(1) is deprecated Sami Kerola
` (13 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Sami Kerola @ 2013-08-17 18:15 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
The first removal managed to remove only most of the elvtune, this commit
will complete the task.
Original-removal: 7f1fe74248290c50f5447c2c09fcf0f0575a7666
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
.gitignore | 1 -
Documentation/deprecated.txt | 5 -----
2 files changed, 6 deletions(-)
diff --git a/.gitignore b/.gitignore
index deda9a5..74f0ff1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -84,7 +84,6 @@ tests/run.sh.trs
/delpart
/dmesg
/eject
-/elvtune
/fallocate
/fdformat
/fdisk
diff --git a/Documentation/deprecated.txt b/Documentation/deprecated.txt
index 1266957..f78965c 100644
--- a/Documentation/deprecated.txt
+++ b/Documentation/deprecated.txt
@@ -51,11 +51,6 @@ Why: parallel port printers are probably almost extinct devices
--------------------------
-What: elvtune
-Why: useless for kernel >= 2.6.9
-
----------------------------
-
What: last(1)
Why: nobody uses this implementation
--
1.8.3.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 04/16] docs: be clear which last(1) is deprecated
2013-08-17 18:15 [PATCH 00/16] pull: additions recent to last(1) work, plus few small changes Sami Kerola
` (2 preceding siblings ...)
2013-08-17 18:15 ` [PATCH 03/16] build-sys: complete elvtune removal Sami Kerola
@ 2013-08-17 18:15 ` Sami Kerola
2013-08-17 18:15 ` [PATCH 05/16] docs: add long options to last.1 manual page Sami Kerola
` (12 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Sami Kerola @ 2013-08-17 18:15 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
The recently merged sysvinit last(1) and lastb(1) are supported.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
Documentation/deprecated.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Documentation/deprecated.txt b/Documentation/deprecated.txt
index f78965c..9a21980 100644
--- a/Documentation/deprecated.txt
+++ b/Documentation/deprecated.txt
@@ -51,7 +51,7 @@ Why: parallel port printers are probably almost extinct devices
--------------------------
-What: last(1)
+What: deprecated_last(1)
Why: nobody uses this implementation
----------------------------
--
1.8.3.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 05/16] docs: add long options to last.1 manual page
2013-08-17 18:15 [PATCH 00/16] pull: additions recent to last(1) work, plus few small changes Sami Kerola
` (3 preceding siblings ...)
2013-08-17 18:15 ` [PATCH 04/16] docs: be clear which last(1) is deprecated Sami Kerola
@ 2013-08-17 18:15 ` Sami Kerola
2013-08-17 18:15 ` [PATCH 06/16] include: carefulput: print determined char when unprintable char is found Sami Kerola
` (11 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Sami Kerola @ 2013-08-17 18:15 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
And align the manual page with Documentation/howto-man-page.txt
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
login-utils/last.1 | 180 ++++++++++++++++++++++++++++++-----------------------
1 file changed, 102 insertions(+), 78 deletions(-)
diff --git a/login-utils/last.1 b/login-utils/last.1
index 0eaec11..eff6fe4 100644
--- a/login-utils/last.1
+++ b/login-utils/last.1
@@ -1,4 +1,3 @@
-'\" -*- coding: UTF-8 -*-
.\" Copyright (C) 1998-2004 Miquel van Smoorenburg.
.\"
.\" This program is free software; you can redistribute it and/or modify
@@ -15,113 +14,138 @@
.\" along with this program; if not, write to the Free Software
.\" Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
.\"
-.\"{{{}}}
-.\"{{{ Title
-.TH LAST,LASTB 1 "Jul 31, 2004" "" "Linux System Administrator's Manual"
-.\"}}}
-.\"{{{ Name
+.TH "LAST,LASTB" "1" "August 2013" "util-linux" "User Commands"
.SH NAME
last, lastb \- show listing of last logged in users
-.\"}}}
-.\"{{{ Synopsis
.SH SYNOPSIS
.B last
-.RB [ \-R ]
-.RB [ \-\fInum\fP ]
-.RB "[ \-\fBn\fP \fInum\fP ]"
-.RB [ \-adFiowx ]
-.RB "[ \-\fBf\fP \fIfile\fP ]"
-.RB "[ \-\fBt\fP \fIYYYYMMDDHHMMSS\fP ]"
+.RI [ options ]
.RI [ name... ]
.RI [ tty... ]
.br
.B lastb
-.RB [ \-R ]
-.RB [ \-\fInum\fP ]
-.RB "[ \-\fBn\fP \fInum\fP ]"
-.RB "[ \-\fBf\fP \fIfile\fP ]"
-.RB [ \-adFiowx ]
+.RI [ options ]
.RI [ name... ]
.RI [ tty... ]
-.\"}}}
-.\"{{{ Description
.SH DESCRIPTION
-.B Last
-searches back through the file \fB/var/log/wtmp\fP (or the file
-designated by the \fB\-f\fP flag) and displays a list of all
-users logged in (and out) since that file was created. Names of users
-and tty's can be given, in which case \fBlast\fP will show only those entries
-matching the arguments. Names of ttys can be abbreviated, thus \fBlast
-0\fP is the same as \fBlast tty0\fP.
+.B last
+searches back through the file
+.B /var/log/wtmp
+(or the file designated by the
+.B \-f
+option) and displays a list of all users logged in (and out) since that
+file was created.
+.I Names
+of users and
+.IR tty 's
+can be given, in which case
+.B last
+will show only those entries matching the arguments. Names of
+.I ttys
+can be abbreviated, thus
+.B last 0
+is the same as
+.BR "last tty0" .
.PP
-When \fBlast\fP catches a \s-2SIGINT\s0 signal (generated by the interrupt key,
-usually control-C) or a \s-2SIGQUIT\s0 signal (generated by the quit key,
-usually control-\e), \fBlast\fP will show how far it has searched through the
-file; in the case of the \s-2SIGINT\s0 signal \fBlast\fP will then terminate.
+When
+.B last
+catches a \s-2SIGINT\s0 signal (generated by the interrupt key, usually
+control-C) or a \s-2SIGQUIT\s0 signal,
+.B last
+will show how far it has searched through the file; in the case of the
+\s-2SIGINT\s0 signal
+.B last
+will then terminate.
.PP
-The pseudo user \fBreboot\fP logs in each time the system is rebooted.
-Thus \fBlast reboot\fP will show a log of all reboots since the log file
-was created.
+The pseudo user
+.B reboot
+logs in each time the system is rebooted. Thus
+.B last reboot
+will show a log of all reboots since the log file was created.
.PP
-\fBLastb\fP is the same as \fBlast\fP, except that by default it shows a log
-of the file \fB/var/log/btmp\fP, which contains all the bad login attempts.
-.\"}}}
-.\"{{{ Options
+.B lastb
+is the same as
+.BR last ,
+except that by default it shows a log of the file
+.BR /var/log/btmp ,
+which contains all the bad login attempts.
.SH OPTIONS
-.IP "\fB\-f\fP \fIfile\fP"
-Tells \fBlast\fP to use a specific file instead of \fB/var/log/wtmp\fP.
-.IP \fB\-\fP\fInum\fP
-This is a count telling \fBlast\fP how many lines to show.
-.IP "\fB\-n\fP \fInum\fP"
-The same.
-.IP "\fB\-t\fP \fIYYYYMMDDHHMMSS\fP"
-Display the state of logins as of the specified time. This is
-useful, e.g., to determine easily who was logged in at a particular
-time -- specify that time with \fB\-t\fP and look for "still logged
-in".
-.IP "\fB\-f\fP \fIfile\fP"
-Specifies a file to search other than \fB/var/log/wtmp\fP.
-.IP \fB\-R\fP
+.TP
+\fB\-f\fR, \fB\-\-file\fR \fIfile\fR
+Tell
+.B last
+to use a specific file instead of
+.BR /var/log/wtmp .
+.TP
+\fB\-\fInumber\fR
+.TQ
+\fB\-n\fR, \fB\-\-limit\fR \fInumber\fR
+This is a count telling
+.B last
+how many lines to show.
+.TP
+\fB\-t\fR, \fB\-\-until\fR \fIYYYYMMDDHHMMSS\fR
+Display the state of logins as of the specified time. This is useful,
+e.g., to determine easily who was logged in at a particular time --
+specify that time with
+.B \-\-until
+and look for "still logged in".
+.TP
+\fB\-F\fR, \fB\-\-fulltimes\fR
+Print full login and logout times and dates.
+.TP
+\fB\-R\fR, \fB\-\-nohostname\fR
Suppresses the display of the hostname field.
-.IP \fB\-a\fP
-Display the hostname in the last column. Useful in combination
-with the next flag.
-.IP \fB\-d\fP
+.TP
+\fB\-a\fR, \fB\-\-hostlast\fR
+Display the hostname in the last column. Useful in combination with the
+.B \-\-dns
+option.
+.TP
+\fB\-d\fR, \fB\-\-dns\fR
For non-local logins, Linux stores not only the host name of the remote
-host but its IP number as well. This option translates the IP number
+host but its IP number as well. This option translates the IP number
back into a hostname.
-.IP \fB\-F\fP
+.TP
+\fB\-F\fR, \fB\-\-fullnames\fR
Print full login and logout times and dates.
-.IP \fB\-i\fP
-This option is like \fB-d\fP in that it displays the IP number of the remote
-host, but it displays the IP number in numbers-and-dots notation.
-.IP \fB\-w\fP
+.TP
+\fB\-i\fR, \fB\-\-ip\fR
+This option is like
+.B \-\-dns
+in that it displays the remote host, but it displays the host in IP
+number notation.
+.TP
+\fB\-w\fR, \fB\-\-fullnames\fR
Display full user and domain names in the output.
-.IP \fB\-x\fP
+.TP
+\fB\-x\fR, \fB\-\-system\fR
Display the system shutdown entries and run level changes.
-.\"}}}
.SH NOTES
-The files \fIwtmp\fP and \fIbtmp\fP might not be found. The system only
-logs information in these files if they are present. This is a local
-configuration issue. If you want the files to be used, they can be
-created with a simple \fBtouch\fP(1) command (for example,
-\fItouch /var/log/wtmp\fP).
-.\"{{{ Files
+The files
+.I wtmp
+and
+.I btmp
+might not be found. The system only logs information in these files if
+they are present. This is a local configuration issue. If you want the
+files to be used, they can be created with a simple
+.BR touch (1)
+command (for example,
+.IR "touch /var/log/wtmp" ).
.SH FILES
/var/log/wtmp
.br
/var/log/btmp
-.\"}}}
-.\"{{{ Author
.SH AUTHOR
-Miquel van Smoorenburg, miquels@cistron.nl
-.\"}}}
+.MT miquels@cistron.nl
+Miquel van Smoorenburg
+.ME
.SH AVAILABILITY
The last command is part of the util-linux package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
-.\"{{{ See also
+.UR ftp://\:ftp.kernel.org\:/pub\:/linux\:/utils\:/util-linux/
+Linux Kernel Archive
+.UE .
.SH "SEE ALSO"
.BR shutdown (8),
.BR login (1),
.BR init (8)
-.\"}}}
--
1.8.3.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 06/16] include: carefulput: print determined char when unprintable char is found
2013-08-17 18:15 [PATCH 00/16] pull: additions recent to last(1) work, plus few small changes Sami Kerola
` (4 preceding siblings ...)
2013-08-17 18:15 ` [PATCH 05/16] docs: add long options to last.1 manual page Sami Kerola
@ 2013-08-17 18:15 ` Sami Kerola
2013-08-17 18:15 ` [PATCH 07/16] last: use carefulput() for printable character output Sami Kerola
` (10 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Sami Kerola @ 2013-08-17 18:15 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
This is done to allow reuse of the functin in last(1).
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
include/carefulputc.h | 4 ++--
term-utils/wall.c | 2 +-
term-utils/write.c | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/include/carefulputc.h b/include/carefulputc.h
index 2d857eb..d4d0ee4 100644
--- a/include/carefulputc.h
+++ b/include/carefulputc.h
@@ -10,7 +10,7 @@
#define iso8859x_iscntrl(c) \
(((c) & 0x7f) < 0x20 || (c) == 0x7f)
-static inline int carefulputc(int c, FILE *fp) {
+static inline int carefulputc(int c, FILE *fp, const char fail) {
int ret;
if (c == '\007' || c == '\t' || c == '\r' || c == '\n' ||
@@ -19,7 +19,7 @@ static inline int carefulputc(int c, FILE *fp) {
else if ((c & 0x80) || !isprint(c^0x40))
ret = fprintf(fp, "\\%3o", (unsigned char) c);
else {
- ret = putc('^', fp);
+ ret = putc(fail, fp);
if (ret != EOF)
ret = putc(c^0x40, fp);
}
diff --git a/term-utils/wall.c b/term-utils/wall.c
index f094073..2d87e47 100644
--- a/term-utils/wall.c
+++ b/term-utils/wall.c
@@ -286,7 +286,7 @@ static char *makemsg(char *fname, char **mvec, int mvecsz,
cnt = 0;
}
if (ch != '\n')
- carefulputc(ch, fp);
+ carefulputc(ch, fp, '^');
}
}
}
diff --git a/term-utils/write.c b/term-utils/write.c
index 83937d3..cb3b044 100644
--- a/term-utils/write.c
+++ b/term-utils/write.c
@@ -372,7 +372,7 @@ void wr_fputs(char *s)
{
char c;
-#define PUTC(c) if (carefulputc(c, stdout) == EOF) \
+#define PUTC(c) if (carefulputc(c, stdout, '^') == EOF) \
err(EXIT_FAILURE, _("carefulputc failed"));
while (*s) {
c = *s++;
--
1.8.3.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 07/16] last: use carefulput() for printable character output
2013-08-17 18:15 [PATCH 00/16] pull: additions recent to last(1) work, plus few small changes Sami Kerola
` (5 preceding siblings ...)
2013-08-17 18:15 ` [PATCH 06/16] include: carefulput: print determined char when unprintable char is found Sami Kerola
@ 2013-08-17 18:15 ` Sami Kerola
2013-08-17 18:15 ` [PATCH 08/16] last: check expected numeric user input is number Sami Kerola
` (9 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Sami Kerola @ 2013-08-17 18:15 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
login-utils/last.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/login-utils/last.c b/login-utils/last.c
index 0f475f2..f08632b 100644
--- a/login-utils/last.c
+++ b/login-utils/last.c
@@ -45,6 +45,7 @@
#include "pathnames.h"
#include "xalloc.h"
#include "closestream.h"
+#include "carefulputc.h"
#ifndef SHUTDOWN_TIME
# define SHUTDOWN_TIME 254
@@ -396,12 +397,8 @@ static int list(struct utmp *p, time_t t, int what)
/*
* Print out "final" string safely.
*/
- for (s = final; *s; s++) {
- if (*s == '\n' || (*s >= 32 && (unsigned char)*s <= 126))
- putchar(*s);
- else
- putchar('*');
- }
+ for (s = final; *s; s++)
+ carefulputc(*s, stdout, '*');
if (len < 0 || (size_t)len >= sizeof(final))
putchar('\n');
--
1.8.3.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 08/16] last: check expected numeric user input is number
2013-08-17 18:15 [PATCH 00/16] pull: additions recent to last(1) work, plus few small changes Sami Kerola
` (6 preceding siblings ...)
2013-08-17 18:15 ` [PATCH 07/16] last: use carefulput() for printable character output Sami Kerola
@ 2013-08-17 18:15 ` Sami Kerola
2013-08-17 18:15 ` [PATCH 09/16] last: make switch cases complete, and inform if impossible occurs Sami Kerola
` (8 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Sami Kerola @ 2013-08-17 18:15 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
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>
---
login-utils/Makemodule.am | 2 +-
login-utils/last.c | 7 ++++---
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/login-utils/Makemodule.am b/login-utils/Makemodule.am
index e4361ed..8d65cc5 100644
--- a/login-utils/Makemodule.am
+++ b/login-utils/Makemodule.am
@@ -4,7 +4,7 @@ usrbin_exec_PROGRAMS += last
dist_man_MANS += \
login-utils/last.1 \
login-utils/lastb.1
-last_SOURCES = login-utils/last.c
+last_SOURCES = login-utils/last.c lib/strutils.c
install-exec-hook-last:
cd $(DESTDIR)$(usrsbin_execdir) && ln -sf last lastb
diff --git a/login-utils/last.c b/login-utils/last.c
index f08632b..f188092 100644
--- a/login-utils/last.c
+++ b/login-utils/last.c
@@ -46,6 +46,7 @@
#include "xalloc.h"
#include "closestream.h"
#include "carefulputc.h"
+#include "strutils.h"
#ifndef SHUTDOWN_TIME
# define SHUTDOWN_TIME 254
@@ -72,8 +73,8 @@ struct utmplist *utmplist = NULL;
#define R_TIMECHANGE 7 /* NEW_TIME or OLD_TIME */
/* Global variables */
-static int maxrecs = 0; /* Maximum number of records to list. */
-static int recsdone = 0; /* Number of records listed */
+static unsigned int maxrecs = 0; /* Maximum number of records to list. */
+static unsigned int recsdone = 0; /* Number of records listed */
static int showhost = 1; /* Show hostname too? */
static int altlist = 0; /* Show hostname at the end. */
static int usedns = 0; /* Use DNS to lookup the hostname. */
@@ -540,7 +541,7 @@ int main(int argc, char **argv)
extended = 1;
break;
case 'n':
- maxrecs = atoi(optarg);
+ maxrecs = strtos32_or_err(optarg, _("failed to parse number"));
break;
case 'f':
altufile = xstrdup(optarg);
--
1.8.3.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 09/16] last: make switch cases complete, and inform if impossible occurs
2013-08-17 18:15 [PATCH 00/16] pull: additions recent to last(1) work, plus few small changes Sami Kerola
` (7 preceding siblings ...)
2013-08-17 18:15 ` [PATCH 08/16] last: check expected numeric user input is number Sami Kerola
@ 2013-08-17 18:15 ` Sami Kerola
2013-08-17 18:15 ` [PATCH 10/16] last: prefer enum rather than #definition list Sami Kerola
` (7 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Sami Kerola @ 2013-08-17 18:15 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
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>
---
login-utils/last.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/login-utils/last.c b/login-utils/last.c
index f188092..276d13a 100644
--- a/login-utils/last.c
+++ b/login-utils/last.c
@@ -343,6 +343,8 @@ static int list(struct utmp *p, time_t t, int what)
break;
case R_NORMAL:
break;
+ default:
+ abort();
}
/*
@@ -808,6 +810,15 @@ int main(int argc, char **argv)
utmplist = p;
break;
+ case EMPTY:
+ case INIT_PROCESS:
+ case LOGIN_PROCESS:
+ case ACCOUNTING:
+ /* ignored ut_types */
+ break;
+
+ default:
+ warnx("unrecogized ut_type: %d", ut.ut_type);
}
/*
--
1.8.3.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 10/16] last: prefer enum rather than #definition list
2013-08-17 18:15 [PATCH 00/16] pull: additions recent to last(1) work, plus few small changes Sami Kerola
` (8 preceding siblings ...)
2013-08-17 18:15 ` [PATCH 09/16] last: make switch cases complete, and inform if impossible occurs Sami Kerola
@ 2013-08-17 18:15 ` Sami Kerola
2013-08-17 18:15 ` [PATCH 11/16] last: remove broken code Sami Kerola
` (6 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Sami Kerola @ 2013-08-17 18:15 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
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>
---
login-utils/last.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/login-utils/last.c b/login-utils/last.c
index 276d13a..d561e96 100644
--- a/login-utils/last.c
+++ b/login-utils/last.c
@@ -64,13 +64,15 @@ struct utmplist {
struct utmplist *utmplist = NULL;
/* Types of listing */
-#define R_CRASH 1 /* No logout record, system boot in between */
-#define R_DOWN 2 /* System brought down in decent way */
-#define R_NORMAL 3 /* Normal */
-#define R_NOW 4 /* Still logged in */
-#define R_REBOOT 5 /* Reboot record. */
-#define R_PHANTOM 6 /* No logout record but session is stale. */
-#define R_TIMECHANGE 7 /* NEW_TIME or OLD_TIME */
+enum {
+ R_CRASH = 1, /* No logout record, system boot in between */
+ R_DOWN, /* System brought down in decent way */
+ R_NORMAL, /* Normal */
+ R_NOW, /* Still logged in */
+ R_REBOOT, /* Reboot record. */
+ R_PHANTOM, /* No logout record but session is stale. */
+ R_TIMECHANGE /* NEW_TIME or OLD_TIME */
+};
/* Global variables */
static unsigned int maxrecs = 0; /* Maximum number of records to list. */
--
1.8.3.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 11/16] last: remove broken code
2013-08-17 18:15 [PATCH 00/16] pull: additions recent to last(1) work, plus few small changes Sami Kerola
` (9 preceding siblings ...)
2013-08-17 18:15 ` [PATCH 10/16] last: prefer enum rather than #definition list Sami Kerola
@ 2013-08-17 18:15 ` Sami Kerola
2013-08-17 18:15 ` [PATCH 12/16] last: use as narrow variable scoping as possible Sami Kerola
` (5 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Sami Kerola @ 2013-08-17 18:15 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
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>
---
login-utils/last.c | 36 ------------------------------------
1 file changed, 36 deletions(-)
diff --git a/login-utils/last.c b/login-utils/last.c
index d561e96..63055a7 100644
--- a/login-utils/last.c
+++ b/login-utils/last.c
@@ -52,7 +52,6 @@
# define SHUTDOWN_TIME 254
#endif
-#define CHOP_DOMAIN 0 /* Define to chop off local domainname. */
#define UCHUNKSIZE 16384 /* How much we read at once. */
/* Double linked list of struct utmp's */
@@ -87,10 +86,6 @@ static int domain_len = 16; /* Default print 16 characters of domain */
static char **show = NULL; /* What do they want us to show */
static char *ufile; /* Filename of this file */
static time_t lastdate; /* Last date we've seen */
-#if CHOP_DOMAIn
-static char hostname[256]; /* For gethostbyname() */
-static char *domainname; /* Our domainname. */
-#endif
/*
* Read one utmp entry, return in new format.
@@ -363,13 +358,6 @@ static int list(struct utmp *p, time_t t, int what)
}
if (showhost) {
-#if CHOP_DOMAIN
- /*
- * See if this is in our domain.
- */
- if (!usedns && (s = strchr(p->ut_host, '.')) != NULL &&
- strcmp(s + 1, domainname) == 0) *s = 0;
-#endif
if (!altlist) {
len = snprintf(final, sizeof(final),
fulltime ?
@@ -600,30 +588,6 @@ int main(int argc, char **argv)
*/
lastdate = lastdown;
-#if CHOP_DOMAIN
- /*
- * Find out domainname.
- *
- * 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.
- */
- hostname[0] = 0;
- gethostname(hostname, sizeof(hostname));
-
- if ((domainname = strchr(hostname, '.')) != NULL)
- domainname++;
- if (domainname == NULL || domainname[0] == 0) {
- hostname[0] = 0;
- getdomainname(hostname, sizeof(hostname));
- hostname[sizeof(hostname) - 1] = 0;
- domainname = hostname;
-
- if (strcmp(domainname, "(none)") == 0 || domainname[0] == 0)
- domainname = NULL;
- }
-#endif
/*
* Install signal handlers
*/
--
1.8.3.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 12/16] last: use as narrow variable scoping as possible
2013-08-17 18:15 [PATCH 00/16] pull: additions recent to last(1) work, plus few small changes Sami Kerola
` (10 preceding siblings ...)
2013-08-17 18:15 ` [PATCH 11/16] last: remove broken code Sami Kerola
@ 2013-08-17 18:15 ` Sami Kerola
2013-08-17 18:15 ` [PATCH 13/16] last: use ISO 8601 time format for --fulltimes Sami Kerola
` (4 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Sami Kerola @ 2013-08-17 18:15 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
login-utils/last.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/login-utils/last.c b/login-utils/last.c
index 63055a7..e94f1f0 100644
--- a/login-utils/last.c
+++ b/login-utils/last.c
@@ -259,7 +259,7 @@ static int list(struct utmp *p, time_t t, int what)
char final[512];
char utline[UT_LINESIZE+1];
char domain[256];
- char *s, **walk;
+ char *s;
int mins, hours, days;
int r, len;
@@ -277,6 +277,7 @@ static int list(struct utmp *p, time_t t, int what)
* Is this something we wanna show?
*/
if (show) {
+ char **walk;
for (walk = show; *walk; walk++) {
if (strncmp(p->ut_name, *walk, UT_NAMESIZE) == 0 ||
strcmp(utline, *walk) == 0 ||
--
1.8.3.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 13/16] last: use ISO 8601 time format for --fulltimes
2013-08-17 18:15 [PATCH 00/16] pull: additions recent to last(1) work, plus few small changes Sami Kerola
` (11 preceding siblings ...)
2013-08-17 18:15 ` [PATCH 12/16] last: use as narrow variable scoping as possible Sami Kerola
@ 2013-08-17 18:15 ` Sami Kerola
2013-08-17 18:15 ` [PATCH 14/16] last: global variables are initialize automatically to zero Sami Kerola
` (3 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Sami Kerola @ 2013-08-17 18:15 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
The ISO 8601 format allows easy time stamp parsing, it tells which
timezone the clock is represented, and this format makes sorting and
searching very easy.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
login-utils/last.1 | 2 +-
login-utils/last.c | 23 +++++++++++++++++------
2 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/login-utils/last.1 b/login-utils/last.1
index eff6fe4..c7d2aa6 100644
--- a/login-utils/last.1
+++ b/login-utils/last.1
@@ -92,7 +92,7 @@ specify that time with
and look for "still logged in".
.TP
\fB\-F\fR, \fB\-\-fulltimes\fR
-Print full login and logout times and dates.
+Print full login and logout times and dates in ISO 8601 format.
.TP
\fB\-R\fR, \fB\-\-nohostname\fR
Suppresses the display of the hostname field.
diff --git a/login-utils/last.c b/login-utils/last.c
index e94f1f0..24a752c 100644
--- a/login-utils/last.c
+++ b/login-utils/last.c
@@ -253,6 +253,7 @@ static int dns_lookup(char *result, int size, int useip, int32_t *a)
static int list(struct utmp *p, time_t t, int what)
{
time_t secs, tmp;
+ struct tm *tm;
char logintime[32];
char logouttime[32];
char length[32];
@@ -291,10 +292,13 @@ static int list(struct utmp *p, time_t t, int what)
* Calculate times
*/
tmp = (time_t)p->ut_time;
- strcpy(logintime, ctime(&tmp));
- if (fulltime)
- sprintf(logouttime, "- %s", ctime(&t));
- else {
+ if (fulltime) {
+ tm = localtime(&tmp);
+ strftime(logintime, sizeof(logintime), "%Y-%m-%dT%H:%M:%S%z", tm);
+ tm = localtime(&t);
+ strftime(logouttime, sizeof(logouttime), "- %Y-%m-%dT%H:%M:%S%z", tm);
+ } else {
+ strcpy(logintime, ctime(&tmp));
logintime[16] = 0;
sprintf(logouttime, "- %s", ctime(&t) + 11);
logouttime[7] = 0;
@@ -804,8 +808,15 @@ int main(int argc, char **argv)
}
}
- printf(_("\n%s begins %s"), basename(ufile), ctime(&begintime));
-
+ printf(_("\n%s begins "), basename(ufile));
+ if (fulltime) {
+ char t[32];
+ struct tm *tm;
+ tm = localtime(&begintime);
+ strftime(t, sizeof(t), "%Y-%m-%dT%H:%M:%S%z", tm);
+ puts(t);
+ } else
+ fputs(ctime(&begintime), stdout);
fclose(fp);
return EXIT_SUCCESS;
}
--
1.8.3.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 14/16] last: global variables are initialize automatically to zero
2013-08-17 18:15 [PATCH 00/16] pull: additions recent to last(1) work, plus few small changes Sami Kerola
` (12 preceding siblings ...)
2013-08-17 18:15 ` [PATCH 13/16] last: use ISO 8601 time format for --fulltimes Sami Kerola
@ 2013-08-17 18:15 ` Sami Kerola
2013-08-17 18:15 ` [PATCH 15/16] last: allow --file to be defined multiple times Sami Kerola
` (2 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Sami Kerola @ 2013-08-17 18:15 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
login-utils/last.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/login-utils/last.c b/login-utils/last.c
index 24a752c..713719d 100644
--- a/login-utils/last.c
+++ b/login-utils/last.c
@@ -74,13 +74,13 @@ enum {
};
/* Global variables */
-static unsigned int maxrecs = 0; /* Maximum number of records to list. */
-static unsigned int recsdone = 0; /* Number of records listed */
+static unsigned int maxrecs; /* Maximum number of records to list. */
+static unsigned int recsdone; /* Number of records listed */
static int showhost = 1; /* Show hostname too? */
-static int altlist = 0; /* Show hostname at the end. */
-static int usedns = 0; /* Use DNS to lookup the hostname. */
-static int useip = 0; /* Print IP address in number format */
-static int fulltime = 0; /* Print full dates and times */
+static int altlist; /* Show hostname at the end. */
+static int usedns; /* Use DNS to lookup the hostname. */
+static int useip; /* Print IP address in number format */
+static int fulltime; /* Print full dates and times */
static int name_len = 8; /* Default print 8 characters of name */
static int domain_len = 16; /* Default print 16 characters of domain */
static char **show = NULL; /* What do they want us to show */
--
1.8.3.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 15/16] last: allow --file to be defined multiple times
2013-08-17 18:15 [PATCH 00/16] pull: additions recent to last(1) work, plus few small changes Sami Kerola
` (13 preceding siblings ...)
2013-08-17 18:15 ` [PATCH 14/16] last: global variables are initialize automatically to zero Sami Kerola
@ 2013-08-17 18:15 ` Sami Kerola
2013-08-17 18:15 ` [PATCH 16/16] last: add --present option Sami Kerola
2013-08-23 10:07 ` [PATCH 00/16] pull: additions recent to last(1) work, plus few small changes Karel Zak
16 siblings, 0 replies; 21+ messages in thread
From: Sami Kerola @ 2013-08-17 18:15 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
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>
---
login-utils/last.1 | 4 ++
login-utils/last.c | 204 +++++++++++++++++++++++++++++------------------------
2 files changed, 117 insertions(+), 91 deletions(-)
diff --git a/login-utils/last.1 b/login-utils/last.1
index c7d2aa6..321604d 100644
--- a/login-utils/last.1
+++ b/login-utils/last.1
@@ -76,6 +76,10 @@ Tell
.B last
to use a specific file instead of
.BR /var/log/wtmp .
+The
+.BI \-\-file " file"
+can be specified multiple times, and all of the defined files will be
+processed.
.TP
\fB\-\fInumber\fR
.TQ
diff --git a/login-utils/last.c b/login-utils/last.c
index 713719d..9f12772 100644
--- a/login-utils/last.c
+++ b/login-utils/last.c
@@ -477,7 +477,7 @@ static time_t parsetm(char *ts)
return tm;
}
-int main(int argc, char **argv)
+static void process_wtmp_file(char *ufile, int lastb, int extended, time_t until)
{
FILE *fp; /* Filepointer of wtmp file */
@@ -495,95 +495,6 @@ int main(int argc, char **argv)
struct stat st; /* To stat the [uw]tmp file */
int quit = 0; /* Flag */
int down = 0; /* Down flag */
- int lastb = 0; /* Is this 'lastb' ? */
- int extended = 0; /* Lots of info. */
- char *altufile = NULL; /* Alternate wtmp */
-
- time_t until = 0; /* at what time to stop parsing the file */
-
- static const struct option long_opts[] = {
- { "limit", required_argument, NULL, 'n' },
- { "help", no_argument, NULL, 'h' },
- { "file", required_argument, NULL, 'f' },
- { "nohostname", no_argument, NULL, 'R' },
- { "version", no_argument, NULL, 'V' },
- { "hostlast", no_argument, NULL, 'a' },
- { "until", required_argument, NULL, 't' },
- { "system", no_argument, NULL, 'x' },
- { "dns", no_argument, NULL, 'd' },
- { "ip", no_argument, NULL, 'i' },
- { "fulltimes", no_argument, NULL, 'F' },
- { "fullnames", no_argument, NULL, 'w' },
- { NULL, 0, NULL, 0 }
- };
-
- setlocale(LC_ALL, "");
- bindtextdomain(PACKAGE, LOCALEDIR);
- textdomain(PACKAGE);
- atexit(close_stdout);
-
- while ((c = getopt_long(argc, argv,
- "hVf:n:RxadFit:0123456789w", long_opts, NULL)) != -1) {
- switch(c) {
- case 'h':
- usage(stdout);
- break;
- case 'V':
- printf(UTIL_LINUX_VERSION);
- return EXIT_SUCCESS;
- case 'R':
- showhost = 0;
- break;
- case 'x':
- extended = 1;
- break;
- case 'n':
- maxrecs = strtos32_or_err(optarg, _("failed to parse number"));
- break;
- case 'f':
- altufile = xstrdup(optarg);
- break;
- case 'd':
- usedns++;
- break;
- case 'i':
- useip++;
- break;
- case 'a':
- altlist++;
- break;
- case 'F':
- fulltime++;
- break;
- case 't':
- until = parsetm(optarg);
- if (until == (time_t) -1)
- errx(EXIT_FAILURE, _("invalid time value \"%s\""), optarg);
- break;
- case 'w':
- if (UT_NAMESIZE > name_len)
- name_len = UT_NAMESIZE;
- if (UT_HOSTSIZE > domain_len)
- domain_len = UT_HOSTSIZE;
- break;
- case '0': case '1': case '2': case '3': case '4':
- case '5': case '6': case '7': case '8': case '9':
- maxrecs = 10 * maxrecs + c - '0';
- break;
- default:
- usage(stderr);
- break;
- }
- }
-
- if (optind < argc)
- show = argv + optind;
-
- /*
- * Which file do we want to read?
- */
- lastb = !strcmp(program_invocation_short_name, "lastb");
- ufile = altufile ? altufile : lastb ? _PATH_BTMP : _PATH_WTMP;
time(&lastdown);
lastrch = lastdown;
@@ -807,6 +718,7 @@ int main(int argc, char **argv)
down = 0;
}
}
+ fclose(fp);
printf(_("\n%s begins "), basename(ufile));
if (fulltime) {
@@ -817,6 +729,116 @@ int main(int argc, char **argv)
puts(t);
} else
fputs(ctime(&begintime), stdout);
- fclose(fp);
+
+}
+
+int main(int argc, char **argv)
+{
+ int c, i; /* Scratch */
+ char **altv = NULL; /* Alternate wtmp files */
+ int altc = 0; /* Number of alternative files */
+ int lastb = 0; /* Is this 'lastb' ? */
+ int extended = 0; /* Lots of info. */
+
+ time_t until = 0; /* at what time to stop parsing the file */
+
+ static const struct option long_opts[] = {
+ { "limit", required_argument, NULL, 'n' },
+ { "help", no_argument, NULL, 'h' },
+ { "file", required_argument, NULL, 'f' },
+ { "nohostname", no_argument, NULL, 'R' },
+ { "version", no_argument, NULL, 'V' },
+ { "hostlast", no_argument, NULL, 'a' },
+ { "until", required_argument, NULL, 't' },
+ { "system", no_argument, NULL, 'x' },
+ { "dns", no_argument, NULL, 'd' },
+ { "ip", no_argument, NULL, 'i' },
+ { "fulltimes", no_argument, NULL, 'F' },
+ { "fullnames", no_argument, NULL, 'w' },
+ { NULL, 0, NULL, 0 }
+ };
+
+ setlocale(LC_ALL, "");
+ bindtextdomain(PACKAGE, LOCALEDIR);
+ textdomain(PACKAGE);
+ atexit(close_stdout);
+
+ while ((c = getopt_long(argc, argv,
+ "hVf:n:RxadFit:0123456789w", long_opts, NULL)) != -1) {
+ switch(c) {
+ case 'h':
+ usage(stdout);
+ break;
+ case 'V':
+ printf(UTIL_LINUX_VERSION);
+ return EXIT_SUCCESS;
+ case 'R':
+ showhost = 0;
+ break;
+ case 'x':
+ extended = 1;
+ break;
+ case 'n':
+ maxrecs = strtos32_or_err(optarg, _("failed to parse number"));
+ break;
+ case 'f':
+ if (!altv)
+ altv = xmalloc(sizeof(char *) * argc);
+ altv[altc++] = xstrdup(optarg);
+ break;
+ case 'd':
+ usedns++;
+ break;
+ case 'i':
+ useip++;
+ break;
+ case 'a':
+ altlist++;
+ break;
+ case 'F':
+ fulltime++;
+ break;
+ case 't':
+ until = parsetm(optarg);
+ if (until == (time_t) -1)
+ errx(EXIT_FAILURE, _("invalid time value \"%s\""), optarg);
+ break;
+ case 'w':
+ if (UT_NAMESIZE > name_len)
+ name_len = UT_NAMESIZE;
+ if (UT_HOSTSIZE > domain_len)
+ domain_len = UT_HOSTSIZE;
+ break;
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ maxrecs = 10 * maxrecs + c - '0';
+ break;
+ default:
+ usage(stderr);
+ break;
+ }
+ }
+
+ if (optind < argc)
+ show = argv + optind;
+
+ /*
+ * Which file do we want to read?
+ */
+ lastb = !strcmp(program_invocation_short_name, "lastb");
+ if (!altc) {
+ altv = xmalloc(sizeof(char *));
+ if (lastb)
+ altv[0] = xstrdup(_PATH_BTMP);
+ else
+ altv[0] = xstrdup(_PATH_WTMP);
+ altc++;
+ }
+
+ for (i = 0; i < altc; i++) {
+ process_wtmp_file(altv[i], lastb, extended, until);
+ free(altv[i]);
+ }
+ free(altv);
return EXIT_SUCCESS;
}
--
1.8.3.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 16/16] last: add --present option
2013-08-17 18:15 [PATCH 00/16] pull: additions recent to last(1) work, plus few small changes Sami Kerola
` (14 preceding siblings ...)
2013-08-17 18:15 ` [PATCH 15/16] last: allow --file to be defined multiple times Sami Kerola
@ 2013-08-17 18:15 ` Sami Kerola
2013-08-23 10:07 ` [PATCH 00/16] pull: additions recent to last(1) work, plus few small changes Karel Zak
16 siblings, 0 replies; 21+ messages in thread
From: Sami Kerola @ 2013-08-17 18:15 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
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>
---
login-utils/last.c | 33 ++++++++++++++++++++++-----------
1 file changed, 22 insertions(+), 11 deletions(-)
diff --git a/login-utils/last.c b/login-utils/last.c
index 9f12772..616be97 100644
--- a/login-utils/last.c
+++ b/login-utils/last.c
@@ -250,7 +250,7 @@ static int dns_lookup(char *result, int size, int useip, int32_t *a)
/*
* Show one line of information on screen
*/
-static int list(struct utmp *p, time_t t, int what)
+static int list(struct utmp *p, time_t t, int what, time_t present)
{
time_t secs, tmp;
struct tm *tm;
@@ -292,6 +292,8 @@ static int list(struct utmp *p, time_t t, int what)
* Calculate times
*/
tmp = (time_t)p->ut_time;
+ if (present && (present < tmp || 0 == t || t < present))
+ return 0;
if (fulltime) {
tm = localtime(&tmp);
strftime(logintime, sizeof(logintime), "%Y-%m-%dT%H:%M:%S%z", tm);
@@ -426,6 +428,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
fputs(_(" -n, --limit <number> how many lines to show\n"), out);
fputs(_(" -R, --nohostname don't display the hostname field\n"), out);
fputs(_(" -t, --until <YYYYMMDDHHMMSS> display the state of the specified time\n"), out);
+ fputs(_(" -p, --present <YYYYMMDDHHMMSS> display who where present at the specified time\n"), out);
fputs(_(" -w, --fullnames display full user and domain names\n"), out);
fputs(_(" -x, --system display system shutdown entries and run level changes\n"), out);
@@ -477,7 +480,8 @@ static time_t parsetm(char *ts)
return tm;
}
-static void process_wtmp_file(char *ufile, int lastb, int extended, time_t until)
+static void process_wtmp_file(char *ufile, int lastb, int extended,
+ time_t until, time_t present)
{
FILE *fp; /* Filepointer of wtmp file */
@@ -552,7 +556,7 @@ static void process_wtmp_file(char *ufile, int lastb, int extended, time_t until
lastdate = ut.ut_time;
if (lastb) {
- quit = list(&ut, ut.ut_time, R_NORMAL);
+ quit = list(&ut, ut.ut_time, R_NORMAL, present);
continue;
}
@@ -600,7 +604,7 @@ static void process_wtmp_file(char *ufile, int lastb, int extended, time_t until
case SHUTDOWN_TIME:
if (extended) {
strcpy(ut.ut_line, "system down");
- quit = list(&ut, lastboot, R_NORMAL);
+ quit = list(&ut, lastboot, R_NORMAL, present);
}
lastdown = lastrch = ut.ut_time;
down = 1;
@@ -611,12 +615,12 @@ static void process_wtmp_file(char *ufile, int lastb, int extended, time_t until
strcpy(ut.ut_line,
ut.ut_type == NEW_TIME ? "new time" :
"old time");
- quit = list(&ut, lastdown, R_TIMECHANGE);
+ quit = list(&ut, lastdown, R_TIMECHANGE, present);
}
break;
case BOOT_TIME:
strcpy(ut.ut_line, "system boot");
- quit = list(&ut, lastdown, R_REBOOT);
+ quit = list(&ut, lastdown, R_REBOOT, present);
lastboot = ut.ut_time;
down = 1;
break;
@@ -624,7 +628,7 @@ static void process_wtmp_file(char *ufile, int lastb, int extended, time_t until
x = ut.ut_pid & 255;
if (extended) {
sprintf(ut.ut_line, "(to lvl %c)", x);
- quit = list(&ut, lastrch, R_NORMAL);
+ quit = list(&ut, lastrch, R_NORMAL, present);
}
if (x == '0' || x == '6') {
lastdown = ut.ut_time;
@@ -648,7 +652,7 @@ static void process_wtmp_file(char *ufile, int lastb, int extended, time_t until
/* Show it */
if (c == 0) {
quit = list(&ut, p->ut.ut_time,
- R_NORMAL);
+ R_NORMAL, present);
c = 1;
}
if (p->next) p->next->prev = p->prev;
@@ -673,7 +677,7 @@ static void process_wtmp_file(char *ufile, int lastb, int extended, time_t until
c = R_PHANTOM;
} else
c = whydown;
- quit = list(&ut, lastboot, c);
+ quit = list(&ut, lastboot, c, present);
}
/* FALLTHRU */
@@ -741,6 +745,7 @@ int main(int argc, char **argv)
int extended = 0; /* Lots of info. */
time_t until = 0; /* at what time to stop parsing the file */
+ time_t present = 0; /* who where present at time_t */
static const struct option long_opts[] = {
{ "limit", required_argument, NULL, 'n' },
@@ -750,6 +755,7 @@ int main(int argc, char **argv)
{ "version", no_argument, NULL, 'V' },
{ "hostlast", no_argument, NULL, 'a' },
{ "until", required_argument, NULL, 't' },
+ { "present", required_argument, NULL, 'p' },
{ "system", no_argument, NULL, 'x' },
{ "dns", no_argument, NULL, 'd' },
{ "ip", no_argument, NULL, 'i' },
@@ -764,7 +770,7 @@ int main(int argc, char **argv)
atexit(close_stdout);
while ((c = getopt_long(argc, argv,
- "hVf:n:RxadFit:0123456789w", long_opts, NULL)) != -1) {
+ "hVf:n:RxadFit:p:0123456789w", long_opts, NULL)) != -1) {
switch(c) {
case 'h':
usage(stdout);
@@ -798,6 +804,11 @@ int main(int argc, char **argv)
case 'F':
fulltime++;
break;
+ case 'p':
+ present = parsetm(optarg);
+ if (present == (time_t) -1)
+ errx(EXIT_FAILURE, _("invalid time value \"%s\""), optarg);
+ break;
case 't':
until = parsetm(optarg);
if (until == (time_t) -1)
@@ -836,7 +847,7 @@ int main(int argc, char **argv)
}
for (i = 0; i < altc; i++) {
- process_wtmp_file(altv[i], lastb, extended, until);
+ process_wtmp_file(altv[i], lastb, extended, until, present);
free(altv[i]);
}
free(altv);
--
1.8.3.4
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCH 00/16] pull: additions recent to last(1) work, plus few small changes
2013-08-17 18:15 [PATCH 00/16] pull: additions recent to last(1) work, plus few small changes Sami Kerola
` (15 preceding siblings ...)
2013-08-17 18:15 ` [PATCH 16/16] last: add --present option Sami Kerola
@ 2013-08-23 10:07 ` Karel Zak
2013-08-23 10:42 ` Sami Kerola
16 siblings, 1 reply; 21+ messages in thread
From: Karel Zak @ 2013-08-23 10:07 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
On Sat, Aug 17, 2013 at 07:15:05PM +0100, Sami Kerola wrote:
> build-sys: remove unnecessary environment variable
> docs: update TODO
> build-sys: complete elvtune removal
> docs: be clear which last(1) is deprecated
> docs: add long options to last.1 manual page
> include: carefulput: print determined char when unprintable char is found
> last: use carefulput() for printable character output
> last: check expected numeric user input is number
> last: make switch cases complete, and inform if impossible occurs
> last: prefer enum rather than #definition list
> last: remove broken code
> last: use as narrow variable scoping as possible
Applied.
> last: use ISO 8601 time format for --fulltimes
This is not backwardly compatible. Not applied.
We need --fulltimes[=ctime|iso] or add --output=<list> and use lib/tt.c to
generate output with arbitrary columns and formats.
> last: global variables are initialize automatically to zero
> last: allow --file to be defined multiple times
> last: add --present option
Good ideas, applied. Thanks.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 00/16] pull: additions recent to last(1) work, plus few small changes
2013-08-23 10:07 ` [PATCH 00/16] pull: additions recent to last(1) work, plus few small changes Karel Zak
@ 2013-08-23 10:42 ` Sami Kerola
2013-08-23 11:04 ` Karel Zak
2013-08-23 11:08 ` Karel Zak
0 siblings, 2 replies; 21+ messages in thread
From: Sami Kerola @ 2013-08-23 10:42 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
On 23 August 2013 11:07, Karel Zak <kzak@redhat.com> wrote:
>> last: use ISO 8601 time format for --fulltimes
>
> This is not backwardly compatible. Not applied.
>
> We need --fulltimes[=ctime|iso] or add --output=<list> and use lib/tt.c to
> generate output with arbitrary columns and formats.
I thought the --fulltimes has not been released yet. The backwards
compatibility sounds good reason to do --output=<list>. I'll start
working with that ~next week.
Thank you for reviews & merges.
--
Sami Kerola
http://www.iki.fi/kerolasa/
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 00/16] pull: additions recent to last(1) work, plus few small changes
2013-08-23 10:42 ` Sami Kerola
@ 2013-08-23 11:04 ` Karel Zak
2013-08-23 11:08 ` Karel Zak
1 sibling, 0 replies; 21+ messages in thread
From: Karel Zak @ 2013-08-23 11:04 UTC (permalink / raw)
To: kerolasa; +Cc: util-linux
On Fri, Aug 23, 2013 at 11:42:49AM +0100, Sami Kerola wrote:
> On 23 August 2013 11:07, Karel Zak <kzak@redhat.com> wrote:
> >> last: use ISO 8601 time format for --fulltimes
> >
> > This is not backwardly compatible. Not applied.
> >
> > We need --fulltimes[=ctime|iso] or add --output=<list> and use lib/tt.c to
> > generate output with arbitrary columns and formats.
>
> I thought the --fulltimes has not been released yet.
Well, it's long option for -F which exists for years in sysvinit.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 00/16] pull: additions recent to last(1) work, plus few small changes
2013-08-23 10:42 ` Sami Kerola
2013-08-23 11:04 ` Karel Zak
@ 2013-08-23 11:08 ` Karel Zak
1 sibling, 0 replies; 21+ messages in thread
From: Karel Zak @ 2013-08-23 11:08 UTC (permalink / raw)
To: kerolasa; +Cc: util-linux
On Fri, Aug 23, 2013 at 11:42:49AM +0100, Sami Kerola wrote:
> On 23 August 2013 11:07, Karel Zak <kzak@redhat.com> wrote:
> >> last: use ISO 8601 time format for --fulltimes
> >
> > This is not backwardly compatible. Not applied.
> >
> > We need --fulltimes[=ctime|iso] or add --output=<list> and use lib/tt.c to
> > generate output with arbitrary columns and formats.
>
> I thought the --fulltimes has not been released yet. The backwards
> compatibility sounds good reason to do --output=<list>. I'll start
> working with that ~next week.
>
BTW, for things like --until / --present it would be nice to support
relative times like we have for example in git:
git log --since '1 day ago'
The current YYYYMMDDHHMMSS sucks...
I can image this for dmesg too (--since '1 hour ago').
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 21+ messages in thread
end of thread, other threads:[~2013-08-23 11:08 UTC | newest]
Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-17 18:15 [PATCH 00/16] pull: additions recent to last(1) work, plus few small changes Sami Kerola
2013-08-17 18:15 ` [PATCH 01/16] build-sys: remove unnecessary environment variable Sami Kerola
2013-08-17 18:15 ` [PATCH 02/16] docs: update TODO Sami Kerola
2013-08-17 18:15 ` [PATCH 03/16] build-sys: complete elvtune removal Sami Kerola
2013-08-17 18:15 ` [PATCH 04/16] docs: be clear which last(1) is deprecated Sami Kerola
2013-08-17 18:15 ` [PATCH 05/16] docs: add long options to last.1 manual page Sami Kerola
2013-08-17 18:15 ` [PATCH 06/16] include: carefulput: print determined char when unprintable char is found Sami Kerola
2013-08-17 18:15 ` [PATCH 07/16] last: use carefulput() for printable character output Sami Kerola
2013-08-17 18:15 ` [PATCH 08/16] last: check expected numeric user input is number Sami Kerola
2013-08-17 18:15 ` [PATCH 09/16] last: make switch cases complete, and inform if impossible occurs Sami Kerola
2013-08-17 18:15 ` [PATCH 10/16] last: prefer enum rather than #definition list Sami Kerola
2013-08-17 18:15 ` [PATCH 11/16] last: remove broken code Sami Kerola
2013-08-17 18:15 ` [PATCH 12/16] last: use as narrow variable scoping as possible Sami Kerola
2013-08-17 18:15 ` [PATCH 13/16] last: use ISO 8601 time format for --fulltimes Sami Kerola
2013-08-17 18:15 ` [PATCH 14/16] last: global variables are initialize automatically to zero Sami Kerola
2013-08-17 18:15 ` [PATCH 15/16] last: allow --file to be defined multiple times Sami Kerola
2013-08-17 18:15 ` [PATCH 16/16] last: add --present option Sami Kerola
2013-08-23 10:07 ` [PATCH 00/16] pull: additions recent to last(1) work, plus few small changes Karel Zak
2013-08-23 10:42 ` Sami Kerola
2013-08-23 11:04 ` Karel Zak
2013-08-23 11:08 ` Karel Zak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox