home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume3 / sps / part2 / ttystatus.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  2.8 KB  |  117 lines

  1. # include       "sps.h"
  2. # include       "flags.h"
  3. # include       <stdio.h>
  4. # include       <h/tty.h>
  5. # ifdef CHAOS
  6. # include       <chunix/chsys.h>
  7. # include       <chaos/chaos.h>
  8. # endif
  9.  
  10. /*
  11. ** TTYSTATUS - Reads the kernel memory for tty structures of active processes.
  12. ** The addresses of the associated struct ttys of /dev/kmem are kept in the
  13. ** info structure. Here we use those addresses to access the structures.
  14. ** Actually, we are mostly interested just in the process group of each tty.
  15. */
  16. ttystatus ()
  17. {
  18.     register struct ttyline *lp ;
  19.     struct tty              tty ;
  20.     extern struct flags     Flg ;
  21.     extern struct info      Info ;
  22.     extern int              Flkmem ;
  23.  
  24.     if ( Flg.flg_y )
  25.         printf( "Ty   Dev       Addr Rawq Canq Outq  Pgrp\n" ) ;
  26.     lp = Info.i_ttyline ;
  27. # ifdef CHAOS
  28.     while ( lp->l_name[0] && lp->l_name[0] != 'C' )
  29. # else
  30.     while ( lp->l_name[0] )
  31. # endif
  32.     {
  33.         memseek( Flkmem, (long)lp->l_addr ) ;
  34.         if ( read( Flkmem, (char*)&tty, sizeof( struct tty ) )
  35.         != sizeof( struct tty ) )
  36.         {
  37.             fprintf( stderr,
  38.                 "sps - Can't read struct tty for tty%.2s\n",
  39.                 lp->l_name ) ;
  40.             lp->l_pgrp = 0 ;
  41.             lp++ ;
  42.             continue ;
  43.         }
  44.         lp->l_pgrp = tty.t_pgrp ;
  45.         prtty( lp, &tty ) ;
  46.         lp++ ;
  47.     }
  48. # ifdef CHAOS
  49.     chaosttys( lp ) ;               
  50. # endif
  51. }
  52.  
  53. /* PRTTY - Print out the tty structure */
  54. prtty ( lp, tty )
  55.  
  56. register struct ttyline         *lp ;
  57. register struct tty             *tty ;
  58.  
  59. {
  60.     extern struct flags     Flg ;
  61.  
  62.     if ( !Flg.flg_y )
  63.         return ;
  64.     printf( "%-2.2s %2d,%2d 0x%08x %4d %4d %4d %5d\n",
  65.         lp->l_name,
  66.         major( lp->l_dev ),
  67.         minor( lp->l_dev ),
  68.         lp->l_addr,
  69.         tty->t_rawq.c_cc,
  70.         tty->t_canq.c_cc,
  71.         tty->t_outq.c_cc,
  72.         tty->t_pgrp ) ;
  73. }
  74.  
  75. # ifdef CHAOS
  76.  
  77. /* CHAOSTTYS - Finds ttys attached to the Chaos net */
  78. chaosttys ( lp )
  79.  
  80. register struct ttyline         *lp ;
  81.  
  82. {
  83.     register struct connection      **cnp ;
  84.     register int                    i ;
  85.     struct tty                      tty ;
  86.     struct connection               *conntab[CHNCONNS] ;
  87.     struct connection               conn ;
  88.     extern struct info              Info ;
  89.     extern int                      Flkmem ;
  90.  
  91.     memseek( Flkmem, (long)Info.i_Chconntab ) ;
  92.     (void)read( Flkmem, (char*)conntab, sizeof( conntab ) ) ;
  93.     for ( i = 0, cnp = conntab ; cnp < &conntab[CHNCONNS] ; i++, cnp++ )
  94.     {
  95.         if ( !*cnp )
  96.             continue ;
  97.         memseek( Flkmem, (long)*cnp ) ;
  98.         (void)read( Flkmem, (char*)&conn, sizeof( struct connection ) );
  99.         if ( !(conn.cn_flags & CHTTY) )
  100.             continue ;
  101.         memseek( Flkmem, (long)conn.cn_ttyp ) ;
  102.         (void)read( Flkmem, (char*)&tty, sizeof( struct tty ) ) ;
  103.         if ( lp >= &Info.i_ttyline[MAXTTYS] )
  104.             prexit( "sps - Too many chaos ttys\n" ) ;
  105.         lp->l_addr = conn.cn_ttyp ;
  106.         lp->l_pgrp = tty.t_pgrp ;
  107.         lp->l_dev = tty.t_dev ;
  108.         lp->l_name[0] = 'C' ;
  109.         lp->l_name[1] = i < 10 ? '0'+i : i-10 <= 'z'-'a' ? i-10+'a' :
  110.                 i-10-('z'-'a')+'A' ;
  111.         prtty( lp, &tty ) ;
  112.         lp++ ;
  113.     }
  114. }
  115.  
  116. # endif
  117.