home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-07-02 | 51.9 KB | 2,039 lines |
- Newsgroups: comp.sources.misc
- subject: v13i104: u386mon 1.12 part 02.04
- From: wht@gatech.edu@n4hgf.UUCP (Warren Tucker)
- Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
-
- Posting-number: Volume 13, Issue 104
- Submitted-by: wht@gatech.edu@n4hgf.UUCP (Warren Tucker)
- Archive-name: u386mon-1.12/part02
-
- #!/bin/sh
- # This is part 02 of u386mon.1.12
- if touch 2>&1 | fgrep 'mmdd' > /dev/null
- then TOUCH=touch
- else TOUCH=true
- 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 Defined functions:
- X display_proc_stat(win,iproc,initial)
- X display_proc_stats(win,initial)
- X find_utmp_for_pgrp(pgrp)
- X get_cpu_time_str(ticks)
- X get_user(tproc,tuser)
- X getpwent_and_enter(uid)
- X init_uid_name_hash()
- X pgrp_to_ttyname(pgrp)
- X proc_pid_compare(p1,p2)
- X read_and_sort_procs(initial)
- X read_utmp()
- X uid_name_enter(uid,name)
- X uid_to_name(uid)
- X
- X--------------------------------------------------------------------------*/
- X/*+:EDITS:*/
- X/*:06-27-1990-01:57-wht@n4hgf-1.10 - incorporate suggestions from alpha testers */
- X/*:06-25-1990-04:14-wht@n4hgf-1.02-better error handling */
- X/*:06-24-1990-20:53-wht@n4hgf-v1.01-add ISC support thanks to peter@radig.de */
- X/*:06-21-1990-14:26-r@n4hgf-version x0.12 seems bug free */
- X/*:01-05-1989-13:27-wht-creation */
- X
- X#define M_TERMINFO
- X
- X#include <curses.h>
- X#include <panel.h>
- X#include <signal.h>
- X#include <string.h>
- X#include <fcntl.h>
- X#include <nlist.h>
- X#include <errno.h>
- X#include <time.h>
- X#include <pwd.h>
- X#include <sys/types.h>
- X#include <utmp.h>
- X#include <sys/stat.h>
- X#include <sys/ascii.h>
- X#undef NGROUPS_MAX
- X#undef NULL
- X#include <sys/param.h>
- X#include <sys/bootinfo.h>
- X#include <sys/tuneable.h>
- X#include <sys/sysinfo.h>
- X#include <sys/sysmacros.h>
- X#include <sys/immu.h>
- X#include <sys/region.h>
- X#include <sys/proc.h>
- X#include <sys/fs/s5dir.h>
- X#include <sys/user.h>
- X#include <sys/var.h>
- X
- X#include "nlsym.h"
- X#include "libkmem.h"
- X#include "libmem.h"
- X#include "libswap.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;
- Xint max_procs_to_display;
- X
- Xstruct user user;
- X
- X#define min(a,b) (((a) > (b)) ? (b) : (a))
- X
- X#define p_slotnum p_whystop /* reuse a field we dont look at */
- X
- X#define MAX_UTMP 64
- 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 char *cptr;
- Xstruct proc *tproc;
- X
- X disp_msg(cpINFO,"");
- X if(!initial)
- X {
- X (void)memcpy((char *)oldprocs,
- X (char *)procs,v.v_proc * sizeof(struct proc));
- 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_slotnum = iproc; /* save slot number */
- X if( (tproc->p_stat == 0) || /* if slot not in use, ... */
- X (tproc->p_pid == 1) || /* ... or proc is init, ... */
- X (tproc->p_flag & SSYS)) /* ... or proc is system process */
- X { /* eliminate from consideration */
- X tproc->p_pid = 32767; /* force below selected procs in qsort */
- X continue;
- X }
- X nprocs++;
- X }
- X
- X/* if too many procs, whittle down */
- X if(nprocs > max_procs_to_display)
- X {
- X nprocs = 0;
- X for(iproc = 0; iproc < v.v_proc; iproc++)
- X {
- X tproc = procs + iproc;
- X if(tproc->p_pid == 32767) /* previously eliminated? */
- X continue;
- X else if(get_user(tproc,&user))
- X {
- X if( !strcmp(cptr = user.u_comm,"csh") ||
- X !strcmp(cptr,"sh") ||
- X !strcmp(cptr,"ksh") ||
- X !strcmp(cptr,"getty") ||
- X !strcmp(cptr,"uugetty") )
- X {
- X tproc->p_pid = 32767;
- X continue;
- X }
- X }
- X nprocs++;
- X }
- X disp_msg(cpLIT,"shells and gettys not displayed");
- X }
- X
- X/* if still too many procs, whittle swapped */
- X if(nprocs > max_procs_to_display)
- X {
- X nprocs = 0;
- X for(iproc = 0; iproc < v.v_proc; iproc++)
- X {
- X tproc = procs + iproc;
- X if(tproc->p_pid == 32767) /* previously eliminated? */
- X continue;
- X else if((!(tproc->p_flag & SLOAD) && (tproc->p_stat != SRUN)) ||
- X (tproc->p_stat == SZOMB))
- X {
- X tproc->p_pid = 32767;
- X continue;
- X }
- X nprocs++;
- X }
- X disp_msg(cpLIT,"shells, gettys and swapped/zombie procs not displayed");
- X }
- X/* if still too many procs, whittle hard */
- X if(nprocs > max_procs_to_display)
- X {
- X nprocs = 0;
- X for(iproc = 0; iproc < v.v_proc; iproc++)
- X {
- X tproc = procs + iproc;
- X if(tproc->p_pid == 32767) /* previously eliminated? */
- X continue;
- X else if(tproc->p_stat == SSLEEP)
- X {
- X tproc->p_pid = 32767;
- X continue;
- X }
- X nprocs++;
- X }
- X disp_msg(cpLIT,
- X "shells, gettys and swapped/zombie/sleeping procs not displayed");
- X }
- X
- X if(nprocs > max_procs_to_display)
- X disp_msg(cpMED,"display size too small for all processes");
- X
- X/* sort new procs array */
- X (void)qsort((char *)procs,(unsigned)v.v_proc,
- X sizeof(struct proc),proc_pid_compare);
- X
- X if(initial)
- X {
- X (void)memcpy((char *)oldprocs,(char *)procs,
- X v.v_proc * sizeof(struct proc));
- 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",255);
- X
- X while(read(utmpfd,(char *)(tutmp++),sizeof(struct utmp)) > 0)
- X {
- X /* ensure null termination
- X * (clobbers 1st byte of ut_line, but we don't use it)
- X */
- X tutmp->ut_id[sizeof(tutmp->ut_id)] = 0;
- X if(++nutmps == MAX_UTMP)
- X leave_text("too many utmp entries for me to handle",1);
- X }
- X (void)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{
- Xregister itmp;
- 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 {
- X itmp = strlen(tutmp->ut_id);
- X return(&tutmp->ut_id[(itmp >= 2) ? (itmp - 2) : 0]);
- X }
- X} /* end of pgrp_to_ttyname */
- X
- X/*+-------------------------------------------------------------------------
- X get_user(tproc,tuser)
- X--------------------------------------------------------------------------*/
- Xget_user(tproc,tuser)
- Xstruct proc *tproc;
- Xstruct user *tuser;
- X{
- X register caddr_t uptr = (caddr_t)tuser;
- X register int ubrdcount = sizeof(struct user);
- X int ipde;
- X paddr_t mptr;
- X
- X if(tproc->p_flag & SULOAD)
- 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,(daddr_t)mptr,min(ubrdcount,NBPP));
- X uptr += NBPP;
- X if((ubrdcount -= NBPP) <= 0)
- X break;
- X }
- X }
- X else
- X {
- X mptr = tproc->p_ubdbd.dbd_blkno * NBPSCTR;
- X sread(uptr,mptr,ubrdcount);
- X }
- X /*
- X * we can get crap from swap if things change after we get
- X * an address to read from, so validate user as best we can
- X */
- X return((tuser->u_ruid == tproc->p_uid) || /* validate it */
- X (tuser->u_ruid == tproc->p_suid));
- 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 - 1)
- X leave_text("too many user names for me to handle",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 (void)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 (void)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;
- 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 *
- Xget_cpu_time_str(ticks)
- Xtime_t ticks;
- X{
- Xstatic char timestr[10];
- Xtime_t mm,ss;
- Xextern int hz;
- X
- X ticks /= hz;
- X mm = ticks / 60L;
- X ticks -= mm * 60L;
- X ss = ticks;
- X
- X if(mm > 9999)
- X (void)strcpy(timestr,">9999m");
- X else if(mm > 999)
- X (void)sprintf(timestr,"%5ldm",mm);
- X else
- X (void)sprintf(timestr,"%3lu:%02lu",mm,ss);
- X
- X return(timestr);
- X
- 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 CPU_X 18
- X#define PRI_X 22
- X#define NICE_X 26
- X#define UTIME_X 29
- X#define STIME_X 36
- X#define SIZE_X 43
- X#define TTY_X 48
- X#define CMD_X 52
- X
- X/*+-------------------------------------------------------------------------
- X display_proc_stat(win,iproc,initial)
- X00000000001111111111222222222233333333334444444444555555555566666666667777777777
- X01234567890123456789012345678901234567890123456789012345678901234567890123456789
- XS USER PID CPU PRI NI UCPU SCPU SIZE 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 struct proc *tproc = procs + iproc;
- Xstruct proc *oproc = oldprocs + iproc;
- Xint got_user;
- Xstatic char *p_stat_str = " sRzdipx"; /* dependent on values of SSLEEP etc */
- Xchar buf[20];
- X
- X use_cp(win,cpINFO);
- X if((tproc->p_stat == SRUN) && !(tproc->p_flag & SLOAD))
- X use_cp(win,cpHIGH);
- X else if((tproc->p_stat == SRUN) || (oproc->p_stat == SRUN))
- X use_cp(win,cpMED);
- X if(tproc->p_pid != tproc->p_pid)
- X initial = 1;
- X
- X wmove(win,PROC_Y + iproc,PROC_X);
- X waddch(win,(chtype)p_stat_str[tproc->p_stat]);
- X waddch(win,(tproc->p_flag & SLOAD) ? (chtype)' ' : (chtype)'S');
- X positioned = 1;
- X
- X if(initial)
- X {
- X if(!positioned)
- X wmove(win,PROC_Y + iproc,PROC_X + UID_X);
- X (void)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)
- X {
- X if(!positioned)
- X wmove(win,PROC_Y + iproc,PROC_X + PID_X);
- X (void)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_cpu != oproc->p_cpu))
- X {
- X if(!positioned)
- X wmove(win,PROC_Y + iproc,PROC_X + CPU_X);
- X (void)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 (void)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 (void)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,&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 * process size:
- X *
- X * There are ways that seem right to a man, but the end of them is death.
- X * u_tsize and friends are not clicks, but in bytes.
- X * I thought this would have been:
- X * (ctob((u_long)user.u_tsize + user.u_dsize + user.u_ssize)) / 1024);
- X * At least this makes numbers agree with /bin/ps, although I cannot
- X * figure out why there is one extra page charged by ps (user is 2 pages).
- X *
- X * This was evidentally wrong in SCO UNIX 3.2.0 and fixed in 3.2.1.
- X * If you get lots of processes who size is reported as 4, define
- X * USIZE_FIXED
- X */
- X (void)sprintf(buf,"%4lu ",
- X#ifndef M_UNIX /* ISC */
- X /*
- X ** For ISC:
- X ** Reports exactly the same value as ps. The values in the user
- X ** area seem totally bogus (u_tsize is always 0, from observation)
- X ** so this size, the program swap size, seems the best measure.
- X ** Without USIZE_FIXED, on ISC2.02/Dell UNIX 1.1 I get zeroes.
- X ** With USIZE_FIXED I get values, but they're way out (e.g. vpix
- X ** and cron shown as the same size....).
- X */
- X (u_long)tproc->p_size
- X#else /*!ISC*/
- X#ifdef USIZE_FIXED /* SCO UNIX 3.2.1 (and later?) */
- X (ctob((u_long)user.u_tsize + user.u_dsize + user.u_ssize)) / 1024
- X#else /* SCO UNIX 3.2.0 */
- X (((u_long)user.u_tsize + 511) / 1024) +
- X (((u_long)user.u_dsize + 511) / 1024) +
- X (((u_long)user.u_ssize + 511) / 1024) +
- X (((u_long)((user.u_tsize)?1:0) * NBPP) / 1024)
- X#endif
- X#endif /*!ISC*/
- X );
- X waddstr(win,buf);
- X }
- X else
- X waddstr(win,"------ ------ ---- ");
- X
- X/*
- X positioned = 1;
- X if(!positioned)
- X wmove(win,PROC_Y + iproc,PROC_X + TTY_X);
- X*/
- X (void)sprintf(buf,"%3.3s ",pgrp_to_ttyname(tproc->p_pgrp));
- X waddstr(win,buf);
- X positioned = 1;
- X
- X/*
- X if(!positioned)
- X wmove(win,PROC_Y + iproc,PROC_X + CMD_X);
- 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 SZOMB:
- X waddstr(win,"<zombie>");
- X break;
- X case SXBRK:
- X waddstr(win,"<xbreak>");
- X break;
- X default:
- X waddstr(win,"<swapped>");
- 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;
- Xint y,x;
- X
- X if(initial)
- X {
- X use_cp(win,cpBANNER);
- X wmove(win,0,0);
- X waddstr(win,
- X "S USER PID CPU PRI NI UCPU SCPU SIZE TTY CMD");
- X getyx(win,y,x);
- X while(x < getmaxx(win))
- X waddch(win,(chtype)' '),x++;
- X }
- X mypid = getpid();
- X max_procs_to_display = getmaxy(win) - PROC_Y;
- X read_and_sort_procs(initial);
- X max_procs_to_display = min(nprocs,max_procs_to_display);
- X for(iproc = 0; iproc < max_procs_to_display; 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 0628235690 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" != "17149"; then
- echo original size 17149, current size $Wc_c
- fi
- # ============= det_sio.c ==============
- echo "x - extracting det_sio.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > det_sio.c &&
- X/* CHK=0xC5D1 */
- X/*+-------------------------------------------------------------------------
- X det_sio.c - UNIX V/386 system monitor serial I/O detail
- X ...!emory!n4hgf!wht
- X
- X Defined functions:
- X B_to_baud_rate(code)
- X cflag_to_baud_d_p_s(cflag)
- X grok_sio_tty()
- X display_siofull_init(win,tly,tlx,show_flag)
- X display_siofull_update(win,tly,tlx,tsio)
- X display_siosum_update(win,y,tsio)
- X tty_slot_compare(sio1,sio2)
- X
- X--------------------------------------------------------------------------*/
- X/*+:EDITS:*/
- X/*:06-27-1990-17:33-wht@n4hgf-fix bug during 24-line display */
- X/*:06-27-1990-01:57-wht@n4hgf-1.10 - incorporate suggestions from alpha testers */
- X/*:06-26-1990-03:17-wht@n4hgf-creation */
- X
- X#define M_TERMINFO
- X
- X#include <curses.h>
- X#include <panel.h>
- X#include <string.h>
- X#include <nlist.h>
- X#include <sys/types.h>
- X#include <sys/stat.h>
- X#include <sys/ascii.h>
- X#undef NGROUPS_MAX
- X#undef NULL
- X#include <sys/param.h>
- X#include <sys/tty.h>
- X
- X#include "nlsym.h"
- X#include "libkmem.h"
- X#include "libmem.h"
- X#include "libswap.h"
- X#include "libnlsym.h"
- X#include "u386mon.h"
- X
- Xextern int errno;
- Xextern int sys_nerr;
- Xextern char *sys_errlist[];
- X
- X#define SIO_NTTY 16 /* for now */
- Xstruct tty sio[SIO_NTTY];
- X
- X#define t_slot t_delct
- X
- Xint nsio; /* number of sios open */
- X
- Xtypedef struct slabel
- X{
- X int y,x;
- X char *label;
- X} SLABEL;
- X
- XSLABEL tty_slabels[] =
- X{
- X { 0, 0, "iflag:" },
- X { 2, 0, "oflag:" },
- X { 3, 0, "cflag:" },
- X { 4, 0, "lflag:" },
- X { 5, 7, "INTR QUIT ERASE KILL EOF/VMIN EOL/VTIME EOL2 SWTCH" },
- X { 6, 0, "cc:" },
- X { 7, 0, "state:" },
- X { -1,-1, (char *)0}
- X};
- X
- Xtypedef struct bitfld
- X{
- X int y,x;
- X char *label;
- X int flag_num;
- X int mask;
- X} BITFLD;
- X
- X#define IFLAG 1
- X#define OFLAG 2
- X#define LFLAG 3
- X#define CFLAG 4
- X#define STATE 5
- X
- XBITFLD ttybitflds[] =
- X{
- X { 0, 7, "IGNBRK", IFLAG, IGNBRK },
- X { 0, 15, "BRKINT", IFLAG, BRKINT },
- X { 0, 23, "IGNPAR", IFLAG, IGNPAR },
- X { 0, 31, "PARMRK", IFLAG, PARMRK },
- X { 0, 39, "INPCK", IFLAG, INPCK },
- X { 0, 46, "ISTRIP", IFLAG, ISTRIP },
- X { 0, 53, "INLCR", IFLAG, INLCR },
- X { 0, 60, "IGNCR", IFLAG, IGNCR },
- X { 0, 68, "ICRNL", IFLAG, ICRNL },
- X { 1, 7, "IUCLC", IFLAG, IUCLC },
- X { 1, 15, "IXON", IFLAG, IXON },
- X { 1, 23, "IXOFF", IFLAG, IXOFF },
- X { 1, 31, "IXANY", IFLAG, IXANY },
- X { 2, 7, "OPOST", OFLAG, OPOST },
- X { 2, 15, "OLCUC", OFLAG, OLCUC },
- X { 2, 23, "ONLCR", OFLAG, ONLCR },
- X { 2, 31, "OCRNL", OFLAG, OCRNL },
- X { 2, 39, "ONOCR", OFLAG, ONOCR },
- X { 2, 46, "ONLRET", OFLAG, ONLRET },
- X { 2, 53, "OFDEL", OFLAG, OFDEL },
- X { 3, 23, "CREAD", CFLAG, CREAD },
- X { 3, 31, "HUPCL", CFLAG, HUPCL },
- X { 3, 39, "CLOCAL", CFLAG, CLOCAL },
- X#ifdef RTSFLOW
- X { 3, 46, "RTSFLO", CFLAG, RTSFLOW },
- X#endif
- X#ifdef CTSFLOW
- X { 3, 53, "CTSFLO", CFLAG, CTSFLOW },
- X#endif
- X { 4, 7, "ISIG", LFLAG, ISIG },
- X { 4, 15, "ICANON", LFLAG, ICANON },
- X { 4, 23, "XCASE", LFLAG, XCASE },
- X { 4, 31, "ECHO", LFLAG, ECHO },
- X { 4, 39, "ECHOE", LFLAG, ECHOE },
- X { 4, 46, "ECHOK", LFLAG, ECHOK },
- X { 4, 53, "ECHONL", LFLAG, ECHONL },
- X { 4, 60, "NOFLSH", LFLAG, NOFLSH },
- X { 4, 68, "XCLUDE", LFLAG, XCLUDE },
- X { 7, 7, "TO", STATE, TIMEOUT },
- X { 7, 10, "WO", STATE, WOPEN },
- X { 7, 13, "O", STATE, ISOPEN },
- X { 7, 15, "TB", STATE, TBLOCK },
- X { 7, 18, "CD", STATE, CARR_ON },
- X { 7, 21, "BY", STATE, BUSY },
- X { 7, 24, "OSLP", STATE, OASLP },
- X { 7, 29, "ISLP", STATE, IASLP },
- X { 7, 34, "STOP", STATE, TTSTOP },
- X { 7, 39, "EXT", STATE, EXTPROC },
- X { 7, 43, "TACT", STATE, TACT },
- X { 7, 48, "ESC", STATE, CLESC },
- X { 7, 52, "RTO", STATE, RTO },
- X { 7, 56, "IOW", STATE, TTIOW },
- X { 7, 60, "XON", STATE, TTXON },
- X { 7, 64, "XOFF", STATE, TTXOFF },
- X { -1,-1, (char *)0, -1, -1 }
- X};
- X
- Xtypedef struct valyx
- X{
- X int y,x;
- X} VALYX;
- X
- XVALYX ttyvalyx[] =
- X{
- X#define Fc_intr 0
- X { 6, 8 },
- X#define Fcc_quit 1
- X { 6, 13 },
- X#define Fcc_erase 2
- X { 6, 18 },
- X#define Fcc_kill 3
- X { 6, 24 },
- X#define Fcc_eof 4
- X { 6, 30 },
- X#define Fcc_eol 5
- X { 6, 40 },
- X#define Fcc_eol2 6
- X { 6, 49 },
- X#define Fcc_swtch 7
- X { 6, 54 },
- X#define Fbaud_b_p_s 8
- X { 3, 7 }
- X};
- X
- Xtypedef struct b_to_br
- X{
- X char *baud_rate;
- X int B_code;
- X} B_TO_BR;
- X
- XB_TO_BR speeds[] = /* ordered to put less common rates later in table */
- X{ /* and the vagaries of baud rates above 9600 "handled" */
- X " 2400", B2400,
- X " 1200", B1200,
- X " 9600", B9600,
- X#if defined(B19200)
- X "19200", B19200,
- X#endif
- X#if defined(B38400)
- X "38400", B38400,
- X#endif
- X " 4800", B4800,
- X " 300", B300,
- X " 110", B110,
- X " 600", B600,
- X " 75", B75,
- X " 50", B50,
- X " HUP", B0,
- X " EXTA", EXTA,
- X " EXTB", EXTB,
- X
- X (char *)0,0
- X};
- X
- X/*+-------------------------------------------------------------------------
- X tty_slot_compare(sio1,sio2)
- X--------------------------------------------------------------------------*/
- Xint
- Xtty_slot_compare(sio1,sio2)
- Xstruct tty *sio1;
- Xstruct tty *sio2;
- X{
- X return(sio1->t_slot - sio2->t_slot);
- X} /* end of tty_slot_compare */
- X
- X/*+-------------------------------------------------------------------------
- X grok_sio_tty()
- X--------------------------------------------------------------------------*/
- Xvoid
- Xgrok_sio_tty()
- X{
- Xregister isio;
- Xregister struct tty *tsio;
- X
- X nsio = 0;
- X kread((caddr_t)sio,sio_ttyaddr,sizeof(struct tty) * SIO_NTTY);
- X for(isio = 0; isio < SIO_NTTY; isio++)
- X {
- X tsio = &sio[isio];
- X if(tsio->t_state & (WOPEN | ISOPEN))
- X {
- X tsio->t_slot = (ushort)isio;
- X nsio++;
- X continue;
- X }
- X tsio->t_slot = 127;
- X }
- X (void)qsort((char *)sio,(unsigned)SIO_NTTY,
- X sizeof(struct tty),tty_slot_compare);
- X
- X} /* end of grok_sio_tty */
- X
- X/*+-------------------------------------------------------------------------
- X B_to_baud_rate(code) - convert CBAUD B_ code to baud rate string
- X--------------------------------------------------------------------------*/
- Xchar *
- XB_to_baud_rate(code)
- X{
- Xregister int n;
- X
- X for(n=0; speeds[n].baud_rate; n++)
- X if(speeds[n].B_code == code)
- X return(speeds[n].baud_rate);
- X return("-----");
- X} /* end of B_to_baud_rate */
- X
- X/*+-------------------------------------------------------------------------
- X cflag_to_baud_d_p_s(cflag)
- X--------------------------------------------------------------------------*/
- Xchar *
- Xcflag_to_baud_d_p_s(cflag)
- Xint cflag;
- X{
- Xregister char *cptr;
- Xstatic char rtnstr[16];
- X
- X strcpy(rtnstr,B_to_baud_rate(cflag & CBAUD));
- X cptr = rtnstr + strlen(rtnstr);
- X *cptr++ = '-';
- X switch(cflag & CSIZE)
- X {
- X case CS5: *cptr++ = '5'; break;
- X case CS6: *cptr++ = '6'; break;
- X case CS7: *cptr++ = '7'; break;
- X case CS8: *cptr++ = '8'; break;
- X }
- X *cptr++ = '-';
- X *cptr++ = (cflag & PARENB) ? ((cflag & PARODD) ? 'O' : 'E') : 'N';
- X *cptr++ = '-';
- X *cptr++ = (cflag & CSTOPB) ? '2' : '1';
- X *cptr = 0;
- X return(rtnstr);
- X
- X} /* end of cflag_to_baud_d_p_s */
- X
- X/*+-----------------------------------------------------------------------
- X display_siofull_update(win,tly,tlx,tsio)
- X
- X000000000011111111112222222222333333333344444444445555555555666666666677777
- X012345678901234567890123456789012345678901234567890123456789012345678901234
- Xiflag: IGNBRK BRKINT IGNPAR PARMRK INPCK ISTRIP INLCR IGNCR ICRNL
- X IUCLC IXON IXOFF IXANY
- Xoflag: OPOST OLCUC ONLCR OCRNL ONOCR ONLRET OFDEL
- Xcflag: 09600-8-N-1 CREAD HUPCL CLOCAL
- Xlflag: ISIG ICANON XCASE ECHO ECHOE ECHOK ECHONL NOFLSH XCLUDE
- X INTR QUIT ERASE KILL EOF/VMIN EOL/VTIME EOL2 SWTCH
- Xcc: 03 1c 08 15 01 00 00 00
- X
- X------------------------------------------------------------------------*/
- Xvoid
- Xdisplay_siofull_update(win,tly,tlx,tsio)
- XWINDOW *win;
- Xint tly;
- Xint tlx;
- Xstruct tty *tsio;
- X{
- Xregister flag;
- Xregister i_cc;
- Xregister char *cptr;
- XBITFLD *bfptr = ttybitflds;
- XVALYX *vptr = ttyvalyx;
- X
- X use_cp(win,cpLOW);
- X while(bfptr->y >= 0)
- X {
- X switch(bfptr->flag_num)
- X {
- X case IFLAG: flag = tsio->t_iflag; break;
- X case OFLAG: flag = tsio->t_oflag; break;
- X case LFLAG: flag = tsio->t_lflag; break;
- X case CFLAG: flag = tsio->t_cflag; break;
- X case STATE: flag = tsio->t_state; break;
- X }
- X flag &= bfptr->mask;
- X wmove(win,bfptr->y + tly,bfptr->x + tlx);
- X if(flag)
- X use_cp(win,cpREVERSE);
- X waddstr(win,bfptr->label);
- X if(flag)
- X use_cp(win,cpLOW);
- X bfptr++;
- X }
- X for(i_cc = 0; i_cc < NCC; i_cc++)
- X {
- X wmove(win,vptr->y + tly,vptr->x + tlx);
- X wprintw(win,"%02x",tsio->t_cc[i_cc]);
- X vptr++;
- X }
- X
- X vptr = &ttyvalyx[Fbaud_b_p_s];
- X clear_area(win,vptr->y + tly,vptr->x + tlx,12);
- X waddstr(win,cflag_to_baud_d_p_s(tsio->t_cflag));
- X
- X} /* end of display_siofull_update */
- X
- X/*+-------------------------------------------------------------------------
- X display_siofull_init(win,tly,tlx,show_flag)
- X--------------------------------------------------------------------------*/
- Xvoid
- Xdisplay_siofull_init(win,tly,tlx,show_flag)
- XWINDOW *win;
- Xint tly;
- Xint tlx;
- Xint show_flag;
- X{
- Xregister y;
- XSLABEL *sptr = tty_slabels;
- X
- X use_cp(win,cpLIT);
- X for(y = 0; y < 7; y++)
- X clear_area(win,y,0,getmaxy(win));
- X if(show_flag)
- X {
- X while(sptr->y >= 0)
- X {
- X wmove(win,sptr->y + tly,sptr->x + tlx);
- X waddstr(win,sptr->label);
- X sptr++;
- X }
- X }
- X
- X} /* end of display_siofull_init */
- X
- X/*+-------------------------------------------------------------------------
- X display_siosum_update(win,y,tsio)
- X--------------------------------------------------------------------------*/
- Xvoid
- Xdisplay_siosum_update(win,y,tsio)
- Xregister WINDOW *win;
- Xint y;
- Xregister struct tty *tsio;
- X{
- Xregister unsigned int itmp;
- Xregister opened = tsio->t_state & (ISOPEN | WOPEN);
- Xchar s8[8];
- X
- X#define TX 1
- X#define RX 6
- X#define CX 11
- X#define OX 16
- X#define SX 23
- X#define FX 30
- X
- X wmove(win,y,TX);
- X#ifdef M_UNIX
- X waddch(win,(tsio->t_slot < 8) ? '1' : '2');
- X waddch(win,(tsio->t_slot % 8) + 'a');
- X#else
- X wprintw(win,"%02d",tsio->slot);
- X#endif
- X
- X if(!opened)
- X {
- X use_cp(win,cpINFO);
- X clear_area(win,y,TX,COLS - TX);
- X waddstr(win,"closed");
- X return;
- X }
- X
- X wmove(win,y,RX);
- X if((itmp = (unsigned)tsio->t_rawq.c_cc) > 999)
- X itmp = 999;
- X if(itmp > 10)
- X use_cp(win,cpHIGH);
- X else if(itmp > 3)
- X use_cp(win,cpMED);
- X else
- X use_cp(win,cpLOW);
- X wprintw(win,"%3d",itmp);
- X
- X if((itmp = (unsigned)tsio->t_canq.c_cc) > 999)
- X itmp = 999;
- X if(itmp > 20)
- X use_cp(win,cpHIGH);
- X else if(itmp > 10)
- X use_cp(win,cpMED);
- X else
- X use_cp(win,cpLOW);
- X wmove(win,y,CX);
- X wprintw(win,"%3d",itmp);
- X
- X if((itmp = (unsigned)tsio->t_outq.c_cc + tsio->t_tbuf.c_count) > 99999)
- X itmp = 99999;
- X if(itmp > 75)
- X use_cp(win,cpHIGH);
- X else if(itmp > 20)
- X use_cp(win,cpMED);
- X else
- X use_cp(win,cpLOW);
- X wmove(win,y,OX);
- X wprintw(win,"%5d",itmp);
- X
- X use_cp(win,cpINFO);
- X wmove(win,y,SX);
- X waddstr(win,B_to_baud_rate(tsio->t_cflag & CBAUD));
- X
- X strcpy(s8,".....");
- X if(tsio->t_state & WOPEN)
- X s8[0] = 'W';
- X else if(tsio->t_state & ISOPEN)
- X s8[0] = 'O';
- X if(tsio->t_state & CARR_ON)
- X s8[1] = 'C';
- X if(tsio->t_state & BUSY)
- X s8[2] = 'B';
- X if(tsio->t_state & TTSTOP)
- X s8[3] = 'S';
- X if(tsio->t_state & TIMEOUT)
- X s8[4] = 'D';
- X wmove(win,y,FX);
- X waddstr(win,s8);
- X
- X wprintw(win,"%7o",tsio->t_iflag);
- X wprintw(win,"%7o",tsio->t_oflag);
- X wprintw(win,"%7o",tsio->t_cflag);
- X wprintw(win,"%7o",tsio->t_lflag);
- X if(tsio->t_pgrp)
- X wprintw(win,"%6d",tsio->t_pgrp);
- X else
- X waddstr(win," ");
- X
- X} /* end of display_siosum_update */
- X
- X/*+-------------------------------------------------------------------------
- X display_sio_summary(win,initial)
- X--------------------------------------------------------------------------*/
- Xdisplay_sio_summary(win,initial)
- Xregister WINDOW *win;
- Xint initial;
- X{
- Xregister int isio;
- Xint max_displayable_sios = getmaxy(win) - 2;
- Xstatic char *header =
- X" tty raw can out speed state iflag oflag cflag lflag pgrp";
- Xstatic char *legend =
- X"W=wait for open O=open C=carrier on B=output busy S=stopped T=timeout";
- Xstatic couldnt_display_all = 0;
- X
- X if(initial)
- X {
- X use_cp(win,cpBANNER);
- X clear_area(win,0,0,getmaxx(win));
- X waddstr(win,header);
- X use_cp(win,cpLIT);
- X clear_area(win,getmaxy(win)-1,0,getmaxx(win));
- X waddstr(win,legend);
- X couldnt_display_all = 1;
- X }
- X grok_sio_tty();
- X for(isio = 0; (isio < nsio); isio++)
- X {
- X if(isio > max_displayable_sios)
- X {
- X wmove(win,getmaxy(win)-2);
- X use_cp(win,cpMED);
- X waddstr(win,"cannot display all active serial ports");
- X couldnt_display_all = 1;
- X return;
- X }
- X display_siosum_update(win,isio + 1,&sio[isio]);
- X }
- X
- X for(; isio < getmaxy(win)-2; isio++);
- X clear_area(win,isio + 1,0,getmaxx(win));
- X
- X if(couldnt_display_all)
- X {
- X use_cp(win,cpINFO);
- X clear_area(win,getmaxy(win)-2,0,getmaxx(win));
- X couldnt_display_all = 0;
- X }
- X
- X} /* end of display_sio_summary */
- X
- X/* vi: set tabstop=4 shiftwidth=4: */
- X/* end of det_sio.c */
- SHAR_EOF
- $TOUCH -am 0627173390 det_sio.c &&
- chmod 0644 det_sio.c ||
- echo "restore of det_sio.c failed"
- set `wc -c det_sio.c`;Wc_c=$1
- if test "$Wc_c" != "12630"; then
- echo original size 12630, 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-27-1990-01:57-wht@n4hgf-1.10 - incorporate suggestions from alpha testers */
- X/*:06-25-1990-04:14-wht@n4hgf-1.02-better error handling */
- X/*:06-24-1990-20:53-wht@n4hgf-v1.01-add ISC support thanks to peter@radig.de */
- X/*:06-21-1990-14:26-r@n4hgf-version x0.12 seems bug free */
- X/*:06-17-1990-15:15-wht-creation */
- X
- X#define M_TERMINFO
- X
- X#include <curses.h>
- X#include <panel.h>
- X#include <sys/types.h>
- 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/*+-------------------------------------------------------------------------
- X disp_msg(cp,msg)
- X--------------------------------------------------------------------------*/
- Xvoid
- Xdisp_msg(cp,msg)
- Xchtype cp;
- Xchar *msg;
- X{
- Xextern WINDOW *wscr;
- Xint y;
- Xregister int x;
- X
- X wmove(wscr,MSG_TLY,0);
- X use_cp(wscr,cp);
- X waddstr(wscr,msg);
- X getyx(wscr,y,x);
- X while(x < getmaxx(wscr))
- X waddch(wscr,(chtype)' '),x++;
- X} /* end of disp_msg */
- X
- X/* vi: set tabstop=4 shiftwidth=4: */
- X/* end of disputil.c */
- SHAR_EOF
- $TOUCH -am 0627015790 disputil.c &&
- chmod 0644 disputil.c ||
- echo "restore of disputil.c failed"
- set `wc -c disputil.c`;Wc_c=$1
- if test "$Wc_c" != "4936"; then
- echo original size 4936, current size $Wc_c
- fi
- # ============= libkmem.c ==============
- echo "x - extracting libkmem.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > libkmem.c &&
- X/*LINTLIBRARY*/
- X/*+-------------------------------------------------------------------------
- X libkmem.c -- /dev/kmem routines for SCO UNIX/386 (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/*:06-27-1990-01:57-wht@n4hgf-1.10 - incorporate suggestions from alpha testers */
- X/*:06-25-1990-04:14-wht@n4hgf-1.02-better error handling */
- X/*:06-24-1990-20:53-wht@n4hgf-v1.01-add ISC support thanks to peter@radig.de */
- X/*:06-21-1990-14:26-r@n4hgf-version x0.12 seems bug free */
- 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 <sys/types.h>
- X#include <fcntl.h>
- X#include "libkmem.h"
- X
- Xvoid leave_text();
- 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",255);
- 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];
- Xextern daddr_t myreadcnt;
- 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 (void)sprintf(s80,"kmem read seek error addr %08lx",kaddr);
- X leave_text(s80,255);
- X }
- X
- X if(read(fdkmem,caddr,len) != len)
- X {
- X (void)sprintf(s80,"kmem read error len %d addr %08lx",len,kaddr);
- X leave_text(s80,255);
- X }
- X myreadcnt += len;
- 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) == -1L)
- X {
- X (void)sprintf(s80,
- X "/dev/kmem write seek error addr %08lx",kaddr);
- X leave_text(s80,255);
- X }
- X if(write(fdkmem,caddr,len) != len)
- X {
- X (void)sprintf(s80,
- X "/dev/kmem write error addr %08lx len %08lx",kaddr,len);
- X leave_text(s80,255);
- X }
- X} /* end of kwrite */
- X#endif
- X
- X/* vi: set tabstop=4 shiftwidth=4: */
- SHAR_EOF
- $TOUCH -am 0627015790 libkmem.c &&
- chmod 0644 libkmem.c ||
- echo "restore of libkmem.c failed"
- set `wc -c libkmem.c`;Wc_c=$1
- if test "$Wc_c" != "2780"; then
- echo original size 2780, current size $Wc_c
- fi
- # ============= libmem.c ==============
- echo "x - extracting libmem.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > libmem.c &&
- X/*LINTLIBRARY*/
- X/*+-------------------------------------------------------------------------
- X libmem.c -- /dev/mem routines for SCO UNIX/386 (maybe other *NIX)
- X ...!emory!n4hgf!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/*:06-27-1990-01:57-wht@n4hgf-1.10 - incorporate suggestions from alpha testers */
- X/*:06-25-1990-04:14-wht@n4hgf-1.02-better error handling */
- X/*:06-24-1990-20:53-wht@n4hgf-v1.01-add ISC support thanks to peter@radig.de */
- X/*:06-21-1990-14:26-r@n4hgf-version x0.12 seems bug free */
- 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 <sys/types.h>
- X#include <fcntl.h>
- X#include "libmem.h"
- X
- Xvoid leave_text();
- 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",255);
- 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];
- Xextern daddr_t myreadcnt;
- 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 (void)sprintf(s80,"mem seek err (%08lx)",maddr);
- X leave_text(s80,1);
- X }
- X
- X if(read(fdmem,caddr,len) != len)
- X {
- X (void)sprintf(s80,
- X "mem read errno %d len %d addr %08lx",errno,len,maddr);
- X leave_text(s80,1);
- X }
- X myreadcnt += len;
- 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(fdkmem,kaddr,0) == -1L)
- X {
- X (void)sprintf(s80,
- X "/dev/kmem seek error addr %08lx",kaddr);
- X leave_text(s80,255);
- X }
- X if(write(fdkmem,caddr,len) != len)
- X {
- X (void)sprintf(s80,
- X "/dev/kmem write error addr %08lx len %08lx",kaddr,len);
- X leave_text(s80,255);
- X }
- X} /* end of mwrite */
- X#endif /* MWRITE_NEEDED */
- X
- X/* vi: set tabstop=4 shiftwidth=4: */
- SHAR_EOF
- $TOUCH -am 0627015790 libmem.c &&
- chmod 0644 libmem.c ||
- echo "restore of libmem.c failed"
- set `wc -c libmem.c`;Wc_c=$1
- if test "$Wc_c" != "2778"; then
- echo original size 2778, current size $Wc_c
- fi
- # ============= libswap.c ==============
- echo "x - extracting libswap.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > libswap.c &&
- X/*LINTLIBRARY*/
- X/*+-------------------------------------------------------------------------
- X libswap.c -- /dev/swap routines for SCO UNIX/386 (maybe other *NIX)
- X ...!emory!n4hgf!wht
- X
- X Defined functions:
- X sinit()
- X sread(caddr,maddr,len)
- X
- X routines were originally written by Mike "Ford" Ditto: kudos!!!
- X--------------------------------------------------------------------------*/
- X/*+:EDITS:*/
- X/*:06-27-1990-01:57-wht@n4hgf-1.10 - incorporate suggestions from alpha testers */
- X/*:06-25-1990-04:14-wht@n4hgf-1.02-better error handling */
- X/*:06-24-1990-20:53-wht@n4hgf-v1.01-add ISC support thanks to peter@radig.de */
- X/*:06-22-1990-02:00-root@n4hgf-creation from libmem */
- X
- X#include <sys/types.h>
- X#include <fcntl.h>
- X#include "libswap.h"
- X
- Xvoid leave_text();
- X
- Xextern int errno;
- X
- Xstatic int fdswap = -2;
- Xdaddr_t lseek();
- X
- X/*+-------------------------------------------------------------------------
- X sinit()
- X--------------------------------------------------------------------------*/
- Xvoid
- Xsinit()
- X{
- X if(fdswap >= 0)
- X return;
- X if((fdswap=open("/dev/swap",O_RDONLY)) < 0)
- X#ifdef M_SYS5
- X leave_text("can't open /dev/swap (chgrp mem /dev/swap)",1);
- X#else
- X leave_text("can't open /dev/swap (chgrp sys /dev/swap)",1);
- X#endif
- X
- X} /* end of sinit */
- X
- X/*+-------------------------------------------------------------------------
- X sread(caddr,maddr,len)
- X--------------------------------------------------------------------------*/
- Xvoid
- Xsread(caddr,maddr,len)
- Xcaddr_t caddr;
- Xdaddr_t maddr;
- Xint len;
- X{
- Xchar s80[80];
- Xextern daddr_t myreadcnt;
- X
- X#if defined(M_I286)
- X maddr &= 0xFFFFL;
- X#endif
- X
- X if(fdswap == -2)
- X leave_text("sinit() not called",1);
- X
- X if(lseek(fdswap,maddr,0) == -1L)
- X {
- X (void)sprintf(s80,"swap seek error addr %08lx",maddr);
- X leave_text(s80,1);
- X }
- X
- X if(read(fdswap,caddr,len) != len)
- X {
- X (void)sprintf(s80,"swap read error len %d addr %08lx",len,maddr);
- X leave_text(s80,255);
- X }
- X myreadcnt += len;
- X} /* end of sread */
- X
- X/* vi: set tabstop=4 shiftwidth=4: */
- SHAR_EOF
- $TOUCH -am 0627015790 libswap.c &&
- chmod 0644 libswap.c ||
- echo "restore of libswap.c failed"
- set `wc -c libswap.c`;Wc_c=$1
- if test "$Wc_c" != "1964"; then
- echo original size 1964, current size $Wc_c
- fi
- # ============= libnlsym.c ==============
- echo "x - extracting libnlsym.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > libnlsym.c &&
- X/*LINTLIBRARY*/
- X/*+-------------------------------------------------------------------------
- X libnlsym.c -- common runtime for nlsym users
- X ...!emory!n4hgf!wht
- X
- X Defined functions:
- X nlsym_error(text)
- X nlsym_read()
- X
- X--------------------------------------------------------------------------*/
- X/*+:EDITS:*/
- X/*:06-27-1990-01:57-wht@n4hgf-1.10 - incorporate suggestions from alpha testers */
- X/*:06-27-1990-01:55-wht@n4hgf-use 64 bits of unique check */
- X/*:06-25-1990-04:14-wht@n4hgf-1.02-better error handling */
- X/*:06-24-1990-20:53-wht@n4hgf-v1.01-add ISC support thanks to peter@radig.de */
- X/*:06-21-1990-14:26-r@n4hgf-version x0.12 seems bug free */
- X/*:10-27-1988-11:44-wht-creation */
- X
- X#include <stdio.h>
- X#include <sys/types.h>
- X#include <sys/stat.h>
- X#include <fcntl.h>
- X#include <nlist.h>
- X
- Xvoid leave_text();
- 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 (void)strcpy(s128,text);
- X (void)strcat(s128,": run nlsym");
- X leave_text(s128,(errno) ? 255 : 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 (void)time */
- Xlong unique1 = 0;
- Xlong unique2 = 0;
- X
- X if(stat(UNIX_KERNEL,&curstat) < 0)
- X {
- X (void)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 (void)sprintf(s80,"%s open error\n",UNIX_NLSYM);
- X nlsym_error(s80);
- X }
- X
- X if(read(fdnlsym,(char *)&unixstat,sizeof(unixstat)) != sizeof(unixstat))
- X nlsym_error("nlsym_read: /unix stat read error");
- X
- X if(read(fdnlsym,(char *)nlsym,sizeof(nlsym)) != sizeof(nlsym))
- X nlsym_error("nlsym_read: nlsym read error");
- X
- X if(read(fdnlsym,(char *)&unique1,sizeof(unique1)) != sizeof(unique1))
- X nlsym_error("nlsym_read: `unique' read error");
- X
- X if(read(fdnlsym,(char *)&unique2,sizeof(unique2)) != sizeof(unique2))
- X nlsym_error("nlsym_read: `unique' read error");
- X
- X (void)close(fdnlsym);
- X
- X if( (unique1 != NLSYM_UNIQUE1) ||
- X (unique2 != NLSYM_UNIQUE2) ||
- X (unixstat.st_ino != curstat.st_ino) ||
- X (unixstat.st_mtime != curstat.st_mtime) ||
- X (unixstat.st_size != curstat.st_size))
- X {
- X (void)sprintf(s80,"%s out of date",UNIX_NLSYM);
- X nlsym_error(s80);
- X }
- X
- X} /* end of nlsym_read */
- SHAR_EOF
- $TOUCH -am 0627020090 libnlsym.c &&
- chmod 0644 libnlsym.c ||
- echo "restore of libnlsym.c failed"
- set `wc -c libnlsym.c`;Wc_c=$1
- if test "$Wc_c" != "2706"; then
- echo original size 2706, 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 ...!emory!n4hgf!wht
- X
- X Defined functions:
- X main(argc,argv,envp)
- X nlsym_write_error(code)
- X
- X--------------------------------------------------------------------------*/
- X/*+:EDITS:*/
- X/*:06-27-1990-01:57-wht@n4hgf-1.10 - incorporate suggestions from alpha testers */
- X/*:06-27-1990-01:55-wht@n4hgf-use 64 bits of unique check */
- X/*:06-25-1990-04:14-wht@n4hgf-1.02-better error handling */
- X/*:06-24-1990-20:53-wht@n4hgf-v1.01-add ISC support thanks to peter@radig.de */
- X/*:06-21-1990-14:26-r@n4hgf-version x0.12 seems bug free */
- 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 <stdio.h>
- X#include <sys/types.h>
- X#include <sys/stat.h>
- X#include <fcntl.h>
- X#include <nlist.h>
- 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 (void)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--------------------------------------------------------------------------*/
- X/*ARGSUSED*/
- 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 (void)time */
- Xint fdnlsym;
- Xint nlist_error = 0;
- Xlong unique;
- XFILE *kludge;
- X
- X (void)nlist(UNIX_KERNEL,nlsym);
- X
- X nn = nlsym;
- X while(nn->n_name)
- X {
- X if(!nn->n_sclass)
- X {
- X (void)printf("%s: can't nlist\n", nn->n_name);
- X nlist_error = 1;
- X nn++;
- X continue;
- X }
- X (void)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 (void)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 (void)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 (void)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_UNIQUE1;
- X if((itmp = write(fdnlsym,&unique,sizeof(unique))) != sizeof(unique))
- X nlsym_write_error(itmp);
- X
- X unique = NLSYM_UNIQUE2;
- X if((itmp = write(fdnlsym,&unique,sizeof(unique))) != sizeof(unique))
- X nlsym_write_error(itmp);
- X
- X (void)close(fdnlsym);
- X exit(0);
- X /*NOTREACHED*/
- X} /* end of main */
- X
- X/* vi: set tabstop=4 shiftwidth=4: */
- SHAR_EOF
- $TOUCH -am 0627015790 nlsym.c &&
- chmod 0644 nlsym.c ||
- echo "restore of nlsym.c failed"
- set `wc -c nlsym.c`;Wc_c=$1
- if test "$Wc_c" != "2933"; then
- echo original size 2933, current size $Wc_c
- fi
- echo "End of part 2, continue with part 3"
- exit 0
- ---------------------------------------------------------------------
- Warren Tucker, TuckerWare emory!n4hgf!wht or wht@n4hgf.Mt-Park.GA.US
- Any perceptible delay will eventually get on your nerves. --Bob Hyers
-
-