Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/who PR/56013: Kouichi Hashikawa: Move setutent/setut...



details:   https://anonhg.NetBSD.org/src/rev/91c636cb9e3b
branches:  trunk
changeset: 959813:91c636cb9e3b
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Feb 26 02:45:43 2021 +0000

description:
PR/56013: Kouichi Hashikawa: Move setutent/setutxent right before the loops.

diffstat:

 usr.bin/who/utmpentry.c |  21 ++++++++-------------
 1 files changed, 8 insertions(+), 13 deletions(-)

diffs (67 lines):

diff -r 37daf57d2a72 -r 91c636cb9e3b usr.bin/who/utmpentry.c
--- a/usr.bin/who/utmpentry.c   Fri Feb 26 02:18:55 2021 +0000
+++ b/usr.bin/who/utmpentry.c   Fri Feb 26 02:45:43 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: utmpentry.c,v 1.21 2019/10/05 23:35:57 mrg Exp $       */
+/*     $NetBSD: utmpentry.c,v 1.22 2021/02/26 02:45:43 christos Exp $  */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: utmpentry.c,v 1.21 2019/10/05 23:35:57 mrg Exp $");
+__RCSID("$NetBSD: utmpentry.c,v 1.22 2021/02/26 02:45:43 christos Exp $");
 #endif
 
 #include <sys/stat.h>
@@ -95,14 +95,7 @@
        struct stat st;
        const char *sfname;
 
-       if (fname == NULL) {
-#ifdef SUPPORT_UTMPX
-               setutxent();
-#endif
-#ifdef SUPPORT_UTMP
-               setutent();
-#endif
-       } else {
+       if (fname != NULL) {
                size_t len = strlen(fname);
                if (len == 0)
                        errx(1, "Filename cannot be 0 length.");
@@ -133,9 +126,9 @@
                        what &= ~1;
                } else {
                        if (timespeccmp(&st.st_mtimespec, &utmpxtime, >))
-                           utmpxtime = st.st_mtimespec;
+                               utmpxtime = st.st_mtimespec;
                        else
-                           what &= ~1;
+                               what &= ~1;
                }
        }
 #endif
@@ -204,10 +197,11 @@
 #endif
 
 #ifdef SUPPORT_UTMPX
+       setutxent();
        while ((what & 1) && (utx = getutxent()) != NULL) {
                if (fname == NULL && ((1 << utx->ut_type) & etype) == 0)
                        continue;
-               if ((ep = calloc(1, sizeof(struct utmpentry))) == NULL) {
+               if ((ep = calloc(1, sizeof(*ep))) == NULL) {
                        warn(NULL);
                        return 0;
                }
@@ -218,6 +212,7 @@
 #endif
 
 #ifdef SUPPORT_UTMP
+       setutent();
        if ((etype & (1 << USER_PROCESS)) != 0) {
                while ((what & 2) && (ut = getutent()) != NULL) {
                        if (fname == NULL && (*ut->ut_name == '\0' ||



Home | Main Index | Thread Index | Old Index