home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume6 / bsd.ps.patch / ps.c.patch < prev   
Encoding:
Text File  |  1986-11-30  |  5.0 KB  |  274 lines

  1. % diff ps.c.old ps.c
  2. 21a22,24
  3. > #ifdef ECN
  4. > #include <sys/file.h>
  5. > #endif
  6. 23a27
  7. > #ifdef ECN /* share nlist with w so keep fields same */
  8. 48a53,58
  9. >     { "_swapdev" },
  10. > #define    X_SWAPDEV    12
  11. >     { "_avenrun" },
  12. > #define    X_AVENRUN    13
  13. >     { "_boottime" },
  14. > #define    X_BOOTTIME    14
  15. 50a61,89
  16. > #else
  17. > struct nlist nl[] = {
  18. >     { "_proc" },
  19. > #define    X_PROC        0
  20. >     { "_Usrptmap" },
  21. > #define    X_USRPTMA    1
  22. >     { "_usrpt" },
  23. > #define    X_USRPT        2
  24. >     { "_text" },
  25. > #define    X_TEXT        3
  26. >     { "_nswap" },
  27. > #define    X_NSWAP        4
  28. >     { "_maxslp" },
  29. > #define    X_MAXSLP    5
  30. >     { "_ccpu" },
  31. > #define    X_CCPU        6
  32. >     { "_ecmx" },
  33. > #define    X_ECMX        7
  34. >     { "_nproc" },
  35. > #define    X_NPROC        8
  36. >     { "_ntext" },
  37. > #define    X_NTEXT        9
  38. >     { "_dmmin" },
  39. > #define    X_DMMIN        10
  40. >     { "_dmmax" },
  41. > #define    X_DMMAX        11
  42. >     { "" },
  43. > };
  44. > #endif
  45. 91a131,133
  46. > #ifdef ECN
  47. > struct    proc proc[400];        /* 400 = a few, for less syscalls */
  48. > #else
  49. 92a135
  50. > #endif
  51. 106a150,153
  52. > #ifdef ECN
  53. > int    Rflg, Nflg, nvalue, Uflg;
  54. > char    *mylogin, *lptr;
  55. > #endif
  56. 139a187,189
  57. > #ifdef ECN
  58. > char bigoutbuf[BUFSIZ];
  59. > #endif ECN
  60. 150a201,203
  61. > #ifdef ECN
  62. >     setbuffer(stdout, bigoutbuf, BUFSIZ);
  63. > #endif ECN
  64. 198a252,280
  65. > #ifdef ECN
  66. >         case 'R':
  67. >             Rflg++;
  68. >             xflg++;
  69. >             gflg++;
  70. >             aflg++;
  71. >             break;
  72. >         case 'L':
  73. >             if (*ap)
  74. >                 lptr = ap;
  75. >             xflg++;
  76. >             gflg++;
  77. >             while (*ap)
  78. >                 ap++;
  79. >             break;
  80. >         case 'N':
  81. >             if (*ap)
  82. >                 nvalue = atoi(ap) + 20;
  83. >             aflg++;
  84. >             gflg++;
  85. >             xflg++;
  86. >             Nflg++;
  87. >             while (*ap)
  88. >                 ap++;
  89. >             break;
  90. >         case 'U':
  91. >             Uflg++;
  92. >             break;
  93. > #endif
  94. 231a314,325
  95. > #ifdef ECN
  96. >     if (lptr) {
  97. >         struct passwd *pw, *getpwnam();
  98. >         if ((pw = getpwnam(lptr)) == NULL) {
  99. >             fprintf(stderr, "Unknown user: %s\n", lptr);
  100. >             exit(1);
  101. >         } else {
  102. >             uid = pw->pw_uid;
  103. >         }
  104. >     } else
  105. >         uid = getuid();
  106. > #else
  107. 232a327
  108. > #endif ECN
  109. 236a332,334
  110. > #ifdef ECN
  111. >     for (i=0; i<nproc; i += 400) {
  112. > #else
  113. 237a336
  114. > #endif
  115. 240,241c339,345
  116. <         if (j > 8)
  117. <             j = 8;
  118. ---
  119. > #ifdef ECN
  120. >         if (j > 400)
  121. >             j = 400;
  122. > #else
  123. >         if (j > 400)
  124. >             j = 400;
  125. > #endif
  126. 252a357,367
  127. >             if (Rflg) {
  128. >                 if (mproc->p_stat == SRUN)
  129. >                     save();
  130. >                 continue;
  131. >             }
  132. >             if (Nflg) {
  133. >                 if ((int)mproc->p_nice >= nvalue) {
  134. >                     save();
  135. >                 }
  136. >                 continue;
  137. >             }
  138. 358a474,490
  139. > #ifdef ECN
  140. >     register int fd;
  141. >     if (Uflg)
  142. >         return;
  143. >     else {
  144. >         if (argc > 1)
  145. >             nlist(argv[1],nl);
  146. >         else {
  147. >             if ((fd = open("/etc/psnlist", O_RDONLY)) < 0)
  148. >                 nlist("/vmunix", nl);
  149. >             else {
  150. >                 read(fd, nl, sizeof(nl));
  151. >                 close(fd);
  152. >             }
  153. >         }
  154. >     }
  155. > #else
  156. 360a493
  157. > #endif ECN
  158. 436a570,575
  159. > #ifdef ECN
  160. > #define MAXTTYS 150
  161. > struct ttys *hash_ttys[256]; /* 256 used to find minor */
  162. > struct ttys saved_tty_stat[MAXTTYS]; /* fixed sized used to quickly read in */
  163. > int next_stty = 0;
  164. 438a578,667
  165. >     register int fd;
  166. >     if (Uflg) {
  167. >         if ((fd = open("/etc/psnlist", O_CREAT|O_RDWR, 0444)) >= 0) {
  168. >             nlist("/vmunix", nl);
  169. >             write(fd, nl, sizeof(nl));
  170. >             close(fd);
  171. >         } else {
  172. >             perror("/etc/psnlist");
  173. >             exit(1);
  174. >         }
  175. >         domanual();
  176. >         dosavettys();
  177. >     }
  178. >     if ((fd = open("/etc/psdatabase", O_RDONLY)) <= 0) {
  179. >         domanual();
  180. >         return;
  181. >     }
  182. >     read(fd, hash_ttys, sizeof(hash_ttys));
  183. >     read(fd, saved_tty_stat, sizeof(saved_tty_stat));
  184. >     close(fd);
  185. > }
  186. > dosavettys()
  187. > {
  188. >     register int fd;
  189. >     if ((fd = open("/etc/psdatabase", O_CREAT|O_RDWR, 0444)) <= 0)
  190. >         return;
  191. >     write(fd, hash_ttys, sizeof(hash_ttys));
  192. >     write(fd, saved_tty_stat, sizeof(saved_tty_stat));
  193. >     close(fd);
  194. >     exit(0);
  195. > }
  196. > domanual()
  197. > {
  198. >     register FILE *fp;
  199. >     register int i;
  200. >     register char c;
  201. >     struct stat sbuf;
  202. >     if ((fp = fopen("/etc/ttys", "r")) == NULL) {
  203. >         perror("/etc/ttys");
  204. >         exit(1);
  205. >     }
  206. >     i = 0;
  207. >     while((c = getc(fp)) != EOF) {
  208. >         if (c == '\n') {    /* jump the first 2 chars */
  209. >             saved_tty_stat[next_stty].name[i] = '\0';
  210. >             i = 0;
  211. >             if (stat(saved_tty_stat[next_stty].name,&sbuf)==0 &&
  212. >                 (sbuf.st_mode & S_IFMT) == S_IFCHR)
  213. >                 saved_tty_stat[next_stty].ttyd = sbuf.st_rdev;
  214. >             else
  215. >                 saved_tty_stat[next_stty].ttyd = -2;
  216. >             saved_tty_stat[next_stty].next =
  217. >                 hash_ttys[saved_tty_stat[next_stty].ttyd % 256];
  218. >             hash_ttys[saved_tty_stat[next_stty].ttyd % 256] =
  219. >                 &saved_tty_stat[next_stty];
  220. >             next_stty++;
  221. >             if ((c = getc(fp)) == EOF)
  222. >                 return;
  223. >             if ((c = getc(fp)) == EOF)
  224. >                 return;
  225. >         } else
  226. >             saved_tty_stat[next_stty].name[i++] = c;
  227. >     }
  228. > }
  229. > char *
  230. > gettty()
  231. > {
  232. >     register struct ttys *dp;
  233. >     register char *p;
  234. >     for(dp = hash_ttys[u.u_ttyd % 256]; dp; dp = dp->next)
  235. >         if (dp->ttyd == u.u_ttyd) {
  236. >             p = dp->name;
  237. >             if (p[0] == 't' && p[1] == 't' && p[2] == 'y')
  238. >                 p += 3;
  239. >             return(p);
  240. >         }
  241. >     return("?");
  242. > }
  243. > #else ECN
  244. > getdev()
  245. > {
  246. 596a826
  247. > #endif ECN
  248. 1103a1334,1336
  249. > #ifdef ECN
  250. >     struct passwd            *getpwuid();
  251. > #else
  252. 1105a1339
  253. > #endif
  254. 1118a1353,1359
  255. > #ifdef ECN
  256. >     if ((pw = getpwuid(uid)) == NULL)
  257. >         return((char *)NULL);
  258. >     strncpy(n->nt_name, pw->pw_name, NMAX);
  259. >     n->nt_uid = uid;
  260. >     return(n->nt_name);
  261. > #else
  262. 1145a1387
  263. > #endif
  264.