home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / sun / volume3 / strace / part01 / time.c < prev   
Encoding:
C/C++ Source or Header  |  1992-03-02  |  2.4 KB  |  136 lines

  1. /*
  2.  * @(#)time.c    2.3 92/01/10
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <sys/types.h>
  7. #include <sys/ptrace.h>
  8. #include <sys/time.h>
  9.  
  10. #include "defs.h"
  11.  
  12. void
  13. printtv(pid, addr)
  14. {
  15.     struct timeval tv;
  16.  
  17.     if (addr == 0 || umove(pid, addr, sizeof tv, (char *)&tv) < 0) {
  18.         tprintf("(struct timeval *)0");
  19.     } else {
  20.         tprintf("{%u,%u}", tv.tv_sec, tv.tv_usec);
  21.     }
  22. }
  23.  
  24. int
  25. sys_gettimeofday(tcp)
  26. struct tcb *tcp;
  27. {
  28.     struct timezone tz;
  29.  
  30.     if (exiting(tcp)) {
  31.         if (syserror(tcp)) {
  32.             tprintf("%#x, %#x",
  33.                     tcp->u_args[0], tcp->u_args[1]);
  34.             return 0;
  35.         }
  36.         printtv(tcp->pid, tcp->u_args[0]);
  37.         if (tcp->u_args[1] == 0 || umove(tcp->pid, tcp->u_args[1],
  38.                         sizeof tz, (char *)&tz) < 0) {
  39.             tprintf(", (struct timezone *)0");
  40.         } else {
  41.             tprintf(", {%d west,%d dst}",
  42.                 tz.tz_minuteswest, tz.tz_dsttime);
  43.         }
  44.     }
  45.     return 0;
  46. }
  47.  
  48. int
  49. sys_settimeofday(tcp)
  50. struct tcb *tcp;
  51. {
  52.     struct timezone tz;
  53.  
  54.     if (entering(tcp)) {
  55.         printtv(tcp->pid, tcp->u_args[0]);
  56.         if (tcp->u_args[1] == 0 || umove(tcp->pid, tcp->u_args[1],
  57.                         sizeof tz, (char *)&tz) < 0) {
  58.             tprintf(", (struct timezone *)0");
  59.         } else {
  60.             tprintf(", {%d west,%d dst}",
  61.                 tz.tz_minuteswest, tz.tz_dsttime);
  62.         }
  63.     }
  64.     return 0;
  65. }
  66.  
  67. int
  68. sys_adjtime(tcp)
  69. struct tcb *tcp;
  70. {
  71.     if (entering(tcp)) {
  72.         printtv(tcp->pid, tcp->u_args[0]);
  73.         tprintf(", ");
  74.     } else {
  75.         if (syserror(tcp))
  76.             tprintf("%#x", tcp->u_args[1]);
  77.         else
  78.             printtv(tcp->pid, tcp->u_args[1]);
  79.     }
  80. }
  81.  
  82. static Xlat which[] = {
  83.     ITIMER_REAL,    "ITIMER_REAL",
  84.     ITIMER_VIRTUAL,    "ITIMER_VIRTUAL",
  85.     ITIMER_PROF,    "ITIMER_PROF",
  86.     0,        NULL,
  87. };
  88.  
  89. static void
  90. printitv(pid, addr)
  91. {
  92.     struct itimerval itv;
  93.  
  94.     if (addr == 0 || umove(pid, addr, sizeof itv, (char *)&itv) < 0) {
  95.         tprintf("(struct itimerval *)0");
  96.     } else {
  97.         tprintf("{{%u,%u},{%u,%u}}",
  98.         itv.it_interval.tv_sec, itv.it_interval.tv_usec,
  99.         itv.it_value.tv_sec, itv.it_value.tv_usec);
  100.     }
  101. }
  102.  
  103. int
  104. sys_getitimer(tcp)
  105. struct tcb *tcp;
  106. {
  107.     if (entering(tcp)) {
  108.         printxval(which, tcp->u_args[0], "ITMER_???");
  109.         tprintf(", ");
  110.     } else {
  111.         if (syserror(tcp))
  112.             tprintf("%#x", tcp->u_args[1]);
  113.         else
  114.             printitv(tcp->pid, tcp->u_args[1]);
  115.     }
  116.     return 0;
  117. }
  118.  
  119. int
  120. sys_setitimer(tcp)
  121. struct tcb *tcp;
  122. {
  123.     if (entering(tcp)) {
  124.         printxval(which, tcp->u_args[0], "ITMER_???");
  125.         tprintf(", ");
  126.         printitv(tcp->pid, tcp->u_args[1]);
  127.         tprintf(", ");
  128.     } else {
  129.         if (syserror(tcp))
  130.             tprintf("%#x", tcp->u_args[2]);
  131.         else
  132.             printitv(tcp->pid, tcp->u_args[2]);
  133.     }
  134.     return 0;
  135. }
  136.