Path: utzoo!mnetor!uunet!husc6!bbn!rochester!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: <3932@whuts.UUCP> Date: 16 Mar 88 03:05:38 GMT References: <352@vsi.UUCP> Distribution: comp Organization: AT&T Bell Laboratories Lines: 39 Keywords: ttyname, sxt, shl, layers 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? #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)); } } This will work, iff your /etc/inittab is "right", ie. the id field corresponds to the tty name; in other words: 220:2:respawn:/etc/getty -t 60 tty220 9600 ^^^ corresponds to ^^^ According to my utmp(4) man page, the ut_id is the "/etc/inittab id (usually line #)". So I guess that is the convention. BTW, if you must edit your inittab ID field, do so in single user mode only. Since init keeps its own internal table, if you modified the inittab ID field in multi user mode, and did a "init q", init would have two entries for the same tty; one with the old id, one with the new id. Then all the programs (such as newgrp) that call getlogin, ttyslot .. etc wouldn't work. Has anyone seen this, or is my init brain-damaged? Paul Ho