From: wht@n4hgf.uucp (Warren Tucker) Newsgroups: alt.sources Subject: u386mon x0.11, trying again, part 1/2 Message-ID: <106@n4hgf.uucp> Date: 21 Jun 90 02:28:53 GMT Archive-name: u386mon011/part01 Well, here is another, slightly enhanced u386mon, a hack monitor for SCO UNIX V/386. It may work with other UNIX systems with a little work. It requires terminfo style curses and will use color if you have it. This time I promise all the sources are here. Thanks for all the mail telling me I skipped supplying 1/3 the source. #!/bin/sh # This is u386mon.x0.11, a shell archive (shar 3.30) # made 06/21/1990 02:17 UTC by wht@n4hgf # Source directory /u1/src/u386mon # # existing files WILL be overwritten # # This shar contains: # length mode name # ------ ---------- ------------------------------------------ # 6508 -rw-r--r-- README # 5273 -rw-r--r-- Makefile # 2358 -rw-r--r-- bootinfo.c # 3591 -rw-r--r-- detail.c # 12760 -rw-r--r-- det_proc.c # 4227 -rw-r--r-- disputil.c # 2280 -rw-r--r-- libkmem.c # 2290 -rw-r--r-- libmem.c # 2146 -rw-r--r-- libnlsym.c # 2390 -rw-r--r-- nlsym.c # 3085 -rw-r--r-- proc.c # 1602 -rw-r--r-- tune.c # 23942 -rw-r--r-- u386mon.c # 1453 -rw-r--r-- var.c # 584 -rw-r--r-- libkmem.h # 580 -rw-r--r-- libmem.h # 551 -rw-r--r-- libnlsym.h # 5612 -rw-r--r-- lint_args.h # 4869 -rw-r--r-- nlsym.h # 2941 -rw-r--r-- u386mon.h # if touch 2>&1 | fgrep 'mmdd' > /dev/null then TOUCH=touch else TOUCH=true fi # ============= README ============== echo "x - extracting README (Text)" sed 's/^X//' << 'SHAR_EOF' > README && XWhat X==== X XWell, here is another, slightly enhanced u386mon, a hack monitor for SCO XUNIX V/386. It may work with other UNIX systems with a little work. It Xrequires terminfo style curses and will use color if you have it. X XThis time I promise all the sources are here. XThanks for all the mail telling me I skipped supplying 1/3 the source. X XApology X======= X XThis is a horribly unreleasable, preliminary, experimental, hacked Xlittle light show, but it has already helped me diagnose the Xtraditional "stop-the-world-and-beat-disk-continually-for-15-seconds" Xproblem as memory exhaustion. X XThe process status display shows zero user and system times, but I Xhaven't figured out why yet. X XSample output X============= X(with 43-line screen) X X u386mon x0.09 n4hgf - i386 3.2 wht@n4hgf X---- CPU --- tot usr ker brk --------------------------------------------------- X Instant % 17 4 13 0 uukkkkkk X 5 Sec Avg % 71 48 23 0 uuuuuuuuuuuuuuuuuuuuuuuukkkkkkkkkkk X10 Sec Avg % 82 66 16 0 uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuukkkkkkkk X---- Wait -- tot io swp pio -- (% of real time) ------------------------------- X Instant % 0 0 0 0 X 5 Sec Avg % 2 2 0 0 i X10 Sec Avg % 1 1 0 0 X---- Sysinfo/Minfo --- (last 1 second activity) -------------------------------- Xbread 0 rawch 0 pswitch 8 vfault 0 unmodfl 0 Xbwrite 7 canch 0 syscall 16 demand 0 psoutok 0 Xlread 0 outch 3076 sysread 4 pfault 0 psinfai 0 Xlwrite 7 syswrit 5 cw 0 psinok 0 Xphread 0 msg 0 sysfork 0 steal 0 rsout 0 Xphwrit 0 sema 0 sysexec 0 frdpgs 0 rsin 0 Xiget 0 vfpg 0 Xnamei 0 maxmem 5716k runque 1 sfpg 0 pages on Xdirblk 0 frmem 3036k runocc 1 vspg 0 swap 0 Xreadch 34680 mem used 47% swpque 0 sspg 0 cache 0 Xwritch 3076 nswap 10000k swpocc 0 unmodsw 0 file 0 X frswp 10000k X swp used 0% X X X X-- var --------- -- bootinfo ---------- -- tune --------- -- proc --- Xv_buf 600 basemem 655360 t_gpgslo 25 sleep 23 Xv_inode 200 extmem 6291456 t_gpgshi 40 run 0 Xv_file 200 bflags 00000000 t_gpgsmsk 0x420 zombie 0 Xv_mount 5 memory avail t_ageintvl 9 stop 0 Xv_proc 100 00000000 000a0000 t_maxsc 1 idle 0 Xv_clist 200 00100000 00600000 t_maxfc 1 onproc 1 Xv_sptmap 50 00f40000 00060000 NODM t_maxumem 2560 xbrk 0 Xv_vhndfrac 16 memory used t_bdflushr 1 total 24 Xv_maxpmem 0 00000000 00004000 RSVD t_minarmem 25 in mem 24 X 006b9000 00038000 KBSS t_minasmem 25 X 006f1000 0000f000 KDTA X 00fa5000 0005b000 KTXT X X XWhat the display means X====================== X XA brief description of reported information: X X1. The CPU utilization is shown with smoothing of 1 ("instant"), X 5 and 10 seconds. Total CPU usage is shown, with user, kernel X and "break" subdivided. Most performance utilities (vmstat) X lump kernel (CPU_KERNEL) and wait (CPU_WAIT) times together X as kernel time. u386mon considers CPU_WAIT time as idle (the X CPU could have been doing something if an otherwise ready process X wasn't waited). X X On a color display, total cpu utilization is displayed in X green if the cpu utilization is below 70%, yellow (brown, sigh) X if utilization is between 70% and 89% and red if 90% or above. X X2. The Wait display shows the 1 ("instant"), 5 and 10 second smoothed X percentages of real time no process could be run because otherwise X ready to run processes were waiting on logical, swap or physical I/O. X X3. Sysinfo/Minfo display shows, generally, the number of events for a X measured value since the last display update. For example, runque X shows the number of times a process was placed on the run queue. X An exception is the memory and swap space fields: These numbers X reflect absolute current utilization. X X4. If you run u386mon on a 43 line display, extra information is displayed X on the bottom of the screen (from the struct var v, bootinfo X and proc kernel databases). X X5. On a color display, static numeric values, such as maxmem appear X in blue (the same color as screen literals/labels). Dynamic X numeric values are displayed in green, red or yellow. X X6. An "INEXACT" indication on the top line means that u386mon was X not scheduled quickly enough to capture accurate 1 second X values. Continued INEXACT indication suggests the 5 and 10 X second smoothed values are also wrong. X X An "INVALID" indication means u386mon was not scheduled for 4 X seconds or more. All dynamic values are suspect. X X7. Pressing 'p' causes a process status display of sorts to be X shown. This is very preliminary. Press 'm' to return to the X main screen. X X XA $0.0002 tour X============== X XAccess to kernel memory is required for u386mon to do its thing. X XThe 'nlist' procedure is performed by a separate program (nlsym) Xand the resulting nlist structure array is stored in /unix.nlsym. Xu386mon thus may obtain nlist information rapidly without nlist(S) each Xtime it is executed. Also stored in /unix.nlsym is a stat structure of X/unix at the time of nlsym execution. A unique word is stored at the Xend of the file in case /unix.nlsym's nlist structure is expanded for Xother applications. The u386mon program reads /unix.nlsym by means Xof facilities in libnlsym.c. If the stat structure in /unix.nlsym Xdoes not match a dynamic stat of /unix or if the unique word does Xnot match, the nlist information is not trusted and u386mon prompts Xthe user to run (or have run) the nlsym program to update /unix.nlsym. X XHow to get going X================ X X1. you must run the make as root X X2. nlsym must be run by root (the Makefile will do this the first time) X X3. making against Makefile as root will X a. make nlsym X b. make u386mon and set-gid to group 'mem' X c. run nlsym to produce /unix.nlsym X X4. Sources are in 4-spaced tab format (please don't flame :-)). X XComments are appreciated. XWarren Tucker N4HGF emory!n4hgf!wht -or- wht%n4hgf.uucp@emory.mathcs.emory.edu X SHAR_EOF $TOUCH -am 0620214890 README && chmod 0644 README || echo "restore of README failed" set `wc -c README`;Wc_c=$1 if test "$Wc_c" != "6508"; then echo original size 6508, current size $Wc_c fi # ============= Makefile ============== echo "x - extracting Makefile (Text)" sed 's/^X//' << 'SHAR_EOF' > Makefile && X#+-------------------------------------------------------------- X# Makefile for nlsym utilities for SCO UNIX V/386 X# ...!emory!n4hgf!wht X#--------------------------------------------------------------- X#+:EDITS: X#:06-19-1990-21:37-wht@n4hgf-get ready for 0.08 release X XVERSION = x0.11 X X#handle Sys V make "feature" of using SHELL XSHELL = /bin/sh X XCFLAGS = -c -Octl -DLINT_ARGS X XLIB = -lpanel -lcurses -lx X#FCRC = fcrc -u $*.c ; X X.c.o:; $(FCRC) cc $(CFLAGS) $*.c X XSRC = \ X bootinfo.c\ X detail.c\ X det_proc.c\ X disputil.c\ X libkmem.c\ X libmem.c\ X libnlsym.c\ X nlsym.c\ X proc.c\ X tune.c\ X u386mon.c\ X var.c X XHDR = \ X libkmem.h\ X libmem.h\ X libnlsym.h\ X lint_args.h\ X nlsym.h\ X u386mon.h X XNLSYM_OBJ =\ X nlsym.o X XU386MON_OBJ =\ X u386mon.o\ X detail.o\ X det_proc.o\ X bootinfo.o\ X proc.o\ X tune.o\ X var.o\ X disputil.o\ X libkmem.o\ X libmem.o\ X libnlsym.o X Xall: nlsym u386mon /unix.nlsym X Xnlsym: $(NLSYM_OBJ) X cc -o $@ $(NLSYM_OBJ) $(LIB) X Xu386mon: $(U386MON_OBJ) X cc -o $@ $(U386MON_OBJ) $(LIB) X chmod 2711 u386mon X chgrp mem u386mon X X/unix.nlsym: nlsym /unix X nlsym X chmod 644 /unix.nlsym X X#not delivered Xsrc.fls: $(SRC) Makefile X ls $(SRC) > src.fls X Xlint: src.fls X echo ' ' > lint_args.h X csh zgcc src.fls lint_args.h $(CFLAGS) X Xclean: X rm -f $(U386MON_OBJ) $(NLSYM_OBJ) X Xclobber: clean X rm -f nlsym u386mon u386mon.sh.0[1234] X X#for shar 3.27 or later Xshar: X shar -l 50 -n u386mon.$(VERSION) -o u386mon.sh \ X README Makefile $(SRC) $(HDR) X X# MAKE DEPEND: regenerate .c:.h, .ol:.c, .ol:.asm dependencies automatically X# Xdepend: X rm -f depend.tmp X if test '$(SRC)' ;\ X then (grep '^#include' $(SRC) \ X | sed -e 's?:[^<]*<\([^>]*\)>.*?: /usr/include/\1?'\ X -e 's?:[^"]*"\([^"]*\)".*?: \1?'\ X -e 's?\(.*\)\.c?\1.o?'\ X >> depend.tmp) ;\ X fi X X echo '/^# DO NOT DELETE THIS LINE' >exdep.tmp X echo '.+1,$$d' >>exdep.tmp X echo 'r depend.tmp' >> exdep.tmp X echo 'w' >> exdep.tmp X cp Makefile Makefile.new X ex Makefile.new < exdep.tmp X rm exdep.tmp depend.tmp X echo '# DEPENDENCIES MUST END AT END OF FILE' >>Makefile.new X echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY'>>Makefile.new X echo '# see make depend above'>>Makefile.new X mv Makefile Makefile.bak X mv Makefile.new Makefile X X# DO NOT DELETE THIS LINE Xbootinfo.o: /usr/include/curses.h Xbootinfo.o: /usr/include/panel.h Xbootinfo.o: /usr/include/sys/types.h Xbootinfo.o: /usr/include/sys/bootinfo.h Xbootinfo.o: u386mon.h Xdetail.o: /usr/include/curses.h Xdetail.o: /usr/include/panel.h Xdetail.o: /usr/include/signal.h Xdetail.o: /usr/include/string.h Xdetail.o: /usr/include/fcntl.h Xdetail.o: /usr/include/nlist.h Xdetail.o: /usr/include/errno.h Xdetail.o: /usr/include/time.h Xdetail.o: /usr/include/sys/types.h Xdetail.o: /usr/include/sys/utsname.h Xdetail.o: /usr/include/sys/stat.h Xdetail.o: /usr/include/sys/ascii.h Xdetail.o: /usr/include/sys/param.h Xdetail.o: /usr/include/sys/bootinfo.h Xdetail.o: /usr/include/sys/tuneable.h Xdetail.o: /usr/include/sys/sysinfo.h Xdetail.o: /usr/include/sys/sysmacros.h Xdetail.o: /usr/include/sys/immu.h Xdetail.o: /usr/include/sys/region.h Xdetail.o: /usr/include/sys/proc.h Xdetail.o: /usr/include/sys/var.h Xdetail.o: nlsym.h Xdetail.o: libkmem.h Xdetail.o: libnlsym.h Xdetail.o: u386mon.h Xdisputil.o: /usr/include/curses.h Xdisputil.o: /usr/include/panel.h Xdisputil.o: u386mon.h Xlibkmem.o: /usr/include/sys/types.h Xlibkmem.o: /usr/include/fcntl.h Xlibkmem.o: libkmem.h Xlibnlsym.o: /usr/include/stdio.h Xlibnlsym.o: /usr/include/sys/types.h Xlibnlsym.o: /usr/include/sys/stat.h Xlibnlsym.o: /usr/include/fcntl.h Xlibnlsym.o: /usr/include/nlist.h Xlibnlsym.o: nlsym.h Xlibnlsym.o: libnlsym.h Xnlsym.o: /usr/include/stdio.h Xnlsym.o: /usr/include/sys/types.h Xnlsym.o: /usr/include/sys/stat.h Xnlsym.o: /usr/include/fcntl.h Xnlsym.o: /usr/include/nlist.h Xnlsym.o: nlsym.h Xproc.o: /usr/include/curses.h Xproc.o: /usr/include/panel.h Xproc.o: /usr/include/sys/types.h Xproc.o: /usr/include/sys/param.h Xproc.o: /usr/include/sys/immu.h Xproc.o: /usr/include/sys/region.h Xproc.o: /usr/include/sys/proc.h Xproc.o: /usr/include/nlist.h Xproc.o: nlsym.h Xproc.o: libkmem.h Xproc.o: libnlsym.h Xproc.o: u386mon.h Xtune.o: /usr/include/curses.h Xtune.o: /usr/include/panel.h Xtune.o: /usr/include/sys/types.h Xtune.o: /usr/include/sys/tuneable.h Xtune.o: u386mon.h Xu386mon.o: /usr/include/curses.h Xu386mon.o: /usr/include/panel.h Xu386mon.o: /usr/include/signal.h Xu386mon.o: /usr/include/string.h Xu386mon.o: /usr/include/fcntl.h Xu386mon.o: /usr/include/nlist.h Xu386mon.o: /usr/include/errno.h Xu386mon.o: /usr/include/time.h Xu386mon.o: /usr/include/sys/types.h Xu386mon.o: /usr/include/sys/utsname.h Xu386mon.o: /usr/include/sys/stat.h Xu386mon.o: /usr/include/sys/ascii.h Xu386mon.o: /usr/include/sys/param.h Xu386mon.o: /usr/include/sys/bootinfo.h Xu386mon.o: /usr/include/sys/tuneable.h Xu386mon.o: /usr/include/sys/sysinfo.h Xu386mon.o: /usr/include/sys/sysmacros.h Xu386mon.o: /usr/include/sys/immu.h Xu386mon.o: /usr/include/sys/region.h Xu386mon.o: /usr/include/sys/proc.h Xu386mon.o: /usr/include/sys/var.h Xu386mon.o: nlsym.h Xu386mon.o: libkmem.h Xu386mon.o: libnlsym.h Xu386mon.o: u386mon.h Xvar.o: /usr/include/curses.h Xvar.o: /usr/include/panel.h Xvar.o: /usr/include/sys/types.h Xvar.o: /usr/include/sys/var.h Xvar.o: u386mon.h X# DEPENDENCIES MUST END AT END OF FILE X# IF YOU PUT STUFF HERE IT WILL GO AWAY X# see make depend above SHAR_EOF $TOUCH -am 0620214890 Makefile && chmod 0644 Makefile || echo "restore of Makefile failed" set `wc -c Makefile`;Wc_c=$1 if test "$Wc_c" != "5273"; then echo original size 5273, current size $Wc_c fi # ============= bootinfo.c ============== echo "x - extracting bootinfo.c (Text)" sed 's/^X//' << 'SHAR_EOF' > bootinfo.c && X/*+------------------------------------------------------------------------- X bootinfo.c - u386mon bootinfo struct display X X Defined functions: X bmemf_text(flags) X display_bootinfo(win,y,x) X X--------------------------------------------------------------------------*/ X/*+:EDITS:*/ X/*:06-17-1990-14:59-wht-creation */ X X#define M_TERMINFO X X#include X#include X#include X#include X#include "u386mon.h" X X/*+------------------------------------------------------------------------- X bmemf_text(flags) X--------------------------------------------------------------------------*/ Xchar * Xbmemf_text(flags) Xulong flags; X{ X flags &= ~B_MEM_DOWN; X if(!flags) X return(" "); X switch(flags) X { X case B_MEM_RSRVD: return("RSVD"); X case B_MEM_KTEXT: return("KTXT"); X case B_MEM_KDATA: return("KDTA"); X case B_MEM_KBSS: return("KBSS"); X case B_MEM_NODMA: return("NODM"); X } X return("????"); X} /* end of bmemf_text */ X X/*+------------------------------------------------------------------------- X display_bootinfo(win,y,x) X--------------------------------------------------------------------------*/ Xvoid Xdisplay_bootinfo(win,y,x) XWINDOW *win; Xint y; Xint x; X{ Xregister itmp; Xregister struct bootmem *bmem; X X use_cp(win,cpBANNER); X wmove(win,y++,x); X waddstr(win,"-- bootinfo ----------"); X wmove(win,y++,x); X disp_static_long(win,"basemem ","%8ld",bootinfo.basemem); X wmove(win,y++,x); X disp_static_long(win,"extmem ","%8ld",bootinfo.extmem); X wmove(win,y++,x); X disp_static_long(win,"bflags ","%08lx",bootinfo.bootflags); X X wmove(win,y++,x); waddstr(win,"memory avail"); X for(itmp = 0; itmp < bootinfo.memavailcnt; itmp++) X { X bmem = &bootinfo.memavail[itmp]; X if(bmem->flags & B_MEM_DOWN) X { X bmem->base -= bmem->extent; X bmem->flags &= ~B_MEM_DOWN; X } X wmove(win,y++,x); X wprintw(win,"%08lx %08lx %s",bmem->base,bmem->extent, X bmemf_text(bmem->flags)); X } X X wmove(win,y++,x); waddstr(win,"memory used"); X for(itmp = 0; itmp < bootinfo.memusedcnt; itmp++) X { X bmem = &bootinfo.memused[itmp]; X if(bmem->flags & B_MEM_DOWN) X { X bmem->base -= bmem->extent; X bmem->flags &= ~B_MEM_DOWN; X } X wmove(win,y++,x); X wprintw(win,"%08lx %08lx %s",bmem->base,bmem->extent, X bmemf_text(bmem->flags)); X } X X} /* end of display_bootinfo */ X X/* vi: set tabstop=4 shiftwidth=4: */ X/* end of bootinfo.c */ SHAR_EOF $TOUCH -am 0620163490 bootinfo.c && chmod 0644 bootinfo.c || echo "restore of bootinfo.c failed" set `wc -c bootinfo.c`;Wc_c=$1 if test "$Wc_c" != "2358"; then echo original size 2358, current size $Wc_c fi # ============= detail.c ============== echo "x - extracting detail.c (Text)" sed 's/^X//' << 'SHAR_EOF' > detail.c && X/*+------------------------------------------------------------------------- X detail.c - UNIX 386 system monitor detail window X--------------------------------------------------------------------------*/ X/*+:EDITS:*/ X/*:06-15-1990-18:32-wht@n4hgf-creation */ X X#define M_TERMINFO X X#include X#include X#include X#include X#include X#include X#include X#include X#include X#include X#include X#include X#include X#include X#undef NGROUPS_MAX X#undef NULL X#include X#include X#include X#include X#include X#include X#include X#include X#include X X#include "nlsym.h" X#include "libkmem.h" X#include "libnlsym.h" X#include "u386mon.h" X X#define DPT_NONE 0 X#define DPT_PROC_STATUS 1 X XPANEL *mkpanel(); X Xextern PANEL *pscr; Xextern WINDOW *wscr; X XPANEL *pdet; XWINDOW *wdet; Xu_char detail_panel_type = DPT_NONE; Xint detail_panel_length; Xint detail_panel_cols; X X/*+------------------------------------------------------------------------- X detail_panel_proc_status_init() X--------------------------------------------------------------------------*/ Xvoid Xdetail_panel_proc_status_init() X{ Xregister y,x; X#define DETAIL_PROC_STATUS_COLS ((LINES >= 43) ? EXTRA4_TLX - 1 : PER_SEC4_TLX) X X detail_panel_length = DETAIL_LENGTH; X/* X detail_panel_cols = DETAIL_PROC_STATUS_COLS; X*/ X detail_panel_cols = COLS; X if(!(pdet = mkpanel(detail_panel_length,detail_panel_cols, X DETAIL_TLY,0))) X { X leave_text("cannot make detail panel",0); X } X wdet = panel_window(pdet); X hide_panel(pdet); X use_cp(wdet,cpBANNER); X for(y = 0; y < getmaxy(wdet); y++) X { X for(x = 0; x < getmaxx(wdet); x++) X { X wmove(wdet,y,x); X waddch(wdet,(chtype)' '); X } X } X show_panel(pdet); X top_panel(pdet); X X display_proc_stats(wdet,1); X X} /* end of detail_panel_proc_status_init */ X X/*+------------------------------------------------------------------------- X detail_panel_proc_status_update() X--------------------------------------------------------------------------*/ Xvoid Xdetail_panel_proc_status_update() X{ X X display_proc_stats(wdet,0); X} /* end of detail_panel_proc_status_update */ X X/*+------------------------------------------------------------------------- X detail_panel_cmd(cmd) X X command: m main screen X p proc status X--------------------------------------------------------------------------*/ Xvoid Xdetail_panel_cmd(cmd) Xchtype cmd; X{ X switch(cmd) X { X case 'm': X if(detail_panel_type == DPT_NONE) X break; X hide_panel(pdet); X delwin(wdet); X del_panel(pdet); X top_panel(pscr); X detail_panel_type = DPT_NONE; X break; X X case 'p': X if(detail_panel_type == DPT_PROC_STATUS) X break; X detail_panel_proc_status_init(); X detail_panel_type = DPT_PROC_STATUS; X break; X } X} /* end of detail_panel_cmd */ X X/*+------------------------------------------------------------------------- X detail_panel_update() X--------------------------------------------------------------------------*/ Xvoid Xdetail_panel_update() X{ X switch(detail_panel_type) X { X case DPT_PROC_STATUS: X detail_panel_proc_status_update(); X break; X } X} /* end of detail_panel_update */ X X/*+------------------------------------------------------------------------- X detail_init() X--------------------------------------------------------------------------*/ Xvoid Xdetail_init() X{ X} /* end of detail_init */ X X/* vi: set tabstop=4 shiftwidth=4: */ X/* end of detail.c */ SHAR_EOF $TOUCH -am 0620194290 detail.c && chmod 0644 detail.c || echo "restore of detail.c failed" set `wc -c detail.c`;Wc_c=$1 if test "$Wc_c" != "3591"; then echo original size 3591, current size $Wc_c fi # ============= det_proc.c ============== echo "x - extracting det_proc.c (Text)" sed 's/^X//' << 'SHAR_EOF' > det_proc.c && X/* CHK=0xC5D1 */ X/*+------------------------------------------------------------------------- X det_proc.c - UNIX V/386 system monitor proc status detail X ...!emory!n4hgf!wht X--------------------------------------------------------------------------*/ X/*+:EDITS:*/ X/*:01-05-1989-13:27-wht-creation */ X X#define M_TERMINFO X X#include X#include X#include X#include X#include X#include X#include X#include X#include X#include X#include X#include X#include X#undef NGROUPS_MAX X#undef NULL X#include X#include X#include X#include X#include X#include X#include X#include X#include X#undef DIRSIZ X#include X#include X#include X X#include "nlsym.h" X#include "libkmem.h" X#include "libnlsym.h" X#include "u386mon.h" X Xextern int errno; X Xextern int nprocs; Xextern struct var v; Xextern struct proc *procs; Xextern struct proc *oldprocs; X Xint mypid; Xint noldprocs = 0; Xint nprocs = 0; X Xstruct user user; X X#define min(a,b) ((a > b) ? b : a) X X#define p_dummy0 p_hold /* reuse a field we dont look at */ X X#define MAX_UTMP 32 Xint nutmps = 0; Xstruct utmp utmps[MAX_UTMP]; X X/*+------------------------------------------------------------------------- X proc_pid_compare(p1,p2) X--------------------------------------------------------------------------*/ Xproc_pid_compare(p1,p2) Xstruct proc *p1; Xstruct proc *p2; X{ X return(p1->p_pid - p2->p_pid); X} /* end of proc_pid_compare */ X X/*+------------------------------------------------------------------------- X read_and_sort_procs(initial) X--------------------------------------------------------------------------*/ Xvoid Xread_and_sort_procs(initial) Xint initial; X{ Xregister int iproc; Xregister int proc_size = v.v_proc * sizeof(struct proc); Xstruct proc *tproc; X X if(!initial) X { X memcpy((char *)oldprocs,(char *)procs,proc_size); X noldprocs = nprocs; X } X X/* read current procs */ X grok_proc(); X X/* if slot not in use, force to end when sorting */ X nprocs = 0; X for(iproc = 0;iproc < v.v_proc;iproc++) X { X tproc = procs + iproc; X tproc->p_dummy0 = iproc; /* save slot number */ X if((tproc->p_stat == 0) || X ((tproc->p_pgrp == tproc->p_pid) && (LINES < 43)) || X (tproc->p_pgrp == 0)) X tproc->p_pid = 32767; X else X nprocs++; X } X X/* sort new procs array */ X qsort((char *)procs,v.v_proc,sizeof(struct proc),proc_pid_compare); X X if(initial) X { X memcpy((char *)oldprocs,(char *)procs,proc_size); X noldprocs = nprocs; X } X X} /* end of read_and_sort_procs */ X X/*+------------------------------------------------------------------------- X read_utmp() X--------------------------------------------------------------------------*/ Xvoid Xread_utmp() X{ Xint utmpfd; Xregister struct utmp *tutmp = utmps; X X nutmps = 0; X if((utmpfd = open("/etc/utmp",O_RDONLY,755)) < 0) X leave_text("/etc/utmp open error",errno); X X while(read(utmpfd,(char *)(tutmp++),sizeof(struct utmp)) > 0) X { X if(++nutmps == MAX_UTMP) X leave_text("too many utmp entries for me to handle",1); X } X close(utmpfd); X} /* end of read_utmp */ X X/*+------------------------------------------------------------------------- X find_utmp_for_pgrp(pgrp) X--------------------------------------------------------------------------*/ Xstruct utmp * Xfind_utmp_for_pgrp(pgrp) Xint pgrp; X{ Xstruct utmp *tutmp = utmps; Xregister int count = nutmps; X X while(count--) X { X if(tutmp->ut_pid == pgrp) X return(tutmp); X tutmp++; X } X return((struct utmp *)0); X} /* end of find_utmp_for_pgrp */ X X/*+------------------------------------------------------------------------- X pgrp_to_ttyname(pgrp) X--------------------------------------------------------------------------*/ Xchar * Xpgrp_to_ttyname(pgrp) Xint pgrp; X{ Xstruct utmp *tutmp; X X if(!(tutmp = find_utmp_for_pgrp(pgrp))) X { X read_utmp(); X tutmp = find_utmp_for_pgrp(pgrp); X } X if(!tutmp) X return("??"); X else X return(&tutmp->ut_id[strlen(tutmp->ut_id) - 2]); X} /* end of pgrp_to_ttyname */ X X/*+------------------------------------------------------------------------- X get_user(tproc,slot,user) X--------------------------------------------------------------------------*/ Xget_user(tproc,slot,user) Xstruct proc *tproc; Xint slot; /* not used */ Xstruct user *user; X{ X int ipde; X int ubrdcount = sizeof(struct user); X caddr_t uptr = (caddr_t)user; X daddr_t mptr; X X if(tproc->p_flag & SLOAD) X { X for(ipde = 0; ipde < tproc->p_usize; ipde++) X { X if(!tproc->p_ubptbl[ipde].pgm.pg_pres) /* if not resident */ X return(0); X mptr = tproc->p_ubptbl[ipde].pgm.pg_pfn * NBPP; X mread(uptr,mptr,min(ubrdcount,NBPP)); X uptr += NBPP; X if((ubrdcount -= NBPP) <= 0) X break; X } X return(1); X } X return(0); X X} /* end of get_user */ X X/*+------------------------------------------------------------------------- Xuid to username conversion; thanks for the idea to William LeFebvre X--------------------------------------------------------------------------*/ X#define UID_NAME_HASH_SIZE 127 /* prime */ X#define HASH_EMPTY -1 X#define HASHIT(i) ((i) % UID_NAME_HASH_SIZE) X Xstruct uid_name_hash_entry { X int uid; X char name[10]; X}; X Xstruct uid_name_hash_entry uid_name_table[UID_NAME_HASH_SIZE]; Xint uid_count = 0; X X/*+------------------------------------------------------------------------- X init_uid_name_hash() X--------------------------------------------------------------------------*/ Xvoid Xinit_uid_name_hash() X{ Xregister int ihash = 0; Xregister struct uid_name_hash_entry *hashent = uid_name_table; X X while(ihash++ < UID_NAME_HASH_SIZE) X { X hashent->uid = HASH_EMPTY; X hashent++; X } X} /* end of init_uid_name_hash */ X X/*+------------------------------------------------------------------------- X uid_name_enter(uid,name) X--------------------------------------------------------------------------*/ Xint Xuid_name_enter(uid,name) Xregister int uid; Xregister char *name; X{ Xregister int table_uid; Xregister int hashval; X X if(++uid_count >= UID_NAME_HASH_SIZE) X leave_text("too many user names",1); X X hashval = HASHIT(uid); X while((table_uid = uid_name_table[hashval].uid) != HASH_EMPTY) X { X if(table_uid == uid) X return(hashval); X hashval = (hashval + 1) % UID_NAME_HASH_SIZE; X } X X uid_name_table[hashval].uid = uid; X strncpy(uid_name_table[hashval].name,name, X sizeof(uid_name_table[0].name)); X X return(hashval); X X} /* end of uid_name_enter */ X X/*+------------------------------------------------------------------------- X getpwent_and_enter(uid) X--------------------------------------------------------------------------*/ Xgetpwent_and_enter(uid) Xregister int uid; X{ Xregister int hashval; Xregister struct passwd *pwd; Xchar errant[10]; Xstruct passwd *getpwuid(); X X pwd = getpwuid(uid); X endpwent(); X if(pwd) X { X hashval = uid_name_enter(pwd->pw_uid,pwd->pw_name); X return(hashval); X } X sprintf(errant,"%d",uid); X return(uid_name_enter(uid,errant)); X} /* end of getpwent_and_enter */ X X/*+------------------------------------------------------------------------- X uid_to_name(uid) X--------------------------------------------------------------------------*/ Xchar * Xuid_to_name(uid) Xregister int uid; X{ Xregister int uid_hash; Xregister int table_uid; Xregister char *name; X X uid_hash = HASHIT(uid); X while((table_uid = uid_name_table[uid_hash].uid) != uid) X { X if(table_uid == HASH_EMPTY) X { X /* not in hash table */ X uid_hash = getpwent_and_enter(uid); X break; /* out of while */ X } X uid_hash = (uid_hash + 1) % UID_NAME_HASH_SIZE; X } X return(uid_name_table[uid_hash].name); X} /* end of char *uid_to_name */ X X/*+----------------------------------------------------------------------- X char *get_cpu_time_str(ticks) X 6-char static string address is returned X------------------------------------------------------------------------*/ Xchar *get_cpu_time_str(ticks) Xtime_t ticks; X{ Xstatic char timestr[10]; Xtime_t mm,ss; Xstatic int hz; X X if(!hz) X { X char *cptr; X char *getenv(); X if(cptr = getenv("HZ")) X hz = atoi(cptr); X else X hz = HZ; X } X X ticks /= hz; X mm = ticks / 60L; X ticks -= mm * 60L; X ss = ticks; X X if(mm > 999) X sprintf(timestr,"%5ldm",mm); X else X sprintf(timestr,"%3lu:%02lu",mm,ss); X return(timestr); X} /* end of get_cpu_time_str */ X X#define PROC_Y 1 X#define PROC_X 0 X#define UID_X 2 X#define PID_X 12 X#define PPID_X 18 X#define CPU_X 24 X#define PRI_X 28 X#define NICE_X 32 X#define UTIME_X 35 X#define STIME_X 42 X#define TTY_X 49 X#define CMD_X 53 X X/*+------------------------------------------------------------------------- X display_proc_stat(win,iproc,initial) X00000000001111111111222222222233333333334444444444555555555566666666667777777777 X01234567890123456789012345678901234567890123456789012345678901234567890123456789 XS USER PID PPID CPU PRI NI UCPU SCPU TTY CMD X# ########X ##### ##### ### ### ## ###### ###### ### ######## X--------------------------------------------------------------------------*/ Xvoid Xdisplay_proc_stat(win,iproc,initial) XWINDOW *win; Xregister int iproc; Xregister int initial; X{ Xregister int positioned = 0; Xregister int itmp; Xregister int got_user; Xstruct proc *tproc = procs + iproc; Xstruct proc *oproc = oldprocs + iproc; Xstatic char *p_stat_str = " sRzji*x"; /* dependent on values of SSLEEP etc */ Xchar buf[20]; X X use_cp(win,cpINFO); X if((itmp = (tproc->p_stat == SRUN)) || X ((tproc->p_stat != SRUN) && (oproc->p_stat == SRUN))) X { X initial = 1; X use_cp(win,cpMED); X } X X if(initial || (tproc->p_stat != oproc->p_stat)) X { X wmove(win,PROC_Y + iproc,PROC_X); X waddch(win,p_stat_str[tproc->p_stat]); X waddch(win,' '); X positioned = 1; X } X X if(initial || (tproc->p_uid != oproc->p_uid)) X { X if(!positioned) X wmove(win,PROC_Y + iproc,PROC_X + UID_X); X sprintf(buf,"%8s",uid_to_name(tproc->p_uid)); X waddstr(win,buf); X waddch(win,(tproc->p_uid != tproc->p_suid) ? '#' : ' '); X waddch(win,' '); X positioned = 1; X } X else X positioned = 0; X X if(initial || (tproc->p_pid != oproc->p_pid)) X { X if(!positioned) X wmove(win,PROC_Y + iproc,PROC_X + PID_X); X sprintf(buf,"%5d ",tproc->p_pid); X waddstr(win,buf); X positioned = 1; X } X else X positioned = 0; X X if(initial || (tproc->p_ppid != oproc->p_ppid)) X { X if(!positioned) X wmove(win,PROC_Y + iproc,PROC_X + PPID_X); X sprintf(buf,"%5d ",tproc->p_ppid); X waddstr(win,buf); X positioned = 1; X } X else X positioned = 0; X X if(initial || (tproc->p_cpu != oproc->p_cpu)) X { X if(!positioned) X wmove(win,PROC_Y + iproc,PROC_X + CPU_X); X sprintf(buf,"%3u ",tproc->p_cpu); X waddstr(win,buf); X positioned = 1; X } X else X positioned = 0; X X if(initial || (tproc->p_pri != oproc->p_pri)) X { X if(!positioned) X wmove(win,PROC_Y + iproc,PROC_X + PRI_X); X sprintf(buf,"%3u ",tproc->p_pri); X waddstr(win,buf); X positioned = 1; X } X else X positioned = 0; X X if(initial || (tproc->p_nice != oproc->p_nice)) X { X if(!positioned) X wmove(win,PROC_Y + iproc,PROC_X + NICE_X); X sprintf(buf,"%2d ",tproc->p_nice); X waddstr(win,buf); X positioned = 1; X } X else X positioned = 0; X X/* since not saving user area, always update fields from it */ X if(!positioned) X wmove(win,PROC_Y + iproc,PROC_X + UTIME_X); X if(got_user = get_user(tproc,iproc,&user)) X { X waddstr(win,get_cpu_time_str(user.u_utime)); X waddch(win,' '); X waddstr(win,get_cpu_time_str(user.u_stime)); X waddch(win,' '); X } X else X waddstr(win,"------ ------ "); X positioned = 1; X X if(!positioned) X wmove(win,PROC_Y + iproc,PROC_X + TTY_X); X sprintf(buf,"%3.3s ",pgrp_to_ttyname(tproc->p_pgrp)); X waddstr(win,buf); X positioned = 1; X X if(!positioned) X wmove(win,PROC_Y + iproc,PROC_X + CMD_X); X if(got_user) X { X register char *cptr = user.u_psargs; X int y,x,maxx = getmaxx(win); X getyx(win,y,x); X while(*cptr && (x < maxx)) X { X *cptr &= 0x7F; X if(*cptr < 0x20) X *cptr = 0x20; X waddch(win,*cptr); X cptr++,x++; X } X } X else X { X switch(tproc->p_stat) X { X case SIDL: X waddstr(win,""); X break; X case SZOMB: X waddstr(win,""); X break; X default: X waddstr(win,""); X } X } X X wclrtoeol(win); X X} /* end of display_proc_stat */ X X/*+------------------------------------------------------------------------- X display_proc_stats(win,initial) X--------------------------------------------------------------------------*/ Xvoid Xdisplay_proc_stats(win,initial) XWINDOW *win; Xint initial; X{ Xregister int iproc; X X if(initial) X { X use_cp(win,cpBANNER); X wmove(win,0,0); X waddstr(win, X "S USER PID PPID CPU PRI NI UCPU SCPU TTY CMD"); X } X mypid = getpid(); X read_and_sort_procs(1); X for(iproc = 0; iproc < min(nprocs,getmaxy(win) - PROC_Y); iproc++) X display_proc_stat(win,iproc,1); X wclrtobot(win); X} /* end of display_proc_stats */ X X/* vi: set tabstop=4 shiftwidth=4: */ X/* end of det_proc.c */ SHAR_EOF $TOUCH -am 0620220890 det_proc.c && chmod 0644 det_proc.c || echo "restore of det_proc.c failed" set `wc -c det_proc.c`;Wc_c=$1 if test "$Wc_c" != "12760"; then echo original size 12760, current size $Wc_c fi # ============= disputil.c ============== echo "x - extracting disputil.c (Text)" sed 's/^X//' << 'SHAR_EOF' > disputil.c && X/*+------------------------------------------------------------------------- X disputil.c - u386mon display utilities X X Defined functions: X clear_area(win,y,x,len) X clear_area_char(win,y,x,len,fillchar) X disp_info_int(win,label,fmt,value) X disp_info_long(win,label,fmt,value) X disp_static_int(win,label,fmt,value) X disp_static_long(win,label,fmt,value) X mkpanel(rows,cols,tly,tlx) X pflush() X wperror(win,desc) X X--------------------------------------------------------------------------*/ X/*+:EDITS:*/ X/*:06-17-1990-15:15-wht-creation */ X X#define M_TERMINFO X X#include X#include X#include X#include "u386mon.h" X X/*+------------------------------------------------------------------------- X clear_area_char(win,y,x,len,fillchar) X--------------------------------------------------------------------------*/ Xvoid Xclear_area_char(win,y,x,len,fillchar) XWINDOW *win; Xint y; Xint x; Xint len; Xu_char fillchar; X{ X wmove(win,y,x); X while(len-- > 0) X waddch(win,(chtype)fillchar); X wmove(win,y,x); X X} /* end of clear_area_char */ X X/*+------------------------------------------------------------------------- X clear_area(win,y,x,len) X--------------------------------------------------------------------------*/ Xvoid Xclear_area(win,y,x,len) XWINDOW *win; Xint y; Xint x; Xint len; X{ X clear_area_char(win,y,x,len,' '); X} /* end of clear_area_char */ X X/*+------------------------------------------------------------------------- X pflush() - do update_panels() and doupdate() X--------------------------------------------------------------------------*/ Xvoid Xpflush() X{ X update_panels(); X curs_set(0); X doupdate(); X curs_set(1); X} /* end of pflush */ X X/*+------------------------------------------------------------------------- X wperror(win,desc) X--------------------------------------------------------------------------*/ Xvoid Xwperror(win,desc) XWINDOW *win; Xchar *desc; X{ Xextern int errno; Xextern int sys_nerr; Xextern char *sys_errlist[]; X X waddstr(win,desc); X waddstr(win,": "); X if(errno < sys_nerr) X waddstr(win,sys_errlist[errno]); X else X wprintw(win,"error %u",errno); X X} /* end of wperror */ X X/*+------------------------------------------------------------------------- X mkpanel(rows,cols,tly,tlx) - alloc a win and panel and associate them X--------------------------------------------------------------------------*/ XPANEL * Xmkpanel(rows,cols,tly,tlx) Xint rows; Xint cols; Xint tly; Xint tlx; X{ XWINDOW *win = newwin(rows,cols,tly,tlx); XPANEL *pan; X X if(!win) X return((PANEL *)0); X if(pan = new_panel(win)) X return(pan); X delwin(win); X return((PANEL *)0); X} /* end of mkpanel */ X X/*+------------------------------------------------------------------------- X disp_info_long(win,label,fmt,value) X--------------------------------------------------------------------------*/ Xvoid Xdisp_info_long(win,label,fmt,value) XWINDOW *win; Xchar *label; Xchar *fmt; Xlong value; X{ X use_cp(win,cpLIT); X waddstr(win,label); X use_cp(win,cpINFO); X wprintw(win,fmt,value); X} /* end of disp_info_long */ X X/*+------------------------------------------------------------------------- X disp_info_int(win,label,fmt,value) X--------------------------------------------------------------------------*/ Xvoid Xdisp_info_int(win,label,fmt,value) XWINDOW *win; Xchar *label; Xchar *fmt; Xint value; X{ X use_cp(win,cpLIT); X waddstr(win,label); X use_cp(win,cpINFO); X wprintw(win,fmt,value); X} /* end of disp_info_int */ X X/*+------------------------------------------------------------------------- X disp_static_long(win,label,fmt,value) X--------------------------------------------------------------------------*/ Xvoid Xdisp_static_long(win,label,fmt,value) XWINDOW *win; Xchar *label; Xchar *fmt; Xlong value; X{ X use_cp(win,cpLIT); X waddstr(win,label); X wprintw(win,fmt,value); X} /* end of disp_static_long */ X X/*+------------------------------------------------------------------------- X disp_static_int(win,label,fmt,value) X--------------------------------------------------------------------------*/ Xvoid Xdisp_static_int(win,label,fmt,value) XWINDOW *win; Xchar *label; Xchar *fmt; Xint value; X{ X use_cp(win,cpLIT); X waddstr(win,label); X wprintw(win,fmt,value); X} /* end of disp_static_int */ X X/* vi: set tabstop=4 shiftwidth=4: */ X/* end of disputil.c */ SHAR_EOF $TOUCH -am 0620155490 disputil.c && chmod 0644 disputil.c || echo "restore of disputil.c failed" set `wc -c disputil.c`;Wc_c=$1 if test "$Wc_c" != "4227"; then echo original size 4227, current size $Wc_c fi # ============= libkmem.c ============== echo "x - extracting libkmem.c (Text)" sed 's/^X//' << 'SHAR_EOF' > libkmem.c && X/*+------------------------------------------------------------------------- X libkmem.c -- /dev/kmem routines for SCO UNIX V/286 (maybe other *NIX) X ...!emory!n4hgf!wht X X Defined functions: X kinit(write_needed) X kread(caddr,kaddr,len) X kwrite(kaddr,caddr,len) X X routines were originally written by Mike "Ford" Ditto: kudos!!! X--------------------------------------------------------------------------*/ X/*+:EDITS:*/ X/*:12-07-1988-22:06-wht-put in test for initialized fdkmem */ X/*:10-27-1988-22:44-wht-creation of file */ X X#include X#include X#include "libkmem.h" X Xextern int errno; X Xstatic int fdkmem = -2; Xdaddr_t lseek(); X X/*+------------------------------------------------------------------------- X kinit(write_needed) X--------------------------------------------------------------------------*/ Xvoid Xkinit(write_needed) Xint write_needed; X{ X if(fdkmem >= 0) X return; X if((fdkmem=open("/dev/kmem",(write_needed) ? O_RDWR : O_RDONLY,0)) < 0) X leave_text("can't open /dev/kmem",1); X X} /* end of kinit */ X X/*+------------------------------------------------------------------------- X kread(caddr,kaddr,len) X--------------------------------------------------------------------------*/ Xvoid Xkread(caddr,kaddr,len) Xcaddr_t caddr; Xdaddr_t kaddr; Xint len; X{ Xchar s80[80]; X X#if defined(M_I286) X kaddr &= 0xFFFFL; X#endif X X if(fdkmem == -2) X leave_text("kinit() not called",1); X X if(lseek(fdkmem,kaddr,0) == -1L) X { X sprintf(s80,"kmem seek err (%08lx)",kaddr); X leave_text(s80,1); X } X X if(read(fdkmem,caddr,len) != len) X { X sprintf(s80,"kmem read errno %d len %d addr %08lx",errno,len,kaddr); X leave_text(s80,1); X } X} /* end of kread */ X X/*+------------------------------------------------------------------------- X kwrite(kaddr,caddr,len) X--------------------------------------------------------------------------*/ X#ifdef KWRITE_NEEDED Xvoid Xkwrite(kaddr,caddr,len) Xdaddr_t kaddr; Xcaddr_t caddr; Xint len; X{ Xchar s80[80]; X X#if defined(M_I286) X kaddr &= 0xFFFFL; X#endif X X if(fdkmem == -2) X leave_text("kinit() not called",1); X X if((lseek(fdkmem,kaddr,0) < 0L) || (write(fdkmem,caddr,len) != len)) X { X sprintf(s80,"/dev/kmem write addr %08lx len %08lx",kaddr,len); X leave_text(s80,1); X } X} /* end of kwrite */ X#endif X X/* vi: set tabstop=4 shiftwidth=4: */ SHAR_EOF $TOUCH -am 0620184790 libkmem.c && chmod 0644 libkmem.c || echo "restore of libkmem.c failed" set `wc -c libkmem.c`;Wc_c=$1 if test "$Wc_c" != "2280"; then echo original size 2280, current size $Wc_c fi # ============= libmem.c ============== echo "x - extracting libmem.c (Text)" sed 's/^X//' << 'SHAR_EOF' > libmem.c && X/*+------------------------------------------------------------------------- X libmem.c -- /dev/mem routines for SCO UNIX V/286 (maybe other *NIX) X ...!gatech!emory!tridom!wht X X Defined functions: X minit(write_needed) X mread(caddr,maddr,len) X mwrite(maddr,caddr,len) X X routines were originally written by Mike "Ford" Ditto: kudos!!! X--------------------------------------------------------------------------*/ X/*+:EDITS:*/ X/*:12-07-1988-22:06-wht-put in test for initialized fdmem */ X/*:10-27-1988-22:44-wht-creation of file */ X X#include X#include X#include "libmem.h" X Xextern int errno; X Xstatic int fdmem = -2; Xdaddr_t lseek(); X X/*+------------------------------------------------------------------------- X minit(write_needed) X--------------------------------------------------------------------------*/ Xvoid Xminit(write_needed) Xint write_needed; X{ X if(fdmem >= 0) X return; X if((fdmem=open("/dev/mem",(write_needed) ? O_RDWR : O_RDONLY,0)) < 0) X leave_text("can't open /dev/mem",1); X X} /* end of minit */ X X/*+------------------------------------------------------------------------- X mread(caddr,maddr,len) X--------------------------------------------------------------------------*/ Xvoid Xmread(caddr,maddr,len) Xcaddr_t caddr; Xdaddr_t maddr; Xint len; X{ Xchar s80[80]; X X#if defined(M_I286) X maddr &= 0xFFFFL; X#endif X X if(fdmem == -2) X leave_text("minit() not called",1); X X if(lseek(fdmem,maddr,0) == -1L) X { X sprintf(s80,"mem seek err (%08lx)",maddr); X leave_text(s80,1); X } X X if(read(fdmem,caddr,len) != len) X { X sprintf(s80,"mem read errno %d len %d addr %08lx",errno,len,maddr); X leave_text(s80,1); X } X} /* end of mread */ X X/*+------------------------------------------------------------------------- X mwrite(maddr,caddr,len) X--------------------------------------------------------------------------*/ X#ifdef MWRITE_NEEDED Xvoid Xmwrite(maddr,caddr,len) Xdaddr_t maddr; Xcaddr_t caddr; Xint len; X{ Xchar s80[80]; X X#if defined(M_I286) X maddr &= 0xFFFFL; X#endif X X if(fdmem == -2) X leave_text("minit() not called",1); X X if((lseek(fdmem,maddr,0) < 0L) || (write(fdmem,caddr,len) != len)) X { X sprintf(s80,"/dev/mem write addr %08lx len %08lx",maddr,len); X leave_text(s80,1); X } X} /* end of mwrite */ X#endif /* MWRITE_NEEDED */ X X/* vi: set tabstop=4 shiftwidth=4: */ SHAR_EOF $TOUCH -am 0620184690 libmem.c && chmod 0644 libmem.c || echo "restore of libmem.c failed" set `wc -c libmem.c`;Wc_c=$1 if test "$Wc_c" != "2290"; then echo original size 2290, current size $Wc_c fi # ============= libnlsym.c ============== echo "x - extracting libnlsym.c (Text)" sed 's/^X//' << 'SHAR_EOF' > libnlsym.c && X/*+------------------------------------------------------------------------- X libnlsym.c -- common runtime for nlsym users X ...!gatech!emory!tridom!wht X X Defined functions: X nlsym_error(text) X nlsym_read() X X--------------------------------------------------------------------------*/ X/*+:EDITS:*/ X/*:10-27-1988-11:44-wht-creation */ X X#include X#include X#include X#include X#include X X#define DEFINE_NLSYM X#include "nlsym.h" X#include "libnlsym.h" X Xextern int errno; Xextern char *sys_errlist[]; X X/*+------------------------------------------------------------------------- X nlsym_error(text) X--------------------------------------------------------------------------*/ Xvoid Xnlsym_error(text) Xchar *text; X{ Xchar s128[128]; X X strcpy(s128,text); X if(errno) X { X strcat(s128," ("); X strcat(s128,sys_errlist[errno]); X strcat(s128,")"); X } X strcat(s128," run nlsym"); X leave_text(s128,1); X} /* end of nlsym_error */ X X/*+------------------------------------------------------------------------- X nlsym_read() X--------------------------------------------------------------------------*/ Xvoid Xnlsym_read() X{ Xchar s80[80]; Xint itmp; Xint fdnlsym; Xstruct stat curstat; /* current /unix status */ Xstruct stat unixstat; /* /unix status at nlsym run time */ Xlong unique; X X if(stat(UNIX_KERNEL,&curstat) < 0) X { X sprintf(s80,"cannot stat %s",UNIX_KERNEL); X nlsym_error(s80); X } X X errno = 0; X if((fdnlsym = open(UNIX_NLSYM,O_RDONLY,0)) < 0) X { X sprintf(s80,"%s open error\n",UNIX_NLSYM); X nlsym_error(s80); X } X X if((itmp = read(fdnlsym,&unixstat,sizeof(unixstat))) != sizeof(unixstat)) X nlsym_error("unix stat error"); X X if((itmp = read(fdnlsym,nlsym,sizeof(nlsym))) != sizeof(nlsym)) X nlsym_error("nlsym error: "); X X if((itmp = read(fdnlsym,&unique,sizeof(unique))) != sizeof(unique)) X nlsym_error("`unique' read error"); X X close(fdnlsym); X X if( (unique != NLSYM_UNIQUE) || X (unixstat.st_ino != curstat.st_ino) || X (unixstat.st_mtime != curstat.st_mtime) || X (unixstat.st_size != curstat.st_size)) X { X sprintf(s80,"%s out of date\n",UNIX_NLSYM); X nlsym_error(s80); X } X X} /* end of nlsym_read */ SHAR_EOF $TOUCH -am 0620150490 libnlsym.c && chmod 0644 libnlsym.c || echo "restore of libnlsym.c failed" set `wc -c libnlsym.c`;Wc_c=$1 if test "$Wc_c" != "2146"; then echo original size 2146, current size $Wc_c fi # ============= nlsym.c ============== echo "x - extracting nlsym.c (Text)" sed 's/^X//' << 'SHAR_EOF' > nlsym.c && X/*+------------------------------------------------------------------------- X nlsym.c -- utility nlist - fast access to kernel /dev/kmem offsets X ...!gatech!emory!tridom!wht X X Defined functions: X main(argc,argv,envp) X nlsym_write_error(code) X X--------------------------------------------------------------------------*/ X/*+:EDITS:*/ X/*:05-12-1989-18:27-wht-fix endless loop error on cannot nlist */ X/*:10-27-1988-10:58-wht-creation */ X X#include X#include X#include X#include X#include X X#define DEFINE_NLSYM X#include "nlsym.h" X X/*+------------------------------------------------------------------------- X nlsym_write_error(code) X--------------------------------------------------------------------------*/ Xvoid Xnlsym_write_error(code) Xint code; X{ X fprintf(stderr,"code %d: ",code); X perror(UNIX_NLSYM); X exit(1); X} /* end of nlsym_write_error */ X X/*+------------------------------------------------------------------------- X main(argc,argv,envp) X--------------------------------------------------------------------------*/ Xmain(argc,argv,envp) Xint argc; Xchar **argv; Xchar **envp; X{ Xregister int itmp; Xregister struct nlist *nn; Xstruct stat unixstat; /* /unix status at nlsym run time */ Xint fdnlsym; Xint nlist_error = 0; Xlong unique; XFILE *kludge; X X nlist(UNIX_KERNEL,nlsym); X X nn = nlsym; X while(nn->n_name) X { X if(!nn->n_sclass) X { X printf("%s: can't nlist\n", nn->n_name); X nlist_error = 1; X nn++; X continue; X } X printf("%-12.12s storage class: %04x value: %08lx\n", X nn->n_name, X nn->n_sclass, X nn->n_value); X nn++; X } X X if(nlist_error) X { X fprintf(stderr,"%s NOT produced\n",UNIX_NLSYM); X exit(1); X } X X if((kludge = fopen(UNIX_NLSYM,"w")) == NULL) /* scratch/create */ X nlsym_write_error(-1); X fclose(kludge); X X if((fdnlsym = open(UNIX_NLSYM,O_WRONLY,0)) < 0) X nlsym_write_error(fdnlsym); X X if(stat(UNIX_KERNEL,&unixstat) < 0) X { X fputs("cannot stat ",stderr); X perror(UNIX_KERNEL); X exit(1); X } X X if((itmp = write(fdnlsym,&unixstat,sizeof(unixstat))) != sizeof(unixstat)) X nlsym_write_error(itmp); X X if((itmp = write(fdnlsym,nlsym,sizeof(nlsym))) != sizeof(nlsym)) X nlsym_write_error(itmp); X X unique = NLSYM_UNIQUE; X if((itmp = write(fdnlsym,&unique,sizeof(unique))) != sizeof(unique)) X nlsym_write_error(itmp); X X close(fdnlsym); X exit(0); X} /* end of main */ X X/* vi: set tabstop=4 shiftwidth=4: */ SHAR_EOF $TOUCH -am 0620150490 nlsym.c && chmod 0644 nlsym.c || echo "restore of nlsym.c failed" set `wc -c nlsym.c`;Wc_c=$1 if test "$Wc_c" != "2390"; then echo original size 2390, current size $Wc_c fi echo "End of part 1, continue with part 2" exit 0 --------------------------------------------------------------------- Warren Tucker, TuckerWare gatech!n4hgf!wht or wht%n4hgf@gatech.edu Any perceptible delay will eventually get on your nerves. --Bob Hyers