PR/56013: Kouichi Hashikawa: Move setutent/setutxent right before the loops.
This commit is contained in:
parent
31c71552cd
commit
e0ecd16b50
@ -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.
|
* Copyright (c) 2002 The NetBSD Foundation, Inc.
|
||||||
@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#ifndef lint
|
#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
|
#endif
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -95,14 +95,7 @@ setup(const char *fname)
|
|||||||
struct stat st;
|
struct stat st;
|
||||||
const char *sfname;
|
const char *sfname;
|
||||||
|
|
||||||
if (fname == NULL) {
|
if (fname != NULL) {
|
||||||
#ifdef SUPPORT_UTMPX
|
|
||||||
setutxent();
|
|
||||||
#endif
|
|
||||||
#ifdef SUPPORT_UTMP
|
|
||||||
setutent();
|
|
||||||
#endif
|
|
||||||
} else {
|
|
||||||
size_t len = strlen(fname);
|
size_t len = strlen(fname);
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
errx(1, "Filename cannot be 0 length.");
|
errx(1, "Filename cannot be 0 length.");
|
||||||
@ -204,10 +197,11 @@ getutentries(const char *fname, struct utmpentry **epp)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SUPPORT_UTMPX
|
#ifdef SUPPORT_UTMPX
|
||||||
|
setutxent();
|
||||||
while ((what & 1) && (utx = getutxent()) != NULL) {
|
while ((what & 1) && (utx = getutxent()) != NULL) {
|
||||||
if (fname == NULL && ((1 << utx->ut_type) & etype) == 0)
|
if (fname == NULL && ((1 << utx->ut_type) & etype) == 0)
|
||||||
continue;
|
continue;
|
||||||
if ((ep = calloc(1, sizeof(struct utmpentry))) == NULL) {
|
if ((ep = calloc(1, sizeof(*ep))) == NULL) {
|
||||||
warn(NULL);
|
warn(NULL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -218,6 +212,7 @@ getutentries(const char *fname, struct utmpentry **epp)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SUPPORT_UTMP
|
#ifdef SUPPORT_UTMP
|
||||||
|
setutent();
|
||||||
if ((etype & (1 << USER_PROCESS)) != 0) {
|
if ((etype & (1 << USER_PROCESS)) != 0) {
|
||||||
while ((what & 2) && (ut = getutent()) != NULL) {
|
while ((what & 2) && (ut = getutent()) != NULL) {
|
||||||
if (fname == NULL && (*ut->ut_name == '\0' ||
|
if (fname == NULL && (*ut->ut_name == '\0' ||
|
||||||
|
Loading…
Reference in New Issue
Block a user