rpms/coreutils/devel coreutils-stale-utmp.patch, 1.2, 1.3 coreutils.spec, 1.58, 1.59

fedora-cvs-commits at redhat.com fedora-cvs-commits at redhat.com
Tue Mar 29 13:25:45 UTC 2005


Update of /cvs/dist/rpms/coreutils/devel
In directory cvs.devel.redhat.com:/tmp/cvs-serv11675

Modified Files:
	coreutils.spec 
Added Files:
	coreutils-stale-utmp.patch 
Log Message:
* Tue Mar 29 2005 Tim Waugh <twaugh at redhat.com>
- Added "stale utmp" patch from upstream.


coreutils-stale-utmp.patch:
 lib/readutmp.c |   43 +++++++++++++++++++++++++++++++++----------
 lib/readutmp.h |   15 ++++++++++++++-
 src/pinky.c    |    2 +-
 src/uptime.c   |   11 ++++++-----
 src/users.c    |   11 ++++++-----
 src/who.c      |   21 +++++++++------------
 6 files changed, 69 insertions(+), 34 deletions(-)

Index: coreutils-stale-utmp.patch
===================================================================
RCS file: coreutils-stale-utmp.patch
diff -N coreutils-stale-utmp.patch
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ coreutils-stale-utmp.patch	29 Mar 2005 13:25:42 -0000	1.3
@@ -0,0 +1,249 @@
+--- coreutils-5.2.1/lib/readutmp.c.stale-utmp	2003-10-16 08:58:22.000000000 +0100
++++ coreutils-5.2.1/lib/readutmp.c	2005-03-29 13:20:09.000000000 +0100
+@@ -23,6 +23,8 @@
+ 
+ #include <sys/types.h>
+ #include <sys/stat.h>
++#include <signal.h>
++#include <stdbool.h>
+ #include <string.h>
+ #include <stdlib.h>
+ 
+@@ -49,15 +51,28 @@
+   return trimmed_name;
+ }
+ 
++/* Is the utmp entry U desired by the user who asked for OPTIONS?  */
++
++static inline bool
++desirable_utmp_entry (STRUCT_UTMP const *u, int options)
++{
++  return ! (options & READ_UTMP_CHECK_PIDS
++	    && (UT_PID (u) <= 0
++		|| (kill (UT_PID (u), 0) < 0 && errno == ESRCH)));
++}
++
+ /* Read the utmp entries corresponding to file FILENAME into freshly-
+    malloc'd storage, set *UTMP_BUF to that pointer, set *N_ENTRIES to
+    the number of entries, and return zero.  If there is any error,
+-   return non-zero and don't modify the parameters.  */
++   return -1, setting errno, and don't modify the parameters.
++   If OPTIONS & READ_UTMP_CHECK_PIDS is nonzero, omit entries whose
++   process-IDs do not currently exist.  */
+ 
+ #ifdef UTMP_NAME_FUNCTION
+ 
+ int
+-read_utmp (const char *filename, int *n_entries, STRUCT_UTMP **utmp_buf)
++read_utmp (const char *filename, int *n_entries, STRUCT_UTMP **utmp_buf,
++	   int options)
+ {
+   int n_read;
+   STRUCT_UTMP *u;
+@@ -73,13 +88,14 @@
+ 
+   n_read = 0;
+   while ((u = GET_UTMP_ENT ()) != NULL)
+-    {
+-      ++n_read;
+-      utmp = (STRUCT_UTMP *) realloc (utmp, n_read * sizeof (STRUCT_UTMP));
+-      if (utmp == NULL)
+-	return 1;
+-      utmp[n_read - 1] = *u;
+-    }
++    if (desirable_utmp_entry (u, options))
++      {
++	++n_read;
++	utmp = (STRUCT_UTMP *) realloc (utmp, n_read * sizeof (STRUCT_UTMP));
++	if (utmp == NULL)
++	  return 1;
++	utmp[n_read - 1] = *u;
++      }
+ 
+   END_UTMP_ENT ();
+ 
+@@ -98,6 +114,8 @@
+   struct stat file_stats;
+   size_t n_read;
+   size_t size;
++  size_t i;
++  size_t n_desired;
+   STRUCT_UTMP *buf;
+ 
+   utmp = fopen (filename, "r");
+@@ -130,7 +148,12 @@
+       return 1;
+     }
+ 
+-  *n_entries = n_read;
++  n_desired = 0;
++  for (i = 0; i < n_read; i++)
++    if (desirable_utmp_entry (&utmp[i], options))
++      utmp[n_desired++] = utmp[i];
++
++  *n_entries = n_desired;
+   *utmp_buf = buf;
+ 
+   return 0;
+--- coreutils-5.2.1/lib/readutmp.h.stale-utmp	2003-08-17 08:51:49.000000000 +0100
++++ coreutils-5.2.1/lib/readutmp.h	2005-03-29 13:20:09.000000000 +0100
+@@ -179,7 +179,20 @@
+ #  define WTMP_FILE "/etc/wtmp"
+ # endif
+ 
++# if HAVE_STRUCT_XTMP_UT_PID
++#  define UT_PID(U) ((U)->ut_pid)
++# else
++#  define UT_PID(U) 0
++# endif
++
++/* Options for read_utmp.  */
++enum
++  {
++    READ_UTMP_CHECK_PIDS = 1
++  };
++
+ char *extract_trimmed_name (const STRUCT_UTMP *ut);
+-int read_utmp (const char *filename, int *n_entries, STRUCT_UTMP **utmp_buf);
++int read_utmp (const char *filename, int *n_entries, STRUCT_UTMP **utmp_buf,
++	       int options);
+ 
+ #endif /* __READUTMP_H__ */
+--- coreutils-5.2.1/src/pinky.c.stale-utmp	2004-01-21 22:27:02.000000000 +0000
++++ coreutils-5.2.1/src/pinky.c	2005-03-29 13:20:09.000000000 +0100
+@@ -440,7 +440,7 @@
+ {
+   int n_users;
+   STRUCT_UTMP *utmp_buf;
+-  int fail = read_utmp (filename, &n_users, &utmp_buf);
++  int fail = read_utmp (filename, &n_users, &utmp_buf, 0);
+ 
+   if (fail)
+     error (EXIT_FAILURE, errno, "%s", filename);
+--- coreutils-5.2.1/src/uptime.c.stale-utmp	2004-02-05 09:36:07.000000000 +0000
++++ coreutils-5.2.1/src/uptime.c	2005-03-29 13:20:09.000000000 +0100
+@@ -167,14 +167,15 @@
+ }
+ 
+ /* Display the system uptime and the number of users on the system,
+-   according to utmp file FILENAME. */
++   according to utmp file FILENAME.  Use read_utmp OPTIONS to read the
++   utmp file.  */
+ 
+ static void
+-uptime (const char *filename)
++uptime (const char *filename, int options)
+ {
+   int n_users;
+   STRUCT_UTMP *utmp_buf;
+-  int fail = read_utmp (filename, &n_users, &utmp_buf);
++  int fail = read_utmp (filename, &n_users, &utmp_buf, options);
+ 
+   if (fail)
+     error (EXIT_FAILURE, errno, "%s", filename);
+@@ -236,11 +237,11 @@
+   switch (argc - optind)
+     {
+     case 0:			/* uptime */
+-      uptime (UTMP_FILE);
++      uptime (UTMP_FILE, READ_UTMP_CHECK_PIDS);
+       break;
+ 
+     case 1:			/* uptime <utmp file> */
+-      uptime (argv[optind]);
++      uptime (argv[optind], 0);
+       break;
+ 
+     default:			/* lose */
+--- coreutils-5.2.1/src/users.c.stale-utmp	2004-01-21 22:27:02.000000000 +0000
++++ coreutils-5.2.1/src/users.c	2005-03-29 13:20:09.000000000 +0100
+@@ -91,14 +91,15 @@
+   free (u);
+ }
+ 
+-/* Display a list of users on the system, according to utmp file FILENAME. */
++/* Display a list of users on the system, according to utmp file FILENAME.
++   Use read_utmp OPTIONS to read FILENAME.  */
+ 
+ static void
+-users (const char *filename)
++users (const char *filename, int options)
+ {
+   int n_users;
+   STRUCT_UTMP *utmp_buf;
+-  int fail = read_utmp (filename, &n_users, &utmp_buf);
++  int fail = read_utmp (filename, &n_users, &utmp_buf, options);
+ 
+   if (fail)
+     error (EXIT_FAILURE, errno, "%s", filename);
+@@ -160,11 +161,11 @@
+   switch (argc - optind)
+     {
+     case 0:			/* users */
+-      users (UTMP_FILE);
++      users (UTMP_FILE, READ_UTMP_CHECK_PIDS);
+       break;
+ 
+     case 1:			/* users <utmp file> */
+-      users (argv[optind]);
++      users (argv[optind], 0);
+       break;
+ 
+     default:			/* lose */
+--- coreutils-5.2.1/src/who.c.stale-utmp	2004-01-21 22:27:02.000000000 +0000
++++ coreutils-5.2.1/src/who.c	2005-03-29 14:01:19.000000000 +0100
+@@ -78,12 +78,10 @@
+ #define IDLESTR_LEN 6
+ 
+ #if HAVE_STRUCT_XTMP_UT_PID
+-# define UT_PID(U) ((U)->ut_pid)
+ # define PIDSTR_DECL_AND_INIT(Var, Utmp_ent) \
+   char Var[INT_STRLEN_BOUND (Utmp_ent->ut_pid) + 1]; \
+   sprintf (Var, "%d", (int) (Utmp_ent->ut_pid))
+ #else
+-# define UT_PID(U) 0
+ # define PIDSTR_DECL_AND_INIT(Var, Utmp_ent) \
+   const char *Var = ""
+ #endif
+@@ -590,13 +588,14 @@
+     }
+ }
+ 
+-/* Display a list of who is on the system, according to utmp file filename. */
++/* Display a list of who is on the system, according to utmp file FILENAME.
++   Use read_utmp OPTIONS to read the file.  */
+ static void
+-who (const char *filename)
++who (const char *filename, int options)
+ {
+   int n_users;
+   STRUCT_UTMP *utmp_buf;
+-  int fail = read_utmp (filename, &n_users, &utmp_buf);
++  int fail = read_utmp (filename, &n_users, &utmp_buf, options);
+ 
+   if (fail)
+     error (EXIT_FAILURE, errno, "%s", filename);
+@@ -787,18 +786,16 @@
+ 
+   switch (argc - optind)
+     {
++    case 2:			/* who <blurf> <glop> */
++      my_line_only = 1;
++      /* Fall through.  */
+     case -1:
+     case 0:			/* who */
+-      who (UTMP_FILE);
++      who (UTMP_FILE, READ_UTMP_CHECK_PIDS);
+       break;
+ 
+     case 1:			/* who <utmp file> */
+-      who (argv[optind]);
+-      break;
+-
+-    case 2:			/* who <blurf> <glop> */
+-      my_line_only = 1;
+-      who (UTMP_FILE);
++      who (argv[optind], 0);
+       break;
+ 
+     default:			/* lose */


Index: coreutils.spec
===================================================================
RCS file: /cvs/dist/rpms/coreutils/devel/coreutils.spec,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -r1.58 -r1.59
--- coreutils.spec	24 Mar 2005 16:23:46 -0000	1.58
+++ coreutils.spec	29 Mar 2005 13:25:42 -0000	1.59
@@ -54,6 +54,7 @@
 Patch921: coreutils-chown.patch
 Patch922: coreutils-rmaccess.patch
 Patch923: coreutils-copy.patch
+Patch924: coreutils-stale-utmp.patch
 
 #SELINUX Patch
 Patch950: coreutils-selinux.patch
@@ -116,6 +117,7 @@
 %patch921 -p1 -b .chown
 %patch922 -p1 -b .rmaccess
 %patch923 -p1 -b .copy
+%patch924 -p1 -b .stale-utmp
 
 #SELinux
 %patch950 -p1 -b .selinux
@@ -253,6 +255,9 @@
 /sbin/runuser
 
 %changelog
+* Tue Mar 29 2005 Tim Waugh <twaugh at redhat.com>
+- Added "stale utmp" patch from upstream.
+
 * Thu Mar 24 2005 Tim Waugh <twaugh at redhat.com> 5.2.1-43
 - Removed patch that adds -C option to install(1).
 




More information about the fedora-cvs-commits mailing list