]> xenbits.xensource.com Git - freebsd.git/commitdiff
Fix address annotation in xml output from w
authorkarels <karels@FreeBSD.org>
Thu, 29 Aug 2019 02:44:18 +0000 (02:44 +0000)
committerkarels <karels@FreeBSD.org>
Thu, 29 Aug 2019 02:44:18 +0000 (02:44 +0000)
The libxo xml feature of adding an annotation with the "original"
address from the utmpx file if it is different than the final "from"
field was broken by r351379. This was pointed out by the gcc error
that save_p might be used uninitialized. Save the original address
as needed in each entry, don't just use the last one from the previous
loop.

Reviewed by: marcel@
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D21390

usr.bin/w/w.c

index 9af0f3c3cd501442d4254044adb6a5104392f35c..06da99f086604bfe6d77fd77d175ba3706a336a4 100644 (file)
@@ -118,6 +118,7 @@ static struct entry {
        char    *args;                  /* arg list of interesting process */
        struct  kinfo_proc *dkp;        /* debug option proc list */
        char    *from;                  /* "from": name or addr */
+       char    *save_from;             /* original "from": name or addr */
 } *ep, *ehead = NULL, **nextp = &ehead;
 
 #define        debugproc(p) *(&((struct kinfo_proc *)p)->ki_udata)
@@ -209,7 +210,6 @@ main(int argc, char *argv[])
        if (*argv)
                sel_users = argv;
 
-       save_p = NULL;
        setutxent();
        for (nusers = 0; (utmp = getutxent()) != NULL;) {
                struct addrinfo hints, *res;
@@ -312,6 +312,8 @@ main(int argc, char *argv[])
                ep->from = strdup(p);
                if ((i = strlen(p)) > fromwidth)
                        fromwidth = i;
+               if (save_p != p)
+                       ep->save_from = strdup(save_p);
        }
        endutxent();
 
@@ -451,8 +453,8 @@ main(int argc, char *argv[])
                         strncmp(ep->utmp.ut_line, "cua", 3) ?
                         ep->utmp.ut_line : ep->utmp.ut_line + 3) : "-");
 
-               if (save_p && save_p != p)
-                   xo_attr("address", "%s", save_p);
+               if (ep->save_from)
+                   xo_attr("address", "%s", ep->save_from);
                xo_emit("{:from/%-*.*s/%@**@s} ",
                    fromwidth, fromwidth, ep->from);
                t = ep->utmp.ut_tv.tv_sec;