From owner-svn-src-stable@freebsd.org Tue Sep 4 09:59:33 2018 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2163CFE9990; Tue, 4 Sep 2018 09:59:33 +0000 (UTC) (envelope-from araujobsdport@gmail.com) Received: from mail-lf1-x142.google.com (mail-lf1-x142.google.com [IPv6:2a00:1450:4864:20::142]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 7C49F90B9A; Tue, 4 Sep 2018 09:59:32 +0000 (UTC) (envelope-from araujobsdport@gmail.com) Received: by mail-lf1-x142.google.com with SMTP id h64-v6so2429846lfi.10; Tue, 04 Sep 2018 02:59:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:reply-to:in-reply-to:references:from:date:message-id :subject:to:cc; bh=6a1shjHvDEmKJ26KED68MPUpiwGhzJBvAcBqVysIKXE=; b=SncvS/7HByHHt10bfWkR/IDUXqn/vrblgkBmH8BQWT9RrGHIbiQv2BLEZISNgFdBon lxClMt5NR2B8fDSeBeY8E0VDdwtLEAr6g8T7IVrfjeeryV1F2VPSTuN8HnDwfHi72LQn d4+y8JZP2XZAdaFbuKexUnA8mNw/wxKIlF6aelg5LjfgcVzTwVfCK259SKYc6Vl4qLRD V1cB9/irfQ+GSbgTAtupbN+91+jf9FDQ4ToRgWFSSoFEE33HvTMKakXCGShpmqXXxIWf RnGhsgu9QmzupAlOg9XnXjC8IJDLuBuPjReXAo1Ca3ag1KtkCJnAOFEroU74q3+6sjeB hRRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:reply-to:in-reply-to:references :from:date:message-id:subject:to:cc; bh=6a1shjHvDEmKJ26KED68MPUpiwGhzJBvAcBqVysIKXE=; b=Mywr1+50rH3qQhfjUXuWdl1yswmxRKtQCjDWS0/YySR9e1CkLvOa/u5spkplZxV6Z8 uJMxgUEs8B9SzbqYgGnvn1VLyjDFieDlwsVLavhU7wFtczBqLugRr3iurBCd9PBeFkqf Q1qKe3tYDME61xrCO0nmBHnLeBRHnHxTXAb5hGJzQPhzNckBpryomUojJ3cpq5pCwiKP zXhMAzRHIQJ2UJ4luDAE96X0vp5gLaAf9mZ+caFNRaX1jwwn10xoNZ/0qD7N+n7oYKWU 4YJ9g7TsX9eLbMQndoj6unJ42920K7+UG7ckvOVsDaOI1Z4xwB/m0auOURxSt+1UcTIz UKTw== X-Gm-Message-State: APzg51DZMNrfwJ6AaJ63PwrEfIIuq1woImJHCVCH/5mlr5BA1uDowZOt 2G+Y2lp9KTJDpmv8g6VcPJIRVYaHnZ+9I6ae4eEr/Q== X-Google-Smtp-Source: ANB0VdbD8I5etAakMETAHkEKeRmFRgpwNi7iz7CQYKm4w6wuXbtZnB1TbAu2vgnV3/L1OuVw9hqKniKVpLaYtfbA/3w= X-Received: by 2002:a19:4b15:: with SMTP id y21-v6mr19708690lfa.118.1536055170997; Tue, 04 Sep 2018 02:59:30 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a19:db4b:0:0:0:0:0 with HTTP; Tue, 4 Sep 2018 02:59:30 -0700 (PDT) Reply-To: araujo@freebsd.org In-Reply-To: <201809040953.w849rj4j082295@repo.freebsd.org> References: <201809040953.w849rj4j082295@repo.freebsd.org> From: Marcelo Araujo Date: Tue, 4 Sep 2018 17:59:30 +0800 Message-ID: Subject: Re: svn commit: r338451 - stable/11/usr.bin/last To: Philip Paeps Cc: src-committers , svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.27 X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Sep 2018 09:59:33 -0000 2018-09-04 17:53 GMT+08:00 Philip Paeps : > Author: philip > Date: Tue Sep 4 09:53:45 2018 > New Revision: 338451 > URL: https://svnweb.freebsd.org/changeset/base/338451 > > Log: > MFC r319508: > Fix a memory leak with last > free memory allocated to 'buf' > Is that the right patch? Or the commit message missed adding support to libxo(3)? > > Submitted by: Thomas Rix > > MFC r338352: > Add libxo(3) support to last(1). > > Modified: > stable/11/usr.bin/last/Makefile > stable/11/usr.bin/last/last.1 > stable/11/usr.bin/last/last.c > Directory Properties: > stable/11/ (props changed) > > Modified: stable/11/usr.bin/last/Makefile > ============================================================ > ================== > --- stable/11/usr.bin/last/Makefile Mon Sep 3 22:27:27 2018 > (r338450) > +++ stable/11/usr.bin/last/Makefile Tue Sep 4 09:53:45 2018 > (r338451) > @@ -2,6 +2,7 @@ > # $FreeBSD$ > > PROG= last > +LIBADD= xo > > NO_WFORMAT= > > > Modified: stable/11/usr.bin/last/last.1 > ============================================================ > ================== > --- stable/11/usr.bin/last/last.1 Mon Sep 3 22:27:27 2018 > (r338450) > +++ stable/11/usr.bin/last/last.1 Tue Sep 4 09:53:45 2018 > (r338451) > @@ -28,7 +28,7 @@ > .\" @(#)last.1 8.1 (Berkeley) 6/6/93 > .\" $FreeBSD$ > .\" > -.Dd June 6, 2015 > +.Dd August 28, 2018 > .Dt LAST 1 > .Os > .Sh NAME > @@ -36,6 +36,7 @@ > .Nd indicate last logins of users and ttys > .Sh SYNOPSIS > .Nm > +.Op Fl -libxo > .Op Fl swy > .Oo > .Fl d > @@ -72,6 +73,13 @@ will so indicate. > .Pp > The following options are available: > .Bl -tag -width indent-two > +.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 d Ar date > Specify the snapshot date and time. > All users logged in at the snapshot date and time will > @@ -201,6 +209,8 @@ login data base > .Xr getutxent 3 , > .Xr ac 8 , > .Xr lastlogin 8 > +.Xr libxo 3 , > +.Xr xo_parse_args 3 > .Sh HISTORY > .Nm > utility first appeared in > @@ -211,6 +221,10 @@ The original version was written by > .An Howard P. Katseff ; > .An Keith Bostic > rewrote it in 1986/87 to add functionality and to improve code quality. > +.An Philip Paeps > +added > +.Xr libxo 3 > +support in August 2018. > .Sh BUGS > If a login shell should terminate abnormally for some reason, it is likely > that a logout record will not be written to the > > Modified: stable/11/usr.bin/last/last.c > ============================================================ > ================== > --- stable/11/usr.bin/last/last.c Mon Sep 3 22:27:27 2018 > (r338450) > +++ stable/11/usr.bin/last/last.c Tue Sep 4 09:53:45 2018 > (r338451) > @@ -1,6 +1,7 @@ > /* > * Copyright (c) 1987, 1993, 1994 > * The Regents of the University of California. All rights reserved. > + * Copyright (c) 2018 Philip Paeps > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions > @@ -58,6 +59,8 @@ __FBSDID("$FreeBSD$"); > #include > #include > > +#include > + > #define NO 0 /* false/no */ > #define YES 1 /* true/yes */ > #define ATOI2(ar) ((ar)[0] - '0') * 10 + ((ar)[1] - '0'); > (ar) += 2; > @@ -108,7 +111,7 @@ static void wtmp(void); > static void > usage(void) > { > - (void)fprintf(stderr, > + xo_error( > "usage: last [-swy] [-d [[CC]YY][MMDD]hhmm[.SS]] [-f file] [-h host]\n" > " [-n maxrec] [-t tty] [user ...]\n"); > exit(1); > @@ -123,6 +126,11 @@ main(int argc, char *argv[]) > (void) setlocale(LC_TIME, ""); > d_first = (*nl_langinfo(D_MD_ORDER) == 'd'); > > + argc = xo_parse_args(argc, argv); > + if (argc < 0) > + exit(1); > + atexit(xo_finish_atexit); > + > maxrec = -1; > snaptime = 0; > while ((ch = getopt(argc, argv, "0123456789d:f:h:n:st:wy")) != -1) > @@ -157,7 +165,7 @@ main(int argc, char *argv[]) > maxrec = strtol(optarg, &p, 10); > if (p == optarg || *p != '\0' || errno != 0 || > maxrec <= 0) > - errx(1, "%s: bad line count", optarg); > + xo_errx(1, "%s: bad line count", optarg); > break; > case 's': > sflag++; /* Show delta as seconds */ > @@ -212,14 +220,16 @@ wtmp(void) > SLIST_INIT(&idlist); > (void)time(&t); > > + xo_open_container("last-information"); > + > /* Load the last entries from the file. */ > if (setutxdb(UTXDB_LOG, file) != 0) > - err(1, "%s", file); > + xo_err(1, "%s", file); > while ((ut = getutxent()) != NULL) { > if (amount % 128 == 0) { > buf = realloc(buf, (amount + 128) * sizeof *ut); > if (buf == NULL) > - err(1, "realloc"); > + xo_err(1, "realloc"); > } > memcpy(&buf[amount++], ut, sizeof *ut); > if (t > ut->ut_tv.tv_sec) > @@ -228,12 +238,17 @@ wtmp(void) > endutxent(); > > /* Display them in reverse order. */ > + xo_open_list("last"); > while (amount > 0) > doentry(&buf[--amount]); > - > + xo_close_list("last"); > + free(buf); > tm = localtime(&t); > (void) strftime(ct, sizeof(ct), "%+", tm); > - printf("\n%s begins %s\n", ((file == NULL) ? "utx.log" : file), > ct); > + xo_emit("\n{:utxdb/%s}", (file == NULL) ? "utx.log" : file); > + xo_attr("seconds", "%lu", (unsigned long) t); > + xo_emit(" begins {:begins/%s}\n", ct); > + xo_close_container("last-information"); > } > > /* > @@ -288,7 +303,7 @@ doentry(struct utmpx *bp) > /* add new one */ > tt = malloc(sizeof(struct idtab)); > if (tt == NULL) > - errx(1, "malloc failure"); > + xo_errx(1, "malloc failure"); > tt->logout = currentout; > memcpy(tt->id, bp->ut_id, sizeof bp->ut_id); > SLIST_INSERT_HEAD(&idlist, tt, list); > @@ -324,6 +339,7 @@ printentry(struct utmpx *bp, struct idtab *tt) > > if (maxrec != -1 && !maxrec--) > exit(0); > + xo_open_instance("last"); > t = bp->ut_tv.tv_sec; > tm = localtime(&t); > (void) strftime(ct, sizeof(ct), d_first ? > @@ -331,48 +347,55 @@ printentry(struct utmpx *bp, struct idtab *tt) > (yflag ? "%a %b %e %Y %R" : "%a %b %e %R"), tm); > switch (bp->ut_type) { > case BOOT_TIME: > - printf("%-42s", "boot time"); > + xo_emit("{:user/%-42s/%s}", "boot time"); > break; > case SHUTDOWN_TIME: > - printf("%-42s", "shutdown time"); > + xo_emit("{:user/%-42s/%s}", "shutdown time"); > break; > case OLD_TIME: > - printf("%-42s", "old time"); > + xo_emit("{:user/%-42s/%s}", "old time"); > break; > case NEW_TIME: > - printf("%-42s", "new time"); > + xo_emit("{:user/%-42s/%s}", "new time"); > break; > case USER_PROCESS: > - printf("%-10s %-8s %-22.22s", > + xo_emit("{:user/%-10s/%s} {:tty/%-8s/%s} > {:from/%-22.22s/%s}", > bp->ut_user, bp->ut_line, bp->ut_host); > break; > } > - printf(" %s%c", ct, tt == NULL ? '\n' : ' '); > + xo_attr("seconds", "%lu", (unsigned long)t); > + xo_emit(" {:login-time/%s%c/%s}", ct, tt == NULL ? '\n' : ' '); > if (tt == NULL) > - return; > + goto end; > if (!tt->logout) { > - puts(" still logged in"); > - return; > + xo_emit(" {:logout-time/still logged in}\n"); > + goto end; > } > if (tt->logout < 0) { > tt->logout = -tt->logout; > - printf("- %s", crmsg); > + xo_emit("- {:logout-reason/%s}", crmsg); > } else { > tm = localtime(&tt->logout); > (void) strftime(ct, sizeof(ct), "%R", tm); > - printf("- %s", ct); > + xo_attr("seconds", "%lu", (unsigned long)tt->logout); > + xo_emit("- {:logout-time/%s}", ct); > } > delta = tt->logout - bp->ut_tv.tv_sec; > + xo_attr("seconds", "%ld", (long)delta); > if (sflag) { > - printf(" (%8ld)\n", (long)delta); > + xo_emit(" ({:session-length/%8ld})\n", (long)delta); > } else { > tm = gmtime(&delta); > (void) strftime(ct, sizeof(ct), width >= 8 ? "%T" : "%R", > tm); > if (delta < 86400) > - printf(" (%s)\n", ct); > + xo_emit(" ({:session-length/%s})\n", ct); > else > - printf(" (%ld+%s)\n", (long)delta / 86400, ct); > + xo_emit(" ({:session-length/%ld+%s})\n", > + (long)delta / 86400, ct); > } > + > +end: > + xo_close_instance("last"); > } > > /* > @@ -423,7 +446,7 @@ addarg(int type, char *arg) > ARG *cur; > > if ((cur = malloc(sizeof(ARG))) == NULL) > - errx(1, "malloc failure"); > + xo_errx(1, "malloc failure"); > cur->next = arglist; > cur->type = type; > cur->name = arg; > @@ -448,7 +471,7 @@ hostconv(char *arg) > if (first) { > first = 0; > if (gethostname(name, sizeof(name))) > - err(1, "gethostname"); > + xo_err(1, "gethostname"); > hostdot = strchr(name, '.'); > } > if (hostdot && !strcasecmp(hostdot, argdot)) > @@ -471,7 +494,7 @@ ttyconv(char *arg) > if (strlen(arg) == 2) { > /* either 6 for "ttyxx" or 8 for "console" */ > if ((mval = malloc(8)) == NULL) > - errx(1, "malloc failure"); > + xo_errx(1, "malloc failure"); > if (!strcmp(arg, "co")) > (void)strcpy(mval, "console"); > else { > @@ -501,9 +524,9 @@ dateconv(char *arg) > > /* Start with the current time. */ > if (time(&timet) < 0) > - err(1, "time"); > + xo_err(1, "time"); > if ((t = localtime(&timet)) == NULL) > - err(1, "localtime"); > + xo_err(1, "localtime"); > > /* [[CC]YY]MMDDhhmm[.SS] */ > if ((p = strchr(arg, '.')) == NULL) > @@ -552,7 +575,7 @@ dateconv(char *arg) > t->tm_isdst = -1; /* Figure out DST. */ > timet = mktime(t); > if (timet == -1) > -terr: errx(1, > +terr: xo_errx(1, > "out of range or illegal time specification: > [[CC]YY]MMDDhhmm[.SS]"); > return timet; > } > > -- -- Marcelo Araujo (__)araujo@FreeBSD.org \\\'',)http://www.FreeBSD.org \/ \ ^ Power To Server. .\. /_)