who.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1992-2012 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* who.c
* Written by David Korn
* Thu Aug 15 00:12:29 EDT 1996
*/
static const char usage[] =
"[-?\n@(#)$Id: who (AT&T Research) 2004-03-25 $\n]"
"[+NAME?who - display who is on the system]"
"[+DESCRIPTION?\bwho\b displays various pieces of information about "
"logged in users to standard output.]"
"[+?\bwho\b lists the user's name, terminal line, login time, and remote "
"host name, if applicable, for each logged "
"in user it reports.]"
"[+?The second form, \bwho am I\b is equivalent to \bwho -m\b.]"
"[i:idle?Also writes the idle time for each displayed user. The idle time "
"is the time since last activity on that line.]"
"[m?Write only information about the current terminal.]"
"[q:count?Writes only the login names and the number of users logged on. "
"This options overrides other options.]"
"[s?This option is ignored.]"
"[u:?Equivalent to \b-i\b.]"
"[w:writable?Equivalent to \b-T\b.]"
"[H:heading?Put a heading line in before of the output.]"
"[T:mesg?Specifies the state of the terminal as one of the following:]{"
"[++?The terminal allows write access to other users.]"
"[+-?The terminal denies write access to other users.]"
"[+???The write access cannot be determined.]"
"}"
"\n"
"\n[am I]\n"
"\n"
"[+EXIT STATUS]{"
"[+0?Successful completion.]"
"[+>0?One or more errors occurred.]"
"}"
"[+SEE ALSO?\bdate\b(1), \blogin\b(1)]"
;
#include <cmd.h>
#include <ls.h>
#include <time.h>
#if _hdr_utmp
# include <utmp.h>
#endif
#endif
#if _hdr_utmpx
# include <utmpx.h>
# if _mem_ut_tv_utmpx
# endif
# if ! _mem_ut_user_utmpx
# endif
# ifdef UTMPX_FILE
# define UTMP UTMPX_FILE
# else
# if _hdr_paths
# include <paths.h>
# endif
# ifdef _PATH_UTMPX
# define UTMP _PATH_UTMPX
# else
# ifdef UTMP_FILE
# else
# ifdef _PATH_UTMP
# define UTMP _PATH_UTMP
# else
# endif
# endif
# endif
# endif
#else
# if _mem_ut_tv_utmp
# endif
# if ! _mem_ut_user_utmp
# endif
# ifdef UTMP_FILE
# else
# if _hdr_paths
# include <paths.h>
# endif
# ifdef _PATH_UTMP
# define UTMP _PATH_UTMP
# else
# endif
# endif
#endif
#ifdef nonuser
#else
# if _mem_ut_type_utmp || _mem_ut_type_utmpx
# ifdef USER_PROCESS
# else
# ifndef DEAD_PROCESS
# define DEAD_PROCESS 8
# endif
# endif
# else
# endif
#endif
typedef struct
{
int flags;
int siz_user;
int siz_line;
int siz_host;
} State_t;
#define FLAG_M 1
#define FLAG_T 2
#define FLAG_U 4
#define FLAG_H 8
#define FLAG_Q 0x10
{
int r = 0;
{
}
{
int state = '?';
if(r>=0)
sfprintf(out,"%-*.*s %c %-*.*s %.12s ",sp->siz_user,sp->siz_user,up->ut_user,state,sp->siz_line,sp->siz_line,up->ut_line,date+4);
}
else
sfprintf(out,"%-*.*s %-*.*s %.12s ",sp->siz_user,sp->siz_user,up->ut_user,sp->siz_line,sp->siz_line,up->ut_line,date+4);
{
{
if(t>24*60)
else
}
else
}
else
#endif
}
{
char *line = 0;
int count = 0;
#endif
line += 5;
{
char *t = "";
t = "MESG";
sfprintf(out,"%-*.*s %2s %-*.*s %.12s %6s %s\n",state.siz_user-3,state.siz_user-3,"USER",t,state.siz_line,state.siz_line,"LINE","LOGIN-TIME","IDLE","FROM");
else
sfprintf(out,"%-*.*s %2s %-*.*s %.12s %s\n",state.siz_user-3,state.siz_user-3,"USER",t,state.siz_line,state.siz_line,"LINE","LOGIN-TIME","FROM");
}
{
continue;
continue;
{
if(count)
}
else
count++;
}
return(0);
}
{
register int n, flags=0;
{
case 'm':
break;
case 'H':
break;
case 'T': case 'w':
break;
case 'q':
break;
case 's':
break;
case 'i':
case 'u':
break;
case ':':
break;
case '?':
break;
}
if(argc==2)
{
argc = 0;
}
return(error_info.errors);
}