[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
coreutils fixes + cleanups for who, uptime, users, pinky
From: |
Paul Eggert |
Subject: |
coreutils fixes + cleanups for who, uptime, users, pinky |
Date: |
Mon, 02 Aug 2004 14:00:58 -0700 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) |
I installed the following cleanups to fix various bugs where "who" and
related programs messed up if the number of users exceeds INT_MAX or
if it causes size calculations to overflow (which can occur with a
fewer number of users; it depends on the platform), or if the clock
has gone bad and the number of idle days "exceeds" 10**8 or
INT_MAX/86400.
2004-08-02 Paul Eggert <address@hidden>
* lib/readutmp.h (UT_USER): Parenthesize properly.
(UT_USER_SIZE): New constant.
(read_utmp): Don't assume that the number of users is less than
INT_MAX.
* lib/readutmp.c (read_utmp): Likewise.
Check for integer overflow in size calculations.
Return -1 (not 1) on failure, since we set errno in that case.
* src/pinky.c (include_idle, include_heading, include_fullname,
include_project, include_plan, include_home_and_shell, do_short_format,
include_where, main): Use bool for booleans.
(count_ampersands, create_fullname, scan_entries, short_pinky):
Use size_t for sizes.
(create_fullname): Check for overflow in size calculations.
(idle_string): Don't assume that the number of idle days
is less than 10**8 and/or INT_MAX/(24*60*60).
(main): No need to pass a non-NULL last arg to getopt_long.
* src/uptime.c (print_uptime, uptime): Use size_t for sizes.
(print_uptime): Remove unused local variable.
(main): No need to pass a non-NULL last arg to getopt_long.
* src/users.c (list_entries_users, users): Use size_t for sizes.
(list_entries_users): Use char for bytes.
(main): No need to pass a non-NULL last arg to getopt_long.
* src/who.c (do_lookup, short_list, short_output, include_idle,
include_heading, include_mesg, include_exit, need_boottime,
need_deadprocs, need_login, need_initspawn, need_clockchange,
need_runlevel, need_users, my_line_only, main): Use bool for booleans.
(print_runlevel): Use unsigned char for bytes.
(list_entries_who, scan_entries, who): Use size_t for sizes.
(main): No need to pass a non-NULL last arg to getopt_long.
Index: lib/readutmp.h
===================================================================
RCS file: /home/eggert/coreutils/cu/lib/readutmp.h,v
retrieving revision 1.15
diff -p -u -r1.15 readutmp.h
--- lib/readutmp.h 18 Aug 2003 09:44:49 -0000 1.15
+++ lib/readutmp.h 18 Jul 2004 05:48:03 -0000
@@ -116,11 +116,11 @@
# else
# if HAVE_STRUCT_UTMP_UT_USER
-# define UT_USER(Utmp) Utmp->ut_user
+# define UT_USER(Utmp) ((Utmp)->ut_user)
# endif
# if HAVE_STRUCT_UTMP_UT_NAME
# undef UT_USER
-# define UT_USER(Utmp) Utmp->ut_name
+# define UT_USER(Utmp) ((Utmp)->ut_name)
# endif
# endif
@@ -143,6 +143,8 @@
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>
@@ -180,6 +182,6 @@ extern int errno;
# endif
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, size_t *n_entries, STRUCT_UTMP
**utmp_buf);
#endif /* __READUTMP_H__ */
Index: lib/readutmp.c
===================================================================
RCS file: /home/eggert/coreutils/cu/lib/readutmp.c,v
retrieving revision 1.20
diff -p -u -r1.20 readutmp.c
--- lib/readutmp.c 12 Jun 2004 08:07:30 -0000 1.20
+++ lib/readutmp.c 17 Jul 2004 03:44:36 -0000
@@ -54,16 +54,17 @@ extract_trimmed_name (const STRUCT_UTMP
/* 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. */
#ifdef UTMP_NAME_FUNCTION
int
-read_utmp (const char *filename, int *n_entries, STRUCT_UTMP **utmp_buf)
+read_utmp (const char *filename, size_t *n_entries, STRUCT_UTMP **utmp_buf)
{
- int n_read;
+ size_t n_read;
+ size_t n_alloc = 4;
+ STRUCT_UTMP *utmp = xmalloc (n_alloc * sizeof *utmp);
STRUCT_UTMP *u;
- STRUCT_UTMP *utmp = NULL;
/* Ignore the return value for now.
Solaris' utmpname returns 1 upon success -- which is contrary
@@ -76,16 +77,12 @@ read_utmp (const char *filename, int *n_
n_read = 0;
while ((u = GET_UTMP_ENT ()) != NULL)
{
- STRUCT_UTMP *p;
- ++n_read;
- p = (STRUCT_UTMP *) realloc (utmp, n_read * sizeof (STRUCT_UTMP));
- if (p == NULL)
+ if (n_read == n_alloc)
{
- free (utmp);
- END_UTMP_ENT ();
- return 1;
+ utmp = xnrealloc (utmp, n_alloc, 2 * sizeof *utmp);
+ n_alloc *= 2;
}
- utmp = p;
+ ++n_read;
utmp[n_read - 1] = *u;
}
@@ -100,7 +97,7 @@ read_utmp (const char *filename, int *n_
#else
int
-read_utmp (const char *filename, int *n_entries, STRUCT_UTMP **utmp_buf)
+read_utmp (const char *filename, size_t *n_entries, STRUCT_UTMP **utmp_buf)
{
FILE *utmp;
struct stat file_stats;
@@ -110,14 +107,14 @@ read_utmp (const char *filename, int *n_
utmp = fopen (filename, "r");
if (utmp == NULL)
- return 1;
+ return -1;
if (fstat (fileno (utmp), &file_stats) != 0)
{
int e = errno;
fclose (utmp);
errno = e;
- return 1;
+ return -1;
}
size = file_stats.st_size;
buf = xmalloc (size);
@@ -128,14 +125,14 @@ read_utmp (const char *filename, int *n_
free (buf);
fclose (utmp);
errno = e;
- return 1;
+ return -1;
}
if (fclose (utmp) != 0)
{
int e = errno;
free (buf);
errno = e;
- return 1;
+ return -1;
}
*n_entries = n_read;
Index: src/pinky.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/pinky.c,v
retrieving revision 1.40
diff -p -u -r1.40 pinky.c
--- src/pinky.c 22 Jun 2004 15:00:53 -0000 1.40
+++ src/pinky.c 20 Jul 2004 05:36:32 -0000
@@ -49,33 +49,33 @@ char *ttyname ();
/* The name this program was run with. */
const char *program_name;
-/* If nonzero, display the hours:minutes since each user has touched
+/* If true, display the hours:minutes since each user has touched
the keyboard, or blank if within the last minute, or days followed
by a 'd' if not within the last day. */
-static int include_idle = 1;
+static bool include_idle = true;
-/* If nonzero, display a line at the top describing each field. */
-static int include_heading = 1;
+/* If true, display a line at the top describing each field. */
+static bool include_heading = true;
-/* if nonzero, display the user's full name from pw_gecos. */
-static int include_fullname = 1;
+/* if true, display the user's full name from pw_gecos. */
+static bool include_fullname = true;
-/* if nonzero, display the user's ~/.project file when doing long format. */
-static int include_project = 1;
+/* if true, display the user's ~/.project file when doing long format. */
+static bool include_project = true;
-/* if nonzero, display the user's ~/.plan file when doing long format. */
-static int include_plan = 1;
+/* if true, display the user's ~/.plan file when doing long format. */
+static bool include_plan = true;
-/* if nonzero, display the user's home directory and shell
+/* if true, display the user's home directory and shell
when doing long format. */
-static int include_home_and_shell = 1;
+static bool include_home_and_shell = true;
-/* if nonzero, use the "short" output format. */
-static int do_short_format = 1;
+/* if true, use the "short" output format. */
+static bool do_short_format = true;
-/* if nonzero, display the ut_host field. */
+/* if true, display the ut_host field. */
#ifdef HAVE_UT_HOST
-static int include_where = 1;
+static bool include_where = true;
#endif
/* The strftime format to use for login times, and its expected
@@ -92,10 +92,10 @@ static struct option const longopts[] =
/* Count and return the number of ampersands in STR. */
-static int
+static size_t
count_ampersands (const char *str)
{
- int count = 0;
+ size_t count = 0;
do
{
if (*str == '&')
@@ -113,10 +113,21 @@ count_ampersands (const char *str)
static char *
create_fullname (const char *gecos_name, const char *user_name)
{
- const int result_len = strlen (gecos_name)
- + count_ampersands (gecos_name) * (strlen (user_name) - 1) + 1;
- char *const result = xmalloc (result_len);
- char *r = result;
+ size_t rsize = strlen (gecos_name) + 1;
+ char *result;
+ char *r;
+ size_t ampersands = count_ampersands (gecos_name);
+
+ if (ampersands != 0)
+ {
+ size_t ulen = strlen (user_name);
+ size_t product = ampersands * ulen;
+ rsize += product - ampersands;
+ if (xalloc_oversized (ulen, ampersands) || rsize < product)
+ xalloc_die ();
+ }
+
+ r = result = xmalloc (rsize);
while (*gecos_name)
{
@@ -147,7 +158,7 @@ static const char *
idle_string (time_t when)
{
static time_t now = 0;
- static char idle_hhmm[10];
+ static char buf[INT_STRLEN_BOUND (long int) + 2];
time_t seconds_idle;
if (now == 0)
@@ -158,13 +169,16 @@ idle_string (time_t when)
return " ";
if (seconds_idle < (24 * 60 * 60)) /* One day. */
{
- sprintf (idle_hhmm, "%02d:%02d",
- (int) (seconds_idle / (60 * 60)),
- (int) ((seconds_idle % (60 * 60)) / 60));
- return (const char *) idle_hhmm;
+ int hours = seconds_idle / (60 * 60);
+ int minutes = (seconds_idle % (60 * 60)) / 60;
+ sprintf (buf, "%02d:%02d", hours, minutes);
}
- sprintf (idle_hhmm, "%dd", (int) (seconds_idle / (24 * 60 * 60)));
- return (const char *) idle_hhmm;
+ else
+ {
+ unsigned long int days = seconds_idle / (24 * 60 * 60);
+ sprintf (buf, "%lud", days);
+ }
+ return buf;
}
/* Return a time string. */
@@ -231,15 +245,15 @@ print_entry (const STRUCT_UTMP *utmp_ent
last_change = 0;
}
- printf ("%-8.*s", (int) sizeof (UT_USER (utmp_ent)), UT_USER (utmp_ent));
+ printf ("%-8.*s", UT_USER_SIZE, UT_USER (utmp_ent));
if (include_fullname)
{
struct passwd *pw;
- char name[sizeof (UT_USER (utmp_ent)) + 1];
+ char name[UT_USER_SIZE + 1];
- strncpy (name, UT_USER (utmp_ent), sizeof (UT_USER (utmp_ent)));
- name[sizeof (UT_USER (utmp_ent))] = '\0';
+ strncpy (name, UT_USER (utmp_ent), UT_USER_SIZE);
+ name[UT_USER_SIZE] = '\0';
pw = getpwnam (name);
if (pw == NULL)
printf (" %19s", " ???");
@@ -422,7 +436,7 @@ print_heading (void)
/* Display UTMP_BUF, which should have N entries. */
static void
-scan_entries (int n, const STRUCT_UTMP *utmp_buf,
+scan_entries (size_t n, const STRUCT_UTMP *utmp_buf,
const int argc_names, char *const argv_names[])
{
if (hard_locale (LC_TIME))
@@ -452,8 +466,8 @@ scan_entries (int n, const STRUCT_UTMP *
int i;
for (i = 0; i < argc_names; i++)
- if (strncmp (UT_USER (utmp_buf), argv_names[i],
- sizeof (UT_USER (utmp_buf))) == 0)
+ if (strncmp (UT_USER (utmp_buf), argv_names[i], UT_USER_SIZE)
+ == 0)
{
print_entry (utmp_buf);
break;
@@ -472,11 +486,10 @@ static void
short_pinky (const char *filename,
const int argc_names, char *const argv_names[])
{
- int n_users;
+ size_t n_users;
STRUCT_UTMP *utmp_buf;
- int fail = read_utmp (filename, &n_users, &utmp_buf);
- if (fail)
+ if (read_utmp (filename, &n_users, &utmp_buf) != 0)
error (EXIT_FAILURE, errno, "%s", filename);
scan_entries (n_users, utmp_buf, argc_names, argv_names);
@@ -530,7 +543,7 @@ The utmp file will be %s.\n\
int
main (int argc, char **argv)
{
- int optc, longind;
+ int optc;
int n_users;
initialize_main (&argc, &argv);
@@ -541,8 +554,7 @@ main (int argc, char **argv)
atexit (close_stdout);
- while ((optc = getopt_long (argc, argv, "sfwiqbhlp", longopts, &longind))
- != -1)
+ while ((optc = getopt_long (argc, argv, "sfwiqbhlp", longopts, NULL)) != -1)
{
switch (optc)
{
@@ -550,46 +562,46 @@ main (int argc, char **argv)
break;
case 's':
- do_short_format = 1;
+ do_short_format = true;
break;
case 'l':
- do_short_format = 0;
+ do_short_format = false;
break;
case 'f':
- include_heading = 0;
+ include_heading = false;
break;
case 'w':
- include_fullname = 0;
+ include_fullname = false;
break;
case 'i':
- include_fullname = 0;
+ include_fullname = false;
#ifdef HAVE_UT_HOST
- include_where = 0;
+ include_where = false;
#endif
break;
case 'q':
- include_fullname = 0;
+ include_fullname = false;
#ifdef HAVE_UT_HOST
- include_where = 0;
+ include_where = false;
#endif
- include_idle = 0;
+ include_idle = false;
break;
case 'h':
- include_project = 0;
+ include_project = false;
break;
case 'p':
- include_plan = 0;
+ include_plan = false;
break;
case 'b':
- include_home_and_shell = 0;
+ include_home_and_shell = false;
break;
case_GETOPT_HELP_CHAR;
@@ -603,7 +615,7 @@ main (int argc, char **argv)
n_users = argc - optind;
- if (do_short_format == 0 && n_users == 0)
+ if (!do_short_format && n_users == 0)
{
error (0, 0, _("no username specified; at least one must be\
specified when using -l"));
Index: src/uptime.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/uptime.c,v
retrieving revision 1.43
diff -p -u -r1.43 uptime.c
--- src/uptime.c 24 Jul 2004 08:03:02 -0000 1.43
+++ src/uptime.c 24 Jul 2004 18:44:44 -0000
@@ -50,9 +50,9 @@ static struct option const longopts[] =
};
static void
-print_uptime (int n, const STRUCT_UTMP *this)
+print_uptime (size_t n, const STRUCT_UTMP *this)
{
- register int entries = 0;
+ size_t entries = 0;
time_t boot_time = 0;
time_t time_now;
time_t uptime = 0;
@@ -70,7 +70,6 @@ print_uptime (int n, const STRUCT_UTMP *
if (fp != NULL)
{
char buf[BUFSIZ];
- int res;
char *b = fgets (buf, BUFSIZ, fp);
if (b == buf)
{
@@ -149,7 +148,8 @@ print_uptime (int n, const STRUCT_UTMP *
printf (ngettext ("%ld day", "%ld days", updays), updays);
printf (" %2d:%02d, ", uphours, upmins);
}
- printf (ngettext ("%d user", "%d users", entries), entries);
+ printf (ngettext ("%lu user", "%lu users", entries),
+ (unsigned long int) entries);
#if defined (HAVE_GETLOADAVG) || defined (C_GETLOADAVG)
loads = getloadavg (avg, 3);
@@ -178,11 +178,10 @@ print_uptime (int n, const STRUCT_UTMP *
static void
uptime (const char *filename)
{
- int n_users;
+ size_t n_users;
STRUCT_UTMP *utmp_buf;
- int fail = read_utmp (filename, &n_users, &utmp_buf);
- if (fail)
+ if (read_utmp (filename, &n_users, &utmp_buf) != 0)
error (EXIT_FAILURE, errno, "%s", filename);
print_uptime (n_users, utmp_buf);
@@ -215,7 +214,7 @@ If FILE is not specified, use %s. %s as
int
main (int argc, char **argv)
{
- int optc, longind;
+ int optc;
initialize_main (&argc, &argv);
program_name = argv[0];
setlocale (LC_ALL, "");
@@ -227,7 +226,7 @@ main (int argc, char **argv)
parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION,
usage, AUTHORS, (char const *) NULL);
- while ((optc = getopt_long (argc, argv, "", longopts, &longind)) != -1)
+ while ((optc = getopt_long (argc, argv, "", longopts, NULL)) != -1)
{
switch (optc)
{
Index: src/users.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/users.c,v
retrieving revision 1.35
diff -p -u -r1.35 users.c
--- src/users.c 21 Jun 2004 15:03:35 -0000 1.35
+++ src/users.c 19 Jul 2004 23:52:54 -0000
@@ -51,15 +51,13 @@ userid_compare (const void *v_a, const v
}
static void
-list_entries_users (int n, const STRUCT_UTMP *this)
+list_entries_users (size_t n, const STRUCT_UTMP *this)
{
- char **u;
- int i;
- int n_entries;
-
- n_entries = 0;
- u = xnmalloc (n, sizeof *u);
- for (i = 0; i < n; i++)
+ char **u = xnmalloc (n, sizeof *u);
+ size_t i;
+ size_t n_entries = 0;
+
+ while (n--)
{
if (UT_USER (this) [0]
#ifdef USER_PROCESS
@@ -81,9 +79,8 @@ list_entries_users (int n, const STRUCT_
for (i = 0; i < n_entries; i++)
{
- int c;
+ char c = (i < n_entries - 1 ? ' ' : '\n');
fputs (u[i], stdout);
- c = (i < n_entries - 1 ? ' ' : '\n');
putchar (c);
}
@@ -97,11 +94,10 @@ list_entries_users (int n, const STRUCT_
static void
users (const char *filename)
{
- int n_users;
+ size_t n_users;
STRUCT_UTMP *utmp_buf;
- int fail = read_utmp (filename, &n_users, &utmp_buf);
- if (fail)
+ if (read_utmp (filename, &n_users, &utmp_buf) != 0)
error (EXIT_FAILURE, errno, "%s", filename);
list_entries_users (n_users, utmp_buf);
@@ -134,7 +130,7 @@ If FILE is not specified, use %s. %s as
int
main (int argc, char **argv)
{
- int optc, longind;
+ int optc;
initialize_main (&argc, &argv);
program_name = argv[0];
setlocale (LC_ALL, "");
@@ -146,7 +142,7 @@ main (int argc, char **argv)
parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION,
usage, AUTHORS, (char const *) NULL);
- while ((optc = getopt_long (argc, argv, "", longopts, &longind)) != -1)
+ while ((optc = getopt_long (argc, argv, "", longopts, NULL)) != -1)
{
switch (optc)
{
Index: src/who.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/who.c,v
retrieving revision 1.100
diff -p -u -r1.100 who.c
--- src/who.c 24 Jul 2004 08:01:49 -0000 1.100
+++ src/who.c 25 Jul 2004 04:53:16 -0000
@@ -119,55 +119,55 @@ char *canon_host ();
/* The name this program was run with. */
char *program_name;
-/* If nonzero, attempt to canonicalize hostnames via a DNS lookup. */
-static int do_lookup;
+/* If true, attempt to canonicalize hostnames via a DNS lookup. */
+static bool do_lookup;
-/* If nonzero, display only a list of usernames and count of
+/* If true, display only a list of usernames and count of
the users logged on.
- Ignored for `who am i'. */
-static int short_list;
+ Ignored for `who am i'. */
+static bool short_list;
-/* If nonzero, display only name, line, and time fields */
-static int short_output;
+/* If true, display only name, line, and time fields. */
+static bool short_output;
-/* If nonzero, display the hours:minutes since each user has touched
+/* If true, display the hours:minutes since each user has touched
the keyboard, or "." if within the last minute, or "old" if
- not within the last day. */
-static int include_idle;
+ not within the last day. */
+static bool include_idle;
-/* If nonzero, display a line at the top describing each field. */
-static int include_heading;
+/* If true, display a line at the top describing each field. */
+static bool include_heading;
-/* If nonzero, display a `+' for each user if mesg y, a `-' if mesg n,
+/* If true, display a `+' for each user if mesg y, a `-' if mesg n,
or a `?' if their tty cannot be statted. */
-static int include_mesg;
+static bool include_mesg;
-/* If nonzero, display process termination & exit status */
-static int include_exit;
+/* If true, display process termination & exit status. */
+static bool include_exit;
-/* If nonzero, display the last boot time */
-static int need_boottime;
+/* If true, display the last boot time. */
+static bool need_boottime;
-/* If nonzero, display dead processes */
-static int need_deadprocs;
+/* If true, display dead processes. */
+static bool need_deadprocs;
-/* If nonzero, display processes waiting for user login */
-static int need_login;
+/* If true, display processes waiting for user login. */
+static bool need_login;
-/* If nonzero, display processes started by init */
-static int need_initspawn;
+/* If true, display processes started by init. */
+static bool need_initspawn;
-/* If nonzero, display the last clock change */
-static int need_clockchange;
+/* If true, display the last clock change. */
+static bool need_clockchange;
-/* If nonzero, display the current runlevel */
-static int need_runlevel;
+/* If true, display the current runlevel. */
+static bool need_runlevel;
-/* If nonzero, display user processes */
-static int need_users;
+/* If true, display user processes. */
+static bool need_users;
-/* If nonzero, display info only for the controlling tty */
-static int my_line_only;
+/* If true, display info only for the controlling tty. */
+static bool my_line_only;
/* The strftime format to use for login times, and its expected
output width. */
@@ -515,8 +515,8 @@ static void
print_runlevel (const STRUCT_UTMP *utmp_ent)
{
static char *runlevline, *comment;
- int last = UT_PID (utmp_ent) / 256;
- int curr = UT_PID (utmp_ent) % 256;
+ unsigned char last = UT_PID (utmp_ent) / 256;
+ unsigned char curr = UT_PID (utmp_ent) % 256;
if (!runlevline)
runlevline = xmalloc (strlen (_("run-level")) + 3);
@@ -535,9 +535,9 @@ print_runlevel (const STRUCT_UTMP *utmp_
/* Print the username of each valid entry and the number of valid entries
in UTMP_BUF, which should have N elements. */
static void
-list_entries_who (int n, const STRUCT_UTMP *utmp_buf)
+list_entries_who (size_t n, const STRUCT_UTMP *utmp_buf)
{
- int entries = 0;
+ unsigned long int entries = 0;
char const *separator = "";
while (n--)
@@ -555,7 +555,7 @@ list_entries_who (int n, const STRUCT_UT
}
utmp_buf++;
}
- printf (_("\n# users=%u\n"), entries);
+ printf (_("\n# users=%lu\n"), entries);
}
static void
@@ -567,7 +567,7 @@ print_heading (void)
/* Display UTMP_BUF, which should have N entries. */
static void
-scan_entries (int n, const STRUCT_UTMP *utmp_buf)
+scan_entries (size_t n, const STRUCT_UTMP *utmp_buf)
{
char *ttyname_b IF_LINT ( = NULL);
time_t boottime = TYPE_MINIMUM (time_t);
@@ -620,11 +620,10 @@ scan_entries (int n, const STRUCT_UTMP *
static void
who (const char *filename)
{
- int n_users;
+ size_t n_users;
STRUCT_UTMP *utmp_buf;
- int fail = read_utmp (filename, &n_users, &utmp_buf);
- if (fail)
+ if (read_utmp (filename, &n_users, &utmp_buf) != 0)
error (EXIT_FAILURE, errno, "%s", filename);
if (short_list)
@@ -688,8 +687,8 @@ If ARG1 ARG2 given, -m presumed: `am i'
int
main (int argc, char **argv)
{
- int optc, longind;
- int assumptions = 1;
+ int optc;
+ bool assumptions = true;
initialize_main (&argc, &argv);
program_name = argv[0];
@@ -699,8 +698,8 @@ main (int argc, char **argv)
atexit (close_stdout);
- while ((optc = getopt_long (argc, argv, "abdilmpqrstuwHT", longopts,
- &longind)) != -1)
+ while ((optc = getopt_long (argc, argv, "abdilmpqrstuwHT", longopts, NULL))
+ != -1)
{
switch (optc)
{
@@ -708,72 +707,72 @@ main (int argc, char **argv)
break;
case 'a':
- need_boottime = 1;
- need_deadprocs = 1;
- need_login = 1;
- need_initspawn = 1;
- need_runlevel = 1;
- need_clockchange = 1;
- need_users = 1;
- include_mesg = 1;
- include_idle = 1;
- include_exit = 1;
- assumptions = 0;
+ need_boottime = true;
+ need_deadprocs = true;
+ need_login = true;
+ need_initspawn = true;
+ need_runlevel = true;
+ need_clockchange = true;
+ need_users = true;
+ include_mesg = true;
+ include_idle = true;
+ include_exit = true;
+ assumptions = false;
break;
case 'b':
- need_boottime = 1;
- assumptions = 0;
+ need_boottime = true;
+ assumptions = false;
break;
case 'd':
- need_deadprocs = 1;
- include_idle = 1;
- include_exit = 1;
- assumptions = 0;
+ need_deadprocs = true;
+ include_idle = true;
+ include_exit = true;
+ assumptions = false;
break;
case 'H':
- include_heading = 1;
+ include_heading = true;
break;
case 'l':
- need_login = 1;
- include_idle = 1;
- assumptions = 0;
+ need_login = true;
+ include_idle = true;
+ assumptions = false;
break;
case 'm':
- my_line_only = 1;
+ my_line_only = true;
break;
case 'p':
- need_initspawn = 1;
- assumptions = 0;
+ need_initspawn = true;
+ assumptions = false;
break;
case 'q':
- short_list = 1;
+ short_list = true;
break;
case 'r':
- need_runlevel = 1;
- include_idle = 1;
- assumptions = 0;
+ need_runlevel = true;
+ include_idle = true;
+ assumptions = false;
break;
case 's':
- short_output = 1;
+ short_output = true;
break;
case 't':
- need_clockchange = 1;
- assumptions = 0;
+ need_clockchange = true;
+ assumptions = false;
break;
case 'T':
case 'w':
- include_mesg = 1;
+ include_mesg = true;
break;
case 'i':
@@ -782,13 +781,13 @@ main (int argc, char **argv)
use -u instead"));
/* Fall through. */
case 'u':
- need_users = 1;
- include_idle = 1;
- assumptions = 0;
+ need_users = true;
+ include_idle = true;
+ assumptions = false;
break;
case LOOKUP_OPTION:
- do_lookup = 1;
+ do_lookup = true;
break;
case_GETOPT_HELP_CHAR;
@@ -802,13 +801,13 @@ main (int argc, char **argv)
if (assumptions)
{
- need_users = 1;
- short_output = 1;
+ need_users = true;
+ short_output = true;
}
if (include_exit)
{
- short_output = 0;
+ short_output = false;
}
if (hard_locale (LC_TIME))
@@ -834,7 +833,7 @@ main (int argc, char **argv)
break;
case 2: /* who <blurf> <glop> */
- my_line_only = 1;
+ my_line_only = true;
who (UTMP_FILE);
break;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- coreutils fixes + cleanups for who, uptime, users, pinky,
Paul Eggert <=