Subject: Re: pstat -t
To: John M Vinopal <banshee@gabriella.resort.com>
From: matthew green <mrg@eterna.com.au>
List: current-users
Date: 05/23/1996 23:41:43
   
   Has pstat -t ever worked?  IS anyone presently looking at making it
   work?

well, i have pstat -t working for non machine-specific
devices (ie, ptys). it's a bit hackish due to the structure
required being only defined in sys/kern/tty_pty.c (for
now; this may change, i hope :). i also removed the sparc
printing the console (no other port did, and, it's not a
real tty/pty anyway), and fixed up the names of all the
machine-specific variables (`foocd' -> `foo_cd'), not that
these work anyway (but at least it will now print, for eg,
`2 zs lines', on the normal saprc).

here's a patch (it won't be commited until the struct
pt_softc issue is resolved).

.mrg.

Index: pstat.c
===================================================================
RCS file: /a/cvsroot/src/usr.sbin/pstat/pstat.c,v
retrieving revision 1.19
diff -c -r1.19 pstat.c
*** pstat.c	1996/05/02 00:13:19	1.19
--- pstat.c	1996/05/23 13:30:23
***************
*** 106,123 ****
  	{ "_niswap" },
  #define VM_NISWDEV	NLMANDATORY + 2
  	{ "_niswdev" },
! #define	SCONS		NLMANDATORY + 3
! 	{ "_constty" },
! #define	SPTY		NLMANDATORY + 4
! 	{ "_pt_tty" },
! #define	SNPTY		NLMANDATORY + 5
  	{ "_npty" },
  
  #ifdef sparc
  #define SZS	(SNPTY+1)
  	{ "_zs_tty" },
  #define SCZS	(SNPTY+2)
! 	{ "_zscd" },
  #endif
  
  #ifdef hp300
--- 106,121 ----
  	{ "_niswap" },
  #define VM_NISWDEV	NLMANDATORY + 2
  	{ "_niswdev" },
! #define	SPTY		NLMANDATORY + 3
! 	{ "_pt_softc" },
! #define	SNPTY		NLMANDATORY + 4
  	{ "_npty" },
  
  #ifdef sparc
  #define SZS	(SNPTY+1)
  	{ "_zs_tty" },
  #define SCZS	(SNPTY+2)
! 	{ "_zs_cd" },
  #endif
  
  #ifdef hp300
***************
*** 150,174 ****
  #define SPC	(SNPTY+1)
  	{ "_pc_tty" },
  #define SCPC	(SNPTY+2)
! 	{ "_pccd" },
  #define SCOM	(SNPTY+3)
  	{ "_com_tty" },
  #define SCCOM	(SNPTY+4)
! 	{ "_comcd" },
  #endif
  #ifdef amiga
  #define SSER	(SNPTY + 1)
  	{ "_ser_tty" },
  #define SCSER	(SNPTY + 2)
! 	{ "_sercd" },
  #define SITE	(SNPTY + 3)
  	{ "_ite_tty" },
  #define SCITE	(SNPTY + 4)
! 	{ "_itecd" },
  #define SMFCS	(SNPTY + 5)
  	{ "_mfcs_tty" },
  #define SCMFCS	(SNPTY + 6)
! 	{ "_mfcscd" },
  #endif
  
  	{ "" }
--- 148,172 ----
  #define SPC	(SNPTY+1)
  	{ "_pc_tty" },
  #define SCPC	(SNPTY+2)
! 	{ "_pc_cd" },
  #define SCOM	(SNPTY+3)
  	{ "_com_tty" },
  #define SCCOM	(SNPTY+4)
! 	{ "_com_cd" },
  #endif
  #ifdef amiga
  #define SSER	(SNPTY + 1)
  	{ "_ser_tty" },
  #define SCSER	(SNPTY + 2)
! 	{ "_ser_cd" },
  #define SITE	(SNPTY + 3)
  	{ "_ite_tty" },
  #define SCITE	(SNPTY + 4)
! 	{ "_ite_cd" },
  #define SMFCS	(SNPTY + 5)
  	{ "_mfcs_tty" },
  #define SCMFCS	(SNPTY + 6)
! 	{ "_mfcs_cd" },
  #endif
  
  	{ "" }
***************
*** 212,217 ****
--- 210,216 ----
  void	ttytype __P((char *, int, int));
  void	ttytype_newcf __P((char *, int, int));
  void	ttytype_oldcf __P((char *, int, int));
+ void	ttytype_ptycf __P((char *, int, int));
  void	ufs_header __P((void));
  int	ufs_print __P((struct vnode *));
  void	usage __P((void));
***************
*** 739,745 ****
  {
  
  #ifdef sparc
- 	ttytype("console", SCONS, 1);
  	ttytype_newcf("zs", SZS, SCZS);
  #endif
  
--- 738,743 ----
***************
*** 781,787 ****
  		ttytype_newcf("mfcs", SMFCS, SCMFCS);
  #endif
  	if (nl[SNPTY].n_type != 0)
! 		ttytype_oldcf("pty", SPTY, SNPTY);
  }
  
  void
--- 779,785 ----
  		ttytype_newcf("mfcs", SMFCS, SCMFCS);
  #endif
  	if (nl[SNPTY].n_type != 0)
! 		ttytype_ptycf("pty", SPTY, SNPTY);
  }
  
  void
***************
*** 814,819 ****
--- 812,851 ----
  			break;
  	free(cd);
  	ttytype(name, type, i + 1);
+ }
+ 
+ /* XXX taken from sys/kern/pty_tty.c */
+ struct  pt_softc {
+         struct  tty *pt_tty;
+         int     pt_flags;
+         struct  selinfo pt_selr, pt_selw;
+         u_char  pt_send;
+         u_char  pt_ucntl;
+ };
+ 
+ 
+ void
+ ttytype_ptycf(name, type, number)
+ 	char *name;
+ 	int type, number;
+ {
+ 	struct pt_softc *ptyp;
+ 	struct tty tty;
+ 	int npty, i;
+ 
+ 	KGET(number, npty);
+ 
+ 	(void)printf("%d %s %s\n", npty, name, (number == 1) ? "line" : "lines");
+ 	if ((ptyp = realloc(ptyp, npty * sizeof *ptyp)) == 0)
+ 		err(1, NULL);
+ 	KGET1(type, ptyp, npty * sizeof *ptyp, "pt_softc array");
+ 	(void)printf(hdr);
+ 	for (i = 0; i < npty; i++) {
+ 		if (ptyp[i].pt_tty) {
+ 			KGET2(ptyp[i].pt_tty, &tty, sizeof tty, "pty struct");
+ 			ttyprt(&tty, i);
+ 		}
+ 	}
  }
  
  void