home *** CD-ROM | disk | FTP | other *** search
- # ifndef lint
- static char SccsId[] = "@(#)findtty.c 1.4\t8/6/90" ;
- # endif
-
- # include "sps.h"
- # include <h/ioctl.h>
- # ifdef SUNOS40
- # include <h/stream.h>
- # else
- # include <h/tty.h>
- # endif
- # ifdef SUNOS41
- # include <h/session.h>
- # endif
-
- /* FINDTTY - Attempts to determine to which tty a process is connected */
- struct ttyline *findtty ( p )
-
- register struct process *p ;
-
- {
- register struct ttyline *lp ;
- extern struct info Info ;
- extern struct ttyline Notty ;
- # ifdef SUNOS41
- struct sess *s ;
- extern struct sess *find_session () ;
- # else
- extern union userstate User ;
- # endif SUNOS41
-
-
- # ifdef SUNOS41
- if ( !p->pr_p.p_pgrp || !p->pr_p.p_sessp )
- return ( &Notty ) ;
- s = find_session( p->pr_p.p_sessp ) ;
- if ( s == 0 || s->s_ttyp == 0 )
- return &Notty;
- for ( lp = Info.i_ttyline ; lp->l_name[0] ; lp++ )
- if ( lp->l_dev == s->s_ttyd )
- return ( lp ) ;
- /* Kludge from outer space ++sja */
- if ( s->s_ttyd == 256 )
- return &Info.i_ttyline[0] ;
- return ( &Notty ) ;
- # else
- # ifdef ULTRIX30
- if ( !p->pr_p.p_pgrp || !p->pr_p.p_ttyp )
- # else
- if ( !p->pr_p.p_pgrp || !User.u_us.u_ttyp )
- # endif
- return ( &Notty ) ;
- for ( lp = Info.i_ttyline ; lp->l_name[0] ; lp++ )
- if ( lp->l_dev == User.u_us.u_ttyd )
- return ( lp ) ;
- return ( &Notty ) ;
- #endif SUNOS41
- }
-