Path: utzoo!mnetor!uunet!husc6!bloom-beacon!tut.cis.ohio-state.edu!rutgers!mtune!mtunx!whuts!paul From: paul@whuts.UUCP (KOLB) Newsgroups: comp.unix.questions Subject: Re: Is there any way to find real tty under shell layers? Message-ID: <3945@whuts.UUCP> Date: 19 Mar 88 23:58:23 GMT References: <3932@whuts.UUCP> <1098@its63b.ed.ac.uk> Organization: AT&T Bell Laboratories Lines: 50 In article <1098@its63b.ed.ac.uk>, simon@its63b.ed.ac.uk (ECSC68 S Brown CS) writes: > In article <3932@whuts.UUCP> paul@whuts.UUCP (KOLB) writes: > >>In article <352@vsi.UUCP>, friedl@vsi.UUCP (Stephen J. Friedl) writes: > >> Does anybody know any way to find out the "real" terminal > >> name when running under shell layers in Sys V? > > > > [description of doing this using getutent() to search for a ut_line > > that looks like ttyname(0)] > > But shl stamps an entry for the current layer "/dev/sxtNNN" in /etc/utmp, > so this won't work. Have you tried to run the program? Here it is again: #include #include #include main() { struct utmp *utmp, *getutent(); char *q; q = ttyname(0)+5; while ((utmp = getutent()) != NULL) { if ( (utmp->ut_type == USER_PROCESS) && (strncmp(utmp->ut_line, q, strlen(q)) == 0) ) printf("tty%d\n", atoi(utmp->ut_id)); } } As I said in my earlier reply to Steve Friedl, inittab's ID field (this ID field becomes utmp->ut_id) has to be corresponded to the tty number. Ie: 123:2:respawn:/etc/getty -t 60 tty123 ^^^ correspond to ^^^ > The only way I can think of is to look in /dev/kmem .... Another setgid to sys program! > Of course, the real problem is that utmp is simply not good enough any more- > it was fine back in the Good Old Days, but when you have windows and ptys and > multiplexing and other good stuff like this, it loses badly. I tried the program with shl and layers, and it works. The Good Old Days are still here :) Paul Ho