home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume33 / u386mon / part04 < prev    next >
Encoding:
Text File  |  1992-11-20  |  50.5 KB  |  1,969 lines

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