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

  1. /*
  2.  * @(#)desc.c    1.5 91/09/05
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <sys/types.h>
  7. #include <sys/file.h>
  8. #include <sys/time.h>
  9. #include <sys/ptrace.h>
  10.  
  11. #include "defs.h"
  12.  
  13.  
  14. static Xlat fcntlcmds[] = {
  15.     F_DUPFD,     "DUPFD",
  16.     F_GETFD,    "GETFD",
  17.     F_SETFD,    "SETFD",
  18.     F_GETFL,    "F_GETFL",
  19.     F_SETFL,    "F_SETFL",
  20.     F_GETLK,    "F_GETLK",
  21.     F_SETLK,    "F_SETLK",
  22.     F_SETLKW,    "F_SETLKW",
  23.     F_GETOWN,    "F_GETOWN",
  24.     F_SETOWN,    "F_SETOWN",
  25.     F_RSETLK,    "F_RSETLK",
  26.     F_RSETLKW,    "F_RSETLKW",
  27.     F_RGETLK,    "F_RGETLK",
  28.     F_CNVT,        "F_CNVT",
  29.     0,        NULL,
  30. };
  31. static Xlat flockcmds[] = {
  32.     LOCK_SH,    "LOCK_SH",
  33.     LOCK_EX,    "LOCK_EX",
  34.     LOCK_NB,    "LOCK_NB",
  35.     LOCK_UN,    "LOCK_UN",
  36.     0,        NULL,
  37. };
  38.  
  39. int
  40. sys_fcntl(tcp)
  41. struct tcb *tcp;
  42. {
  43.     if (entering(tcp)) {
  44.         fprintf(outf, "%u, ", tcp->u_args[0]);
  45.         printxval(fcntlcmds, tcp->u_args[1], "F_???");
  46.         fprintf(outf, ", %#x", tcp->u_args[2]);
  47.     }
  48.     return 0;
  49. }
  50.  
  51. int
  52. sys_flock(tcp)
  53. struct tcb *tcp;
  54. {
  55.     if (entering(tcp)) {
  56.         fprintf(outf, "%u, ", tcp->u_args[0]);
  57.         printflags(flockcmds, tcp->u_args[1]);
  58.     }
  59.     return 0;
  60. }
  61.  
  62. int
  63. sys_close(tcp)
  64. struct tcb *tcp;
  65. {
  66.     if (entering(tcp)) {
  67.         fprintf(outf, "%u", tcp->u_args[0]);
  68.     }
  69.     return 0;
  70. }
  71.  
  72. int
  73. sys_dup(tcp)
  74. struct tcb *tcp;
  75. {
  76.     if (entering(tcp)) {
  77.         fprintf(outf, "%u", tcp->u_args[0]);
  78.     }
  79.     return 0;
  80. }
  81.  
  82. int
  83. sys_dup2(tcp)
  84. struct tcb *tcp;
  85. {
  86.     if (entering(tcp)) {
  87.         fprintf(outf, "%u, %u", tcp->u_args[0], tcp->u_args[1]);
  88.     }
  89.     return 0;
  90. }
  91.  
  92. int
  93. sys_getdtablesize(tcp)
  94. struct tcb *tcp;
  95. {
  96.     return 0;
  97. }
  98.  
  99. int
  100. sys_select(tcp)
  101. struct tcb *tcp;
  102. {
  103.     int i, j, nfds;
  104.     fd_set fds;
  105.     struct timeval tv;
  106.     static char outstr[1024];
  107.  
  108.     if (entering(tcp)) {
  109.         nfds = tcp->u_args[0];
  110.         fprintf(outf, "%u", nfds);
  111.         for (i = 0; i < 3; i++) {
  112.             if (tcp->u_args[i+1] == 0) {
  113.                 fprintf(outf, ", 0", j);
  114.                 continue;
  115.             }
  116.  
  117.             fprintf(outf, ", fdset%u:[", i);
  118.             umove(tcp->pid, tcp->u_args[i+1], sizeof fds, (char *)&fds);
  119.             for (j = 0; j < nfds; j++)
  120.                 if (FD_ISSET(j, &fds))
  121.                     fprintf(outf, " %u", j);
  122.             fprintf(outf, "]");
  123.         }
  124.         if (tcp->u_args[4]) {
  125.             umove(tcp->pid, tcp->u_args[4], sizeof tv, (char *)&tv);
  126.             fprintf(outf, ", tv:[%u,%u]", tv.tv_sec, tv.tv_usec);
  127.         } else
  128.             fprintf(outf, ", (struct timeval *)0");
  129.     } else {
  130.         int cumlen = 0;
  131.  
  132.         if (syserror(tcp))
  133.             return 0;
  134.  
  135.         if ((nfds = tcp->u_rval) == 0) {
  136.             tcp->auxstr = "Timeout";
  137.             return RVAL_STR;
  138.         }
  139.         outstr[0] = '\0';
  140.         for (i = 0; i < 3; i++) {
  141.             int first = 1;
  142.             char str[20];
  143.  
  144.             tcp->auxstr = outstr;
  145.             if (tcp->u_args[i+1] == 0) {
  146.                 continue;
  147.             }
  148.             umove(tcp->pid, tcp->u_args[i+1], sizeof fds, (char *)&fds);
  149.             for (j = 0; j < tcp->u_args[0]; j++) {
  150.                 if (FD_ISSET(j, &fds)) {
  151.                     if (first)
  152.                         sprintf(str, "fdset%u:[%u",
  153.                                 i, j), first=0;
  154.                     else
  155.                         sprintf(str, " %u", j);
  156.  
  157.                     --nfds;
  158.                     if ((cumlen += strlen(str)) < sizeof outstr)
  159.                         strcat(outstr, str);
  160.                 }
  161.             }
  162.             if (cumlen) strcat(outstr, "]");
  163.             if (nfds == 0) break;
  164.         }
  165.         return RVAL_STR;
  166.     }
  167.     return 0;
  168. }
  169.