home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume13 / u386mon-1.12 / part02 < prev    next >
Encoding:
Text File  |  1990-07-02  |  51.9 KB  |  2,039 lines

  1. Newsgroups: comp.sources.misc
  2. subject: v13i104: u386mon 1.12 part 02.04
  3. From: wht@gatech.edu@n4hgf.UUCP (Warren Tucker)
  4. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5.  
  6. Posting-number: Volume 13, Issue 104
  7. Submitted-by: wht@gatech.edu@n4hgf.UUCP (Warren Tucker)
  8. Archive-name: u386mon-1.12/part02
  9.  
  10. #!/bin/sh
  11. # This is part 02 of u386mon.1.12
  12. if touch 2>&1 | fgrep 'mmdd' > /dev/null
  13.  then TOUCH=touch
  14.  else TOUCH=true
  15. fi
  16. # ============= det_proc.c ==============
  17. echo "x - extracting det_proc.c (Text)"
  18. sed 's/^X//' << 'SHAR_EOF' > det_proc.c &&
  19. X/* CHK=0xC5D1 */
  20. X/*+-------------------------------------------------------------------------
  21. X    det_proc.c - UNIX V/386 system monitor proc status detail
  22. X    ...!emory!n4hgf!wht
  23. X
  24. X  Defined functions:
  25. X    display_proc_stat(win,iproc,initial)
  26. X    display_proc_stats(win,initial)
  27. X    find_utmp_for_pgrp(pgrp)
  28. X    get_cpu_time_str(ticks)
  29. X    get_user(tproc,tuser)
  30. X    getpwent_and_enter(uid)
  31. X    init_uid_name_hash()
  32. X    pgrp_to_ttyname(pgrp)
  33. X    proc_pid_compare(p1,p2)
  34. X    read_and_sort_procs(initial)
  35. X    read_utmp()
  36. X    uid_name_enter(uid,name)
  37. X    uid_to_name(uid)
  38. X
  39. X--------------------------------------------------------------------------*/
  40. X/*+:EDITS:*/
  41. X/*:06-27-1990-01:57-wht@n4hgf-1.10 - incorporate suggestions from alpha testers */
  42. X/*:06-25-1990-04:14-wht@n4hgf-1.02-better error handling */
  43. X/*:06-24-1990-20:53-wht@n4hgf-v1.01-add ISC support thanks to peter@radig.de */
  44. X/*:06-21-1990-14:26-r@n4hgf-version x0.12 seems bug free */
  45. X/*:01-05-1989-13:27-wht-creation */
  46. X
  47. X#define M_TERMINFO
  48. X
  49. X#include <curses.h>
  50. X#include <panel.h>
  51. X#include <signal.h>
  52. X#include <string.h>
  53. X#include <fcntl.h>
  54. X#include <nlist.h>
  55. X#include <errno.h>
  56. X#include <time.h>
  57. X#include <pwd.h>
  58. X#include <sys/types.h>
  59. X#include <utmp.h>
  60. X#include <sys/stat.h>
  61. X#include <sys/ascii.h>
  62. X#undef NGROUPS_MAX
  63. X#undef NULL
  64. X#include <sys/param.h>
  65. X#include <sys/bootinfo.h>
  66. X#include <sys/tuneable.h>
  67. X#include <sys/sysinfo.h>
  68. X#include <sys/sysmacros.h>
  69. X#include <sys/immu.h>
  70. X#include <sys/region.h>
  71. X#include <sys/proc.h>
  72. X#include <sys/fs/s5dir.h>
  73. X#include <sys/user.h>
  74. X#include <sys/var.h>
  75. X
  76. X#include "nlsym.h"
  77. X#include "libkmem.h"
  78. X#include "libmem.h"
  79. X#include "libswap.h"
  80. X#include "libnlsym.h"
  81. X#include "u386mon.h"
  82. X
  83. Xextern int errno;
  84. X
  85. Xextern int nprocs;
  86. Xextern struct var v;
  87. Xextern struct proc *procs;
  88. Xextern struct proc *oldprocs;
  89. X
  90. Xint mypid;
  91. Xint noldprocs = 0;
  92. Xint nprocs = 0;
  93. Xint max_procs_to_display;
  94. X
  95. Xstruct user user;
  96. X
  97. X#define min(a,b) (((a) > (b)) ? (b) : (a))
  98. X
  99. X#define p_slotnum    p_whystop    /* reuse a field we dont look at */
  100. X
  101. X#define MAX_UTMP 64
  102. Xint nutmps = 0;
  103. Xstruct utmp utmps[MAX_UTMP];
  104. X
  105. X/*+-------------------------------------------------------------------------
  106. X    proc_pid_compare(p1,p2)
  107. X--------------------------------------------------------------------------*/
  108. Xproc_pid_compare(p1,p2)
  109. Xstruct proc *p1;
  110. Xstruct proc *p2;
  111. X{
  112. X    return(p1->p_pid - p2->p_pid);
  113. X}    /* end of proc_pid_compare */
  114. X
  115. X/*+-------------------------------------------------------------------------
  116. X    read_and_sort_procs(initial)
  117. X--------------------------------------------------------------------------*/
  118. Xvoid
  119. Xread_and_sort_procs(initial)
  120. Xint initial;
  121. X{
  122. Xregister int iproc;
  123. Xregister char *cptr;
  124. Xstruct proc *tproc;
  125. X
  126. X    disp_msg(cpINFO,"");
  127. X    if(!initial)
  128. X    {
  129. X        (void)memcpy((char *)oldprocs,
  130. X            (char *)procs,v.v_proc * sizeof(struct proc));
  131. X        noldprocs = nprocs;
  132. X    }
  133. X
  134. X/* read current procs */
  135. X    grok_proc();
  136. X
  137. X/* if slot not in use, force to end when sorting */
  138. X    nprocs = 0;
  139. X    for(iproc = 0; iproc < v.v_proc; iproc++)
  140. X    {
  141. X        tproc = procs + iproc;
  142. X        tproc->p_slotnum = iproc;        /* save slot number */
  143. X        if(    (tproc->p_stat == 0) ||        /* if slot not in use, ... */
  144. X            (tproc->p_pid == 1)  ||        /* ... or proc is init, ... */
  145. X            (tproc->p_flag & SSYS))        /* ... or proc is system process */
  146. X        {                            /* eliminate from consideration */
  147. X            tproc->p_pid = 32767;    /* force below selected procs in qsort */
  148. X            continue;
  149. X        }
  150. X        nprocs++;
  151. X    }
  152. X
  153. X/* if too many procs, whittle down */
  154. X    if(nprocs > max_procs_to_display)
  155. X    {
  156. X        nprocs = 0;
  157. X        for(iproc = 0; iproc < v.v_proc; iproc++)
  158. X        {
  159. X            tproc = procs + iproc;
  160. X            if(tproc->p_pid == 32767)    /* previously eliminated? */
  161. X                continue;
  162. X            else if(get_user(tproc,&user))
  163. X            {
  164. X                if( !strcmp(cptr = user.u_comm,"csh") ||
  165. X                    !strcmp(cptr,"sh")        ||
  166. X                    !strcmp(cptr,"ksh")        ||
  167. X                    !strcmp(cptr,"getty")    ||
  168. X                    !strcmp(cptr,"uugetty")        )
  169. X                {
  170. X                    tproc->p_pid = 32767;
  171. X                    continue;
  172. X                }
  173. X            }
  174. X            nprocs++;
  175. X        }
  176. X        disp_msg(cpLIT,"shells and gettys not displayed");
  177. X    }
  178. X
  179. X/* if still too many procs, whittle swapped */
  180. X    if(nprocs > max_procs_to_display)
  181. X    {
  182. X        nprocs = 0;
  183. X        for(iproc = 0; iproc < v.v_proc; iproc++)
  184. X        {
  185. X            tproc = procs + iproc;
  186. X            if(tproc->p_pid == 32767)    /* previously eliminated? */
  187. X                continue;
  188. X            else if((!(tproc->p_flag & SLOAD) && (tproc->p_stat != SRUN)) ||
  189. X                (tproc->p_stat == SZOMB))
  190. X            {
  191. X                tproc->p_pid = 32767;
  192. X                continue;
  193. X            }
  194. X            nprocs++;
  195. X        }
  196. X        disp_msg(cpLIT,"shells, gettys and swapped/zombie procs not displayed");
  197. X    }
  198. X/* if still too many procs, whittle hard */
  199. X    if(nprocs > max_procs_to_display)
  200. X    {
  201. X        nprocs = 0;
  202. X        for(iproc = 0; iproc < v.v_proc; iproc++)
  203. X        {
  204. X            tproc = procs + iproc;
  205. X            if(tproc->p_pid == 32767)    /* previously eliminated? */
  206. X                continue;
  207. X            else if(tproc->p_stat == SSLEEP)
  208. X            {
  209. X                tproc->p_pid = 32767;
  210. X                continue;
  211. X            }
  212. X            nprocs++;
  213. X        }
  214. X        disp_msg(cpLIT,
  215. X            "shells, gettys and swapped/zombie/sleeping procs not displayed");
  216. X    }
  217. X
  218. X    if(nprocs > max_procs_to_display)
  219. X        disp_msg(cpMED,"display size too small for all processes");
  220. X
  221. X/* sort new procs array */
  222. X    (void)qsort((char *)procs,(unsigned)v.v_proc,
  223. X        sizeof(struct proc),proc_pid_compare);
  224. X
  225. X    if(initial)
  226. X    {
  227. X        (void)memcpy((char *)oldprocs,(char *)procs,
  228. X            v.v_proc * sizeof(struct proc));
  229. X        noldprocs = nprocs;
  230. X    }
  231. X
  232. X}    /* end of read_and_sort_procs */
  233. X
  234. X/*+-------------------------------------------------------------------------
  235. X    read_utmp()
  236. X--------------------------------------------------------------------------*/
  237. Xvoid
  238. Xread_utmp()
  239. X{
  240. Xint utmpfd;
  241. Xregister struct utmp *tutmp = utmps;
  242. X
  243. X    nutmps = 0;
  244. X    if((utmpfd = open("/etc/utmp",O_RDONLY,755)) < 0)
  245. X        leave_text("/etc/utmp open error",255);
  246. X
  247. X    while(read(utmpfd,(char *)(tutmp++),sizeof(struct utmp)) > 0)
  248. X    {
  249. X        /* ensure null termination
  250. X         * (clobbers 1st byte of ut_line, but we don't use it)
  251. X         */
  252. X        tutmp->ut_id[sizeof(tutmp->ut_id)] = 0;
  253. X        if(++nutmps == MAX_UTMP)
  254. X            leave_text("too many utmp entries for me to handle",1);
  255. X    }
  256. X    (void)close(utmpfd);
  257. X}    /* end of read_utmp */
  258. X
  259. X/*+-------------------------------------------------------------------------
  260. X    find_utmp_for_pgrp(pgrp)
  261. X--------------------------------------------------------------------------*/
  262. Xstruct utmp *
  263. Xfind_utmp_for_pgrp(pgrp)
  264. Xint pgrp;
  265. X{
  266. Xstruct utmp *tutmp = utmps;
  267. Xregister int count = nutmps;
  268. X
  269. X    while(count--)
  270. X    {
  271. X        if(tutmp->ut_pid == pgrp)
  272. X            return(tutmp);
  273. X        tutmp++;
  274. X    }
  275. X    return((struct utmp *)0);
  276. X}    /* end of find_utmp_for_pgrp */
  277. X
  278. X/*+-------------------------------------------------------------------------
  279. X    pgrp_to_ttyname(pgrp)
  280. X--------------------------------------------------------------------------*/
  281. Xchar *
  282. Xpgrp_to_ttyname(pgrp)
  283. Xint pgrp;
  284. X{
  285. Xregister itmp;
  286. Xstruct utmp *tutmp;
  287. X
  288. X    if(!(tutmp = find_utmp_for_pgrp(pgrp)))
  289. X    {
  290. X        read_utmp();
  291. X        tutmp = find_utmp_for_pgrp(pgrp);
  292. X    }
  293. X    if(!tutmp)
  294. X        return("??");
  295. X    else
  296. X    {
  297. X        itmp = strlen(tutmp->ut_id);
  298. X        return(&tutmp->ut_id[(itmp >= 2) ? (itmp - 2) : 0]);
  299. X    }
  300. X}    /* end of pgrp_to_ttyname */
  301. X
  302. X/*+-------------------------------------------------------------------------
  303. X    get_user(tproc,tuser)
  304. X--------------------------------------------------------------------------*/
  305. Xget_user(tproc,tuser)
  306. Xstruct proc *tproc;
  307. Xstruct user *tuser;
  308. X{
  309. X    register caddr_t uptr = (caddr_t)tuser;
  310. X    register int ubrdcount = sizeof(struct user);
  311. X    int ipde;
  312. X    paddr_t mptr;
  313. X
  314. X    if(tproc->p_flag & SULOAD)
  315. X    {
  316. X        for(ipde = 0; ipde < tproc->p_usize; ipde++)
  317. X        {
  318. X            if(!tproc->p_ubptbl[ipde].pgm.pg_pres)    /* if not resident */
  319. X                return(0);
  320. X            mptr = tproc->p_ubptbl[ipde].pgm.pg_pfn * NBPP;
  321. X            mread(uptr,(daddr_t)mptr,min(ubrdcount,NBPP));
  322. X            uptr += NBPP;
  323. X            if((ubrdcount -= NBPP) <= 0)
  324. X                break;
  325. X        }
  326. X    }
  327. X    else
  328. X    {
  329. X        mptr = tproc->p_ubdbd.dbd_blkno * NBPSCTR;
  330. X        sread(uptr,mptr,ubrdcount);
  331. X    }
  332. X    /*
  333. X     * we can get crap from swap if things change after we get
  334. X     * an address to read from, so validate user as best we can
  335. X     */
  336. X    return((tuser->u_ruid == tproc->p_uid) ||    /* validate it */
  337. X            (tuser->u_ruid == tproc->p_suid));
  338. X
  339. X}    /* end of get_user */
  340. X
  341. X/*+-------------------------------------------------------------------------
  342. Xuid to username conversion; thanks for the idea to William LeFebvre
  343. X--------------------------------------------------------------------------*/
  344. X#define UID_NAME_HASH_SIZE    127    /* prime */
  345. X#define HASH_EMPTY            -1
  346. X#define HASHIT(i)            ((i) % UID_NAME_HASH_SIZE)
  347. X
  348. Xstruct uid_name_hash_entry {
  349. X    int  uid;
  350. X    char name[10];
  351. X};
  352. X
  353. Xstruct uid_name_hash_entry uid_name_table[UID_NAME_HASH_SIZE];
  354. Xint uid_count = 0;
  355. X
  356. X/*+-------------------------------------------------------------------------
  357. X    init_uid_name_hash()
  358. X--------------------------------------------------------------------------*/
  359. Xvoid
  360. Xinit_uid_name_hash()
  361. X{
  362. Xregister int ihash = 0;
  363. Xregister struct uid_name_hash_entry *hashent = uid_name_table;
  364. X
  365. X    while(ihash++ < UID_NAME_HASH_SIZE)
  366. X    {
  367. X        hashent->uid = HASH_EMPTY;
  368. X        hashent++;
  369. X    }
  370. X}    /* end of init_uid_name_hash */
  371. X
  372. X/*+-------------------------------------------------------------------------
  373. X    uid_name_enter(uid,name)
  374. X--------------------------------------------------------------------------*/
  375. Xint
  376. Xuid_name_enter(uid,name)
  377. Xregister int uid;
  378. Xregister char *name;
  379. X{
  380. Xregister int table_uid;
  381. Xregister int hashval;
  382. X
  383. X    if(++uid_count >= UID_NAME_HASH_SIZE - 1)
  384. X        leave_text("too many user names for me to handle",1);
  385. X
  386. X    hashval = HASHIT(uid);
  387. X    while((table_uid = uid_name_table[hashval].uid) != HASH_EMPTY)
  388. X    {
  389. X        if(table_uid == uid)
  390. X            return(hashval);
  391. X        hashval = (hashval + 1) % UID_NAME_HASH_SIZE;
  392. X    }
  393. X
  394. X    uid_name_table[hashval].uid = uid;
  395. X    (void)strncpy(uid_name_table[hashval].name,name,
  396. X        sizeof(uid_name_table[0].name));
  397. X
  398. X    return(hashval);
  399. X
  400. X}    /* end of uid_name_enter */
  401. X
  402. X/*+-------------------------------------------------------------------------
  403. X    getpwent_and_enter(uid)
  404. X--------------------------------------------------------------------------*/
  405. Xgetpwent_and_enter(uid)
  406. Xregister int uid;
  407. X{
  408. Xregister int hashval;
  409. Xregister struct passwd *pwd;
  410. Xchar errant[10];
  411. Xstruct passwd *getpwuid();
  412. X
  413. X    pwd = getpwuid(uid);
  414. X    endpwent();
  415. X    if(pwd)
  416. X    {
  417. X        hashval = uid_name_enter(pwd->pw_uid,pwd->pw_name);
  418. X        return(hashval);
  419. X    }
  420. X    (void)sprintf(errant,"%d",uid);
  421. X    return(uid_name_enter(uid,errant));
  422. X}    /* end of getpwent_and_enter */
  423. X
  424. X/*+-------------------------------------------------------------------------
  425. X    uid_to_name(uid)
  426. X--------------------------------------------------------------------------*/
  427. Xchar *
  428. Xuid_to_name(uid)
  429. Xregister int uid;
  430. X{
  431. Xregister int uid_hash;
  432. Xregister int table_uid;
  433. X
  434. X    uid_hash = HASHIT(uid);
  435. X    while((table_uid = uid_name_table[uid_hash].uid) != uid)
  436. X    {
  437. X        if(table_uid == HASH_EMPTY)
  438. X        {
  439. X            /* not in hash table */
  440. X            uid_hash = getpwent_and_enter(uid);
  441. X            break;        /* out of while */
  442. X        }
  443. X        uid_hash = (uid_hash + 1) % UID_NAME_HASH_SIZE;
  444. X    }
  445. X    return(uid_name_table[uid_hash].name);
  446. X}    /* end of char *uid_to_name */
  447. X
  448. X/*+-----------------------------------------------------------------------
  449. X    char *get_cpu_time_str(ticks)
  450. X  6-char static string address is returned
  451. X------------------------------------------------------------------------*/
  452. Xchar *
  453. Xget_cpu_time_str(ticks)
  454. Xtime_t ticks;
  455. X{
  456. Xstatic char timestr[10];
  457. Xtime_t mm,ss;
  458. Xextern int hz;
  459. X
  460. X    ticks /= hz;
  461. X    mm = ticks / 60L;
  462. X    ticks -= mm * 60L;
  463. X    ss = ticks;
  464. X
  465. X    if(mm > 9999)
  466. X        (void)strcpy(timestr,">9999m");
  467. X    else if(mm > 999)
  468. X        (void)sprintf(timestr,"%5ldm",mm);
  469. X    else
  470. X        (void)sprintf(timestr,"%3lu:%02lu",mm,ss);
  471. X
  472. X    return(timestr);
  473. X
  474. X}    /* end of get_cpu_time_str */
  475. X
  476. X#define PROC_Y        1
  477. X#define PROC_X        0
  478. X#define UID_X        2
  479. X#define PID_X        12
  480. X#define CPU_X        18
  481. X#define PRI_X        22
  482. X#define NICE_X        26
  483. X#define UTIME_X        29
  484. X#define STIME_X        36
  485. X#define SIZE_X        43
  486. X#define TTY_X        48
  487. X#define CMD_X        52
  488. X
  489. X/*+-------------------------------------------------------------------------
  490. X    display_proc_stat(win,iproc,initial)
  491. X00000000001111111111222222222233333333334444444444555555555566666666667777777777
  492. X01234567890123456789012345678901234567890123456789012345678901234567890123456789
  493. XS     USER   PID  CPU PRI NI  UCPU   SCPU  SIZE TTY CMD
  494. X#!########X ##### ### ### ## ###### ###### #### ### ########
  495. X--------------------------------------------------------------------------*/
  496. Xvoid
  497. Xdisplay_proc_stat(win,iproc,initial)
  498. XWINDOW *win;
  499. Xregister int iproc;
  500. Xregister int initial;
  501. X{
  502. Xregister int positioned = 0;
  503. Xregister struct proc *tproc = procs + iproc;
  504. Xstruct proc *oproc = oldprocs + iproc;
  505. Xint got_user;
  506. Xstatic char *p_stat_str = " sRzdipx";    /* dependent on values of SSLEEP etc */
  507. Xchar buf[20];
  508. X
  509. X    use_cp(win,cpINFO);
  510. X    if((tproc->p_stat == SRUN) && !(tproc->p_flag & SLOAD))
  511. X        use_cp(win,cpHIGH);
  512. X    else if((tproc->p_stat == SRUN) || (oproc->p_stat == SRUN))
  513. X        use_cp(win,cpMED);
  514. X    if(tproc->p_pid != tproc->p_pid)
  515. X        initial = 1;
  516. X
  517. X    wmove(win,PROC_Y + iproc,PROC_X);
  518. X    waddch(win,(chtype)p_stat_str[tproc->p_stat]);
  519. X    waddch(win,(tproc->p_flag & SLOAD) ? (chtype)' ' : (chtype)'S');
  520. X    positioned = 1;
  521. X
  522. X    if(initial)
  523. X    {
  524. X        if(!positioned)
  525. X            wmove(win,PROC_Y + iproc,PROC_X + UID_X);
  526. X        (void)sprintf(buf,"%8s",uid_to_name(tproc->p_uid));
  527. X        waddstr(win,buf);
  528. X        waddch(win,(tproc->p_uid != tproc->p_suid) ? '#' : ' ');
  529. X        waddch(win,' ');
  530. X        positioned = 1;
  531. X    }
  532. X    else
  533. X        positioned = 0;
  534. X
  535. X    if(initial)
  536. X    {
  537. X        if(!positioned)
  538. X            wmove(win,PROC_Y + iproc,PROC_X + PID_X);
  539. X        (void)sprintf(buf,"%5d ",tproc->p_pid);
  540. X        waddstr(win,buf);
  541. X        positioned = 1;
  542. X    }
  543. X    else
  544. X        positioned = 0;
  545. X
  546. X    if(initial || (tproc->p_cpu != oproc->p_cpu))
  547. X    {
  548. X        if(!positioned)
  549. X            wmove(win,PROC_Y + iproc,PROC_X + CPU_X);
  550. X        (void)sprintf(buf,"%3u ",tproc->p_cpu);
  551. X        waddstr(win,buf);
  552. X        positioned = 1;
  553. X    }
  554. X    else
  555. X        positioned = 0;
  556. X
  557. X    if(initial || (tproc->p_pri != oproc->p_pri))
  558. X    {
  559. X        if(!positioned)
  560. X            wmove(win,PROC_Y + iproc,PROC_X + PRI_X);
  561. X        (void)sprintf(buf,"%3u ",tproc->p_pri);
  562. X        waddstr(win,buf);
  563. X        positioned = 1;
  564. X    }
  565. X    else
  566. X        positioned = 0;
  567. X
  568. X    if(initial || (tproc->p_nice != oproc->p_nice))
  569. X    {
  570. X        if(!positioned)
  571. X            wmove(win,PROC_Y + iproc,PROC_X + NICE_X);
  572. X        (void)sprintf(buf,"%2d ",tproc->p_nice);
  573. X        waddstr(win,buf);
  574. X        positioned = 1;
  575. X    }
  576. X    else
  577. X        positioned = 0;
  578. X
  579. X/* since not saving user area, always update fields from it */
  580. X    if(!positioned)
  581. X        wmove(win,PROC_Y + iproc,PROC_X + UTIME_X);
  582. X    if(got_user = get_user(tproc,&user))
  583. X    {
  584. X        waddstr(win,get_cpu_time_str(user.u_utime));
  585. X        waddch(win,' ');
  586. X        waddstr(win,get_cpu_time_str(user.u_stime));
  587. X        waddch(win,' ');
  588. X/*
  589. X * process size:
  590. X *
  591. X * There are ways that seem right to a man, but the end of them is death.
  592. X * u_tsize and friends are not clicks, but in bytes.
  593. X * I thought this would have been:
  594. X *        (ctob((u_long)user.u_tsize + user.u_dsize + user.u_ssize)) / 1024);
  595. X * At least this makes numbers agree with /bin/ps, although I cannot
  596. X * figure out why there is one extra page charged by ps (user is 2 pages).
  597. X *
  598. X * This was evidentally wrong in SCO UNIX 3.2.0 and fixed in 3.2.1.
  599. X * If you get lots of processes who size is reported as 4, define
  600. X * USIZE_FIXED
  601. X */
  602. X        (void)sprintf(buf,"%4lu ",
  603. X#ifndef M_UNIX /* ISC */
  604. X    /*
  605. X    ** For ISC:
  606. X    ** Reports exactly the same value as ps.  The values in the user
  607. X    ** area seem totally bogus (u_tsize is always 0, from observation)
  608. X    ** so this size, the program swap size, seems the best measure.
  609. X    ** Without USIZE_FIXED, on ISC2.02/Dell UNIX 1.1 I get zeroes.
  610. X    ** With USIZE_FIXED I get values, but they're way out (e.g. vpix
  611. X    ** and cron shown as the same size....).
  612. X    */
  613. X            (u_long)tproc->p_size
  614. X#else /*!ISC*/
  615. X#ifdef USIZE_FIXED    /* SCO UNIX 3.2.1 (and later?) */
  616. X            (ctob((u_long)user.u_tsize + user.u_dsize + user.u_ssize)) / 1024
  617. X#else                /* SCO UNIX 3.2.0 */
  618. X            (((u_long)user.u_tsize + 511) / 1024) +
  619. X            (((u_long)user.u_dsize + 511) / 1024) +
  620. X            (((u_long)user.u_ssize + 511) / 1024) +
  621. X            (((u_long)((user.u_tsize)?1:0) * NBPP) / 1024)
  622. X#endif
  623. X#endif /*!ISC*/
  624. X        );
  625. X        waddstr(win,buf);
  626. X    }
  627. X    else
  628. X        waddstr(win,"------ ------ ---- ");
  629. X
  630. X/*
  631. X    positioned = 1;
  632. X    if(!positioned)
  633. X        wmove(win,PROC_Y + iproc,PROC_X + TTY_X);
  634. X*/
  635. X    (void)sprintf(buf,"%3.3s ",pgrp_to_ttyname(tproc->p_pgrp));
  636. X    waddstr(win,buf);
  637. X    positioned = 1;
  638. X
  639. X/*
  640. X    if(!positioned)
  641. X        wmove(win,PROC_Y + iproc,PROC_X + CMD_X);
  642. X*/
  643. X    if(got_user)
  644. X    {
  645. X    register char *cptr = user.u_psargs;
  646. X    int y,x,maxx = getmaxx(win);
  647. X        getyx(win,y,x);
  648. X        while(*cptr && (x < maxx))
  649. X        {
  650. X            *cptr &= 0x7F;
  651. X            if(*cptr < 0x20)
  652. X                *cptr = 0x20;
  653. X            waddch(win,*cptr);
  654. X            cptr++,x++;
  655. X        }
  656. X    }
  657. X    else
  658. X    {
  659. X        switch(tproc->p_stat)
  660. X        {
  661. X            case SZOMB:
  662. X                waddstr(win,"<zombie>");
  663. X                break;
  664. X            case SXBRK:
  665. X                waddstr(win,"<xbreak>");
  666. X                break;
  667. X            default:
  668. X                waddstr(win,"<swapped>");
  669. X        }
  670. X    }
  671. X
  672. X    wclrtoeol(win);
  673. X
  674. X}    /* end of display_proc_stat */
  675. X
  676. X/*+-------------------------------------------------------------------------
  677. X    display_proc_stats(win,initial)
  678. X--------------------------------------------------------------------------*/
  679. Xvoid
  680. Xdisplay_proc_stats(win,initial)
  681. XWINDOW *win;
  682. Xint initial;
  683. X{
  684. Xregister int iproc;
  685. Xint y,x;
  686. X
  687. X    if(initial)
  688. X    {
  689. X        use_cp(win,cpBANNER);
  690. X        wmove(win,0,0);
  691. X        waddstr(win,
  692. X            "S     USER   PID  CPU PRI NI  UCPU   SCPU  SIZE TTY CMD");
  693. X        getyx(win,y,x);
  694. X        while(x < getmaxx(win))
  695. X            waddch(win,(chtype)' '),x++;
  696. X    }
  697. X    mypid = getpid();
  698. X    max_procs_to_display = getmaxy(win) - PROC_Y;
  699. X    read_and_sort_procs(initial);
  700. X    max_procs_to_display = min(nprocs,max_procs_to_display);
  701. X    for(iproc = 0; iproc < max_procs_to_display; iproc++)
  702. X        display_proc_stat(win,iproc,1);
  703. X    wclrtobot(win);
  704. X}    /* end of display_proc_stats */
  705. X
  706. X/* vi: set tabstop=4 shiftwidth=4: */
  707. X/* end of det_proc.c */
  708. SHAR_EOF
  709. $TOUCH -am 0628235690 det_proc.c &&
  710. chmod 0644 det_proc.c ||
  711. echo "restore of det_proc.c failed"
  712. set `wc -c det_proc.c`;Wc_c=$1
  713. if test "$Wc_c" != "17149"; then
  714.     echo original size 17149, current size $Wc_c
  715. fi
  716. # ============= det_sio.c ==============
  717. echo "x - extracting det_sio.c (Text)"
  718. sed 's/^X//' << 'SHAR_EOF' > det_sio.c &&
  719. X/* CHK=0xC5D1 */
  720. X/*+-------------------------------------------------------------------------
  721. X    det_sio.c - UNIX V/386 system monitor serial I/O detail
  722. X    ...!emory!n4hgf!wht
  723. X
  724. X  Defined functions:
  725. X    B_to_baud_rate(code)
  726. X    cflag_to_baud_d_p_s(cflag)
  727. X    grok_sio_tty()
  728. X    display_siofull_init(win,tly,tlx,show_flag)
  729. X    display_siofull_update(win,tly,tlx,tsio)
  730. X    display_siosum_update(win,y,tsio)
  731. X    tty_slot_compare(sio1,sio2)
  732. X
  733. X--------------------------------------------------------------------------*/
  734. X/*+:EDITS:*/
  735. X/*:06-27-1990-17:33-wht@n4hgf-fix bug during 24-line display */
  736. X/*:06-27-1990-01:57-wht@n4hgf-1.10 - incorporate suggestions from alpha testers */
  737. X/*:06-26-1990-03:17-wht@n4hgf-creation */
  738. X
  739. X#define M_TERMINFO
  740. X
  741. X#include <curses.h>
  742. X#include <panel.h>
  743. X#include <string.h>
  744. X#include <nlist.h>
  745. X#include <sys/types.h>
  746. X#include <sys/stat.h>
  747. X#include <sys/ascii.h>
  748. X#undef NGROUPS_MAX
  749. X#undef NULL
  750. X#include <sys/param.h>
  751. X#include <sys/tty.h>
  752. X
  753. X#include "nlsym.h"
  754. X#include "libkmem.h"
  755. X#include "libmem.h"
  756. X#include "libswap.h"
  757. X#include "libnlsym.h"
  758. X#include "u386mon.h"
  759. X
  760. Xextern int errno;
  761. Xextern int sys_nerr;
  762. Xextern char *sys_errlist[];
  763. X
  764. X#define SIO_NTTY 16    /* for now */
  765. Xstruct tty sio[SIO_NTTY];
  766. X
  767. X#define t_slot    t_delct
  768. X
  769. Xint nsio;    /* number of sios open */
  770. X
  771. Xtypedef struct slabel
  772. X{
  773. X    int y,x;
  774. X    char *label;
  775. X} SLABEL;
  776. X
  777. XSLABEL tty_slabels[] =
  778. X{
  779. X    {  0,  0, "iflag:" },
  780. X    {  2,  0, "oflag:" },
  781. X    {  3,  0, "cflag:" },
  782. X    {  4,  0, "lflag:" },
  783. X    {  5,  7, "INTR QUIT ERASE KILL EOF/VMIN  EOL/VTIME EOL2 SWTCH" },
  784. X    {  6,  0, "cc:" },
  785. X    {  7,  0, "state:" },
  786. X    {  -1,-1, (char *)0}
  787. X};
  788. X
  789. Xtypedef struct bitfld
  790. X{
  791. X    int y,x;
  792. X    char *label;
  793. X    int flag_num;
  794. X    int mask;
  795. X} BITFLD;
  796. X
  797. X#define IFLAG 1
  798. X#define OFLAG 2
  799. X#define LFLAG 3
  800. X#define CFLAG 4
  801. X#define STATE 5
  802. X
  803. XBITFLD ttybitflds[] =
  804. X{
  805. X    {  0,  7, "IGNBRK", IFLAG, IGNBRK },
  806. X    {  0, 15, "BRKINT", IFLAG, BRKINT },
  807. X    {  0, 23, "IGNPAR", IFLAG, IGNPAR },
  808. X    {  0, 31, "PARMRK", IFLAG, PARMRK },
  809. X    {  0, 39, "INPCK",  IFLAG, INPCK },
  810. X    {  0, 46, "ISTRIP", IFLAG, ISTRIP },
  811. X    {  0, 53, "INLCR",  IFLAG, INLCR },
  812. X    {  0, 60, "IGNCR",  IFLAG, IGNCR },
  813. X    {  0, 68, "ICRNL",  IFLAG, ICRNL },
  814. X    {  1,  7, "IUCLC",  IFLAG, IUCLC },
  815. X    {  1, 15, "IXON",   IFLAG, IXON },
  816. X    {  1, 23, "IXOFF",  IFLAG, IXOFF },
  817. X    {  1, 31, "IXANY",  IFLAG, IXANY },
  818. X    {  2,  7, "OPOST",  OFLAG, OPOST },
  819. X    {  2, 15, "OLCUC",  OFLAG, OLCUC },
  820. X    {  2, 23, "ONLCR",  OFLAG, ONLCR },
  821. X    {  2, 31, "OCRNL",  OFLAG, OCRNL },
  822. X    {  2, 39, "ONOCR",  OFLAG, ONOCR },
  823. X    {  2, 46, "ONLRET", OFLAG, ONLRET },
  824. X    {  2, 53, "OFDEL",  OFLAG, OFDEL },
  825. X    {  3, 23, "CREAD",  CFLAG, CREAD },
  826. X    {  3, 31, "HUPCL",  CFLAG, HUPCL },
  827. X    {  3, 39, "CLOCAL", CFLAG, CLOCAL },
  828. X#ifdef RTSFLOW
  829. X    {  3, 46, "RTSFLO", CFLAG, RTSFLOW },
  830. X#endif
  831. X#ifdef CTSFLOW
  832. X    {  3, 53, "CTSFLO", CFLAG, CTSFLOW },
  833. X#endif
  834. X    {  4,  7, "ISIG",   LFLAG, ISIG },
  835. X    {  4, 15, "ICANON", LFLAG, ICANON },
  836. X    {  4, 23, "XCASE",  LFLAG, XCASE },
  837. X    {  4, 31, "ECHO",   LFLAG, ECHO },
  838. X    {  4, 39, "ECHOE",  LFLAG, ECHOE },
  839. X    {  4, 46, "ECHOK",  LFLAG, ECHOK },
  840. X    {  4, 53, "ECHONL", LFLAG, ECHONL },
  841. X    {  4, 60, "NOFLSH", LFLAG, NOFLSH },
  842. X    {  4, 68, "XCLUDE", LFLAG, XCLUDE },
  843. X    {  7,  7, "TO",     STATE, TIMEOUT },
  844. X    {  7, 10, "WO",     STATE, WOPEN },
  845. X    {  7, 13, "O",      STATE, ISOPEN },
  846. X    {  7, 15, "TB",     STATE, TBLOCK },
  847. X    {  7, 18, "CD",     STATE, CARR_ON },
  848. X    {  7, 21, "BY",     STATE, BUSY },
  849. X    {  7, 24, "OSLP",   STATE, OASLP },
  850. X    {  7, 29, "ISLP",   STATE, IASLP },
  851. X    {  7, 34, "STOP",   STATE, TTSTOP },
  852. X    {  7, 39, "EXT",    STATE, EXTPROC },
  853. X    {  7, 43, "TACT",   STATE, TACT },
  854. X    {  7, 48, "ESC",    STATE, CLESC },
  855. X    {  7, 52, "RTO",    STATE, RTO },
  856. X    {  7, 56, "IOW",    STATE, TTIOW },
  857. X    {  7, 60, "XON",    STATE, TTXON },
  858. X    {  7, 64, "XOFF",   STATE, TTXOFF },
  859. X    {  -1,-1, (char *)0,    -1,    -1 }
  860. X};
  861. X
  862. Xtypedef struct valyx
  863. X{
  864. X    int y,x;
  865. X} VALYX;
  866. X
  867. XVALYX ttyvalyx[] =
  868. X{
  869. X#define Fc_intr       0
  870. X    {  6,  8 },
  871. X#define Fcc_quit      1
  872. X    {  6, 13 },
  873. X#define Fcc_erase     2
  874. X    {  6, 18 },
  875. X#define Fcc_kill      3
  876. X    {  6, 24 },
  877. X#define Fcc_eof       4
  878. X    {  6, 30 },
  879. X#define Fcc_eol       5
  880. X    {  6, 40 },
  881. X#define Fcc_eol2      6
  882. X    {  6, 49 },
  883. X#define Fcc_swtch     7
  884. X    {  6, 54 },
  885. X#define Fbaud_b_p_s   8
  886. X    {  3,  7 }
  887. X};
  888. X
  889. Xtypedef struct b_to_br
  890. X{
  891. X    char *baud_rate;
  892. X    int B_code;
  893. X} B_TO_BR;
  894. X
  895. XB_TO_BR speeds[] =     /* ordered to put less common rates later in table */
  896. X{                    /* and the vagaries of baud rates above 9600 "handled" */
  897. X    " 2400",    B2400,
  898. X    " 1200",    B1200,
  899. X    " 9600",    B9600,
  900. X#if defined(B19200)
  901. X    "19200",    B19200,
  902. X#endif
  903. X#if defined(B38400)
  904. X    "38400",    B38400,
  905. X#endif
  906. X    " 4800",    B4800,
  907. X    "  300",    B300,
  908. X    "  110",    B110,
  909. X    "  600",    B600,
  910. X    "   75",    B75,
  911. X    "   50",    B50,
  912. X    "  HUP",    B0,
  913. X    " EXTA",    EXTA,
  914. X    " EXTB",    EXTB,
  915. X
  916. X    (char *)0,0
  917. X};
  918. X
  919. X/*+-------------------------------------------------------------------------
  920. X    tty_slot_compare(sio1,sio2)
  921. X--------------------------------------------------------------------------*/
  922. Xint
  923. Xtty_slot_compare(sio1,sio2)
  924. Xstruct tty *sio1;
  925. Xstruct tty *sio2;
  926. X{
  927. X    return(sio1->t_slot - sio2->t_slot);
  928. X}    /* end of tty_slot_compare */
  929. X
  930. X/*+-------------------------------------------------------------------------
  931. X    grok_sio_tty()
  932. X--------------------------------------------------------------------------*/
  933. Xvoid
  934. Xgrok_sio_tty()
  935. X{
  936. Xregister isio;
  937. Xregister struct tty *tsio;
  938. X
  939. X    nsio = 0;
  940. X    kread((caddr_t)sio,sio_ttyaddr,sizeof(struct tty) * SIO_NTTY);
  941. X    for(isio = 0; isio < SIO_NTTY; isio++)
  942. X    {
  943. X        tsio = &sio[isio];
  944. X        if(tsio->t_state & (WOPEN | ISOPEN))
  945. X        {
  946. X            tsio->t_slot = (ushort)isio;
  947. X            nsio++;
  948. X            continue;
  949. X        }
  950. X        tsio->t_slot = 127;
  951. X    }
  952. X    (void)qsort((char *)sio,(unsigned)SIO_NTTY,
  953. X        sizeof(struct tty),tty_slot_compare);
  954. X
  955. X}    /* end of grok_sio_tty */
  956. X
  957. X/*+-------------------------------------------------------------------------
  958. X    B_to_baud_rate(code) - convert CBAUD B_ code to baud rate string
  959. X--------------------------------------------------------------------------*/
  960. Xchar *
  961. XB_to_baud_rate(code)
  962. X{
  963. Xregister int n;
  964. X
  965. X    for(n=0; speeds[n].baud_rate; n++)
  966. X        if(speeds[n].B_code == code)
  967. X            return(speeds[n].baud_rate);
  968. X    return("-----");
  969. X}    /* end of B_to_baud_rate */
  970. X
  971. X/*+-------------------------------------------------------------------------
  972. X    cflag_to_baud_d_p_s(cflag)
  973. X--------------------------------------------------------------------------*/
  974. Xchar *
  975. Xcflag_to_baud_d_p_s(cflag)
  976. Xint cflag;
  977. X{
  978. Xregister char *cptr;
  979. Xstatic char rtnstr[16];
  980. X
  981. X    strcpy(rtnstr,B_to_baud_rate(cflag & CBAUD));
  982. X    cptr = rtnstr + strlen(rtnstr);
  983. X    *cptr++ = '-';
  984. X    switch(cflag & CSIZE)
  985. X    {
  986. X        case CS5: *cptr++ = '5'; break;
  987. X        case CS6: *cptr++ = '6'; break;
  988. X        case CS7: *cptr++ = '7'; break;
  989. X        case CS8: *cptr++ = '8'; break;
  990. X    }
  991. X    *cptr++ = '-';
  992. X    *cptr++ = (cflag & PARENB) ? ((cflag & PARODD) ? 'O' : 'E') : 'N';
  993. X    *cptr++ = '-';
  994. X    *cptr++ = (cflag & CSTOPB) ? '2' : '1';
  995. X    *cptr = 0;
  996. X    return(rtnstr);
  997. X
  998. X}    /* end of cflag_to_baud_d_p_s */
  999. X
  1000. X/*+-----------------------------------------------------------------------
  1001. X    display_siofull_update(win,tly,tlx,tsio)
  1002. X
  1003. X000000000011111111112222222222333333333344444444445555555555666666666677777
  1004. X012345678901234567890123456789012345678901234567890123456789012345678901234
  1005. Xiflag: IGNBRK  BRKINT  IGNPAR  PARMRK  INPCK  ISTRIP INLCR  IGNCR   ICRNL
  1006. X       IUCLC   IXON    IXOFF   IXANY
  1007. Xoflag: OPOST   OLCUC   ONLCR   OCRNL   ONOCR  ONLRET OFDEL
  1008. Xcflag: 09600-8-N-1     CREAD   HUPCL   CLOCAL
  1009. Xlflag: ISIG    ICANON  XCASE   ECHO    ECHOE  ECHOK  ECHONL NOFLSH  XCLUDE
  1010. X       INTR QUIT ERASE KILL EOF/VMIN  EOL/VTIME EOL2 SWTCH 
  1011. Xcc:     03   1c   08    15    01        00       00   00   
  1012. X
  1013. X------------------------------------------------------------------------*/
  1014. Xvoid
  1015. Xdisplay_siofull_update(win,tly,tlx,tsio)
  1016. XWINDOW *win;
  1017. Xint tly;
  1018. Xint tlx;
  1019. Xstruct tty *tsio;
  1020. X{
  1021. Xregister flag;
  1022. Xregister i_cc;
  1023. Xregister char *cptr;
  1024. XBITFLD *bfptr = ttybitflds;
  1025. XVALYX *vptr = ttyvalyx;
  1026. X
  1027. X    use_cp(win,cpLOW);
  1028. X    while(bfptr->y >= 0)
  1029. X    {
  1030. X        switch(bfptr->flag_num)
  1031. X        {
  1032. X            case IFLAG: flag = tsio->t_iflag; break;
  1033. X            case OFLAG: flag = tsio->t_oflag; break;
  1034. X            case LFLAG: flag = tsio->t_lflag; break;
  1035. X            case CFLAG: flag = tsio->t_cflag; break;
  1036. X            case STATE: flag = tsio->t_state; break;
  1037. X        }
  1038. X        flag &= bfptr->mask;
  1039. X        wmove(win,bfptr->y + tly,bfptr->x + tlx);
  1040. X        if(flag)
  1041. X            use_cp(win,cpREVERSE);
  1042. X        waddstr(win,bfptr->label);
  1043. X        if(flag)
  1044. X            use_cp(win,cpLOW);
  1045. X        bfptr++;
  1046. X    }
  1047. X    for(i_cc = 0; i_cc < NCC; i_cc++)
  1048. X    {
  1049. X        wmove(win,vptr->y + tly,vptr->x + tlx);
  1050. X        wprintw(win,"%02x",tsio->t_cc[i_cc]);
  1051. X        vptr++;
  1052. X    }
  1053. X
  1054. X    vptr = &ttyvalyx[Fbaud_b_p_s];
  1055. X    clear_area(win,vptr->y + tly,vptr->x + tlx,12);
  1056. X    waddstr(win,cflag_to_baud_d_p_s(tsio->t_cflag));
  1057. X
  1058. X}    /* end of display_siofull_update */
  1059. X
  1060. X/*+-------------------------------------------------------------------------
  1061. X    display_siofull_init(win,tly,tlx,show_flag)
  1062. X--------------------------------------------------------------------------*/
  1063. Xvoid
  1064. Xdisplay_siofull_init(win,tly,tlx,show_flag)
  1065. XWINDOW *win;
  1066. Xint tly;
  1067. Xint tlx;
  1068. Xint show_flag;
  1069. X{
  1070. Xregister y;
  1071. XSLABEL *sptr = tty_slabels;
  1072. X
  1073. X    use_cp(win,cpLIT);
  1074. X    for(y = 0; y < 7; y++)
  1075. X        clear_area(win,y,0,getmaxy(win));
  1076. X    if(show_flag)
  1077. X    {
  1078. X        while(sptr->y >= 0)
  1079. X        {
  1080. X            wmove(win,sptr->y + tly,sptr->x + tlx);
  1081. X            waddstr(win,sptr->label);
  1082. X            sptr++;
  1083. X        }
  1084. X    }
  1085. X
  1086. X}    /* end of display_siofull_init */
  1087. X
  1088. X/*+-------------------------------------------------------------------------
  1089. X    display_siosum_update(win,y,tsio)
  1090. X--------------------------------------------------------------------------*/
  1091. Xvoid
  1092. Xdisplay_siosum_update(win,y,tsio)
  1093. Xregister WINDOW *win;
  1094. Xint y;
  1095. Xregister struct tty *tsio;
  1096. X{
  1097. Xregister unsigned int itmp;
  1098. Xregister opened = tsio->t_state & (ISOPEN | WOPEN);
  1099. Xchar s8[8];
  1100. X
  1101. X#define TX 1
  1102. X#define RX 6
  1103. X#define CX 11
  1104. X#define OX 16
  1105. X#define SX 23
  1106. X#define FX 30
  1107. X
  1108. X    wmove(win,y,TX);
  1109. X#ifdef M_UNIX
  1110. X    waddch(win,(tsio->t_slot < 8) ? '1' : '2');
  1111. X    waddch(win,(tsio->t_slot % 8) + 'a');
  1112. X#else
  1113. X    wprintw(win,"%02d",tsio->slot);
  1114. X#endif
  1115. X
  1116. X    if(!opened)
  1117. X    {
  1118. X        use_cp(win,cpINFO);
  1119. X        clear_area(win,y,TX,COLS - TX);
  1120. X        waddstr(win,"closed");
  1121. X        return;
  1122. X    }
  1123. X
  1124. X    wmove(win,y,RX);
  1125. X    if((itmp = (unsigned)tsio->t_rawq.c_cc) > 999)
  1126. X        itmp = 999;
  1127. X    if(itmp > 10)
  1128. X        use_cp(win,cpHIGH);
  1129. X    else if(itmp > 3)
  1130. X        use_cp(win,cpMED);
  1131. X    else
  1132. X        use_cp(win,cpLOW);
  1133. X    wprintw(win,"%3d",itmp);
  1134. X
  1135. X    if((itmp = (unsigned)tsio->t_canq.c_cc) > 999)
  1136. X        itmp = 999;
  1137. X    if(itmp > 20)
  1138. X        use_cp(win,cpHIGH);
  1139. X    else if(itmp > 10)
  1140. X        use_cp(win,cpMED);
  1141. X    else
  1142. X        use_cp(win,cpLOW);
  1143. X    wmove(win,y,CX);
  1144. X    wprintw(win,"%3d",itmp);
  1145. X
  1146. X    if((itmp = (unsigned)tsio->t_outq.c_cc + tsio->t_tbuf.c_count) > 99999)
  1147. X        itmp = 99999;
  1148. X    if(itmp > 75)
  1149. X        use_cp(win,cpHIGH);
  1150. X    else if(itmp > 20)
  1151. X        use_cp(win,cpMED);
  1152. X    else
  1153. X        use_cp(win,cpLOW);
  1154. X    wmove(win,y,OX);
  1155. X    wprintw(win,"%5d",itmp);
  1156. X
  1157. X    use_cp(win,cpINFO);
  1158. X    wmove(win,y,SX);
  1159. X    waddstr(win,B_to_baud_rate(tsio->t_cflag & CBAUD));
  1160. X
  1161. X    strcpy(s8,".....");
  1162. X    if(tsio->t_state & WOPEN)
  1163. X        s8[0] = 'W';
  1164. X    else if(tsio->t_state & ISOPEN)
  1165. X        s8[0] = 'O';
  1166. X    if(tsio->t_state & CARR_ON)
  1167. X        s8[1] = 'C';
  1168. X    if(tsio->t_state & BUSY)
  1169. X        s8[2] = 'B';
  1170. X    if(tsio->t_state & TTSTOP)
  1171. X        s8[3] = 'S';
  1172. X    if(tsio->t_state & TIMEOUT)
  1173. X        s8[4] = 'D';
  1174. X    wmove(win,y,FX);
  1175. X    waddstr(win,s8);
  1176. X
  1177. X    wprintw(win,"%7o",tsio->t_iflag);
  1178. X    wprintw(win,"%7o",tsio->t_oflag);
  1179. X    wprintw(win,"%7o",tsio->t_cflag);
  1180. X    wprintw(win,"%7o",tsio->t_lflag);
  1181. X    if(tsio->t_pgrp)
  1182. X        wprintw(win,"%6d",tsio->t_pgrp);
  1183. X    else
  1184. X        waddstr(win,"      ");
  1185. X
  1186. X}    /* end of display_siosum_update */
  1187. X
  1188. X/*+-------------------------------------------------------------------------
  1189. X    display_sio_summary(win,initial)
  1190. X--------------------------------------------------------------------------*/
  1191. Xdisplay_sio_summary(win,initial)
  1192. Xregister WINDOW *win;
  1193. Xint initial;
  1194. X{
  1195. Xregister int isio;
  1196. Xint max_displayable_sios = getmaxy(win) - 2;
  1197. Xstatic char *header  = 
  1198. X" tty  raw  can    out  speed  state  iflag  oflag  cflag  lflag  pgrp";
  1199. Xstatic char *legend =
  1200. X"W=wait for open  O=open C=carrier on  B=output busy  S=stopped  T=timeout";
  1201. Xstatic couldnt_display_all = 0;
  1202. X
  1203. X    if(initial)
  1204. X    {
  1205. X        use_cp(win,cpBANNER);
  1206. X        clear_area(win,0,0,getmaxx(win));
  1207. X        waddstr(win,header);
  1208. X        use_cp(win,cpLIT);
  1209. X        clear_area(win,getmaxy(win)-1,0,getmaxx(win));
  1210. X        waddstr(win,legend);
  1211. X        couldnt_display_all = 1;
  1212. X    }
  1213. X    grok_sio_tty();
  1214. X    for(isio = 0; (isio < nsio); isio++)
  1215. X    {
  1216. X        if(isio > max_displayable_sios)
  1217. X        {
  1218. X            wmove(win,getmaxy(win)-2);
  1219. X            use_cp(win,cpMED);
  1220. X            waddstr(win,"cannot display all active serial ports");
  1221. X            couldnt_display_all = 1;
  1222. X            return;
  1223. X        }
  1224. X        display_siosum_update(win,isio + 1,&sio[isio]);
  1225. X    }
  1226. X
  1227. X    for(; isio < getmaxy(win)-2; isio++);
  1228. X        clear_area(win,isio + 1,0,getmaxx(win));
  1229. X
  1230. X    if(couldnt_display_all)
  1231. X    {
  1232. X        use_cp(win,cpINFO);
  1233. X        clear_area(win,getmaxy(win)-2,0,getmaxx(win));
  1234. X        couldnt_display_all = 0;
  1235. X    }
  1236. X
  1237. X}    /* end of display_sio_summary */
  1238. X
  1239. X/* vi: set tabstop=4 shiftwidth=4: */
  1240. X/* end of det_sio.c */
  1241. SHAR_EOF
  1242. $TOUCH -am 0627173390 det_sio.c &&
  1243. chmod 0644 det_sio.c ||
  1244. echo "restore of det_sio.c failed"
  1245. set `wc -c det_sio.c`;Wc_c=$1
  1246. if test "$Wc_c" != "12630"; then
  1247.     echo original size 12630, current size $Wc_c
  1248. fi
  1249. # ============= disputil.c ==============
  1250. echo "x - extracting disputil.c (Text)"
  1251. sed 's/^X//' << 'SHAR_EOF' > disputil.c &&
  1252. X/*+-------------------------------------------------------------------------
  1253. X    disputil.c - u386mon display utilities
  1254. X
  1255. X  Defined functions:
  1256. X    clear_area(win,y,x,len)
  1257. X    clear_area_char(win,y,x,len,fillchar)
  1258. X    disp_info_int(win,label,fmt,value)
  1259. X    disp_info_long(win,label,fmt,value)
  1260. X    disp_static_int(win,label,fmt,value)
  1261. X    disp_static_long(win,label,fmt,value)
  1262. X    mkpanel(rows,cols,tly,tlx)
  1263. X    pflush()
  1264. X    wperror(win,desc)
  1265. X
  1266. X--------------------------------------------------------------------------*/
  1267. X/*+:EDITS:*/
  1268. X/*:06-27-1990-01:57-wht@n4hgf-1.10 - incorporate suggestions from alpha testers */
  1269. X/*:06-25-1990-04:14-wht@n4hgf-1.02-better error handling */
  1270. X/*:06-24-1990-20:53-wht@n4hgf-v1.01-add ISC support thanks to peter@radig.de */
  1271. X/*:06-21-1990-14:26-r@n4hgf-version x0.12 seems bug free */
  1272. X/*:06-17-1990-15:15-wht-creation */
  1273. X
  1274. X#define M_TERMINFO
  1275. X
  1276. X#include <curses.h>
  1277. X#include <panel.h>
  1278. X#include <sys/types.h>
  1279. X#include "u386mon.h"
  1280. X
  1281. X/*+-------------------------------------------------------------------------
  1282. X    clear_area_char(win,y,x,len,fillchar)
  1283. X--------------------------------------------------------------------------*/
  1284. Xvoid
  1285. Xclear_area_char(win,y,x,len,fillchar)
  1286. XWINDOW *win;
  1287. Xint y;
  1288. Xint x;
  1289. Xint len;
  1290. Xu_char fillchar;
  1291. X{
  1292. X    wmove(win,y,x);
  1293. X    while(len-- > 0)
  1294. X        waddch(win,(chtype)fillchar);
  1295. X    wmove(win,y,x);
  1296. X
  1297. X}    /* end of clear_area_char */
  1298. X
  1299. X/*+-------------------------------------------------------------------------
  1300. X    clear_area(win,y,x,len)
  1301. X--------------------------------------------------------------------------*/
  1302. Xvoid
  1303. Xclear_area(win,y,x,len)
  1304. XWINDOW *win;
  1305. Xint y;
  1306. Xint x;
  1307. Xint len;
  1308. X{
  1309. X    clear_area_char(win,y,x,len,' ');
  1310. X}    /* end of clear_area_char */
  1311. X
  1312. X/*+-------------------------------------------------------------------------
  1313. X    pflush() - do update_panels() and doupdate()
  1314. X--------------------------------------------------------------------------*/
  1315. Xvoid
  1316. Xpflush()
  1317. X{
  1318. X    update_panels();
  1319. X    curs_set(0);
  1320. X    doupdate();
  1321. X    curs_set(1);
  1322. X}    /* end of pflush */
  1323. X
  1324. X/*+-------------------------------------------------------------------------
  1325. X    wperror(win,desc)
  1326. X--------------------------------------------------------------------------*/
  1327. Xvoid
  1328. Xwperror(win,desc)
  1329. XWINDOW *win;
  1330. Xchar *desc;
  1331. X{
  1332. Xextern int errno;
  1333. Xextern int sys_nerr;
  1334. Xextern char *sys_errlist[];
  1335. X
  1336. X    waddstr(win,desc);
  1337. X    waddstr(win,": ");
  1338. X    if(errno < sys_nerr)
  1339. X        waddstr(win,sys_errlist[errno]);
  1340. X    else
  1341. X        wprintw(win,"error %u",errno);
  1342. X
  1343. X}    /* end of wperror */
  1344. X
  1345. X/*+-------------------------------------------------------------------------
  1346. X    mkpanel(rows,cols,tly,tlx) - alloc a win and panel and associate them
  1347. X--------------------------------------------------------------------------*/
  1348. XPANEL *
  1349. Xmkpanel(rows,cols,tly,tlx)
  1350. Xint rows;
  1351. Xint cols;
  1352. Xint tly;
  1353. Xint tlx;
  1354. X{
  1355. XWINDOW *win = newwin(rows,cols,tly,tlx);
  1356. XPANEL *pan;
  1357. X
  1358. X    if(!win)
  1359. X        return((PANEL *)0);
  1360. X    if(pan = new_panel(win))
  1361. X        return(pan);
  1362. X    delwin(win);
  1363. X    return((PANEL *)0);
  1364. X}    /* end of mkpanel */
  1365. X
  1366. X/*+-------------------------------------------------------------------------
  1367. X    disp_info_long(win,label,fmt,value)
  1368. X--------------------------------------------------------------------------*/
  1369. Xvoid
  1370. Xdisp_info_long(win,label,fmt,value)
  1371. XWINDOW *win;
  1372. Xchar *label;
  1373. Xchar *fmt;
  1374. Xlong value;
  1375. X{
  1376. X    use_cp(win,cpLIT);
  1377. X    waddstr(win,label);
  1378. X    use_cp(win,cpINFO);
  1379. X    wprintw(win,fmt,value);
  1380. X}    /* end of disp_info_long */
  1381. X
  1382. X/*+-------------------------------------------------------------------------
  1383. X    disp_info_int(win,label,fmt,value)
  1384. X--------------------------------------------------------------------------*/
  1385. Xvoid
  1386. Xdisp_info_int(win,label,fmt,value)
  1387. XWINDOW *win;
  1388. Xchar *label;
  1389. Xchar *fmt;
  1390. Xint value;
  1391. X{
  1392. X    use_cp(win,cpLIT);
  1393. X    waddstr(win,label);
  1394. X    use_cp(win,cpINFO);
  1395. X    wprintw(win,fmt,value);
  1396. X}    /* end of disp_info_int */
  1397. X
  1398. X/*+-------------------------------------------------------------------------
  1399. X    disp_static_long(win,label,fmt,value)
  1400. X--------------------------------------------------------------------------*/
  1401. Xvoid
  1402. Xdisp_static_long(win,label,fmt,value)
  1403. XWINDOW *win;
  1404. Xchar *label;
  1405. Xchar *fmt;
  1406. Xlong value;
  1407. X{
  1408. X    use_cp(win,cpLIT);
  1409. X    waddstr(win,label);
  1410. X    wprintw(win,fmt,value);
  1411. X}    /* end of disp_static_long */
  1412. X
  1413. X/*+-------------------------------------------------------------------------
  1414. X    disp_static_int(win,label,fmt,value)
  1415. X--------------------------------------------------------------------------*/
  1416. Xvoid
  1417. Xdisp_static_int(win,label,fmt,value)
  1418. XWINDOW *win;
  1419. Xchar *label;
  1420. Xchar *fmt;
  1421. Xint value;
  1422. X{
  1423. X    use_cp(win,cpLIT);
  1424. X    waddstr(win,label);
  1425. X    wprintw(win,fmt,value);
  1426. X}    /* end of disp_static_int */
  1427. X
  1428. X/*+-------------------------------------------------------------------------
  1429. X    disp_msg(cp,msg)
  1430. X--------------------------------------------------------------------------*/
  1431. Xvoid
  1432. Xdisp_msg(cp,msg)
  1433. Xchtype cp;
  1434. Xchar *msg;
  1435. X{
  1436. Xextern WINDOW *wscr;
  1437. Xint y;
  1438. Xregister int x;
  1439. X
  1440. X    wmove(wscr,MSG_TLY,0);
  1441. X    use_cp(wscr,cp);
  1442. X    waddstr(wscr,msg);
  1443. X    getyx(wscr,y,x);
  1444. X    while(x < getmaxx(wscr))
  1445. X        waddch(wscr,(chtype)' '),x++;
  1446. X}    /* end of disp_msg */
  1447. X
  1448. X/* vi: set tabstop=4 shiftwidth=4: */
  1449. X/* end of disputil.c */
  1450. SHAR_EOF
  1451. $TOUCH -am 0627015790 disputil.c &&
  1452. chmod 0644 disputil.c ||
  1453. echo "restore of disputil.c failed"
  1454. set `wc -c disputil.c`;Wc_c=$1
  1455. if test "$Wc_c" != "4936"; then
  1456.     echo original size 4936, current size $Wc_c
  1457. fi
  1458. # ============= libkmem.c ==============
  1459. echo "x - extracting libkmem.c (Text)"
  1460. sed 's/^X//' << 'SHAR_EOF' > libkmem.c &&
  1461. X/*LINTLIBRARY*/
  1462. X/*+-------------------------------------------------------------------------
  1463. X    libkmem.c -- /dev/kmem routines for SCO UNIX/386 (maybe other *NIX)
  1464. X    ...!emory!n4hgf!wht
  1465. X
  1466. X  Defined functions:
  1467. X    kinit(write_needed)
  1468. X    kread(caddr,kaddr,len)
  1469. X    kwrite(kaddr,caddr,len)
  1470. X
  1471. X routines were originally written by Mike "Ford" Ditto: kudos!!!
  1472. X--------------------------------------------------------------------------*/
  1473. X/*+:EDITS:*/
  1474. X/*:06-27-1990-01:57-wht@n4hgf-1.10 - incorporate suggestions from alpha testers */
  1475. X/*:06-25-1990-04:14-wht@n4hgf-1.02-better error handling */
  1476. X/*:06-24-1990-20:53-wht@n4hgf-v1.01-add ISC support thanks to peter@radig.de */
  1477. X/*:06-21-1990-14:26-r@n4hgf-version x0.12 seems bug free */
  1478. X/*:12-07-1988-22:06-wht-put in test for initialized fdkmem */
  1479. X/*:10-27-1988-22:44-wht-creation of file */
  1480. X
  1481. X#include <sys/types.h>
  1482. X#include <fcntl.h>
  1483. X#include "libkmem.h"
  1484. X
  1485. Xvoid leave_text();
  1486. X
  1487. Xextern int errno;
  1488. X
  1489. Xstatic int fdkmem = -2;
  1490. Xdaddr_t lseek();
  1491. X
  1492. X/*+-------------------------------------------------------------------------
  1493. X    kinit(write_needed)
  1494. X--------------------------------------------------------------------------*/
  1495. Xvoid
  1496. Xkinit(write_needed)
  1497. Xint write_needed;
  1498. X{
  1499. X    if(fdkmem >= 0)
  1500. X        return;
  1501. X    if((fdkmem=open("/dev/kmem",(write_needed) ? O_RDWR : O_RDONLY,0)) < 0)
  1502. X        leave_text("can't open /dev/kmem",255);
  1503. X
  1504. X}    /* end of kinit */
  1505. X
  1506. X/*+-------------------------------------------------------------------------
  1507. X    kread(caddr,kaddr,len)
  1508. X--------------------------------------------------------------------------*/
  1509. Xvoid
  1510. Xkread(caddr,kaddr,len)
  1511. Xcaddr_t caddr;
  1512. Xdaddr_t kaddr;
  1513. Xint len;
  1514. X{
  1515. Xchar s80[80];
  1516. Xextern daddr_t myreadcnt;
  1517. X
  1518. X#if defined(M_I286)
  1519. X    kaddr &= 0xFFFFL;
  1520. X#endif
  1521. X
  1522. X    if(fdkmem == -2)
  1523. X        leave_text("kinit() not called",1);
  1524. X
  1525. X    if(lseek(fdkmem,kaddr,0) == -1L)
  1526. X    {
  1527. X        (void)sprintf(s80,"kmem read seek error addr %08lx",kaddr);
  1528. X        leave_text(s80,255);
  1529. X    }
  1530. X
  1531. X    if(read(fdkmem,caddr,len) != len)
  1532. X    {
  1533. X        (void)sprintf(s80,"kmem read error len %d addr %08lx",len,kaddr);
  1534. X        leave_text(s80,255);
  1535. X    }
  1536. X    myreadcnt += len;
  1537. X}    /* end of kread */
  1538. X
  1539. X/*+-------------------------------------------------------------------------
  1540. X    kwrite(kaddr,caddr,len)
  1541. X--------------------------------------------------------------------------*/
  1542. X#ifdef KWRITE_NEEDED
  1543. Xvoid
  1544. Xkwrite(kaddr,caddr,len)
  1545. Xdaddr_t kaddr;
  1546. Xcaddr_t caddr;
  1547. Xint len;
  1548. X{
  1549. Xchar s80[80];
  1550. X
  1551. X#if defined(M_I286)
  1552. X    kaddr &= 0xFFFFL;
  1553. X#endif
  1554. X
  1555. X    if(fdkmem == -2)
  1556. X        leave_text("kinit() not called",1);
  1557. X
  1558. X    if(lseek(fdkmem,kaddr,0) == -1L)
  1559. X    {
  1560. X        (void)sprintf(s80,
  1561. X            "/dev/kmem write seek error addr %08lx",kaddr);
  1562. X        leave_text(s80,255);
  1563. X    }
  1564. X    if(write(fdkmem,caddr,len) != len)
  1565. X    {
  1566. X        (void)sprintf(s80,
  1567. X            "/dev/kmem write error addr %08lx len %08lx",kaddr,len);
  1568. X        leave_text(s80,255);
  1569. X    }
  1570. X}    /* end of kwrite */
  1571. X#endif
  1572. X
  1573. X/* vi: set tabstop=4 shiftwidth=4: */
  1574. SHAR_EOF
  1575. $TOUCH -am 0627015790 libkmem.c &&
  1576. chmod 0644 libkmem.c ||
  1577. echo "restore of libkmem.c failed"
  1578. set `wc -c libkmem.c`;Wc_c=$1
  1579. if test "$Wc_c" != "2780"; then
  1580.     echo original size 2780, current size $Wc_c
  1581. fi
  1582. # ============= libmem.c ==============
  1583. echo "x - extracting libmem.c (Text)"
  1584. sed 's/^X//' << 'SHAR_EOF' > libmem.c &&
  1585. X/*LINTLIBRARY*/
  1586. X/*+-------------------------------------------------------------------------
  1587. X    libmem.c -- /dev/mem routines for SCO UNIX/386 (maybe other *NIX)
  1588. X    ...!emory!n4hgf!wht
  1589. X
  1590. X  Defined functions:
  1591. X    minit(write_needed)
  1592. X    mread(caddr,maddr,len)
  1593. X    mwrite(maddr,caddr,len)
  1594. X
  1595. X routines were originally written by Mike "Ford" Ditto: kudos!!!
  1596. X--------------------------------------------------------------------------*/
  1597. X/*+:EDITS:*/
  1598. X/*:06-27-1990-01:57-wht@n4hgf-1.10 - incorporate suggestions from alpha testers */
  1599. X/*:06-25-1990-04:14-wht@n4hgf-1.02-better error handling */
  1600. X/*:06-24-1990-20:53-wht@n4hgf-v1.01-add ISC support thanks to peter@radig.de */
  1601. X/*:06-21-1990-14:26-r@n4hgf-version x0.12 seems bug free */
  1602. X/*:12-07-1988-22:06-wht-put in test for initialized fdmem */
  1603. X/*:10-27-1988-22:44-wht-creation of file */
  1604. X
  1605. X#include <sys/types.h>
  1606. X#include <fcntl.h>
  1607. X#include "libmem.h"
  1608. X
  1609. Xvoid leave_text();
  1610. X
  1611. Xextern int errno;
  1612. X
  1613. Xstatic int fdmem = -2;
  1614. Xdaddr_t lseek();
  1615. X
  1616. X/*+-------------------------------------------------------------------------
  1617. X    minit(write_needed)
  1618. X--------------------------------------------------------------------------*/
  1619. Xvoid
  1620. Xminit(write_needed)
  1621. Xint write_needed;
  1622. X{
  1623. X    if(fdmem >= 0)
  1624. X        return;
  1625. X    if((fdmem=open("/dev/mem",(write_needed) ? O_RDWR : O_RDONLY,0)) < 0)
  1626. X        leave_text("can't open /dev/mem",255);
  1627. X
  1628. X}    /* end of minit */
  1629. X
  1630. X/*+-------------------------------------------------------------------------
  1631. X    mread(caddr,maddr,len)
  1632. X--------------------------------------------------------------------------*/
  1633. Xvoid
  1634. Xmread(caddr,maddr,len)
  1635. Xcaddr_t caddr;
  1636. Xdaddr_t maddr;
  1637. Xint len;
  1638. X{
  1639. Xchar s80[80];
  1640. Xextern daddr_t myreadcnt;
  1641. X
  1642. X#if defined(M_I286)
  1643. X    maddr &= 0xFFFFL;
  1644. X#endif
  1645. X
  1646. X    if(fdmem == -2)
  1647. X        leave_text("minit() not called",1);
  1648. X
  1649. X    if(lseek(fdmem,maddr,0) == -1L)
  1650. X    {
  1651. X        (void)sprintf(s80,"mem seek err (%08lx)",maddr);
  1652. X        leave_text(s80,1);
  1653. X    }
  1654. X
  1655. X    if(read(fdmem,caddr,len) != len)
  1656. X    {
  1657. X        (void)sprintf(s80,
  1658. X            "mem read errno %d len %d addr %08lx",errno,len,maddr);
  1659. X        leave_text(s80,1);
  1660. X    }
  1661. X    myreadcnt += len;
  1662. X}    /* end of mread */
  1663. X
  1664. X/*+-------------------------------------------------------------------------
  1665. X    mwrite(maddr,caddr,len)
  1666. X--------------------------------------------------------------------------*/
  1667. X#ifdef MWRITE_NEEDED
  1668. Xvoid
  1669. Xmwrite(maddr,caddr,len)
  1670. Xdaddr_t maddr;
  1671. Xcaddr_t caddr;
  1672. Xint len;
  1673. X{
  1674. Xchar s80[80];
  1675. X
  1676. X#if defined(M_I286)
  1677. X    maddr &= 0xFFFFL;
  1678. X#endif
  1679. X
  1680. X    if(fdmem == -2)
  1681. X        leave_text("minit() not called",1);
  1682. X
  1683. X    if(lseek(fdkmem,kaddr,0) == -1L)
  1684. X    {
  1685. X        (void)sprintf(s80,
  1686. X            "/dev/kmem seek error addr %08lx",kaddr);
  1687. X        leave_text(s80,255);
  1688. X    }
  1689. X    if(write(fdkmem,caddr,len) != len)
  1690. X    {
  1691. X        (void)sprintf(s80,
  1692. X            "/dev/kmem write error addr %08lx len %08lx",kaddr,len);
  1693. X        leave_text(s80,255);
  1694. X    }
  1695. X}    /* end of mwrite */
  1696. X#endif /* MWRITE_NEEDED */
  1697. X
  1698. X/* vi: set tabstop=4 shiftwidth=4: */
  1699. SHAR_EOF
  1700. $TOUCH -am 0627015790 libmem.c &&
  1701. chmod 0644 libmem.c ||
  1702. echo "restore of libmem.c failed"
  1703. set `wc -c libmem.c`;Wc_c=$1
  1704. if test "$Wc_c" != "2778"; then
  1705.     echo original size 2778, current size $Wc_c
  1706. fi
  1707. # ============= libswap.c ==============
  1708. echo "x - extracting libswap.c (Text)"
  1709. sed 's/^X//' << 'SHAR_EOF' > libswap.c &&
  1710. X/*LINTLIBRARY*/
  1711. X/*+-------------------------------------------------------------------------
  1712. X    libswap.c -- /dev/swap routines for SCO UNIX/386 (maybe other *NIX)
  1713. X    ...!emory!n4hgf!wht
  1714. X
  1715. X  Defined functions:
  1716. X    sinit()
  1717. X    sread(caddr,maddr,len)
  1718. X
  1719. X routines were originally written by Mike "Ford" Ditto: kudos!!!
  1720. X--------------------------------------------------------------------------*/
  1721. X/*+:EDITS:*/
  1722. X/*:06-27-1990-01:57-wht@n4hgf-1.10 - incorporate suggestions from alpha testers */
  1723. X/*:06-25-1990-04:14-wht@n4hgf-1.02-better error handling */
  1724. X/*:06-24-1990-20:53-wht@n4hgf-v1.01-add ISC support thanks to peter@radig.de */
  1725. X/*:06-22-1990-02:00-root@n4hgf-creation from libmem */
  1726. X
  1727. X#include <sys/types.h>
  1728. X#include <fcntl.h>
  1729. X#include "libswap.h"
  1730. X
  1731. Xvoid leave_text();
  1732. X
  1733. Xextern int errno;
  1734. X
  1735. Xstatic int fdswap = -2;
  1736. Xdaddr_t lseek();
  1737. X
  1738. X/*+-------------------------------------------------------------------------
  1739. X    sinit()
  1740. X--------------------------------------------------------------------------*/
  1741. Xvoid
  1742. Xsinit()
  1743. X{
  1744. X    if(fdswap >= 0)
  1745. X        return;
  1746. X    if((fdswap=open("/dev/swap",O_RDONLY)) < 0)
  1747. X#ifdef M_SYS5
  1748. X        leave_text("can't open /dev/swap (chgrp mem /dev/swap)",1);
  1749. X#else
  1750. X        leave_text("can't open /dev/swap (chgrp sys /dev/swap)",1);
  1751. X#endif
  1752. X
  1753. X}    /* end of sinit */
  1754. X
  1755. X/*+-------------------------------------------------------------------------
  1756. X    sread(caddr,maddr,len)
  1757. X--------------------------------------------------------------------------*/
  1758. Xvoid
  1759. Xsread(caddr,maddr,len)
  1760. Xcaddr_t caddr;
  1761. Xdaddr_t maddr;
  1762. Xint len;
  1763. X{
  1764. Xchar s80[80];
  1765. Xextern daddr_t myreadcnt;
  1766. X
  1767. X#if defined(M_I286)
  1768. X    maddr &= 0xFFFFL;
  1769. X#endif
  1770. X
  1771. X    if(fdswap == -2)
  1772. X        leave_text("sinit() not called",1);
  1773. X
  1774. X    if(lseek(fdswap,maddr,0) == -1L)
  1775. X    {
  1776. X        (void)sprintf(s80,"swap seek error addr %08lx",maddr);
  1777. X        leave_text(s80,1);
  1778. X    }
  1779. X
  1780. X    if(read(fdswap,caddr,len) != len)
  1781. X    {
  1782. X        (void)sprintf(s80,"swap read error len %d addr %08lx",len,maddr);
  1783. X        leave_text(s80,255);
  1784. X    }
  1785. X    myreadcnt += len;
  1786. X}    /* end of sread */
  1787. X
  1788. X/* vi: set tabstop=4 shiftwidth=4: */
  1789. SHAR_EOF
  1790. $TOUCH -am 0627015790 libswap.c &&
  1791. chmod 0644 libswap.c ||
  1792. echo "restore of libswap.c failed"
  1793. set `wc -c libswap.c`;Wc_c=$1
  1794. if test "$Wc_c" != "1964"; then
  1795.     echo original size 1964, current size $Wc_c
  1796. fi
  1797. # ============= libnlsym.c ==============
  1798. echo "x - extracting libnlsym.c (Text)"
  1799. sed 's/^X//' << 'SHAR_EOF' > libnlsym.c &&
  1800. X/*LINTLIBRARY*/
  1801. X/*+-------------------------------------------------------------------------
  1802. X    libnlsym.c -- common runtime for nlsym users
  1803. X    ...!emory!n4hgf!wht
  1804. X
  1805. X  Defined functions:
  1806. X    nlsym_error(text)
  1807. X    nlsym_read()
  1808. X
  1809. X--------------------------------------------------------------------------*/
  1810. X/*+:EDITS:*/
  1811. X/*:06-27-1990-01:57-wht@n4hgf-1.10 - incorporate suggestions from alpha testers */
  1812. X/*:06-27-1990-01:55-wht@n4hgf-use 64 bits of unique check */
  1813. X/*:06-25-1990-04:14-wht@n4hgf-1.02-better error handling */
  1814. X/*:06-24-1990-20:53-wht@n4hgf-v1.01-add ISC support thanks to peter@radig.de */
  1815. X/*:06-21-1990-14:26-r@n4hgf-version x0.12 seems bug free */
  1816. X/*:10-27-1988-11:44-wht-creation */
  1817. X
  1818. X#include <stdio.h>
  1819. X#include <sys/types.h>
  1820. X#include <sys/stat.h>
  1821. X#include <fcntl.h>
  1822. X#include <nlist.h>
  1823. X
  1824. Xvoid leave_text();
  1825. X
  1826. X#define DEFINE_NLSYM
  1827. X#include "nlsym.h"
  1828. X#include "libnlsym.h"
  1829. X
  1830. Xextern int errno;
  1831. Xextern char *sys_errlist[];
  1832. X
  1833. X/*+-------------------------------------------------------------------------
  1834. X    nlsym_error(text)
  1835. X--------------------------------------------------------------------------*/
  1836. Xvoid
  1837. Xnlsym_error(text)
  1838. Xchar *text;
  1839. X{
  1840. Xchar s128[128];
  1841. X
  1842. X    (void)strcpy(s128,text);
  1843. X    (void)strcat(s128,": run nlsym");
  1844. X    leave_text(s128,(errno) ? 255 : 1);
  1845. X}    /* end of nlsym_error */
  1846. X
  1847. X/*+-------------------------------------------------------------------------
  1848. X    nlsym_read()
  1849. X--------------------------------------------------------------------------*/
  1850. Xvoid
  1851. Xnlsym_read()
  1852. X{
  1853. Xchar s80[80];
  1854. Xint itmp;
  1855. Xint fdnlsym;
  1856. Xstruct stat curstat;    /* current /unix status */
  1857. Xstruct stat unixstat;        /* /unix status at nlsym run (void)time */
  1858. Xlong unique1 = 0;
  1859. Xlong unique2 = 0;
  1860. X
  1861. X    if(stat(UNIX_KERNEL,&curstat) < 0)
  1862. X    {
  1863. X        (void)sprintf(s80,"cannot stat %s",UNIX_KERNEL);
  1864. X        nlsym_error(s80);
  1865. X    }
  1866. X
  1867. X    errno = 0;
  1868. X    if((fdnlsym = open(UNIX_NLSYM,O_RDONLY,0)) < 0)
  1869. X    {
  1870. X        (void)sprintf(s80,"%s open error\n",UNIX_NLSYM);
  1871. X        nlsym_error(s80);
  1872. X    }
  1873. X
  1874. X    if(read(fdnlsym,(char *)&unixstat,sizeof(unixstat)) != sizeof(unixstat))
  1875. X        nlsym_error("nlsym_read: /unix stat read error");
  1876. X
  1877. X    if(read(fdnlsym,(char *)nlsym,sizeof(nlsym)) != sizeof(nlsym))
  1878. X        nlsym_error("nlsym_read: nlsym read error");
  1879. X
  1880. X    if(read(fdnlsym,(char *)&unique1,sizeof(unique1)) != sizeof(unique1))
  1881. X        nlsym_error("nlsym_read: `unique' read error");
  1882. X
  1883. X    if(read(fdnlsym,(char *)&unique2,sizeof(unique2)) != sizeof(unique2))
  1884. X        nlsym_error("nlsym_read: `unique' read error");
  1885. X
  1886. X    (void)close(fdnlsym);
  1887. X
  1888. X    if( (unique1 != NLSYM_UNIQUE1) ||
  1889. X        (unique2 != NLSYM_UNIQUE2) ||
  1890. X        (unixstat.st_ino != curstat.st_ino) ||
  1891. X        (unixstat.st_mtime != curstat.st_mtime) ||
  1892. X        (unixstat.st_size != curstat.st_size))
  1893. X    {
  1894. X        (void)sprintf(s80,"%s out of date",UNIX_NLSYM);
  1895. X        nlsym_error(s80);
  1896. X    }
  1897. X
  1898. X}    /* end of nlsym_read */
  1899. SHAR_EOF
  1900. $TOUCH -am 0627020090 libnlsym.c &&
  1901. chmod 0644 libnlsym.c ||
  1902. echo "restore of libnlsym.c failed"
  1903. set `wc -c libnlsym.c`;Wc_c=$1
  1904. if test "$Wc_c" != "2706"; then
  1905.     echo original size 2706, current size $Wc_c
  1906. fi
  1907. # ============= nlsym.c ==============
  1908. echo "x - extracting nlsym.c (Text)"
  1909. sed 's/^X//' << 'SHAR_EOF' > nlsym.c &&
  1910. X/*+-------------------------------------------------------------------------
  1911. X    nlsym.c -- utility nlist - fast access to kernel /dev/kmem offsets
  1912. X    ...!emory!n4hgf!wht
  1913. X
  1914. X  Defined functions:
  1915. X    main(argc,argv,envp)
  1916. X    nlsym_write_error(code)
  1917. X
  1918. X--------------------------------------------------------------------------*/
  1919. X/*+:EDITS:*/
  1920. X/*:06-27-1990-01:57-wht@n4hgf-1.10 - incorporate suggestions from alpha testers */
  1921. X/*:06-27-1990-01:55-wht@n4hgf-use 64 bits of unique check */
  1922. X/*:06-25-1990-04:14-wht@n4hgf-1.02-better error handling */
  1923. X/*:06-24-1990-20:53-wht@n4hgf-v1.01-add ISC support thanks to peter@radig.de */
  1924. X/*:06-21-1990-14:26-r@n4hgf-version x0.12 seems bug free */
  1925. X/*:05-12-1989-18:27-wht-fix endless loop error on cannot nlist */
  1926. X/*:10-27-1988-10:58-wht-creation */
  1927. X
  1928. X#include <stdio.h>
  1929. X#include <sys/types.h>
  1930. X#include <sys/stat.h>
  1931. X#include <fcntl.h>
  1932. X#include <nlist.h>
  1933. X
  1934. X#define DEFINE_NLSYM
  1935. X#include "nlsym.h"
  1936. X
  1937. X/*+-------------------------------------------------------------------------
  1938. X    nlsym_write_error(code)
  1939. X--------------------------------------------------------------------------*/
  1940. Xvoid
  1941. Xnlsym_write_error(code)
  1942. Xint code;
  1943. X{
  1944. X    (void)fprintf(stderr,"code %d: ",code);
  1945. X    perror(UNIX_NLSYM);
  1946. X    exit(1);
  1947. X}    /* end of nlsym_write_error */
  1948. X
  1949. X/*+-------------------------------------------------------------------------
  1950. X    main(argc,argv,envp)
  1951. X--------------------------------------------------------------------------*/
  1952. X/*ARGSUSED*/
  1953. Xmain(argc,argv,envp)
  1954. Xint argc;
  1955. Xchar **argv;
  1956. Xchar **envp;
  1957. X{
  1958. Xregister int itmp;
  1959. Xregister struct nlist *nn;
  1960. Xstruct stat unixstat;        /* /unix status at nlsym run (void)time */
  1961. Xint fdnlsym;
  1962. Xint nlist_error = 0;
  1963. Xlong unique;
  1964. XFILE *kludge;
  1965. X
  1966. X    (void)nlist(UNIX_KERNEL,nlsym);
  1967. X
  1968. X    nn = nlsym;
  1969. X    while(nn->n_name)
  1970. X    {
  1971. X        if(!nn->n_sclass)
  1972. X        {
  1973. X            (void)printf("%s: can't nlist\n", nn->n_name);
  1974. X            nlist_error = 1;
  1975. X            nn++;
  1976. X            continue;
  1977. X        }
  1978. X        (void)printf("%-12.12s  storage class: %04x value: %08lx\n",
  1979. X            nn->n_name,
  1980. X            nn->n_sclass,
  1981. X            nn->n_value);
  1982. X        nn++;
  1983. X    }
  1984. X
  1985. X    if(nlist_error)
  1986. X    {
  1987. X        (void)fprintf(stderr,"%s NOT produced\n",UNIX_NLSYM);
  1988. X        exit(1);
  1989. X    }
  1990. X
  1991. X    if((kludge = fopen(UNIX_NLSYM,"w")) == NULL)    /* scratch/create */
  1992. X        nlsym_write_error(-1);
  1993. X    (void)fclose(kludge);
  1994. X
  1995. X    if((fdnlsym = open(UNIX_NLSYM,O_WRONLY,0)) < 0)
  1996. X        nlsym_write_error(fdnlsym);
  1997. X
  1998. X    if(stat(UNIX_KERNEL,&unixstat) < 0)
  1999. X    {
  2000. X        (void)fputs("cannot stat ",stderr);
  2001. X        perror(UNIX_KERNEL);
  2002. X        exit(1);
  2003. X    }
  2004. X
  2005. X    if((itmp = write(fdnlsym,&unixstat,sizeof(unixstat))) != sizeof(unixstat))
  2006. X        nlsym_write_error(itmp);
  2007. X
  2008. X    if((itmp = write(fdnlsym,nlsym,sizeof(nlsym))) != sizeof(nlsym))
  2009. X        nlsym_write_error(itmp);
  2010. X
  2011. X    unique = NLSYM_UNIQUE1;
  2012. X    if((itmp = write(fdnlsym,&unique,sizeof(unique))) != sizeof(unique))
  2013. X        nlsym_write_error(itmp);
  2014. X
  2015. X    unique = NLSYM_UNIQUE2;
  2016. X    if((itmp = write(fdnlsym,&unique,sizeof(unique))) != sizeof(unique))
  2017. X        nlsym_write_error(itmp);
  2018. X
  2019. X    (void)close(fdnlsym);
  2020. X    exit(0);
  2021. X    /*NOTREACHED*/
  2022. X}    /* end of main */
  2023. X
  2024. X/* vi: set tabstop=4 shiftwidth=4: */
  2025. SHAR_EOF
  2026. $TOUCH -am 0627015790 nlsym.c &&
  2027. chmod 0644 nlsym.c ||
  2028. echo "restore of nlsym.c failed"
  2029. set `wc -c nlsym.c`;Wc_c=$1
  2030. if test "$Wc_c" != "2933"; then
  2031.     echo original size 2933, current size $Wc_c
  2032. fi
  2033. echo "End of part 2, continue with part 3"
  2034. exit 0
  2035. ---------------------------------------------------------------------
  2036. Warren Tucker, TuckerWare  emory!n4hgf!wht or wht@n4hgf.Mt-Park.GA.US
  2037. Any perceptible delay will eventually get on your nerves. --Bob Hyers
  2038.  
  2039.