]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(UT_TYPE_UNDEF, UT_TYPE, IS_USER_PROCESS): Define.
authorJim Meyering <jim@meyering.net>
Tue, 16 Apr 2002 10:39:29 +0000 (10:39 +0000)
committerJim Meyering <jim@meyering.net>
Tue, 16 Apr 2002 10:39:29 +0000 (10:39 +0000)
(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

index 24361c26bcb00f975e54001b81519c78373d4504..0125a260561c7eecb93095aed436af2e6cddce52 100644 (file)
--- a/src/who.c
+++ b/src/who.c
 # 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);