Who is "logged in" when you are running multiple login windows?

Boyd Ostroff ostroff at Oswego.EDU
Fri Mar 23 01:29:27 AEST 1990


I'm still a little confused over the original problem here, but I've
also had problems telling who the user is when running multiple windows
on the system console.  (Note: I've been using a very simple UA replacement
which provides multiple 24x80 console windows in a small font for over a 
year without problems - it's called "wlogin" and I posted it some time ago -
write if interested).

Anyway, I wrote this little function to use as a getlogin() replacement and
include it here since it might be of use to someone.  It just finds out
your tty name then reads through the utmp file until it finds a matching
entry.

||| Boyd Ostroff - Tech Director - Dept of Theatre - SUNY Oswego 
||| Sys Admin - "The CallBoard" - (315) 947-6414 - 1200/2400 baud 
||| ostroff at oswego.oswego.edu - cboard!ostroff at oswego.oswego.edu 

------------------------- cut here ---------------------------
#include <sys/types.h>
#include <utmp.h>
#include <time.h>
#include <stdio.h>
#include <pwd.h>
#include <string.h>


char *get_login()           /* added this function to replace getlogin() */
{                           /* which doesn't work properly with multiple */
struct utmp *getutent();    /* windows on the Unix-PC system console */
struct utmp *u;             /* Boyd Ostroff (ostroff at oswego.oswego.edu) */
char *ttyname();
char *where;

    where = 1 + strrchr(ttyname(0), '/');
    setutent();
    while ((u = getutent()) != NULL)
        {
        if (u->ut_type == 7) 
            {
            if (strcmp(where, u->ut_line) ==0)
                {
                 return(u->ut_user);
                }
            }
        }
    endutent();
}



More information about the Comp.sys.att mailing list