summaryrefslogtreecommitdiff
path: root/src/who.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2002-04-16 10:39:29 +0000
committerJim Meyering <jim@meyering.net>2002-04-16 10:39:29 +0000
commit6f0db0ac6e69e9d245e126b1ea0d2ced5fb50052 (patch)
treeb46f92e88cdc57b1270c896d85c747ebaf0efe15 /src/who.c
parentaef17cff0fc3e81b86ecb0f23e3796a22928efab (diff)
downloadcoreutils-6f0db0ac6e69e9d245e126b1ea0d2ced5fb50052.tar.xz
(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.
Diffstat (limited to 'src/who.c')
-rw-r--r--src/who.c19
1 files 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);