SunOS 4.0 /usr/ucb/w can't find console processes (pa

Craig Leres leres at helios.ee.lbl.gov
Sat Jan 14 12:27:09 AEST 1989


I noticed that under 4.0, w never showed anything running on the console.
I also noticed that ps worked correctly so I looked at its source and
found some clever ifdef's with some interesting looking code. I
incorporated these into w and they seem to do the trick.  Appended are
context diffs. Note that I've only tested this change on the sparc (but it
ought to work on the 68k).

		Craig
------
diff -c w.c w.c.new
*** w.c	Fri Nov 11 21:36:49 1988
--- w.c.new	Fri Jan  6 21:12:28 1989
***************
*** 11,17 ****
  #endif not lint

  #ifndef lint
! static	char sccsid[] = "@(#)w.c 1.14 88/02/08 SMI"; /* from UCB 5.3 2/23/86 */
  #endif not lint
  /*
   * w, uptime - print system status (who and what)
--- 11,17 ----
  #endif not lint

  #ifndef lint
! static	char sccsid[] = "@(#)w.c 1.14++ 88/02/08 SMI"; /* from UCB 5.3 2/23/86 */
  #endif not lint
  /*
   * w, uptime - print system status (who and what)
***************
*** 57,62 ****
--- 57,66 ----
  #define	X_BOOTTIME	1
  	{ "_nproc" },
  #define	X_NPROC		2
+ #ifdef sun
+ 	{ "_rconsdev" },
+ #define	X_NRCONSDEV	3
+ #endif
  	{ "" },
  };

***************
*** 69,74 ****
--- 73,81 ----
  char	doing[520];		/* process attached to terminal */
  time_t	proctime;		/* cpu time of process in doing */
  long	avenrun[3];
+ #ifdef sun
+ dev_t	rconsdev;
+ #endif

  #define	DIV60(t)	((t+30)/60)    /* x/60 rounded */ 
  #define	TTYEQ		(tty == pr[i].w_tty && (uid == 0 || uid == pr[i].w_uid))
***************
*** 431,436 ****
--- 438,446 ----
  	 * allocate proc table
  	 */
  	readsym(X_NPROC, &nproc, sizeof(nproc));
+ #ifdef sun
+ 	readsym(X_NRCONSDEV, &rconsdev, sizeof (rconsdev));
+ #endif
  	pr = (struct pr *)calloc(nproc, sizeof (struct pr));
  	np = 0;
  	while ((mproc = kvm_nextproc(kd)) != NULL) {
***************
*** 455,460 ****
--- 465,475 ----
  		    up->u_ru.ru_utime.tv_sec + up->u_ru.ru_stime.tv_sec;
  		pr[np].w_ctime =
  		    up->u_cru.ru_utime.tv_sec + up->u_cru.ru_stime.tv_sec;
+ #ifdef sun
+ 		if (up->u_ttyd == rconsdev)
+ 			up->u_ttyd = makedev(0, 0);	/* "/dev/console" */
+ 
+ #endif
  		pr[np].w_tty = up->u_ttyd;
  		pr[np].w_uid = mproc->p_uid;
  		strcpyn(pr[np].w_comm, up->u_comm, sizeof (pr->w_comm));



More information about the Comp.sys.sun mailing list