home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3998 / resource.c < prev    next >
C/C++ Source or Header  |  1991-09-08  |  3KB  |  144 lines

  1. /*
  2.  * @(#)resource.c    1.5 91/09/05
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <sys/types.h>
  7. #include <sys/time.h>
  8. #include <sys/ptrace.h>
  9. #include <sys/resource.h>
  10. #include <ufs/quota.h>
  11.  
  12. #include "defs.h"
  13.  
  14. static Xlat resources[] = {
  15.     RLIMIT_CPU,    "CPU",
  16.     RLIMIT_FSIZE,    "FSIZE",
  17.     RLIMIT_DATA,    "DATA",
  18.     RLIMIT_STACK,    "STACK",
  19.     RLIMIT_CORE,    "CORE",
  20.     RLIMIT_RSS,    "RSS",
  21.     RLIMIT_NOFILE,    "NOFILE",
  22.     0,        NULL,
  23. };
  24.  
  25. int
  26. sys_getrlimit(tcp)
  27. struct tcb *tcp;
  28. {
  29.     struct rlimit rlim;
  30.  
  31.     if (entering(tcp)) {
  32.         printxval(resources, tcp->u_args[0], "RLIMIT_???");
  33.     } else {
  34.         if (syserror(tcp) || umove(tcp->pid, tcp->u_args[1],
  35.                     sizeof rlim, (char *)&rlim) < 0) {
  36.             fprintf(outf, ", %#x", tcp->u_args[1]);
  37.         } else {
  38.             fprintf(outf, ", {cur: %u, max: %u}",
  39.                     rlim.rlim_cur, rlim.rlim_max);
  40.         }
  41.     }
  42.     return 0;
  43. }
  44.  
  45. int
  46. sys_setrlimit(tcp)
  47. struct tcb *tcp;
  48. {
  49.     struct rlimit rlim;
  50.  
  51.     if (entering(tcp)) {
  52.         printxval(resources, tcp->u_args[0], "RLIMIT_???");
  53.         if (umove(tcp->pid, tcp->u_args[1],
  54.                     sizeof rlim, (char *)&rlim) < 0)
  55.             fprintf(outf, ", %#x", tcp->u_args[1]);
  56.         else
  57.             fprintf(outf, ", {cur: %u, max: %u}",
  58.                     rlim.rlim_cur, rlim.rlim_max);
  59.     }
  60.     return 0;
  61. }
  62.  
  63. static Xlat usagewho[] = {
  64.     RUSAGE_SELF,        "RUSAGE_SELF",
  65.     RUSAGE_CHILDREN,    "RUSAGE_CHILDREN",
  66.     0,            NULL,
  67. };
  68.  
  69. int
  70. sys_getrusage(tcp)
  71. struct tcb *tcp;
  72. {
  73.     struct rusage ru;
  74.  
  75.     if (entering(tcp)) {
  76.         printxval(usagewho, tcp->u_args[0], "RUSAGE_???");
  77.     } else {
  78.         if (syserror(tcp) || umove(tcp->pid, tcp->u_args[1],
  79.                     sizeof ru, (char *)&ru) < 0) {
  80.             fprintf(outf, ", %#x", tcp->u_args[1]);
  81.         } else {
  82.             fprintf(outf, ", {ut:[%u,%u], st:[%u,%u], ...}",
  83.                     ru.ru_utime.tv_sec,
  84.                     ru.ru_utime.tv_usec,
  85.                     ru.ru_stime.tv_sec,
  86.                     ru.ru_stime.tv_usec);
  87.         }
  88.     }
  89.     return 0;
  90. }
  91.  
  92. static Xlat priorities[] = {
  93.     PRIO_PROCESS,     "PRIO_PROCESS",
  94.     PRIO_PGRP,    "PRIO_PGRP",
  95.     PRIO_USER,    "PRIO_USER",
  96.     0,        NULL,
  97. };
  98.  
  99. int
  100. sys_getpriority(tcp)
  101. struct tcb *tcp;
  102. {
  103.     if (entering(tcp)) {
  104.         printxval(priorities, tcp->u_args[0], "PRIO_???");
  105.         fprintf(outf, ", %u", tcp->u_args[1]);
  106.     }
  107.     return 0;
  108. }
  109.  
  110. int
  111. sys_setpriority(tcp)
  112. struct tcb *tcp;
  113. {
  114.     if (entering(tcp)) {
  115.         printxval(priorities, tcp->u_args[0], "PRIO_???");
  116.         fprintf(outf, ", %u, %d", tcp->u_args[1], tcp->u_args[2]);
  117.     }
  118.     return 0;
  119. }
  120.  
  121. static Xlat quotacmds[] = {
  122.     Q_QUOTAON,    "Q_QUOTAON",
  123.     Q_QUOTAOFF,    "Q_QUOTAOFF",
  124.     Q_GETQUOTA,    "Q_GETQUOTA",
  125.     Q_SETQUOTA,    "Q_SETQUOTA",
  126.     Q_SETQLIM,    "Q_SETQLIM",
  127.     Q_SYNC,        "Q_SYNC",
  128.     0,        NULL,
  129. };
  130.  
  131. int
  132. sys_quotactl(tcp)
  133. struct tcb *tcp;
  134. {
  135.     /* fourth arg (addr) not interpreted here */
  136.     if (entering(tcp)) {
  137.         printxval(quotacmds, tcp->u_args[0], "Q_???");
  138.         fprintf(outf, ", ");
  139.         printstr(tcp->pid, tcp->u_args[1], -1);
  140.         fprintf(outf, ", %u, %#x", tcp->u_args[2], tcp->u_args[3]);
  141.     }
  142.     return 0;
  143. }
  144.