[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Test bug in Coreutils
From: |
Paul Eggert |
Subject: |
Re: Test bug in Coreutils |
Date: |
Tue, 30 Nov 2004 13:49:59 -0800 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) |
Thanks for the extra info about HP-UX 11.11.
I think I see the problem now: "who" and "uptime" get the boot time in
different ways. I looked into this and found several other instances
where these programs (and "users" and "pinky") had diverged
unnecessarily. I installed this patch to try to clean up all the
cruft that I found.
2004-11-30 Paul Eggert <address@hidden>
* lib/readutmp.c: Include readutmp.h first.
Include <errno.h>, since readutmp.h no longer does that.
* lib/readutmp.h: Don't include <sys/types.h>, <errno.h>,
<sys/param.h>, <time.h>; not needed to establish interface.
Include <stddef.h> instead.
(errno): Remove decl.
(HAVE_STRUCT_XTMP_UT_TYPE): Remove; no longer needed.
(UT_TYPE_EQ, UT_TYPE_NOT_DEFINED, UT_TYPE_BOOT_TIME,
UT_TYPE_USER_PROCESS, IS_USER_PROCESS): New macros.
* m4/readutmp.m4 (gl_READUTMP): Don't check for sys/param.h.
* src/pinky.c (gethostname): Remove decl.
(scan_entries): Use IS_USER_PROCESS instead of by-hand code.
* src/uptime.c (print_uptime): Use IS_USER_PROCESS and
UT_TYPE_BOOT_TIME instead of by-hand code.
* src/users.c (list_entries_users): Use IS_USER_PROCESS
instead of by-hand code.
* src/who.c (USER_PROCESS, RUN_LVL, INIT_PROCESS, LOGIN_PROCESS,
DEAD_PROCESS, BOOT_TIME, NEW_TIME, UT_TYPE_UNDEF, UT_TYPE): Remove.
(IS_USER_PROCESS): Move to ../lib/readutmp.h.
(UT_TYPE_RUN_LVL, UT_TYPE_INIT_PROCESS, UT_TYPE_LOGIN_PROCESS,
UT_TYPE_DEAD_PROCESS, UT_TYPE_NEW_TIME): New macros.
(gethostname): Remove decl.
(list_entries_who, scan_entries): Use the new macros defined above,
for consistency with pinky, uptime, and users.
Index: lib/readutmp.c
===================================================================
RCS file: /fetish/cu/lib/readutmp.c,v
retrieving revision 1.22
diff -p -u -r1.22 readutmp.c
--- lib/readutmp.c 4 Oct 2004 20:18:43 -0000 1.22
+++ lib/readutmp.c 30 Nov 2004 21:33:09 -0000
@@ -19,6 +19,9 @@
#include <config.h>
+#include "readutmp.h"
+
+#include <errno.h>
#include <stdio.h>
#include <sys/types.h>
@@ -26,7 +29,6 @@
#include <string.h>
#include <stdlib.h>
-#include "readutmp.h"
#include "xalloc.h"
#if USE_UNLOCKED_IO
Index: lib/readutmp.h
===================================================================
RCS file: /fetish/cu/lib/readutmp.h,v
retrieving revision 1.16
diff -p -u -r1.16 readutmp.h
--- lib/readutmp.h 2 Aug 2004 20:54:45 -0000 1.16
+++ lib/readutmp.h 30 Nov 2004 21:33:09 -0000
@@ -22,7 +22,7 @@
#ifndef __READUTMP_H__
# define __READUTMP_H__
-# include <sys/types.h>
+# include <stddef.h>
/* AIX 4.3.3 has both utmp.h and utmpx.h, but only struct utmp
has the ut_exit member. */
@@ -137,24 +137,10 @@
(HAVE_STRUCT_UTMP_UT_PID \
|| HAVE_STRUCT_UTMPX_UT_PID)
-# define HAVE_STRUCT_XTMP_UT_TYPE \
- (HAVE_STRUCT_UTMP_UT_TYPE \
- || HAVE_STRUCT_UTMPX_UT_TYPE)
-
typedef struct UTMP_STRUCT_NAME STRUCT_UTMP;
enum { UT_USER_SIZE = sizeof UT_USER ((STRUCT_UTMP *) 0) };
-# include <time.h>
-# ifdef HAVE_SYS_PARAM_H
-# include <sys/param.h>
-# endif
-
-# include <errno.h>
-# ifndef errno
-extern int errno;
-# endif
-
# if !defined (UTMP_FILE) && defined (_PATH_UTMP)
# define UTMP_FILE _PATH_UTMP
# endif
@@ -181,6 +167,31 @@ extern int errno;
# define WTMP_FILE "/etc/wtmp"
# endif
+# if HAVE_STRUCT_UTMP_UT_TYPE || HAVE_STRUCT_UTMPX_UT_TYPE
+# define UT_TYPE_EQ(U, V) ((U)->ut_type == (V))
+# define UT_TYPE_NOT_DEFINED 0
+# else
+# define UT_TYPE_EQ(U, V) 0
+# define UT_TYPE_NOT_DEFINED 1
+# endif
+
+# ifdef BOOT_TIME
+# define UT_TYPE_BOOT_TIME(U) UT_TYPE_EQ (U, BOOT_TIME)
+# else
+# define UT_TYPE_BOOT_TIME(U) 0
+# endif
+
+# ifdef USER_PROCESS
+# define UT_TYPE_USER_PROCESS(U) UT_TYPE_EQ (U, USER_PROCESS)
+# else
+# define UT_TYPE_USER_PROCESS(U) 0
+# endif
+
+# define IS_USER_PROCESS(U) \
+ (UT_USER (U)[0] \
+ && (UT_TYPE_USER_PROCESS (U) \
+ || (UT_TYPE_NOT_DEFINED && UT_TIME_MEMBER (U) != 0)))
+
char *extract_trimmed_name (const STRUCT_UTMP *ut);
int read_utmp (const char *filename, size_t *n_entries, STRUCT_UTMP
**utmp_buf);
--- m4/readutmp.m4.~1.3.~ 2004-04-19 12:01:07 -0700
+++ m4/readutmp.m4 2004-11-30 13:45:25 -0800
@@ -1,4 +1,4 @@
-# readutmp.m4 serial 4
+# readutmp.m4 serial 5
dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
dnl This file is free software, distributed under the terms of the GNU
dnl General Public License. As a special exception to the GNU General
@@ -9,7 +9,6 @@ dnl the same distribution terms as the r
AC_DEFUN([gl_READUTMP],
[
dnl Prerequisites of lib/readutmp.h.
- AC_CHECK_HEADERS_ONCE(sys/param.h)
AC_CHECK_HEADERS(utmp.h utmpx.h)
AC_CHECK_FUNCS(utmpname utmpxname)
AC_CHECK_DECLS(getutent,,,[
Index: src/pinky.c
===================================================================
RCS file: /fetish/cu/src/pinky.c,v
retrieving revision 1.43
diff -p -u -r1.43 pinky.c
--- src/pinky.c 16 Nov 2004 20:44:34 -0000 1.43
+++ src/pinky.c 30 Nov 2004 21:33:10 -0000
@@ -43,7 +43,6 @@
# define S_IWGRP 020
#endif
-int gethostname ();
char *ttyname ();
/* The name this program was run with. */
@@ -458,11 +457,7 @@ scan_entries (size_t n, const STRUCT_UTM
while (n--)
{
- if (UT_USER (utmp_buf)[0]
-#ifdef USER_PROCESS
- && utmp_buf->ut_type == USER_PROCESS
-#endif
- )
+ if (IS_USER_PROCESS (utmp_buf))
{
if (argc_names)
{
Index: src/uptime.c
===================================================================
RCS file: /fetish/cu/src/uptime.c,v
retrieving revision 1.47
diff -p -u -r1.47 uptime.c
--- src/uptime.c 17 Nov 2004 00:56:25 -0000 1.47
+++ src/uptime.c 30 Nov 2004 21:33:10 -0000
@@ -95,23 +95,9 @@ print_uptime (size_t n, const STRUCT_UTM
ones, also in the process possibly gleaning boottime. */
while (n--)
{
- if (UT_USER (this) [0]
-#ifdef USER_PROCESS
- && this->ut_type == USER_PROCESS
-#endif
- )
- {
- ++entries;
- }
- /* If BOOT_MSG is defined, we can get boottime from utmp. This avoids
- possibly needing special privs to read /dev/kmem. */
-#ifdef BOOT_MSG
-# if HAVE_PROC_UPTIME
- if (uptime == 0)
-# endif /* HAVE_PROC_UPTIME */
- if (strncmp (this->ut_line, BOOT_MSG, sizeof this->ut_line) == 0)
- boot_time = UT_TIME_MEMBER (this);
-#endif /* BOOT_MSG */
+ entries += IS_USER_PROCESS (this);
+ if (UT_TYPE_BOOT_TIME (this))
+ boot_time = UT_TIME_MEMBER (this);
++this;
}
time_now = time (0);
Index: src/users.c
===================================================================
RCS file: /fetish/cu/src/users.c,v
retrieving revision 1.38
diff -p -u -r1.38 users.c
--- src/users.c 17 Nov 2004 00:56:25 -0000 1.38
+++ src/users.c 30 Nov 2004 21:33:10 -0000
@@ -54,11 +54,7 @@ list_entries_users (size_t n, const STRU
while (n--)
{
- if (UT_USER (this) [0]
-#ifdef USER_PROCESS
- && this->ut_type == USER_PROCESS
-#endif
- )
+ if (IS_USER_PROCESS (this))
{
char *trimmed_name;
Index: src/who.c
===================================================================
RCS file: /fetish/cu/src/who.c,v
retrieving revision 1.104
diff -p -u -r1.104 who.c
--- src/who.c 16 Nov 2004 20:44:34 -0000 1.104
+++ src/who.c 30 Nov 2004 21:33:10 -0000
@@ -51,32 +51,34 @@
# define S_IWGRP 020
#endif
-#ifndef USER_PROCESS
-# define USER_PROCESS INT_MAX
-#endif
-
-#ifndef RUN_LVL
-# define RUN_LVL INT_MAX
-#endif
-
-#ifndef INIT_PROCESS
-# define INIT_PROCESS INT_MAX
+#ifdef RUN_LVL
+# define UT_TYPE_RUN_LVL(U) UT_TYPE_EQ (U, RUN_LVL)
+#else
+# define UT_TYPE_RUN_LVL(U) false
#endif
-#ifndef LOGIN_PROCESS
-# define LOGIN_PROCESS INT_MAX
+#ifdef INIT_PROCESS
+# define UT_TYPE_INIT_PROCESS(U) UT_TYPE_EQ (U, INIT_PROCESS)
+#else
+# define UT_TYPE_INIT_PROCESS(U) false
#endif
-#ifndef DEAD_PROCESS
-# define DEAD_PROCESS INT_MAX
+#ifdef LOGIN_PROCESS
+# define UT_TYPE_LOGIN_PROCESS(U) UT_TYPE_EQ (U, LOGIN_PROCESS)
+#else
+# define UT_TYPE_LOGIN_PROCESS(U) false
#endif
-#ifndef BOOT_TIME
-# define BOOT_TIME 0
+#ifdef DEAD_PROCESS
+# define UT_TYPE_DEAD_PROCESS(U) UT_TYPE_EQ (U, DEAD_PROCESS)
+#else
+# define UT_TYPE_DEAD_PROCESS(U) false
#endif
-#ifndef NEW_TIME
-# define NEW_TIME 0
+#ifdef NEW_TIME
+# define UT_TYPE_NEW_TIME(U) UT_TYPE_EQ (U, NEW_TIME)
+#else
+# define UT_TYPE_NEW_TIME(U) false
#endif
#define IDLESTR_LEN 6
@@ -98,21 +100,6 @@
# define UT_ID(U) "??"
#endif
-#define UT_TYPE_UNDEF 255
-
-#if HAVE_STRUCT_XTMP_UT_TYPE
-# define UT_TYPE(U) ((U)->ut_type)
-#else
-# define UT_TYPE(U) UT_TYPE_UNDEF
-#endif
-
-#define IS_USER_PROCESS(U) \
- (UT_USER (utmp_buf)[0] \
- && (UT_TYPE (utmp_buf) == USER_PROCESS \
- || (UT_TYPE (utmp_buf) == UT_TYPE_UNDEF \
- && UT_TIME_MEMBER (utmp_buf) != 0)))
-
-int gethostname ();
char *ttyname ();
char *canon_host ();
@@ -545,7 +532,7 @@ list_entries_who (size_t n, const STRUCT
while (n--)
{
- if (UT_USER (utmp_buf)[0] && UT_TYPE (utmp_buf) == USER_PROCESS)
+ if (IS_USER_PROCESS (utmp_buf))
{
char *trimmed_name;
@@ -595,24 +582,24 @@ scan_entries (size_t n, const STRUCT_UTM
{
if (need_users && IS_USER_PROCESS (utmp_buf))
print_user (utmp_buf, boottime);
- else if (need_runlevel && UT_TYPE (utmp_buf) == RUN_LVL)
+ else if (need_runlevel && UT_TYPE_RUN_LVL (utmp_buf))
print_runlevel (utmp_buf);
- else if (need_boottime && UT_TYPE (utmp_buf) == BOOT_TIME)
+ else if (need_boottime && UT_TYPE_BOOT_TIME (utmp_buf))
print_boottime (utmp_buf);
/* I've never seen one of these, so I don't know what it should
look like :^)
FIXME: handle OLD_TIME also, perhaps show the delta? */
- else if (need_clockchange && UT_TYPE (utmp_buf) == NEW_TIME)
+ else if (need_clockchange && UT_TYPE_NEW_TIME (utmp_buf))
print_clockchange (utmp_buf);
- else if (need_initspawn && UT_TYPE (utmp_buf) == INIT_PROCESS)
+ else if (need_initspawn && UT_TYPE_INIT_PROCESS (utmp_buf))
print_initspawn (utmp_buf);
- else if (need_login && UT_TYPE (utmp_buf) == LOGIN_PROCESS)
+ else if (need_login && UT_TYPE_LOGIN_PROCESS (utmp_buf))
print_login (utmp_buf);
- else if (need_deadprocs && UT_TYPE (utmp_buf) == DEAD_PROCESS)
+ else if (need_deadprocs && UT_TYPE_DEAD_PROCESS (utmp_buf))
print_deadprocs (utmp_buf);
}
- if (UT_TYPE (utmp_buf) == BOOT_TIME)
+ if (UT_TYPE_BOOT_TIME (utmp_buf))
boottime = UT_TIME_MEMBER (utmp_buf);
utmp_buf++;
- Test bug in Coreutils, Tinsley, Scott S. \(ManTech\) CTR, 2004/11/29
- Re: Test bug in Coreutils,
Paul Eggert <=