Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!mailrus!uwm.edu!cs.utexas.edu!uunet!mcsun!ukc!warwick!cudcv From: cudcv@warwick.ac.uk (Rob McMahon) Newsgroups: comp.sources.bugs Subject: Re: sps and SunOS 4.1 Message-ID: <1990Jul5.165813.6286@warwick.ac.uk> Date: 5 Jul 90 16:58:13 GMT References: <1990Jun28.035921.1537@contact.uucp> <1990Jul3.125358.3247@warwick.ac.uk> <1990Jul4.083124.23742@warwick.ac.uk> Sender: news@warwick.ac.uk (Network news) Organization: Computing Services, Warwick University, UK Lines: 420 Well folks, it seems I was horribly wrong. The version of sps I had was not very much like the one on titan.rice.edu at all, and the patches wouldn't patch that version. As recompense I have spent the day doing it right to the version from titan, here are the changes. I've still punted on the NOFILE_IN_U business, but I've written a version of the stream grabbing stuff which works, and even fixed a bug in the environment printing code. The only nasty left is a warning about the inode table not being found. I'm not clear enough on what they've done with it to fix that. Also someone, someday ought to go chasing the processes' files when they fall off the end of the U area. Have fun, Rob =================================================================== *** /dev/null Thu Jul 5 17:56:04 1990 --- Makefile.sun.4.1 Thu Jul 5 17:19:29 1990 *************** *** 0 **** --- 1,52 ---- + # Makefile for SPS (Sun-2, Sun-3 and Sun-4, SunOS 4.1 Version) + + PROG = sps + OBJS = filecount.o findtty.o flagdecode.o flagsetup.o \ + getcmd.o getupage.o globals1.o globals2.o hashuid.o \ + initialise.o initsymbols.o inittty.o main.o mktree.o \ + needed.o openfiles.o percentmem.o prcmd.o prcpu.o \ + prheader.o printall.o printproc.o prsummary.o readstatus.o \ + selectproc.o selecttty.o stream.o termwidth.o ttystatus.o \ + waitingfor.o + INCS = sps.h + #CC = gcc + #OPT = -O -fstrength-reduce -fomit-frame-pointer -fdelayed-branch + #READONLY = + #READWRITE = -fwritable-strings + CC = cc + OPT = -O + READONLY = -R + READWRITE = + CFLAGS = -DSUN -DBSD42 -DNFS -DVPRINTF -DKVM -DSUNOS40 -DSUNOS41 \ + -DOLDSTATS -Isys + LIBS = -ltermlib -lkvm + DIRINSTALL = /usr/kvm + + all: $(PROG) + .c.o: + $(CC) $(CFLAGS) -c $(OPT) $(READONLY) $< + + globals1.o stream.o waitingfor.o: + $(CC) $(CFLAGS) -c $(OPT) $(READWRITE) $*.c + + $(OBJS): sys $(INCS) + + sys: + -mkdir sys + -ln -s /sys/* sys + -ln -s /sys/sys sys/h + + $(PROG): $(OBJS) + $(CC) $(OPT) -o $@ $(OBJS) $(LIBS) + + install: $(PROG) + strip $(PROG) + mv $(PROG) $(DIRINSTALL)/$(PROG) + /etc/chown root $(DIRINSTALL)/$(PROG) + chgrp kmem $(DIRINSTALL)/$(PROG) + chmod 2755 $(DIRINSTALL)/$(PROG) + + lint: + lint -x -b $(CFLAGS) *.c $(LIBS) + clean: + rm -f $(OBJS) $(PROG) =================================================================== RCS file: Makefile.sun.4.0,v retrieving revision 1.1 diff -c -r1.1 Makefile.sun.4.0 *** /tmp/,RCSt1a02918 Thu Jul 5 17:47:28 1990 --- Makefile.sun.4.0 Thu Jul 5 17:21:02 1990 *************** *** 9,15 **** --- 9,22 ---- selectproc.o selecttty.o stream.o termwidth.o ttystatus.o \ waitingfor.o INCS = sps.h + #CC = gcc + #OPT = -O -fstrength-reduce -fomit-frame-pointer -fdelayed-branch + #READONLY = + #READWRITE = -fwritable-strings CC = cc + OPT = -O + READONLY = -R + READWRITE = CFLAGS = -DSUN -DBSD42 -DNFS -DVPRINTF -DKVM -DSUNOS40 -DOLDSTATS -Isys LIBS = -ltermlib -lkvm DIRINSTALL = /usr/kvm *************** *** 16,25 **** all: $(PROG) .c.o: ! $(CC) $(CFLAGS) -c -O -R $< globals1.o stream.o waitingfor.o: ! $(CC) $(CFLAGS) -c -O $< $(OBJS): sys $(INCS) --- 23,32 ---- all: $(PROG) .c.o: ! $(CC) $(CFLAGS) -c $(OPT) $(READONLY) $< globals1.o stream.o waitingfor.o: ! $(CC) $(CFLAGS) -c $(OPT) $(READWRITE) $*.c $(OBJS): sys $(INCS) *************** *** 29,35 **** -ln -s /sys/sys sys/h $(PROG): $(OBJS) ! $(CC) -o $@ $(OBJS) $(LIBS) install: $(PROG) strip $(PROG) --- 36,42 ---- -ln -s /sys/sys sys/h $(PROG): $(OBJS) ! $(CC) $(OPT) -o $@ $(OBJS) $(LIBS) install: $(PROG) strip $(PROG) =================================================================== RCS file: filecount.c,v retrieving revision 1.1 diff -c -r1.1 filecount.c *** /tmp/,RCSt1a02918 Thu Jul 5 17:47:28 1990 --- filecount.c Thu Jul 5 10:13:43 1990 *************** *** 13,19 **** --- 13,24 ---- extern union userstate User ; count = 0 ; + #ifdef SUNOS41 + /* too hard to do right at the moment ... */ + for ( i = 0, f = User.u_us.u_ofile_arr ; i < NOFILE_IN_U ; i++ ) + #else /* ! SUNOS41 */ for ( i = 0, f = User.u_us.u_ofile ; i < NOFILE ; i++ ) + #endif /* SUNOS41 */ if ( *f++ ) count++ ; return ( count ) ; =================================================================== RCS file: getcmd.c,v retrieving revision 1.1 diff -c -r1.1 getcmd.c *** /tmp/,RCSt1a02918 Thu Jul 5 17:47:28 1990 --- getcmd.c Thu Jul 5 17:12:31 1990 *************** *** 89,96 **** p->pr_csaved = 1 ; sp = argbuf.a_argc ; nbad = 0 ; ! for ( ap = argv ; *ap || ! ( argv && free( (char*)argv ), argv = 0, Flg.flg_e && *( ap = env ) ) ; *sp++ = ' ' ) for ( cp = *ap++ ; *cp ; *sp++ = *cp++ ) { --- 89,98 ---- p->pr_csaved = 1 ; sp = argbuf.a_argc ; nbad = 0 ; ! for ( ap = argv ; ! *ap || ( argv && ! ( free( (char*)argv ), argv = 0, ! Flg.flg_e && *( ap = env ) ) ); *sp++ = ' ' ) for ( cp = *ap++ ; *cp ; *sp++ = *cp++ ) { =================================================================== RCS file: getupage.c,v retrieving revision 1.1 diff -c -r1.1 getupage.c *** /tmp/,RCSt1a02918 Thu Jul 5 17:47:29 1990 --- getupage.c Thu Jul 5 11:09:09 1990 *************** *** 113,128 **** struct user *upage ; extern union userstate User ; extern kvm_t *Flkvm ; ! if (upage = kvm_getu( Flkvm, &p->pr_p ) ) { ! bcopy( (char *) upage, User.u_pg[0], sizeof( struct user ) ) ; ! return ( 1 ) ; } ! fprintf( stderr, ! "sps - Can't read upage of process %d\n", ! p->pr_p.p_pid ) ; ! return ( 0 ) ; } # endif --- 113,143 ---- struct user *upage ; extern union userstate User ; extern kvm_t *Flkvm ; + #ifdef SUNOS41 + static struct sess Sess; + #endif ! if ( (upage = kvm_getu( Flkvm, &p->pr_p )) == NULL ) { ! fprintf( stderr, ! "sps - Can't read upage of process %d\n", ! p->pr_p.p_pid ) ; ! return ( 0 ) ; } ! bcopy( (char *) upage, User.u_pg[0], sizeof( struct user ) ) ; ! #ifdef SUNOS41 ! if ( kvm_read( Flkvm, p->pr_p.p_sessp, (char *)&Sess, sizeof( Sess )) ! != sizeof(Sess) ) ! { ! fprintf( stderr, ! "sps - Can't read session of process %d\n", ! p->pr_p.p_pid ) ; ! return ( 0 ) ; ! } ! User.u_us.u_procp = &p->pr_p ; ! p->pr_p.p_sessp = &Sess ; ! #endif /* SUNOS41 */ ! return ( 1 ) ; } # endif =================================================================== RCS file: globals2.c,v retrieving revision 1.1 diff -c -r1.1 globals2.c *** /tmp/,RCSt1a02918 Thu Jul 5 17:47:29 1990 --- globals2.c Thu Jul 5 15:44:40 1990 *************** *** 74,81 **** --- 74,85 ---- { "_segvn_ops", 0, (caddr_t*)&Info.i_segvn_ops,(char*)0 }, { "_pty_softc", 0, (caddr_t*)&Info.i_ptybase, (char*)0 }, { "_npty", 1, (caddr_t*)&Info.i_npty, (char*)0 }, + # ifndef SUNOS41 { "_streams", 0, (caddr_t*)&Info.i_streams, (char*)0 }, { "_streamsNSTREAMS",1,(caddr_t*)&Info.i_streamsNSTREAMS,(char*)0}, + # else + { "_allstream", 0, (caddr_t*)&Info.i_allstream,(char*)0 }, + # endif { "_Sysbase", 1, (caddr_t*)&Info.i_sysbase, (char*)0 }, # endif /* Kernel addresses associated with process wait states. =================================================================== RCS file: main.c,v retrieving revision 1.1 diff -c -r1.1 main.c *** /tmp/,RCSt1a02918 Thu Jul 5 17:47:30 1990 --- main.c Thu Jul 5 10:55:59 1990 *************** *** 26,31 **** --- 26,35 ---- and Charlie Kim . Ultrix 2.x support by Rob Lehman at CUCCA. */ + /* First attempt at SunOS 4.1 support by Rob McMahon + - 5 Jul 1990 + */ + main ( argc,argv ) int argc ; =================================================================== RCS file: sps.h,v retrieving revision 1.1 diff -c -r1.1 sps.h *** /tmp/,RCSt1a02918 Thu Jul 5 17:47:30 1990 --- sps.h Thu Jul 5 15:44:28 1990 *************** *** 22,30 **** ** in a hash table, this should probably be at least double the number ** of actual users defined in /etc/passwd or by the Yellow Pages.) */ ! # define MAXUSERS 100 /* Maximum # ttys to be considered, plus 1 for the console ... */ ! # define MAXTTYS 65 /* Maximum user name length ... */ --- 22,30 ---- ** in a hash table, this should probably be at least double the number ** of actual users defined in /etc/passwd or by the Yellow Pages.) */ ! # define MAXUSERS 5000 /* Maximum # ttys to be considered, plus 1 for the console ... */ ! # define MAXTTYS 129 /* Maximum user name length ... */ *************** *** 146,153 **** --- 146,157 ---- struct seg_ops *i_segvn_ops ; /* ptr to vnode segment ops */ struct pty *i_ptybase ; int i_npty ; + # ifndef SUNOS41 struct stdata *i_streams ; /* streams list */ struct stdata *i_streamsNSTREAMS ; + # else + struct stdata *i_allstream ; /* streams list */ + # endif caddr_t i_sysbase ; # endif } ; =================================================================== RCS file: stream.c,v retrieving revision 1.1 diff -c -r1.1 stream.c *** /tmp/,RCSt1a02918 Thu Jul 5 17:47:30 1990 --- stream.c Thu Jul 5 16:40:25 1990 *************** *** 8,13 **** --- 8,82 ---- # include static struct stdata *pstreams ; + + # ifdef SUNOS41 + + init_streams_tab() + { + struct stdata *s, *nexts, *p ; + struct vnode *v ; + extern struct info Info ; + + if ( pstreams ) + { + for ( s = pstreams ; s ; s = nexts ) + { + if ( s->sd_vnode != 0 ) + free( (char *)s->sd_vnode ) ; + nexts = s->sd_next ; + free( (char *)s ) ; + } + pstreams = 0; + } + + if ( getkmem( (long)Info.i_allstream, (char *)&p, sizeof( p )) + != sizeof( struct stdata * ) ) + return( 0 ); + s = pstreams = (struct stdata *)getcore( sizeof( struct stdata ) ) ; + while ( p ) + { + if ( getkmem( (long)p, (char *)s, sizeof( struct stdata ) ) + != sizeof( struct stdata ) ) + return ( 0 ); + if ( s->sd_vnode != 0 ) + { + if ( ( v = (struct vnode*)getcore( sizeof( *v ) ) ) + && getkmem( (long)s->sd_vnode, (char*)v, sizeof( *v ) ) + != sizeof( *v ) ) + { + s->sd_vnode = 0 ; + } + + s->sd_vnode = v ; + } + p = s->sd_next ; + if ( p ) + { + s->sd_next = (struct stdata *) + getcore( sizeof( struct stdata ) ) ; + } + s = s->sd_next ; + } + return( 1 ) ; + } + + struct stdata *getstdata ( st, dev ) + + struct streamtab *st ; + dev_t dev ; + + { + register struct stdata *s ; + + for ( s = pstreams ; s ; s = s->sd_next ) + if ( s->sd_strtab == st && s->sd_vnode + && s->sd_vnode->v_rdev == dev ) + return( s ); + return( 0 ) ; + } + + #else /* ! SUNOS41 */ + static struct stdata *pstreamsNSTREAMS ; init_streams_tab() *************** *** 68,73 **** --- 137,144 ---- return( 0 ) ; } + + #endif /* SUNOS41 */ /* 1 if `w' is in the address range defined by `a1' and `a2' ... */ # define INRANGE( w, a1, a2 ) \ -- UUCP: ...!mcsun!ukc!warwick!cudcv PHONE: +44 203 523037 JANET: cudcv@uk.ac.warwick INET: cudcv@warwick.ac.uk Rob McMahon, Computing Services, Warwick University, Coventry CV4 7AL, England