From: andrewc@aurora.cc.monash.edu.au (Andrew J. Cosgriff !)
Subject: [FIX] PS FIX FOR 99p2 !!!
Summary: Patches for ps for 99p2
Keywords: ps fix 99 p2
Organization: Monash University, Melb., Australia.
Date: Sat, 2 Jan 1993 12:07:58 GMT

Okay, in my quest to do something useful for the Linux community, here are some patches to get
ps up and running with 99p2..just a header file location change and an already-used variable,
but, well, it's handy to have it done for you, I guess...

(After spending all day downloading gcc 2.3.3 and patch 2 for the kernel, I needed to compile
something, and ps just happened to need it...)

One note, this patch also includes the fstat patches posted not too long ago, in case people 
missed them (if not, you can ignore them or reverse them first)


Enjoy !

Happy New Year everybody !

Cos !

-----------------------------------------------
diff -c +recursive ps-0.98/Makefile ps/Makefile
*** ps-0.98/Makefile	Wed Oct 21 00:14:19 1992
--- ps/Makefile	Sat Jan  2 22:16:55 1993
***************
*** 2,14 ****
  # for Linux version 0.98
  #
  
! CFLAGS= -O -DVERSION_CHECK
! CFLAGS= -O
  
  # uncomment next line if you are using a compiler older than 2.2.2d
  #CFLAGS= -O -Iinclude -I/usr/src/linux/include -Dhack
  
! #LDFLAGS= -s
  #LDFLAGS= -static
  
  # BINDIR: if you type "make install" the programs will be copied to this
--- 2,14 ----
  # for Linux version 0.98
  #
  
! CFLAGS= -O6 -DVERSION_CHECK
! #CFLAGS= -O6
  
  # uncomment next line if you are using a compiler older than 2.2.2d
  #CFLAGS= -O -Iinclude -I/usr/src/linux/include -Dhack
  
! LDFLAGS= -s
  #LDFLAGS= -static
  
  # BINDIR: if you type "make install" the programs will be copied to this
diff -c +recursive ps-0.98/fstat.c ps/fstat.c
*** ps-0.98/fstat.c	Tue Oct 20 13:33:17 1992
--- ps/fstat.c	Sat Jan  2 22:16:24 1993
***************
*** 21,26 ****
--- 21,29 ----
  struct inode *ino_table;
  struct file *fil_table;
  
+ int _read_pipe_fops;
+ int _write_pipe_fops;
+ 
  caddr_t kbase;
  
  #define	KWORD(a)	(*((unsigned long *)(kbase + (a))))
***************
*** 119,125 ****
      }
  
      mmap_mem();
!     ino_table = KPTR(k_addr("_inode_table"));
      fil_table = KPTR(k_addr("_file_table"));
      p = KPTR(k_addr("_task"));
      for (n = NR_TASKS; n > 0; --n, ++p) {
--- 122,128 ----
      }
  
      mmap_mem();
!     ino_table = KPTR(KWORD(k_addr("_inode_table")));
      fil_table = KPTR(k_addr("_file_table"));
      p = KPTR(k_addr("_task"));
      for (n = NR_TASKS; n > 0; --n, ++p) {
***************
*** 190,196 ****
      int i;
      static int pid = -1;
  
!     if (!inop)
  	return;
  
      inop = KPTR(ino);
--- 193,199 ----
      int i;
      static int pid = -1;
  
!     if (!ino)
  	return;
  
      inop = KPTR(ino);
***************
*** 228,234 ****
  	printf("%5d", type);
      
      if (inop->i_mode == 0 && inop->i_pipe) {
! 	printf("* (pipe %#x)\n", PIPE_BASE(*inop));
  	return;
      }
      if (S_ISSOCK(inop->i_mode)) {
--- 231,248 ----
  	printf("%5d", type);
      
      if (inop->i_mode == 0 && inop->i_pipe) {
! 	char *rw = "?";
! 	if (!_read_pipe_fops) {
! 	    _read_pipe_fops = k_addr("_read_pipe_fops");
! 	    _write_pipe_fops = k_addr("_write_pipe_fops");
! 	}
! 	if ((long)((struct file *)KPTR(task->filp[i]))->f_op == _read_pipe_fops)
! 	    rw = "<-";
! 	else if ((long)((struct file *)KPTR(task->filp[i]))->f_op == _write_pipe_fops)
! 	    rw = "->";
! 	printf("* (pipe %s %#x %d %dr %dw)\n", rw, PIPE_BASE(*inop),
! 		PIPE_SIZE(*inop),
! 		PIPE_READERS(*inop), PIPE_WRITERS(*inop));
  	return;
      }
      if (S_ISSOCK(inop->i_mode)) {
***************
*** 337,342 ****
--- 351,359 ----
  
  #include <linux/socket.h>
  #include "/usr/src/linux/net/kern_sock.h"
+ #include "/usr/src/linux/net/tcp/timer.h"
+ #include "/usr/src/linux/net/tcp/tcp.h"
+ #include "/usr/src/linux/net/tcp/sock.h"
  
  #define	SOCK_INODE(x)	((x)->dummy)
  
***************
*** 345,350 ****
--- 362,373 ----
  int _unix_proto_ops;
  int _inet_proto_ops;
  
+ char *af_name[] = {
+     "????",
+     "unix",
+     "inet",
+ };
+ 
  struct socket *sockets;
  
  print_sock(ino)
***************
*** 351,356 ****
--- 374,380 ----
  struct inode *ino;
  {
      struct socket *sock;
+     int af = 0;
  
      if (sockets == NULL)
  	sock_init();
***************
*** 359,370 ****
  	return;
      }
      if ((long) sock->ops == _unix_proto_ops)
! 	printf("* (unix ");
      else if (_inet_proto_ops != -1 && (long) sock->ops == _inet_proto_ops)
! 	printf("* (inet ");
!     else
! 	printf("* (???? ");
  
      switch (sock->type) {
  	case SOCK_STREAM: printf("stream"); break;
  	case SOCK_DGRAM: printf("dgram"); break;
--- 383,393 ----
  	return;
      }
      if ((long) sock->ops == _unix_proto_ops)
! 	af = AF_UNIX;
      else if (_inet_proto_ops != -1 && (long) sock->ops == _inet_proto_ops)
! 	af = AF_INET;
  
+     printf("* (%s ", af_name[af]);
      switch (sock->type) {
  	case SOCK_STREAM: printf("stream"); break;
  	case SOCK_DGRAM: printf("dgram"); break;
***************
*** 374,380 ****
  	case SOCK_PACKET: printf("packet"); break;
  	default: printf("???");
      }
!     printf(" %x)\n", sock->flags);
  }
  
  struct socket *
--- 397,413 ----
  	case SOCK_PACKET: printf("packet"); break;
  	default: printf("???");
      }
!     printf(" %x", sock->flags);
! 
!     if (af == AF_INET) {
! 	struct sock sk;
! 
! 	if (sock->data) {
! 	    kmemread(&sk, sock->data, sizeof sk);
! 	    printf(" %d", sk.num);
! 	}
!     }
!     printf(")\n");
  }
  
  struct socket *
***************
*** 465,471 ****
  #if 0
      end_mem = get_kword(k_addr("_high_memory"));
  #else
!     end_mem = k_addr("_end");
  #endif
      if (kbase == NULL) {
  	if ((kbase = (caddr_t) malloc(end_mem)) == NULL || ((long) kbase & 0xfff)) {
--- 498,504 ----
  #if 0
      end_mem = get_kword(k_addr("_high_memory"));
  #else
!     end_mem = get_kword(k_addr("_memory_start"));
  #endif
      if (kbase == NULL) {
  	if ((kbase = (caddr_t) malloc(end_mem)) == NULL || ((long) kbase & 0xfff)) {
diff -c +recursive ps-0.98/mmap.c ps/mmap.c
*** ps-0.98/mmap.c	Wed Oct  7 12:10:27 1992
--- ps/mmap.c	Sat Jan  2 22:57:38 1993
***************
*** 1,11 ****
  #define __LIBRARY__
! #include <unistd.h>
  #include <sys/types.h>
  #include <sys/mman.h>
  
  #define __NR__mmap __NR_mmap
! static inline
! _syscall1(caddr_t,_mmap,unsigned long *,buffer);
  
  caddr_t mmap(caddr_t addr, size_t len, int prot, int flags, int fd, off_t off)
  {
--- 1,10 ----
  #define __LIBRARY__
! #include <linux/unistd.h>
  #include <sys/types.h>
  #include <sys/mman.h>
  
  #define __NR__mmap __NR_mmap
! static inline _syscall1(caddr_t,_mmap,unsigned long *,buffer);
  
  caddr_t mmap(caddr_t addr, size_t len, int prot, int flags, int fd, off_t off)
  {
***************
*** 21,23 ****
--- 20,24 ----
  }
  
  _syscall2(int,munmap, caddr_t,addr, size_t,len)
+ 
+ 
diff -c +recursive ps-0.98/top.c ps/top.c
*** ps-0.98/top.c	Sat Jan  2 23:00:48 1993
--- ps/top.c	Sat Jan  2 22:42:58 1993
***************
*** 50,56 ****
  /* some dummy variables to get cmdline.c to link */
  int kern_comm=0;
  int show_env=0;
! int idle,freemem;
  char hdr[200];
  char *title="TOP   by Roger Binns    Ps (c) 1992 Branko Lankester";
  
--- 50,56 ----
  /* some dummy variables to get cmdline.c to link */
  int kern_comm=0;
  int show_env=0;
! int top_idle, freemem;
  char hdr[200];
  char *title="TOP   by Roger Binns    Ps (c) 1992 Branko Lankester";
  
***************
*** 246,260 ****
  	    interval = -jiffies;
  	    jiffies = get_kword(_jiffies);
  	    interval += jiffies;
! 	    idle=freemem=1000;
  	    show_procs();
  	    outstr[0]=0;
  	    sort_vals();
! 	    if(idle<0) idle=0;
  	    freemem = (get_kword(_nr_free_pages) + get_kword(_nr_buffers)*4)
  			* 100 / pages;
  	    if(freemem<0) freemem=0;
! 	    printf("%s%2d%% idle, %2d%% free core - sorted by %s", tgoto(cm,0,3), idle/10, freemem/10, corm?"CPU use    ":"Memory use "); /* can't have two tgoto's - they use a static buffer */
  	    kmemread(av, _aver, sizeof av);
  	    for (i=0; i<3; ++i) {
  		av[i] *= 100;
--- 246,260 ----
  	    interval = -jiffies;
  	    jiffies = get_kword(_jiffies);
  	    interval += jiffies;
! 	    top_idle=freemem=1000;
  	    show_procs();
  	    outstr[0]=0;
  	    sort_vals();
! 	    if(top_idle<0) top_idle=0;
  	    freemem = (get_kword(_nr_free_pages) + get_kword(_nr_buffers)*4)
  			* 100 / pages;
  	    if(freemem<0) freemem=0;
! 	    printf("%s%2d%% top_idle, %2d%% free core - sorted by %s", tgoto(cm,0,3), top_idle/10, freemem/10, corm?"CPU use    ":"Memory use "); /* can't have two tgoto's - they use a static buffer */
  	    kmemread(av, _aver, sizeof av);
  	    for (i=0; i<3; ++i) {
  		av[i] *= 100;
***************
*** 476,482 ****
  	else
  		pmem = task->rss * 1000 / (main_mem / 4096);
  	if(pcpu>999) pcpu=999;
! 	idle-=pcpu;
  	freemem-=pmem;
  	if(corm) vals[num]=(pcpu<<8) + 256 - task->counter;
  	else vals[num]=pmem;
--- 476,482 ----
  	else
  		pmem = task->rss * 1000 / (main_mem / 4096);
  	if(pcpu>999) pcpu=999;
! 	top_idle-=pcpu;
  	freemem-=pmem;
  	if(corm) vals[num]=(pcpu<<8) + 256 - task->counter;
  	else vals[num]=pmem;
diff -c +recursive ps-0.98/w.c ps/w.c
*** ps-0.98/w.c	Tue Oct 13 00:53:21 1992
--- ps/w.c	Sat Jan  2 22:35:51 1993
***************
*** 72,82 ****
  
  #define	proc	task_struct
  
! #ifndef	UT_NAMESIZE
  #define	UT_NAMESIZE	8
  #define	UT_LINESIZE	12
  #define	UT_HOSTSIZE	16
! #endif
  #ifndef	_PATH_UTMP
  #define	_PATH_UTMP	UTMP_FILE
  #endif
--- 72,82 ----
  
  #define	proc	task_struct
  
! /*#ifndef	UT_NAMESIZE*/
  #define	UT_NAMESIZE	8
  #define	UT_LINESIZE	12
  #define	UT_HOSTSIZE	16
! /*#endif*/
  #ifndef	_PATH_UTMP
  #define	_PATH_UTMP	UTMP_FILE
  #endif


-- 
-------------------------------------------------------------------------------
 * Andrew J. Cosgriff ! *                   #include <std_witty_quote.h>
#define HERE cc.monash.edu.au               #include <std_disclaimer.h>
Hassle me at :      andrewc@aurora.HERE ; andrewc@lindblat.HERE ; cos@yoyo.HERE