#include #include #include #include #include int main (int argc, char **argv) { int i; const char *n; struct utmp u, *pu; n = ttyname (STDIN_FILENO); printf ("Terminal name is: %s\n", n); memset (&u, '\0', sizeof (u)); u.ut_type = USER_PROCESS; strcpy (u.ut_line, n); if (!strncasecmp (n, "/dev/", 5)) strncpy (u.ut_line, n + 5, UT_LINESIZE); else strncpy (u.ut_line, n, UT_LINESIZE); for (i = 0; i < 2; i++) { u.ut_id[0] = 'a' + i; setutent (); pututline (&u); printf ("Wrote utmp entry: type %d, id %s, line %s\n", u.ut_type, u.ut_id, u.ut_line); } setutent (); pu = getutid (&u); printf ("Calling getutid () with id %s: id = %s, line = %s\n", u.ut_id, pu->ut_id, pu->ut_line); pu->ut_line[0] = 'T'; printf ("About to write the following utmp entry: id %s, line %s\n", pu->ut_id, pu->ut_line); setutent (); pututline (pu); printf ("Calling pututline () with id %s, setting line to %s\n", pu->ut_id, pu->ut_line); for (i = 0; i < 2; i++) { u.ut_id[0] = 'a' + i; setutent (); pu = getutid (&u); printf ("Calling getutid () with id %s: id = %s, line = %s\n", u.ut_id, pu->ut_id, pu->ut_line); } endutent (); exit (0); }