home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume13 / attrenice.pch / xenix.pat < prev   
Encoding:
Text File  |  1988-03-13  |  9.2 KB  |  433 lines

  1. *** renice.c.orig
  2. --- renice.c
  3. **************
  4. *** 13,18
  5.    * yours, I would appreciate being given the appropriate
  6.    * amount of credit.
  7.    *                -=] Ford [=-
  8.    ************************************************************/
  9.   
  10.   #include <stdio.h>
  11. --- 13,23 -----
  12.    * yours, I would appreciate being given the appropriate
  13.    * amount of credit.
  14.    *                -=] Ford [=-
  15. +  *
  16. +  *
  17. +  *    Modifications
  18. +  *    3/3/88    Ported to Plexus Unix System V    pigs!haugj@rpp386.uucp
  19. +  *    3/3/88    Ported to SCO Xenix System V    jfh@rpp386.uucp
  20.    ************************************************************/
  21.   
  22.   #include <stdio.h>
  23. **************
  24. *** 23,29
  25.   #include <grp.h>
  26.   #include <sys/types.h>
  27.   #include <sys/param.h>
  28. ! #include <sys/tune.h>
  29.   #include <sys/proc.h>
  30.   #include <nlist.h>
  31.   
  32. --- 28,34 -----
  33.   #include <grp.h>
  34.   #include <sys/types.h>
  35.   #include <sys/param.h>
  36. ! #include <sys/page.h>
  37.   #include <sys/proc.h>
  38.   #include <sys/var.h>
  39.   #include <a.out.h>
  40. **************
  41. *** 25,31
  42.   #include <sys/param.h>
  43.   #include <sys/tune.h>
  44.   #include <sys/proc.h>
  45. ! #include <nlist.h>
  46.   
  47.   
  48.   extern long lseek();
  49. --- 30,37 -----
  50.   #include <sys/param.h>
  51.   #include <sys/page.h>
  52.   #include <sys/proc.h>
  53. ! #include <sys/var.h>
  54. ! #include <a.out.h>
  55.   
  56.   
  57.   extern long lseek();
  58. **************
  59. *** 36,43
  60.   
  61.   char *progname;
  62.   
  63. ! #define tuhiaddr (mysyms[0].n_value)
  64. ! #define procaddr (mysyms[1].n_value)
  65.   
  66.   struct nlist mysyms[] =
  67.   {
  68. --- 42,49 -----
  69.   
  70.   char *progname;
  71.   
  72. ! #define procaddr (mysyms[0].xl_value)
  73. ! #define    vaddr (mysyms[1].xl_value)
  74.   
  75.   struct xlist mysyms[] =
  76.   {
  77. **************
  78. *** 39,45
  79.   #define tuhiaddr (mysyms[0].n_value)
  80.   #define procaddr (mysyms[1].n_value)
  81.   
  82. ! struct nlist mysyms[] =
  83.   {
  84.       { "tuhi", },
  85.       { "proc", },
  86. --- 45,51 -----
  87.   #define procaddr (mysyms[0].xl_value)
  88.   #define    vaddr (mysyms[1].xl_value)
  89.   
  90. ! struct xlist mysyms[] =
  91.   {
  92.       { 0,0,0,"_proc", },
  93.       { 0,0,0,"_v", },
  94. **************
  95. *** 41,49
  96.   
  97.   struct nlist mysyms[] =
  98.   {
  99. !     { "tuhi", },
  100. !     { "proc", },
  101. !     { (char *)0, },
  102.   };
  103.   
  104.   char buf[BUFSIZ];
  105. --- 47,55 -----
  106.   
  107.   struct xlist mysyms[] =
  108.   {
  109. !     { 0,0,0,"_proc", },
  110. !     { 0,0,0,"_v", },
  111. !     { 0,0,0,(char *)0, },
  112.   };
  113.   
  114.   char buf[BUFSIZ];
  115. **************
  116. *** 51,57
  117.   int kmem;
  118.   int myuid;
  119.   int NPROC;
  120. ! static struct proc proc;
  121.   
  122.   
  123.   void usage()
  124. --- 57,64 -----
  125.   int kmem;
  126.   int myuid;
  127.   int NPROC;
  128. ! static struct proc proctab;
  129. ! static struct var v;
  130.   
  131.   
  132.   void usage()
  133. **************
  134. *** 108,115
  135.   /* one-time setup of main data structures from the kernel */
  136.   setup()
  137.   {
  138. -     struct tunable tune;
  139.       if ( (kmem=open("/dev/kmem", O_RDWR)) < 0 )
  140.       {
  141.       sprintf(buf, "%s: can't open /dev/kmem", progname);
  142. --- 115,120 -----
  143.   /* one-time setup of main data structures from the kernel */
  144.   setup()
  145.   {
  146.       if ( (kmem=open("/dev/kmem", O_RDWR)) < 0 )
  147.       {
  148.       sprintf(buf, "%s: can't open /dev/kmem", progname);
  149. **************
  150. *** 117,123
  151.       exit(1);
  152.       }
  153.   
  154. !     if (nlist("/unix", mysyms))
  155.       {
  156.       sprintf(buf, "%s: can't nlist /unix", progname);
  157.       perror(buf);
  158. --- 122,128 -----
  159.       exit(1);
  160.       }
  161.   
  162. !     if (xlist("/xenix", mysyms))
  163.       {
  164.       sprintf(buf, "%s: can't xlist /xenix", progname);
  165.       perror(buf);
  166. **************
  167. *** 119,125
  168.   
  169.       if (nlist("/unix", mysyms))
  170.       {
  171. !     sprintf(buf, "%s: can't nlist /unix", progname);
  172.       perror(buf);
  173.       exit(1);
  174.       }
  175. --- 124,130 -----
  176.   
  177.       if (xlist("/xenix", mysyms))
  178.       {
  179. !     sprintf(buf, "%s: can't xlist /xenix", progname);
  180.       perror(buf);
  181.       exit(1);
  182.       }
  183. **************
  184. *** 123,132
  185.       perror(buf);
  186.       exit(1);
  187.       }
  188. -     myuid = getuid();
  189. -     setuid(myuid);
  190.   #ifdef DEBUG
  191.       fprintf(stderr, "tuhi:    0x%08lx\n", tuhiaddr);
  192.   #endif DEBUG
  193. --- 128,133 -----
  194.       perror(buf);
  195.       exit(1);
  196.       }
  197.   #ifdef DEBUG
  198.       fprintf(stderr, "v:    0x%08lx\n", vaddr);
  199.   #endif DEBUG
  200. **************
  201. *** 128,134
  202.       setuid(myuid);
  203.   
  204.   #ifdef DEBUG
  205. !     fprintf(stderr, "tuhi:    0x%08lx\n", tuhiaddr);
  206.   #endif DEBUG
  207.       kcopy((char *)&tune, tuhiaddr, (long) sizeof tune);
  208.   
  209. --- 129,135 -----
  210.       exit(1);
  211.       }
  212.   #ifdef DEBUG
  213. !     fprintf(stderr, "v:    0x%08lx\n", vaddr);
  214.   #endif DEBUG
  215.       kcopy((char *)&v, vaddr, (long) sizeof v);
  216.   
  217. **************
  218. *** 130,136
  219.   #ifdef DEBUG
  220.       fprintf(stderr, "tuhi:    0x%08lx\n", tuhiaddr);
  221.   #endif DEBUG
  222. !     kcopy((char *)&tune, tuhiaddr, (long) sizeof tune);
  223.   
  224.       /* do indirection on the proc address, since it */
  225.       /* is just a pointer in the kernel */
  226. --- 131,137 -----
  227.   #ifdef DEBUG
  228.       fprintf(stderr, "v:    0x%08lx\n", vaddr);
  229.   #endif DEBUG
  230. !     kcopy((char *)&v, vaddr, (long) sizeof v);
  231.   
  232.   #ifdef DEBUG
  233.       fprintf(stderr, "proc:    0x%08lx\n", procaddr);
  234. **************
  235. *** 132,141
  236.   #endif DEBUG
  237.       kcopy((char *)&tune, tuhiaddr, (long) sizeof tune);
  238.   
  239. -     /* do indirection on the proc address, since it */
  240. -     /* is just a pointer in the kernel */
  241. -     kcopy((char *)&procaddr, procaddr, (long) sizeof procaddr);
  242.   #ifdef DEBUG
  243.       fprintf(stderr, "proc:    0x%08lx\n", procaddr);
  244.   #endif DEBUG
  245. --- 133,138 -----
  246.   #endif DEBUG
  247.       kcopy((char *)&v, vaddr, (long) sizeof v);
  248.   
  249.   #ifdef DEBUG
  250.       fprintf(stderr, "proc:    0x%08lx\n", procaddr);
  251.   #endif DEBUG
  252. **************
  253. *** 140,146
  254.       fprintf(stderr, "proc:    0x%08lx\n", procaddr);
  255.   #endif DEBUG
  256.   
  257. !     NPROC = tune.nproc;
  258.   
  259.   #ifdef DEBUG
  260.       fprintf(stderr, "NPROC:    %d\n", NPROC);
  261. --- 137,145 -----
  262.       fprintf(stderr, "proc:    0x%08lx\n", procaddr);
  263.   #endif DEBUG
  264.   
  265. !     NPROC = v.v_proc;
  266. !     myuid = getuid();
  267. !     setuid(myuid);
  268.   
  269.   #ifdef DEBUG
  270.       fprintf(stderr, "NPROC:    %d\n", NPROC);
  271. **************
  272. *** 195,201
  273.   
  274.       for ( i=0 ; i<NPROC ; ++i )
  275.       {
  276. !     kcopy((char *)&proc,
  277.             (long)&((struct proc *)procaddr)[i],
  278.             (long)sizeof proc);
  279.       if ( proc.p_pid == pid )
  280. --- 194,200 -----
  281.   
  282.       for ( i=0 ; i<NPROC ; ++i )
  283.       {
  284. !     kcopy((char *)&proctab,
  285.             (long)&((struct proc *)procaddr)[i],
  286.             (long)sizeof proctab);
  287.       if ( proctab.p_pid == pid )
  288. **************
  289. *** 197,204
  290.       {
  291.       kcopy((char *)&proc,
  292.             (long)&((struct proc *)procaddr)[i],
  293. !           (long)sizeof proc);
  294. !     if ( proc.p_pid == pid )
  295.       {
  296.   #ifdef DEBUG
  297.           fprintf(stderr, "Found it!  proc[%d], p_uid is %d\n",
  298. --- 196,203 -----
  299.       {
  300.       kcopy((char *)&proctab,
  301.             (long)&((struct proc *)procaddr)[i],
  302. !           (long)sizeof proctab);
  303. !     if ( proctab.p_pid == pid )
  304.       {
  305.   #ifdef DEBUG
  306.           fprintf(stderr, "Found it!  proc[%d], p_uid is %d\n",
  307. **************
  308. *** 202,208
  309.       {
  310.   #ifdef DEBUG
  311.           fprintf(stderr, "Found it!  proc[%d], p_uid is %d\n",
  312. !            i, proc.p_uid);
  313.   
  314.           fprintf(stderr, "Old p_nice was %d\n", proc.p_nice);
  315.   #endif DEBUG
  316. --- 201,207 -----
  317.       {
  318.   #ifdef DEBUG
  319.           fprintf(stderr, "Found it!  proc[%d], p_uid is %d\n",
  320. !            i, proctab.p_uid);
  321.   
  322.           fprintf(stderr, "Old p_nice was %d\n", proctab.p_nice);
  323.   #endif DEBUG
  324. **************
  325. *** 204,210
  326.           fprintf(stderr, "Found it!  proc[%d], p_uid is %d\n",
  327.              i, proc.p_uid);
  328.   
  329. !         fprintf(stderr, "Old p_nice was %d\n", proc.p_nice);
  330.   #endif DEBUG
  331.   
  332.           tmpnice = proc.p_nice;
  333. --- 203,209 -----
  334.           fprintf(stderr, "Found it!  proc[%d], p_uid is %d\n",
  335.              i, proctab.p_uid);
  336.   
  337. !         fprintf(stderr, "Old p_nice was %d\n", proctab.p_nice);
  338.   #endif DEBUG
  339.   
  340.           tmpnice = proctab.p_nice;
  341. **************
  342. *** 207,213
  343.           fprintf(stderr, "Old p_nice was %d\n", proc.p_nice);
  344.   #endif DEBUG
  345.   
  346. !         tmpnice = proc.p_nice;
  347.   
  348.           if (relative)
  349.           tmpnice += value;
  350. --- 206,212 -----
  351.           fprintf(stderr, "Old p_nice was %d\n", proctab.p_nice);
  352.   #endif DEBUG
  353.   
  354. !         tmpnice = proctab.p_nice;
  355.   
  356.           if (relative)
  357.           tmpnice += value;
  358. **************
  359. *** 223,229
  360.           fprintf(stderr, "New p_nice is %d\n", tmpnice);
  361.   #endif DEBUG
  362.   
  363. !         if ( myuid && (myuid != proc.p_uid || tmpnice<proc.p_nice) )
  364.           {
  365.           errno = EACCES;
  366.           sprintf(buf, "%s: can't renice process %d", progname, pid);
  367. --- 222,228 -----
  368.           fprintf(stderr, "New p_nice is %d\n", tmpnice);
  369.   #endif DEBUG
  370.   
  371. !         if ( myuid && (myuid != proctab.p_uid || tmpnice<proctab.p_nice) )
  372.           {
  373.           errno = EACCES;
  374.           sprintf(buf, "%s: can't renice process %d", progname, pid);
  375. **************
  376. *** 231,237
  377.           return 1;
  378.           }
  379.   
  380. !         proc.p_nice = tmpnice;
  381.   
  382.           kwrite((long)&((struct proc *)procaddr)[i]
  383.              + ( ((char *)&proc.p_nice) - (char *)&proc ),
  384. --- 230,236 -----
  385.           return 1;
  386.           }
  387.   
  388. !         proctab.p_nice = tmpnice;
  389.   
  390.           kwrite((long)&((struct proc *)procaddr)[i]
  391.              + ( ((char *)&proctab.p_nice) - (char *)&proctab ),
  392. **************
  393. *** 234,242
  394.           proc.p_nice = tmpnice;
  395.   
  396.           kwrite((long)&((struct proc *)procaddr)[i]
  397. !            + ( ((char *)&proc.p_nice) - (char *)&proc ),
  398. !            (char *)&proc.p_nice,
  399. !            (long)sizeof proc.p_nice);
  400.           return 0;
  401.       }
  402.       }
  403. --- 233,241 -----
  404.           proctab.p_nice = tmpnice;
  405.   
  406.           kwrite((long)&((struct proc *)procaddr)[i]
  407. !            + ( ((char *)&proctab.p_nice) - (char *)&proctab ),
  408. !            (char *)&proctab.p_nice,
  409. !            (long)sizeof proctab.p_nice);
  410.           return 0;
  411.       }
  412.       }
  413. **************
  414. *** 240,246
  415.           return 0;
  416.       }
  417.       }
  418.       fprintf(stderr, "%s: process %d not found.\n", progname, pid);
  419.   
  420.       return 1;
  421. --- 239,244 -----
  422.           return 0;
  423.       }
  424.       }
  425.       fprintf(stderr, "%s: process %d not found.\n", progname, pid);
  426.   
  427.       return 1;
  428.