/*
* Extended `who' command, version 1.9.
*
- * (c) 1996--1999 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
+ * (c) 1996--2001 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
*
* This software may be freely distributed and used according to the terms
* of the GNU General Public License. See file COPYING in any of the GNU packages.
struct utrec {
struct utrec *next;
pid_t login_pid;
- char line_id[4];
+ char line[UT_LINESIZE];
time_t login_time, click_time, total_time;
char user_name[UT_NAMESIZE+1];
int usr;
char host_name[MAXHOSTSIZE+1];
- char line_name[12];
int mesg, detach;
struct procrec *proc;
};
{
static struct utmp *ut;
static struct passwd *pw;
+ char *z;
utmpname(UTMP_FILE);
while (ut = getutent())
if (ut->ut_type == USER_PROCESS && ut->ut_user[0])
u->next = first_utrec;
first_utrec = u;
u->login_pid = ut->ut_pid;
- u->line_id[0] = ut->ut_id[0];
- u->line_id[1] = ut->ut_id[1];
- u->line_id[2] = 0;
+ z = ut->ut_line;
+ if (!strncmp(z, "tty", 3))
+ {
+ if (z[3] >= '0' && z[3] <= '9')
+ sprintf(u->line, "c%s", z+3);
+ else
+ strcpy(u->line, z+3);
+ }
+ else if (!strncmp(z, "pts/", 4))
+ strcpy(u->line, z+4);
u->login_time = ut->ut_time;
strcpy_padded(u->user_name, ut->ut_user, UT_NAMESIZE);
pw = getpwnam(u->user_name);
(MAXHOSTSIZE > UT_HOSTSIZE ? UT_HOSTSIZE : MAXHOSTSIZE));
if ((hlen = strlen(u->host_name)) > maxhost)
maxhost = hlen;
- strcpy(u->line_name, ut->ut_line);
- if (*u->line_name)
+ strcpy(u->line, ut->ut_line);
+ if (*u->line)
{
- char *z = u->line_name;
- if (!strncmp(u->line_name, "tty", 3))
- z += 3;
- if (!strncmp(z, "pts/", 4))
- z += 3;
- strncpy(u->line_id, z, 3);
- u->line_id[3] = 0;
- if (u->line_id[0] == '/')
- u->line_id[0] = 'P';
+ char *z = u->line;
+ if (!strncmp(z, "tty", 3))
+ {
+ if (isdigit(z[0]))
+ sprintf(u->line, "c%s", z+3);
+ else
+ strcpy(u->line, z+3);
+ }
+ else if (!strncmp(z, "pts/", 4))
+ strcpy(u->line, z+4);
+ else
+ strcpy(u->line, z);
}
strcpy(device, "/dev/");
- strcat(device, u->line_name);
+ strcat(device, ut->ut_line);
if (stat(device, &st))
u->mesg = 2;
else
dispsys(void)
{
FILE *f;
- char line[256], a[32], b[32], c[32];
+ char line[256];
char *z, *w;
w = NULL;
if (f = fopen("/proc/version", "r"))
}
if (f = fopen("/proc/cpuinfo", "r"))
{
+ char a[32], b[32], c[32];
strcpy(a, "???");
b[0] = 0;
c[0] = 0;
int p,q,p1,q1;
fgets(line, 256, f);
sscanf(line, "%d.%d%d.%d", &p, &p1, &q, &q1);
- printf(", up ");
+ printf(" up ");
puttime(p);
- printf(", run ");
+ printf(" run ");
puttime(p-q);
fclose(f);
}
{
struct tm *tm;
+ char *days[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
now = time(NULL);
tm = localtime(&now);
- printf(" at %02d-%02d-%02d/%d %02d.%02d:%02d\n", tm->tm_mday, tm->tm_mon+1,
- tm->tm_year, (tm->tm_wday+6)%7, tm->tm_hour, tm->tm_min, tm->tm_sec);
+ printf(" on %s %02d-%02d-%02d %02d.%02d:%02d", days[tm->tm_wday], tm->tm_mday, tm->tm_mon+1,
+ tm->tm_year%100, tm->tm_hour, tm->tm_min, tm->tm_sec);
+ printf(" (%u UE)\n", (unsigned int) now);
}
if (f = fopen("/proc/loadavg", "r"))
{
u->next = first_utrec;
first_utrec = u;
u->login_pid = 0;
- u->line_id[0] = 0;
+ u->line[0] = 0;
pw = getpwuid(u->usr = m->usr);
if (pw)
strcpy(u->user_name, pw->pw_name);
else
sprintf(u->user_name, "<%d>", m->usr);
u->host_name[0] = 0;
- u->line_name[0] = 0;
u->mesg = 3;
u->detach = 0;
u->proc = NULL;
return k;
if (!a->host_name[0] && b->host_name[0])
return -1;
- return strcmp(a->line_id, b->line_id);
+ return strcmp(a->line, b->line);
}
static void
printf("Name Li MD %-*s LogT IdleT RunT Command\n", maxhost, "From");
for(u=first_utrec; u; u=u->next)
{
- if (isdigit(u->line_id[0]))
- sprintf(u->line_id, "c%d", atoi(u->line_id));
- if (!u->line_id[0])
- strcpy(u->line_id, "--");
+ if (!u->line[0])
+ strcpy(u->line, "--");
printf("%-8.8s %-3s %c%c %-*.*s ",
u->user_name,
- u->line_id,
+ u->line,
u->mesg ? ' ' : '-',
u->detach ? 'D' : ' ',
maxhost,