From 6f0db0ac6e69e9d245e126b1ea0d2ced5fb50052 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Tue, 16 Apr 2002 10:39:29 +0000 Subject: (UT_TYPE_UNDEF, UT_TYPE, IS_USER_PROCESS): Define. (print_line): Use "%-8.8s" for the format: the user name is not always NUL terminated. (scan_entries) [need_users]: Use IS_USER_PROCESS, so that this works even on systems without ut_type. --- src/who.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/who.c b/src/who.c index 24361c26b..0125a2605 100644 --- a/src/who.c +++ b/src/who.c @@ -106,6 +106,20 @@ # define UT_EXIT_E_EXIT(U) 0 #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 (); @@ -244,7 +258,7 @@ print_line (const char *user, const char state, const char *line, const char *time_str, const char *idle, const char *pid, const char *comment, const char *exitstr) { - printf ("%-8s", user ? user : " ."); + printf ("%-8.8s", user ? user : " ."); if (include_mesg) printf (" %c", state); printf (" %-12s", line); @@ -517,8 +531,7 @@ scan_entries (int n, const STRUCT_UTMP *utmp_buf) strncmp (ttyname_b, utmp_buf->ut_line, sizeof (utmp_buf->ut_line)) == 0) { - if (need_users && UT_USER (utmp_buf)[0] - && UT_TYPE (utmp_buf) == USER_PROCESS) + if (need_users && IS_USER_PROCESS (utmp_buf)) print_user (utmp_buf); else if (need_runlevel && UT_TYPE (utmp_buf) == RUN_LVL) print_runlevel (utmp_buf); -- cgit v1.2.3-70-g09d2