Subject: bin/26335: who(1) doesn't warn about non-existent utmp[x] files
To: None <gnats-bugs@gnats.NetBSD.org>
From: Peter Postma <peter@pointless.nl>
List: netbsd-bugs
Date: 07/15/2004 15:24:53
>Number:         26335
>Category:       bin
>Synopsis:       who(1) doesn't warn about non-existent utmp[x] files
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Thu Jul 15 13:26:01 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator:     Peter Postma
>Release:        NetBSD 2.0G
>Organization:
>Environment:
System: NetBSD mercury.pointless.nl 2.0G NetBSD 2.0G (mercury) #11: Fri Jul 2 17:57:06 CEST 2004 peter@mercury.pointless.nl:/usr/obj/sys/arch/sparc64/compile/mercury sparc64
Architecture: sparc64
Machine: sparc64
>Description:
who(1) doesn't warn about non-existent utmp[x] files. FreeBSD and OpenBSD
seem to do this as an user expects.
>How-To-Repeat:
# who /nonexistent; echo $?
0
>Fix:
An error should be issued out when an utmp[x] file does not exist:

# who /nonexistent; echo $?
who: Cannot open `/nonexistent': No such file or directory
1

I think that the return value of stat() in utmpentry.c should not be ignored
and used instead to check if the file exists. The change only affects the
who(1) utility and not other program which also use utmpentry.c.

Index: utmpentry.c
===================================================================
RCS file: /cvsroot/src/usr.bin/who/utmpentry.c,v
retrieving revision 1.4
diff -u -r1.4 utmpentry.c
--- utmpentry.c	12 Feb 2003 17:39:36 -0000	1.4
+++ utmpentry.c	15 Jul 2004 12:50:58 -0000
@@ -125,7 +125,8 @@
 	}
 #ifdef SUPPORT_UTMPX
 	if (what & 1) {
-		(void)stat(fname ? fname : _PATH_UTMPX, &st);
+		if (stat(fname ? fname : _PATH_UTMPX, &st) < 0)
+			err(1, "Cannot open `%s'", fname ? fname : _PATH_UTMPX);
 		if (st.st_mtime > utmpxtime)
 			utmpxtime = st.st_mtime;
 		else
@@ -134,7 +135,8 @@
 #endif
 #ifdef SUPPORT_UTMP
 	if (what & 2) {
-		(void)stat(fname ? fname : _PATH_UTMP, &st);
+		if (stat(fname ? fname : _PATH_UTMP, &st) < 0)
+			err(1, "Cannot open `%s'", fname ? fname : _PATH_UTMP);
 		if (st.st_mtime > utmptime)
 			utmptime = st.st_mtime;
 		else
>Release-Note:
>Audit-Trail:
>Unformatted: