Page MenuHomeFreeBSD

D16919.diff
No OneTemporary

D16919.diff

Index: head/usr.sbin/lastlogin/Makefile
===================================================================
--- head/usr.sbin/lastlogin/Makefile
+++ head/usr.sbin/lastlogin/Makefile
@@ -2,5 +2,6 @@
PROG= lastlogin
MAN= lastlogin.8
+LIBADD= xo
.include <bsd.prog.mk>
Index: head/usr.sbin/lastlogin/lastlogin.8
===================================================================
--- head/usr.sbin/lastlogin/lastlogin.8
+++ head/usr.sbin/lastlogin/lastlogin.8
@@ -31,7 +31,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd June 6, 2011
+.Dd August 28, 2018
.Dt LASTLOGIN 8
.Os
.Sh NAME
@@ -39,6 +39,7 @@
.Nd indicate last login time of users
.Sh SYNOPSIS
.Nm
+.Op Fl -libxo
.Op Fl f Ar file
.Op Fl rt
.Op Ar user ...
@@ -68,6 +69,13 @@
.Pp
The following options are available:
.Bl -tag -width indent
+.It Fl -libxo
+Generate output via
+.Xr libxo 3
+in a selection of different human and machine readable formats.
+See
+.Xr xo_parse_args 3
+for details on command line arguments.
.It Fl f Ar file
Open last login database
.Ar file
@@ -86,9 +94,15 @@
.Xr last 1 ,
.Xr getutxent 3 ,
.Xr ac 8
+.Xr libxo 3 ,
+.Xr xo_parse_args 3
.Sh AUTHORS
+.An -nosplit
.An John M. Vinopal
wrote this program in January 1996 and contributed it
to the
.Nx
project.
+.An Philip Paeps added
+.Xr libxo 3
+support in August 2018.
Index: head/usr.sbin/lastlogin/lastlogin.c
===================================================================
--- head/usr.sbin/lastlogin/lastlogin.c
+++ head/usr.sbin/lastlogin/lastlogin.c
@@ -2,6 +2,7 @@
* SPDX-License-Identifier: BSD-4-Clause
*
* Copyright (c) 1996 John M. Vinopal
+ * Copyright (c) 2018 Philip Paeps
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -46,6 +47,8 @@
#include <unistd.h>
#include <utmpx.h>
+#include <libxo/xo.h>
+
int main(int, char **);
static void output(struct utmpx *);
static void usage(void);
@@ -79,6 +82,10 @@
int ch, i, ulistsize;
struct utmpx *u, *ulist;
+ argc = xo_parse_args(argc, argv);
+ if (argc < 0)
+ exit(1);
+
while ((ch = getopt(argc, argv, "f:rt")) != -1) {
switch (ch) {
case 'f':
@@ -97,13 +104,16 @@
argc -= optind;
argv += optind;
+ xo_open_container("lastlogin-information");
+ xo_open_list("lastlogin");
+
if (argc > 0) {
/* Process usernames given on the command line. */
for (i = 0; i < argc; i++) {
if (setutxdb(UTXDB_LASTLOGIN, file) != 0)
- err(1, "failed to open lastlog database");
+ xo_err(1, "failed to open lastlog database");
if ((u = getutxuser(argv[i])) == NULL) {
- warnx("user '%s' not found", argv[i]);
+ xo_warnx("user '%s' not found", argv[i]);
continue;
}
output(u);
@@ -112,7 +122,7 @@
} else {
/* Read all lastlog entries, looking for active ones. */
if (setutxdb(UTXDB_LASTLOGIN, file) != 0)
- err(1, "failed to open lastlog database");
+ xo_err(1, "failed to open lastlog database");
ulist = NULL;
ulistsize = 0;
while ((u = getutxent()) != NULL) {
@@ -122,7 +132,7 @@
ulist = realloc(ulist,
(ulistsize + 16) * sizeof(struct utmpx));
if (ulist == NULL)
- err(1, "malloc");
+ xo_err(1, "malloc");
}
ulist[ulistsize++] = *u;
}
@@ -133,6 +143,10 @@
output(&ulist[i]);
}
+ xo_close_list("lastlogin");
+ xo_close_container("lastlogin-information");
+ xo_finish();
+
exit(0);
}
@@ -142,13 +156,18 @@
{
time_t t = u->ut_tv.tv_sec;
- printf("%-10s %-8s %-22.22s %s",
- u->ut_user, u->ut_line, u->ut_host, ctime(&t));
+ xo_open_instance("lastlogin");
+ xo_emit("{:user/%-10s/%s} {:tty/%-8s/%s} {:from/%-22.22s/%s}",
+ u->ut_user, u->ut_line, u->ut_host);
+ xo_attr("seconds", "%lu", (unsigned long)t);
+ xo_emit(" {:login-time/%.24s/%.24s}\n", ctime(&t));
+ xo_close_instance("lastlogin");
}
static void
usage(void)
{
- fprintf(stderr, "usage: lastlogin [-f file] [-rt] [user ...]\n");
+ xo_error("usage: lastlogin [-f file] [-rt] [user ...]\n");
+ xo_finish();
exit(1);
}

File Metadata

Mime Type
text/plain
Expires
Sun, Apr 12, 8:21 PM (5 h, 18 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31369141
Default Alt Text
D16919.diff (3 KB)

Event Timeline