Is there any way to find real tty under shell layers?

KOLB paul at whuts.UUCP
Wed Mar 16 13:05:38 AEST 1988


In article <352 at vsi.UUCP>, friedl at 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 <sys/types.h>
#include <utmp.h>
#include <stdio.h>

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



More information about the Comp.unix.questions mailing list