Re: bloated wtmp
Paul Slootman <paul@wau.mis.ah.nl> writes:
> OffTopic: In cases like this I sorely miss the SysV "who -a" option,
> that shows each entry, not just the logins. As there isn't any other
> method of displaying the utmp/wtmp files short of "od", such an option
> would be great.
Here's some crusty code that I needed to write a while back. It'll
read utmp with no arguments and wtmp with an argument of `w'.
#include <sys/types.h>
#include <fcntl.h>
#include <utmp.h>
#include <time.h>
#include <paths.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
char* uts (int size, char *src) {
static char string[1024];
strncpy (string, src, size);
string[size]=0;
return string;
}
int main(int ac, char **av) {
struct utmp *ut, ut2;
struct tm *tm;
char *type[] = {"UT_UNKNOWN ",
"RUN_LVL ",
"BOOT_TIME ",
"NEW_TIME ",
"OLD_TIME ",
"INIT_PROCESS ",
"LOGIN_PROCESS",
"USER_PROCESS ",
"DEAD_PROCESS "};
int w=0;
if (av[1] && *av[1]=='w') {
if ((w = open(_PATH_WTMP, O_RDONLY)) < 0)
exit(1);
ut=&ut2;
}
else
setutent();
printf ("type\t\tpid\tline\tid\ttime\t\tuser\t\thost\taddr\n");
while (w ? (read(w, ut, sizeof(struct utmp))) : (ut=getutent())) {
printf ("%s\t%d\t%s",
type[ut->ut_type],
ut->ut_pid,
uts(UT_LINESIZE,ut->ut_line));
printf ("\t%s",
uts(4, ut->ut_id) /* header says 4; man page says 2 */
);
tm = localtime(&ut->ut_time);
printf ("\t%02d/%02d %02d:%02d\t%-13s",
tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min,
uts(UT_NAMESIZE, ut->ut_user));
printf ("\t%s\n",
uts(UT_HOSTSIZE, ut->ut_host));
}
exit(0);
}
--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-devel-request@lists.debian.org .
Trouble? e-mail to templin@bucknell.edu .
Reply to: