home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / c / condor40.zip / CONDOR / src / condor_shadow / ops.c < prev    next >
C/C++ Source or Header  |  1989-09-01  |  36KB  |  1,515 lines

  1. /* 
  2. ** Copyright 1986, 1987, 1988, 1989 University of Wisconsin
  3. ** 
  4. ** Permission to use, copy, modify, and distribute this software and its
  5. ** documentation for any purpose and without fee is hereby granted,
  6. ** provided that the above copyright notice appear in all copies and that
  7. ** both that copyright notice and this permission notice appear in
  8. ** supporting documentation, and that the name of the University of
  9. ** Wisconsin not be used in advertising or publicity pertaining to
  10. ** distribution of the software without specific, written prior
  11. ** permission.  The University of Wisconsin makes no representations about
  12. ** the suitability of this software for any purpose.  It is provided "as
  13. ** is" without express or implied warranty.
  14. ** 
  15. ** THE UNIVERSITY OF WISCONSIN DISCLAIMS ALL WARRANTIES WITH REGARD TO
  16. ** THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. ** FITNESS. IN NO EVENT SHALL THE UNIVERSITY OF WISCONSIN  BE LIABLE FOR
  18. ** ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19. ** WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  20. ** ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  21. ** OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22. ** 
  23. ** Authors:  Allan Bricker and Michael J. Litzkow,
  24. **              University of Wisconsin, Computer Sciences Dept.
  25. ** 
  26. */ 
  27.  
  28.  
  29. #include <stdio.h>
  30. #include "errno.h"
  31. #include <sys/types.h>
  32. #include <sys/param.h>
  33. #include <sys/time.h>
  34. #include <sys/resource.h>
  35. #include <sys/stat.h>
  36.  
  37. #if !defined(ultrix)
  38. #include <sys/vfs.h>
  39. #endif !defined(ultrix)
  40.  
  41. #include <sys/wait.h>
  42. #include <sys/ioctl.h>
  43. #include <rpc/types.h>
  44. #include <rpc/xdr.h>
  45.  
  46. #include "condor_types.h"
  47. #include "condor_sys.h"
  48. #include "condor_rsc.h"
  49. #include "trace.h"
  50. #include "except.h"
  51. #include "debug.h"
  52. #include "fileno.h"
  53. #include "proc.h"
  54. #include "xdr_lib.h"
  55. #include "clib.h"
  56.  
  57. static char *_FileName_ = __FILE__;        /* Used by EXCEPT (see except.h)     */
  58.  
  59. static int RSCSock;
  60. static int LogSock;
  61. extern int    MyPipe;
  62. extern int    LogPipe;
  63. extern int    LockFd;
  64.  
  65. static FILE *LogFP;
  66.  
  67.  
  68. #define XDR_BUFSIZE    (4 * 1024)
  69.  
  70. static XDR xdr_RSC, *xdr_syscall = &xdr_RSC;
  71.  
  72. XDR *
  73. RSC_ShadowInit( rscsock, errsock )
  74. {
  75.     int XDR_ShadowRead(), XDR_ShadowWrite();
  76.  
  77.     RSCSock = rscsock;
  78.     xdrrec_create( xdr_syscall, XDR_BUFSIZE, XDR_BUFSIZE, &RSCSock,
  79.             XDR_ShadowRead, XDR_ShadowWrite );
  80.     
  81.     xdr_syscall->x_op = XDR_ENCODE;
  82.  
  83.     LogSock = errsock;
  84.     LogFP = fdopen(LogSock, "r");
  85.  
  86.     if( LogFP == NULL ) {
  87.         EXCEPT("Cannot fdopen LogSock");
  88.     }
  89.  
  90.     return( xdr_syscall );
  91. }
  92.  
  93. static
  94. XDR_ShadowRead( iohandle, buf, len )
  95. register int *iohandle;
  96. char     *buf;
  97. int     len;
  98. {
  99.     register int cnt;
  100.     fd_set readfds;
  101.     int nfds;
  102.  
  103.     FD_ZERO(&readfds);
  104.  
  105.     nfds = MAX(*iohandle, LogSock) + 1;
  106.  
  107.     for(;;) {
  108.         FD_SET(*iohandle, &readfds);
  109.         FD_SET(LogSock, &readfds);
  110.  
  111.  
  112.         dprintf(D_XDR,
  113.         "Shadow: XDR_ShadowRead: about to select on <%d, %d, and %d>\n",
  114.                 *iohandle, LogSock, UMBILICAL);
  115.  
  116.         cnt = select(nfds, (int *)&readfds, (int *)0, (int *)0,
  117.                                                         (struct timeval *)0);
  118.         if( cnt < 0 ) {
  119.             EXCEPT("XDR_ShadowRead: select");
  120.         }
  121.  
  122.         if( FD_ISSET(LogSock, &readfds) ) {
  123.             HandleLog();
  124.             continue;
  125.         }
  126.  
  127.         if( FD_ISSET(*iohandle, &readfds) ) {
  128.             break;
  129.         }
  130.  
  131.         if( FD_ISSET(UMBILICAL, &readfds) ) {
  132.             dprintf(D_ALWAYS,
  133.                 "Shadow: Local scheduler apparently died, so I die too\n");
  134.             exit(1);
  135.         }
  136.     }
  137.  
  138.     dprintf(D_XDR, "Shadow: XDR_ShadowRead: about to read(%d, 0x%x, %d)\n",
  139.             *iohandle, buf, len );
  140.     
  141.     cnt = read( *iohandle, buf, len );
  142.  
  143.     dprintf(D_XDR, "Shadow: XDR_ShadowRead: cnt = %d\n", cnt );
  144.  
  145.     return( cnt );
  146. }
  147.  
  148. static
  149. XDR_ShadowWrite( iohandle, buf, len )
  150. register int *iohandle;
  151. char *buf;
  152. int     len;
  153. {
  154.     register int cnt;
  155.     fd_set readfds;
  156.     fd_set writefds;
  157.     int nfds;
  158.  
  159.     FD_ZERO(&readfds);
  160.     FD_ZERO(&writefds);
  161.  
  162.     nfds = MAX(*iohandle, LogSock) + 1;
  163.  
  164.     for(;;) {
  165.         FD_SET(*iohandle, &writefds);
  166.         FD_SET(LogSock, &readfds);
  167.  
  168.  
  169.         dprintf(D_XDR,
  170.         "Shadow: XDR_ShadowWrite: about to select on <%d, %d, and %d>\n",
  171.                 *iohandle, LogSock, UMBILICAL);
  172.  
  173.         cnt = select(nfds, (int *)&readfds, (int *)&writefds, (int *)0, 
  174.                                                         (struct timeval *)0 );
  175.         if( cnt < 0 ) {
  176.             EXCEPT("XDR_ShadowWrite: select");
  177.         }
  178.  
  179.         if( FD_ISSET(LogSock, &readfds) ) {
  180.             HandleLog();
  181.             continue;
  182.         }
  183.  
  184.         if( FD_ISSET(*iohandle, &writefds) ) {
  185.             break;
  186.         }
  187.  
  188.         if( FD_ISSET(UMBILICAL, &readfds) ) {
  189.             dprintf(D_ALWAYS,
  190.                 "Shadow: Local scheduler apparently died, so I'm dying too\n");
  191.             exit(1);
  192.         }
  193.     }
  194.  
  195.     dprintf(D_XDR, "Shadow: XDR_ShadowWrite: about to write(%d, 0x%x, %d)\n",
  196.             *iohandle, buf, len );
  197.     
  198.     cnt = write( *iohandle, buf, len );
  199.  
  200.     dprintf(D_XDR, "Shadow: XDR_ShadowWrite: cnt = %d\n", cnt );
  201.  
  202.     ASSERT(cnt == len);
  203.  
  204.     return( cnt );
  205. }
  206.  
  207.  
  208. static char *MemToFree = NULL;
  209.  
  210. #define RSC_NO_ARGS(func) { \
  211.     int func(); \
  212.     return( RSC_no_args(func, condor_sysnum) ); \
  213. }
  214.  
  215. #define RSC_1INT(func) { \
  216.     int func(); \
  217.     return( RSC_1int(func, condor_sysnum) ); \
  218. }
  219.  
  220. #define RSC_2INT(func) { \
  221.     int func(); \
  222.     return( RSC_2int(func, condor_sysnum) ); \
  223. }
  224.  
  225. #define RSC_3INT(func) { \
  226.     int func(); \
  227.     return( RSC_3int(func, condor_sysnum) ); \
  228. }
  229.  
  230. #define RSC_1STR(func) { \
  231.     int func(); \
  232.     return( RSC_1str(func, condor_sysnum) ); \
  233. }
  234.  
  235. #define RSC_1STR_1INT(func) { \
  236.     int func(); \
  237.     return( RSC_1str_1int(func, condor_sysnum) ); \
  238. }
  239.  
  240. #define RSC_1STR_2INT(func) { \
  241.     int func(); \
  242.     return( RSC_1str_2int(func, condor_sysnum) ); \
  243. }
  244.  
  245. #define RSC_2STR(func) { \
  246.     int func(); \
  247.     return( RSC_2str(func, condor_sysnum) ); \
  248. }
  249.  
  250. #define RSC_1INT_1RBUF(func, s_name, xdr_func) { \
  251.     int func(), xdr_func(); \
  252.     return( RSC_1int_1Rbuf(func, condor_sysnum, \
  253.                     sizeof(struct s_name), xdr_func) ); \
  254. }
  255.  
  256. #define RSC_1STR_1RBUF(func, s_name, xdr_func) { \
  257.     int func(), xdr_func(); \
  258.     return( RSC_1str_1Rbuf(func, condor_sysnum, \
  259.                 sizeof(struct s_name), xdr_func) ); \
  260. }
  261.  
  262. int condor_sysnum;
  263. do_REMOTE_syscall()
  264. {
  265.     int rval;
  266.     extern errno;
  267.  
  268.     xdr_syscall->x_op = XDR_DECODE;
  269.  
  270.     ASSERT( xdrrec_skiprecord(xdr_syscall) );
  271.     ASSERT( xdr_int(xdr_syscall, &condor_sysnum) );
  272.  
  273.     dprintf(D_SYSCALLS, "Shadow: got request for syscall %d <%s>\n",
  274.                 condor_sysnum, CONDOR_SYSCALLNAME(condor_sysnum));
  275.  
  276.     switch( condor_sysnum ) {
  277.     /*
  278.     **    System calls with no arguments
  279.     */
  280.     case CONDOR_async_daemon:    /* async_daemon()                            */
  281.         RSC_NO_ARGS(CONDOR_NotSupported);
  282.  
  283.     case CONDOR_fork:            /* fork()                                    */
  284.         RSC_NO_ARGS(CONDOR_NotSupported);
  285.  
  286.     case CONDOR_getdtablesize:    /* getdtablesize()                           */
  287.         RSC_NO_ARGS(getdtablesize);
  288.  
  289. #ifdef DAYAO
  290.     case PSEUDO_processlogging: /* log file transfer times                     */
  291.         RSC_2INT(ProcessLogging);
  292. #endif DAYAO
  293.  
  294.     case PSEUDO_getegid:    /* getegid()                                     */
  295.         RSC_NO_ARGS(getegid);
  296.  
  297.     case PSEUDO_geteuid:    /* geteuid()                                     */
  298.         RSC_NO_ARGS(geteuid);
  299.  
  300.     case CONDOR_getgid:            /* getgid()                                  */
  301.         RSC_NO_ARGS(getgid);
  302.  
  303.     case CONDOR_gethostid:        /* gethostid()                               */
  304.         RSC_NO_ARGS(gethostid);
  305.  
  306.     case CONDOR_getpagesize:    /* getpagesize()                             */
  307.         RSC_NO_ARGS(getpagesize);
  308.  
  309.     case CONDOR_getpid:            /* getpid()                                  */
  310.         RSC_NO_ARGS(condor_getpid);
  311.  
  312.     case PSEUDO_getppid:    /* getppid()                                     */
  313.         RSC_NO_ARGS(condor_getppid);
  314.  
  315.     case CONDOR_getuid:            /* getuid()                                  */
  316.         RSC_NO_ARGS(getuid);
  317.  
  318.     case CONDOR_sync:            /* sync()                                    */
  319.         RSC_NO_ARGS(sync);
  320.  
  321.     case CONDOR_vhangup:        /* vhangup()                                 */
  322.         RSC_NO_ARGS(vhangup);
  323.  
  324.     /*
  325.     **    System calls which take one integer argument
  326.     */
  327.     case CONDOR_close:            /* close( int d )                            */
  328.         RSC_1INT(condor_close);
  329.  
  330.     case CONDOR_dup:            /* dup( int oldd )                           */
  331.         RSC_1INT(dup);
  332.  
  333.     case CONDOR__exit:            /* _exit( int status )                       */
  334.         RSC_1INT(condor_exit);
  335.  
  336.     case CONDOR_fsync:            /* fsync( int fd )                           */
  337.         RSC_1INT(fsync);
  338.  
  339.  
  340.     case CONDOR_getpgrp:        /* getpgrp( int pid )                        */
  341.         RSC_1INT(getpgrp);
  342.  
  343.     case CONDOR_nfssvc:            /* nfssvc( int sock )                        */
  344.         RSC_1INT(CONDOR_NotSupported);
  345.  
  346.     case CONDOR_reboot:            /* reboot( int howto )                       */
  347.         RSC_1INT(reboot);
  348.  
  349.     case CONDOR_umask:            /* umask( int numask )                       */
  350.         RSC_1INT(umask);
  351.  
  352.     /*
  353.     **    System calls which take one long argument
  354.     */
  355.     case CONDOR_sethostid:        /* sethostid( int hostid )                   */
  356.     {
  357.         int hostid;
  358.  
  359.         ASSERT(xdr_int(xdr_syscall, &hostid));
  360.  
  361. #ifdef SYS_sethostid
  362.         rval = sethostid( hostid );
  363. #else SYS_sethostid
  364.         rval = CONDOR_NotSupported();
  365. #endif SYS_sethostid
  366.  
  367.         dprintf(D_SYSCALLS, "Shadow: sethostid(%d) = %d\n", hostid, rval);
  368.  
  369.         PUT_RVAL(xdr_syscall, rval);
  370.         END_RVAL(xdr_syscall, 0);
  371.     }
  372.  
  373.     /*
  374.     **    System calls which take two integer arguments
  375.     */
  376.     case CONDOR_dup2:            /* dup2( int oldd, int newd )                */
  377.         RSC_2INT(condor_dup2);
  378.  
  379.     case CONDOR_fchmod:            /* fchmod( int fd, int mode )                */
  380.         RSC_2INT(fchmod);
  381.  
  382.     case CONDOR_flock:            /* flock( int fd, int operation )            */
  383.         RSC_2INT(flock);
  384.  
  385.     case CONDOR_getpriority:    /* getpriority( int which, int who )         */
  386.         RSC_2INT(getpriority);
  387.  
  388.     case CONDOR_kill:            /* kill( int pid, int sig )                  */
  389.         RSC_2INT(CONDOR_NotSupported);
  390.  
  391.     case CONDOR_killpg:            /* killpg( int pgrp, int sig )               */
  392.         RSC_2INT(CONDOR_NotSupported);
  393.  
  394.     case CONDOR_listen:            /* listen( int s, int backlog )              */
  395.         RSC_2INT(listen);
  396.  
  397.     case CONDOR_setpgrp:        /* setpgrp( int pid, int pgrp )              */
  398.         RSC_2INT(setpgrp);
  399.  
  400.     case CONDOR_setregid:        /* setregid( int rgid, int egid )            */
  401.         RSC_2INT(setregid);
  402.  
  403.     case CONDOR_setreuid:        /* setreuid( int ruid, int euid )            */
  404.         RSC_2INT(setreuid);
  405.  
  406.     case CONDOR_shutdown:        /* shutdown( int s, int how )                */
  407.         RSC_2INT(shutdown);
  408.  
  409.     /*
  410.     **    System calls which take an integer argument and an off_t argument
  411.     */
  412.     case CONDOR_ftruncate:        /* ftruncate( int fd, off_t length )         */
  413.     {
  414.         int fd, length;
  415.  
  416.         ASSERT(xdr_int(xdr_syscall, &fd));
  417.         ASSERT(xdr_int(xdr_syscall, &length));
  418.  
  419.         rval = ftruncate( fd, length );
  420.  
  421.         dprintf(D_SYSCALLS, "Shadow: ftruncate(%d, %d) = %d\n",
  422.                 fd, length, rval);
  423.  
  424.         PUT_RVAL(xdr_syscall, rval);
  425.         END_RVAL(xdr_syscall, 0);
  426.     }
  427.  
  428.     /*
  429.     **    System calls which take three integer arguments
  430.     */
  431.     case CONDOR_fchown:            /* fchown( int fd, int owner, int group )    */
  432.         RSC_3INT(fchown);
  433.  
  434.     case CONDOR_fcntl:            /* fcntl( int fd, int cmd, int arg )         */
  435.         RSC_3INT(fcntl);
  436.  
  437.     case CONDOR_setpriority:    /* setpriority( int which, int who,
  438.                                 **                    int prio )
  439.                                 */
  440.         RSC_3INT(setpriority);
  441.  
  442.     case CONDOR_socket:            /* socket( int domain, int type,
  443.                                 **                    int protocol ) 
  444.                                 */
  445.         RSC_3INT(CONDOR_NotSupported);
  446.  
  447.     /*
  448.     **  System calls which take an integer argument followed by
  449.     **  an off_t argument followed by another integer argument.
  450.     */
  451.     case CONDOR_lseek:            /* lseek( int d, off_t offset, int whence )  */
  452.     {
  453.         int d, whence;
  454.         off_t pos, offset;
  455.  
  456.         ASSERT(xdr_int(xdr_syscall, &d));
  457.         ASSERT(xdr_int(xdr_syscall, &offset));
  458.         ASSERT(xdr_int(xdr_syscall, &whence));
  459.  
  460.         pos = lseek( d, offset, whence );
  461.  
  462.         dprintf(D_SYSCALLS, "Shadow: lseek(%d, %d, %d) = %d\n",
  463.                 d, offset, whence, pos);
  464.  
  465.         PUT_RVAL(xdr_syscall, pos);
  466.         END_RVAL(xdr_syscall, 0);
  467.     }
  468.  
  469.     /*
  470.     **    System calls which take one string argument
  471.     */
  472.     case CONDOR_acct:            /* acct( char *file  )                       */
  473.         RSC_1STR(acct);
  474.  
  475.     case CONDOR_chdir:            /* chdir( char *path )                       */
  476.         RSC_1STR(chdir);
  477.  
  478.     case CONDOR_chroot:            /* chroot( char *dirname )                   */
  479.         RSC_1STR(chroot);
  480.  
  481.     case CONDOR_rmdir:            /* rmdir( char *path )                       */
  482.         RSC_1STR(rmdir);
  483.  
  484.     case CONDOR_swapon:            /* swapon( char *special )                   */
  485.         RSC_1STR(swapon);
  486.  
  487.     case CONDOR_unlink:            /* unlink( char *path )                      */
  488.         RSC_1STR(unlink);
  489.  
  490.     case CONDOR_unmount:        /* unmount( char *name )                     */
  491.         RSC_1STR(CONDOR_NotSupported);
  492.  
  493.     /*
  494.     **    System calls which take one string and one integer as arguments
  495.     */
  496.     case CONDOR_access:            /* access( char *path, int mode )            */
  497.         RSC_1STR_1INT(access);
  498.  
  499.     case CONDOR_chmod:            /* chmod( char *path, int mode )             */
  500.         RSC_1STR_1INT(chmod);
  501.  
  502.     case CONDOR_creat:            /* creat( char *path, int mode )             */
  503.         RSC_1STR_1INT(creat);
  504.  
  505.     case CONDOR_mkdir:            /* mkdir( char *path, int mode )             */
  506.         RSC_1STR_1INT(mkdir);
  507.  
  508.     case CONDOR_setdomainname:    /* setdomainname( char *name, int namelen )  */
  509. #ifdef SYS_setdomainname
  510.         RSC_1STR_1INT(setdomainname);
  511. #else SYS_setdomainname
  512.         RSC_1STR_1INT(CONDOR_NotSupported);
  513. #endif SYS_setdomainname
  514.  
  515.     case CONDOR_sethostname:    /* sethostname( char *name, int namelen )    */
  516.         RSC_1STR_1INT(sethostname);
  517.  
  518.     /*
  519.     **    System calls which take one string and one off_t as arguments
  520.     */
  521.     case CONDOR_truncate:        /* truncate( char *path, off_t length )      */
  522.     {
  523.         char path[ MAXPATHLEN ], *pp = path;
  524.         off_t length;
  525.  
  526.         ASSERT(xdr_string(xdr_syscall, &pp, (u_int) MAXPATHLEN));
  527.         ASSERT(xdr_int(xdr_syscall, &length));
  528.  
  529.         rval = truncate(path, length);
  530.  
  531.         dprintf(D_SYSCALLS, "Shadow: truncate(%s, %d) = %d\n",
  532.                 path, length, rval);
  533.  
  534.         PUT_RVAL(xdr_syscall, rval);
  535.         END_RVAL(xdr_syscall, 0);
  536.     }
  537.  
  538.     /*
  539.     **    System calls which take one string and two integers as arguments
  540.     */
  541.     case CONDOR_chown:            /* chown( char *path, int owner, int group ) */
  542.         RSC_1STR_2INT(chown);
  543.  
  544.     case CONDOR_mknod:            /* mknod( char *path, int mode, int dev )    */
  545.         RSC_1STR_2INT(mknod);
  546.  
  547.     case CONDOR_open:            /* open( char *path, int flags, int mode )   */
  548.         RSC_1STR_2INT(open);
  549.  
  550.     /*
  551.     **    System calls which take two strings as arguments
  552.     */
  553.     case CONDOR_link:            /* link( char *name1, char *name2 )          */
  554.         RSC_2STR(link);
  555.  
  556.     case CONDOR_rename:            /* rename( char *from, char *to )            */
  557.         RSC_2STR(rename);
  558.  
  559.     case CONDOR_symlink:        /* symlink( char *name1, char *name2 )       */
  560.         RSC_2STR(symlink);
  561.  
  562.     /*
  563.     **    Others...
  564.     */
  565.     case CONDOR_wait:            /* wait( R union wait *status )              */
  566.     {
  567.         union wait status;
  568.  
  569.         /*
  570.         ** rval = wait( &status );
  571.         */
  572.         rval = CONDOR_NotSupported();
  573.  
  574.         dprintf(D_SYSCALLS, "Shadow: wait(0x%x) = %d\n", &status, rval );
  575.  
  576.         PUT_RVAL(xdr_syscall, rval);
  577.  
  578.         ASSERT(xdr_wait(xdr_syscall, &status));
  579.  
  580.         END_RVAL(xdr_syscall, 0);
  581.     }
  582.  
  583.     case PSEUDO_reallyexit:    /* reallyexit( M union wait *status )            */
  584.     {
  585.         extern union wait JobStatus;
  586.         extern struct rusage JobRusage;
  587.  
  588.         ASSERT(xdr_wait(xdr_syscall, &JobStatus));
  589.         ASSERT(xdr_rusage(xdr_syscall, &JobRusage));
  590.  
  591.         rval = 0;
  592.         dprintf(D_SYSCALLS, "Shadow: reallyexit(0x%x, 0x%x) = %d\n",
  593.                                 &JobStatus, &JobRusage, rval );
  594.  
  595.         PUT_RVAL(xdr_syscall, rval);
  596.         END_RVAL(xdr_syscall, -1);
  597.     }
  598.  
  599.     case PSEUDO_wait3:    /* wait3( R union wait *status, int options,
  600.                         **                        struct rusage *rusage )
  601.                         */
  602.     {
  603.         int xdr_rusage();
  604.         union wait status;
  605.         int options;
  606.         struct rusage *rusage;
  607.  
  608.         ASSERT(xdr_int(xdr_syscall, &options));
  609.         ASSERT(xdr_ptr(xdr_syscall, (caddr_t *) &rusage, xdr_rusage));
  610.  
  611.         /*
  612.         **    rval = wait3( &status, options, rusage );
  613.         */
  614.         rval = CONDOR_NotSupported();
  615.  
  616.         dprintf(D_SYSCALLS, "Shadow: wait3(0x%x, 0%o, 0x%x) = %d\n",
  617.             &status, options, rusage, rval );
  618.  
  619.         PUT_RVAL(xdr_syscall, rval);
  620.  
  621.         ASSERT(xdr_wait(xdr_syscall, &status));
  622.         ASSERT(xdr_ptr(xdr_syscall, (caddr_t *) &rusage, xdr_rusage));
  623.  
  624.         END_RVAL(xdr_syscall, 0);
  625.     }
  626.  
  627.     case PSEUDO_getwd: /* getwd( R char *pathname )                          */
  628.     {
  629.         char pathname[ MAXPATHLEN ], *pnp = pathname;
  630.  
  631.         if( getwd(pathname) ) {
  632.             rval = 1;
  633.         } else {
  634.             rval = 0;
  635.         }
  636.  
  637.         dprintf(D_SYSCALLS, "Shadow: getwd(%s) = 0x%x\n", pathname, rval);
  638.  
  639.         PUT_RVAL(xdr_syscall, rval);
  640.         ASSERT(xdr_string(xdr_syscall, &pnp, (u_int) MAXPATHLEN));
  641.         END_RVAL(xdr_syscall, 0);
  642.     }
  643.  
  644.     case CONDOR_lstat:            /* lstat( char *path, R struct stat *buf )   */
  645.         RSC_1STR_1RBUF(lstat,stat,xdr_stat);
  646.  
  647.     case CONDOR_stat:            /* stat( char *path, R struct stat *buf )    */
  648.         RSC_1STR_1RBUF(stat,stat,xdr_stat);
  649.  
  650.     case CONDOR_pipe:            /* pipe( int fildes[2] )                     */
  651.     {
  652.         int fildes[2];
  653.  
  654.         /*
  655.         **    rval = pipe(fildes);
  656.         */
  657.         rval = CONDOR_NotSupported();
  658.  
  659.         dprintf(D_SYSCALLS, "Shadow: pipe(0x%x) = %d\n", fildes, rval);
  660.  
  661.         PUT_RVAL(xdr_syscall, rval);
  662.  
  663.         ASSERT(xdr_int(xdr_syscall, &fildes[0]));
  664.         ASSERT(xdr_int(xdr_syscall, &fildes[1]));
  665.  
  666.         END_RVAL(xdr_syscall, 0);
  667.     }
  668.  
  669.     case CONDOR_settimeofday:    /* settimeofday( struct timeval *tp,
  670.                                 **                 struct timezone *tzp )
  671.                                 */
  672.     {
  673.         struct timeval tv, *tp = &tv;
  674.         struct timezone tz, *tzp = &tz;
  675.         int xdr_timezone();
  676.         
  677.         ASSERT(timeval_xdr(xdr_syscall, tp));
  678.         ASSERT(xdr_ptr(xdr_syscall, (caddr_t *) &tzp, xdr_timezone));
  679.  
  680.         rval = settimeofday( tp, tzp );
  681.  
  682.         dprintf(D_SYSCALLS, "Shadow: settimeofday(0x%x, 0x%x) = %d\n",
  683.                     tp, tzp, rval);
  684.  
  685.         PUT_RVAL(xdr_syscall, rval);
  686.  
  687.         END_RVAL(xdr_syscall, 0);
  688.     }
  689.  
  690.     case CONDOR_gettimeofday:    /* gettimeofday( R struct timeval *tp,
  691.                             **                 R struct timezone *tzp )
  692.                             */
  693.     {
  694.         struct timeval tv, *tp = &tv;
  695.         struct timezone tz, *tzp = &tz;
  696.         int xdr_timezone();
  697.         
  698.         ASSERT(xdr_ptr(xdr_syscall, (caddr_t *) &tzp, xdr_timezone));
  699.  
  700.         rval = gettimeofday( tp, tzp );
  701.  
  702.         dprintf(D_SYSCALLS,
  703.             "Shadow: gettimeofday(0x%x <%d, %d>, 0x%x <%d, %d>) = %d\n",
  704.                 tp, tp->tv_sec, tp->tv_usec,
  705.                 tzp, (tzp?tzp->tz_minuteswest:0), (tzp?tzp->tz_dsttime:0),
  706.                 rval);
  707.  
  708.         PUT_RVAL(xdr_syscall, rval);
  709.  
  710.         ASSERT(timeval_xdr(xdr_syscall, tp));
  711.         ASSERT(xdr_ptr(xdr_syscall, (caddr_t *) &tzp, xdr_timezone));
  712.  
  713.         END_RVAL(xdr_syscall, 0);
  714.     }
  715.  
  716.     case CONDOR_getdomainname:    /* getdomainname( R char *name, int namelen )*/
  717.     {
  718.         char *name, *malloc();
  719.         int namelen;
  720.         
  721.         ASSERT(xdr_int(xdr_syscall, &namelen));
  722.  
  723.         MemToFree = name = malloc( (unsigned)namelen );
  724.         if( name == NULL ) {
  725.             rval = -1;
  726.         } else {
  727.             rval = getdomainname( name, namelen );
  728.         }
  729.  
  730.         dprintf(D_SYSCALLS, "Shadow: getdomainname(%s, %d) = %d\n",
  731.                     name, namelen, rval);
  732.  
  733.         PUT_RVAL(xdr_syscall, rval);
  734.         ASSERT(xdr_string(xdr_syscall, &name, (u_int) namelen));
  735.         END_RVAL(xdr_syscall, 0);
  736.     }
  737.  
  738.     case CONDOR_gethostname:    /* gethostname( R char *name, int namelen )  */
  739.     {
  740.         char *name, *malloc();
  741.         int namelen;
  742.         
  743.         ASSERT(xdr_int(xdr_syscall, &namelen));
  744.  
  745.         MemToFree = name = malloc( (unsigned)namelen );
  746.         if( name == NULL ) {
  747.             rval = -1;
  748.         } else {
  749.             rval = gethostname( name, namelen );
  750.         }
  751.  
  752.         dprintf(D_SYSCALLS, "Shadow: gethostname(%s, %d) = %d\n",
  753.                     name, namelen, rval);
  754.  
  755.         PUT_RVAL(xdr_syscall, rval);
  756.         ASSERT(xdr_string(xdr_syscall, &name, (u_int) namelen));
  757.         END_RVAL(xdr_syscall, 0);
  758.     }
  759.  
  760.     case CONDOR_select:        /* select( int nfds,
  761.                             **        0/VR fd_set *readfds,
  762.                             **        0/VR fd_set *writefds,
  763.                             **        0/VR fd_set *exceptfds,
  764.                             **        0/V struct timeval *timeout )
  765.                             */
  766.     {
  767.         int xdr_fdset(), timeval_xdr();
  768.         int nfds;
  769.         fd_set Rfds, *readfds = &Rfds;
  770.         fd_set Wfds, *writefds = &Wfds;
  771.         fd_set Efds, *exceptfds = &Efds;
  772.         struct timeval TO, *timeout = &TO;
  773.  
  774.         ASSERT(xdr_int(xdr_syscall, &nfds));
  775.         ASSERT(xdr_ptr(xdr_syscall, (caddr_t *) &readfds, xdr_fdset));
  776.         ASSERT(xdr_ptr(xdr_syscall, (caddr_t *) &writefds, xdr_fdset));
  777.         ASSERT(xdr_ptr(xdr_syscall, (caddr_t *) &exceptfds, xdr_fdset));
  778.         ASSERT(xdr_ptr(xdr_syscall, (caddr_t *) &timeout, timeval_xdr));
  779.  
  780.         rval = select( nfds, (int *)readfds, (int *)writefds,
  781.                                                 (int *)exceptfds, timeout );
  782.  
  783.         PUT_RVAL(xdr_syscall, rval);
  784.  
  785.         ASSERT(xdr_ptr(xdr_syscall, (caddr_t *) &readfds, xdr_fdset));
  786.         ASSERT(xdr_ptr(xdr_syscall, (caddr_t *) &writefds, xdr_fdset));
  787.         ASSERT(xdr_ptr(xdr_syscall, (caddr_t *) &exceptfds, xdr_fdset));
  788.         ASSERT(xdr_ptr(xdr_syscall, (caddr_t *) &timeout, timeval_xdr));
  789.  
  790.         END_RVAL(xdr_syscall, 0);
  791.     }
  792.  
  793.     case CONDOR_setgroups:        /* setgroups( int ngroups, M int *gidset )   */
  794.     {
  795.         int ngroups, xdr_int();
  796.         int GIDSet[ NGROUPS ], *gidset = GIDSet;
  797.  
  798.         ASSERT(xdr_array(xdr_syscall, &gidset, &ngroups, NGROUPS, sizeof(int), xdr_int));
  799.  
  800.         rval = setgroups( ngroups, gidset );
  801.  
  802.         PUT_RVAL(xdr_syscall, rval);
  803.         END_RVAL(xdr_syscall, 0);
  804.     }
  805.  
  806.     case CONDOR_setitimer:        /* setitimer( int which,
  807.                                 **            M struct itimerval *value,
  808.                                 **          R/0 struct itimerval *ovalue )
  809.                                 */
  810.     {
  811.         int which;
  812.         struct itimerval Val, *value = &Val;
  813.         struct itimerval OVal, *ovalue = &OVal;
  814.         
  815.         ASSERT(xdr_int(xdr_syscall, &which));
  816.         ASSERT(xdr_itimerval(xdr_syscall, value));
  817.         ASSERT(xdr_ptr(xdr_syscall, (caddr_t *) &ovalue, timeval_xdr));
  818.  
  819.         /*
  820.         ** rval = setitimer( which, value, ovalue );
  821.         */
  822.         rval = CONDOR_NotSupported();
  823.  
  824.         PUT_RVAL(xdr_syscall, rval);
  825.  
  826.         ASSERT(xdr_ptr(xdr_syscall, (caddr_t *) &ovalue, timeval_xdr));
  827.         END_RVAL(xdr_syscall, 0);
  828.     }
  829.  
  830.     case CONDOR_setrlimit:        /* setrlimit( int resource,
  831.                                 **            M struct rlimit *rlp )
  832.                                 */
  833.     {
  834.         int resource;
  835.         struct rlimit RLim, *rlp = &RLim;
  836.         
  837.         ASSERT(xdr_int(xdr_syscall, &resource));
  838.         ASSERT(xdr_rlimit(xdr_syscall, rlp));
  839.  
  840.         rval = setrlimit( resource, rlp );
  841.  
  842.         PUT_RVAL(xdr_syscall, rval);
  843.         END_RVAL(xdr_syscall, 0);
  844.     }
  845.  
  846.     case CONDOR_getdirentries:    /* getdirentries( int fd,
  847.                                 **                R char *buf,
  848.                                 **                  int nbytes,
  849.                                 **                R off_t *basep )
  850.                                 */
  851.     {
  852.         int fd;
  853.         char *buf;
  854.         int nbytes;
  855.         long Base, *basep = &Base;
  856.  
  857.         ASSERT(xdr_int(xdr_syscall, &fd));
  858.         ASSERT(xdr_int(xdr_syscall, &nbytes));
  859.  
  860.         MemToFree = buf = malloc( (unsigned)nbytes );
  861. #if defined(SYS_getdirentries) && !defined(SUNOS40)
  862.         rval = getdirentries( fd, buf, (unsigned)nbytes, basep );
  863. #else defined(SYS_getdirentries) && !defined(SUNOS40)
  864.         rval = CONDOR_NotSupported();
  865. #endif defined(SYS_getdirentries) && !defined(SUNOS40)
  866.  
  867.         PUT_RVAL(xdr_syscall, rval);
  868.  
  869.         ASSERT(xdr_direntries(xdr_syscall, buf, rval));
  870.         ASSERT(xdr_off_t(xdr_syscall, basep));
  871.  
  872.         END_RVAL(xdr_syscall, 0);
  873.     }
  874.  
  875.     case CONDOR_getgroups:        /* getgroups( int gidsetlen, R int *gidset ) */
  876.     {
  877.         int gidsetlen;
  878.         int GidSet[ NGROUPS ], *gidset = GidSet;
  879.         register int i;
  880.  
  881.         ASSERT(xdr_int(xdr_syscall, &gidsetlen));
  882.  
  883.         rval = getgroups( gidsetlen, gidset );
  884.  
  885.         PUT_RVAL(xdr_syscall, rval);
  886.  
  887.         for( i = 0; i < rval; i++ ) {
  888.             ASSERT(xdr_int(xdr_syscall, &gidset[i]));
  889.         }
  890.         END_RVAL(xdr_syscall, 0);
  891.     }
  892.  
  893.     case CONDOR_getitimer:        /* getitimer( int which,
  894.                                 **            R struct itimerval *value )
  895.                                 */
  896.         RSC_1INT_1RBUF(getitimer,itimerval,xdr_itimerval);
  897.  
  898.     case CONDOR_getrlimit:        /* getrlimit( int resource,
  899.                                 **            R struct rlimit *rlp )
  900.                                 */
  901.         RSC_1INT_1RBUF(getrlimit,rlimit,xdr_rlimit);
  902.  
  903.     case CONDOR_getrusage:        /* getrusage( int who,
  904.                                 **            R struct rusage *rusage )
  905.                                 */
  906.         RSC_1INT_1RBUF(getrusage,rusage,xdr_rusage);
  907.  
  908.     case CONDOR_fstat:            /* fstat( int fd, R struct stat *buf )       */
  909.         RSC_1INT_1RBUF(fstat,stat,xdr_stat);
  910.  
  911. #if !defined(ultrix)
  912.     case CONDOR_fstatfs:        /* fstatfs( int fd, struct statfs *buf )     */
  913.         RSC_1INT_1RBUF(fstatfs,statfs,xdr_statfs);
  914. #endif !defined(ultrix)
  915.  
  916.     case CONDOR_utimes:            /* utimes( char *file,
  917.                                 **            M struct timeval *tvp )
  918.                                 */
  919.     {
  920.         char File[ MAXPATHLEN ], *file = File;
  921.         struct timeval tvp[2];
  922.  
  923.         ASSERT(xdr_string(xdr_syscall, &file, (u_int) MAXPATHLEN));
  924.         ASSERT(timeval_xdr(xdr_syscall, &tvp[0]));
  925.         ASSERT(timeval_xdr(xdr_syscall, &tvp[1]));
  926.  
  927.         rval = utimes( file, tvp );
  928.  
  929.         PUT_RVAL(xdr_syscall, rval);
  930.         END_RVAL(xdr_syscall, 0);
  931.     }
  932.  
  933.     case CONDOR_readlink:        /* readlink( char *path, char *buf,
  934.                                 **                    int bufsiz )
  935.                                 */
  936.     {
  937.         char Path[ MAXPATHLEN ], *path = Path;
  938.         char *buf;
  939.         int bufsiz;
  940.  
  941.         ASSERT(xdr_string(xdr_syscall, &path, (u_int) MAXPATHLEN));
  942.         ASSERT(xdr_int(xdr_syscall, &bufsiz));
  943.  
  944.         MemToFree = buf = malloc( (unsigned)bufsiz );
  945.         rval = readlink( path, buf, bufsiz );
  946.  
  947.         PUT_RVAL(xdr_syscall, rval);
  948.         ASSERT(xdr_string(xdr_syscall, &buf, (u_int) bufsiz));
  949.         END_RVAL(xdr_syscall, 0);
  950.     }
  951.  
  952.     case CONDOR_adjtime:        /* adjtime( M struct timeval *delta,
  953.                                 **          R/0 struct timeval *olddelta )
  954.                                 */
  955.     {
  956.         struct timeval Delta, *delta = Δ
  957.         struct timeval OldDelta, *olddelta = &OldDelta;
  958.  
  959.         ASSERT(timeval_xdr(xdr_syscall, delta));
  960.         ASSERT(xdr_ptr(xdr_syscall, (caddr_t *) &olddelta, timeval_xdr));
  961.  
  962. #if !sequent
  963.         rval = adjtime( delta, olddelta );
  964. #else
  965.         rval = -1;
  966.         errno = ESYSNOTSUPP;
  967. #endif !sequent
  968.  
  969.         PUT_RVAL(xdr_syscall, rval);
  970.  
  971.         ASSERT(xdr_ptr(xdr_syscall, (caddr_t *) &olddelta, timeval_xdr));
  972.  
  973.         END_RVAL(xdr_syscall, 0);
  974.     }
  975.  
  976. #if !defined(ultrix)
  977.     case CONDOR_statfs:            /* statfs( char *path, R struct statfs *buf )*/
  978.         RSC_1STR_1RBUF(statfs,statfs,xdr_statfs);
  979. #endif !defined(ultrix)
  980.  
  981.     case CONDOR_write:            /* write( int, M caddr_t, int )              */
  982.     {
  983.         int d, nbytes;
  984.         char *buf = 0;
  985.  
  986.         ASSERT(xdr_int(xdr_syscall, &d));
  987.         ASSERT(xdr_int(xdr_syscall, &nbytes));
  988.         ASSERT(xdr_bytes(xdr_syscall, &buf, &nbytes, nbytes));
  989.  
  990.         rval = write( d, buf, nbytes );
  991.  
  992.         dprintf(D_SYSCALLS, "Shadow: write(%d, 0x%x, %d) = %d\n",
  993.                 d, buf, nbytes, rval);
  994.  
  995.         PUT_RVAL(xdr_syscall, rval);
  996.  
  997.         xdr_syscall->x_op = XDR_FREE;
  998.  
  999.         ASSERT(xdr_bytes(xdr_syscall, &buf, &nbytes, nbytes));
  1000.  
  1001.         END_RVAL(xdr_syscall, 0);
  1002.     }
  1003.  
  1004.     case CONDOR_read:            /* read( int, R caddr_t, int )               */
  1005.     {
  1006.         int d, nbytes;
  1007.         char *buf, *malloc();
  1008.  
  1009.         ASSERT(xdr_int(xdr_syscall, &d));
  1010.         ASSERT(xdr_int(xdr_syscall, &nbytes));
  1011.  
  1012.         MemToFree = buf = malloc( (unsigned)nbytes );
  1013.         if( buf == NULL ) {
  1014.             rval = -1;
  1015.         } else {
  1016.             rval = read(d, buf, nbytes);
  1017.         }
  1018.  
  1019.         dprintf(D_SYSCALLS, "Shadow: read(%d, buf, %d) = %d\n",
  1020.                 d, nbytes, rval);
  1021.  
  1022.         PUT_RVAL(xdr_syscall, rval);
  1023.  
  1024.         ASSERT(xdr_bytes(xdr_syscall, &buf, &nbytes, nbytes));
  1025.  
  1026.         END_RVAL(xdr_syscall, 0);
  1027.     }
  1028.  
  1029.     case CONDOR_ioctl:            /* ioctl( int d, u_long request, char *argp )*/
  1030.     {
  1031.         int d;
  1032.         char *argp = 0;
  1033.         u_long request;
  1034.  
  1035.         ASSERT(xdr_int(xdr_syscall, &d));
  1036.         ASSERT(xdr_u_long(xdr_syscall, &request));
  1037.  
  1038.         if( request & IOC_IN ) {
  1039.             MemToFree = argp = malloc( (unsigned)(request & IOCPARM_MASK) );
  1040.             if( argp == NULL ) {
  1041.                 EXCEPT("ioctl: tried to allocate %d bytes\n",
  1042.                             request & IOCPARM_MASK);
  1043.             }
  1044.  
  1045.             ASSERT(xdr_opaque(xdr_syscall,argp,(u_int)(request&IOCPARM_MASK)));
  1046.         }
  1047.  
  1048.         /*
  1049.         **    rval = ioctl( d, request, argp );
  1050.         */
  1051.         rval = CONDOR_NotSupported();
  1052.  
  1053.         dprintf(D_SYSCALLS, "Shadow: ioctl(%d, 0x%x, 0x%x) = %d\n",
  1054.                 d, request, argp, rval);
  1055.  
  1056.         PUT_RVAL(xdr_syscall, rval);
  1057.  
  1058.         if( request & IOC_OUT ) {
  1059.             ASSERT(xdr_opaque(xdr_syscall,argp,(u_int)(request&IOCPARM_MASK)));
  1060.         }
  1061.  
  1062.         END_RVAL(xdr_syscall, 0);
  1063.     }
  1064.  
  1065.  
  1066. #ifdef IMPLEMENTED
  1067.     /*
  1068.     **    System calls with (as yet) unknown arguments
  1069.     */
  1070.     case CONDOR_exportfs:
  1071.     case CONDOR_getdopt:
  1072.     case CONDOR_getfh:
  1073.     case CONDOR_madvise:
  1074.     case CONDOR_mincore:
  1075.     case CONDOR_mmap:
  1076.     case CONDOR_mprotect:
  1077.     case CONDOR_mremap:
  1078.     case CONDOR_munmap:
  1079.     case CONDOR_setdopt:
  1080.     case CONDOR_sstk:
  1081.         break;
  1082.  
  1083.  
  1084.     /*
  1085.     **    Other system calls
  1086.     */
  1087.  
  1088.         break;
  1089.  
  1090.  
  1091.     case CONDOR_writev:            /* writev( int d, struct iovec *iov,
  1092.                                 **                    int iovcnt )
  1093.                                 */
  1094.     case CONDOR_readv:            /* readv( int d, struct iovec *iov,
  1095.                                 **                    int iovcnt )
  1096.                                 */
  1097.  
  1098.     case CONDOR_ptrace:            /* ptrace( int, int, VR int *, int           */
  1099.     case CONDOR_quotactl:        /* quotaactl( int, str, int, VRU caddr_t )   */
  1100.     case CONDOR_execv:            /* execv( str, M str[] )                     */
  1101.     case CONDOR_execve:            /* execve( str, M str[], M str[] )           */
  1102.  
  1103.     case CONDOR_send:            /* send( int, M caddr_t, int, int )          */
  1104.     case CONDOR_sendto:            /* sendto( int, M caddr_t, int, int,
  1105.                                         M sockaddr *, int                    */
  1106.     case CONDOR_sendmsg:        /* sendmsg( int, V msghdr[], int )           */
  1107.  
  1108.     case CONDOR_recv:            /* recv( int, R caddr_t, int, int )          */
  1109.     case CONDOR_recvfrom:        /* recvfrom( int, R caddr_t, int, int,
  1110.                                             0/R sockaddr *, VR int * )       */
  1111.     case CONDOR_recvmsg:        /* recvmsg( int, VR msghdr[], int )          */
  1112.  
  1113.     case CONDOR_setsockopt:        /* setsockopt(int, int, int, M caddr_t, int) */
  1114.     case CONDOR_getsockopt:        /* getsockopt( int, int, int,
  1115.                                 **        R caddr_t, VR int * )
  1116.                                 */
  1117.     case CONDOR_socketpair:        /* socketpair( int, int, int, R int[2] )     */
  1118.     case CONDOR_bind:            /* bind( int, sockaddr *, int )              */
  1119.     case CONDOR_connect:        /* connect( int, sockaddr *, int )           */
  1120.     case CONDOR_mount:            /* mount( int, str, int,
  1121.                                 **        MU caddr_t )
  1122.                                 */
  1123.  
  1124.     case CONDOR_accept:            /* accept( int, R sockaddr *, VR int * )     */
  1125.     case CONDOR_getsockname:    /* getsockname( int, R sockaddr *, VR int * )*/
  1126.     case CONDOR_getpeername:    /* getpeername( int, R sockaddr *, VR int * )*/
  1127.         break;
  1128. #endif IMPLEMENTED
  1129.  
  1130.     default:
  1131.         dprintf(D_ALWAYS, "Shadow: ERROR: %d is an unknown system call\n",
  1132.             condor_sysnum);
  1133.  
  1134.         errno = EINVAL;
  1135.  
  1136.         PUT_RVAL(xdr_syscall, -1);
  1137.         END_RVAL(xdr_syscall, 0);
  1138.     }
  1139. }
  1140.  
  1141. #ifdef notdef
  1142. debug( str )
  1143. char    *str;
  1144. {
  1145.     dprintf( D_ALWAYS, str );
  1146. }
  1147.  
  1148. /*
  1149. ** Convert a timeval struct to a float.
  1150. */
  1151. float
  1152. tv_to_f( tv )
  1153. struct timeval    tv;
  1154. {
  1155.     return (float)tv.tv_sec + ((float)tv.tv_usec)/(float)1000000;
  1156. }
  1157. #endif notdef
  1158.  
  1159.  
  1160. char MsgBuf[ BUFSIZ ];
  1161. HandleChildLog( log_fp )
  1162. FILE    *log_fp;
  1163. {
  1164.     register char *nlp;
  1165.     char *index();
  1166.     char buf[ BUFSIZ ];
  1167.  
  1168.     for(;;) {
  1169.         bzero(buf, sizeof(buf));
  1170.  
  1171.         if( fgets(buf, sizeof(buf), log_fp) == NULL ) {
  1172.             return -1;
  1173.         }
  1174.  
  1175.         nlp = index(buf, '\n');
  1176.         if( nlp != NULL ) {
  1177.             *nlp = '\0';
  1178.         }
  1179.  
  1180.         dprintf(D_ALWAYS|D_NOHEADER, "%s\n", buf );
  1181.         if( strncmp("ERROR",buf,5) == 0 ) {
  1182.             (void)strcpy( MsgBuf, buf );
  1183.         }
  1184.  
  1185.         /*
  1186.         **    If there is more to read, read it, otherwise just return...
  1187.         */
  1188.         if( log_fp->_cnt == 0 ) {
  1189.             return 0;
  1190.         }
  1191.     }
  1192. }
  1193.  
  1194. HandleLog()
  1195. {
  1196.     register char *nlp;
  1197.     char buf[ BUFSIZ ];
  1198.     char *index();
  1199.  
  1200.     for(;;) {
  1201.         bzero(buf, sizeof(buf));
  1202.  
  1203.         if( fgets(buf, sizeof(buf), LogFP) == NULL ) {
  1204.             EXCEPT("Peer went away.  buf = '%s'", buf);
  1205.         }
  1206.  
  1207.  
  1208.         nlp = index(buf, '\n');
  1209.         if( nlp != NULL ) {
  1210.             *nlp = '\0';
  1211.         }
  1212.  
  1213.         dprintf(D_ALWAYS, "Read: %s\n", buf );
  1214.  
  1215.         /*
  1216.         **    If there is more to read, read it, otherwise just return...
  1217.         */
  1218.         if( LogFP->_cnt == 0 ) {
  1219.             return;
  1220.         }
  1221.     }
  1222. }
  1223.  
  1224. RSC_no_args( func, condor_sysnum )
  1225. int (*func)();
  1226. int condor_sysnum;
  1227. {
  1228.     int rval = (*func)();
  1229.  
  1230.     dprintf(D_SYSCALLS, "Shadow: %s() = %d\n",
  1231.             CONDOR_SYSCALLNAME(condor_sysnum), rval);
  1232.  
  1233.     PUT_RVAL(xdr_syscall, rval);
  1234.     END_RVAL(xdr_syscall, 0);
  1235. }
  1236.  
  1237. RSC_1int(func, condor_sysnum)
  1238. int (*func)();
  1239. int condor_sysnum;
  1240. {
  1241.     int rval;
  1242.     int arg1;
  1243.  
  1244.     ASSERT(xdr_int(xdr_syscall, &arg1));
  1245.  
  1246.     rval = (*func)( arg1 );
  1247.  
  1248.     dprintf(D_SYSCALLS, "Shadow: %s(%d) = %d\n",
  1249.         CONDOR_SYSCALLNAME(condor_sysnum), arg1, rval);
  1250.  
  1251.     PUT_RVAL(xdr_syscall, rval);
  1252.     END_RVAL(xdr_syscall, 0);
  1253. }
  1254.  
  1255. RSC_2int(func, condor_sysnum)
  1256. int (*func)();
  1257. int condor_sysnum;
  1258. {
  1259.     int rval;
  1260.     int arg1, arg2;
  1261.  
  1262.     ASSERT(xdr_int(xdr_syscall, &arg1));
  1263.     ASSERT(xdr_int(xdr_syscall, &arg2));
  1264.  
  1265.     rval = (*func)( arg1, arg2 );
  1266.  
  1267.     dprintf(D_SYSCALLS, "Shadow: %s(%d, %d) = %d\n",
  1268.         CONDOR_SYSCALLNAME(condor_sysnum), arg1, arg2, rval);
  1269.  
  1270.     PUT_RVAL(xdr_syscall, rval);
  1271.     END_RVAL(xdr_syscall, 0);
  1272. }
  1273.  
  1274. RSC_3int(func, condor_sysnum)
  1275. int (*func)();
  1276. int condor_sysnum;
  1277. {
  1278.     int rval;
  1279.     int arg1, arg2, arg3;
  1280.  
  1281.     ASSERT(xdr_int(xdr_syscall, &arg1));
  1282.     ASSERT(xdr_int(xdr_syscall, &arg2));
  1283.     ASSERT(xdr_int(xdr_syscall, &arg3));
  1284.  
  1285.     rval = (*func)( arg1, arg2, arg3 );
  1286.  
  1287.     dprintf(D_SYSCALLS, "Shadow: %s(%d, %d, %d) = %d\n",
  1288.         CONDOR_SYSCALLNAME(condor_sysnum), arg1, arg2, arg3, rval);
  1289.  
  1290.     PUT_RVAL(xdr_syscall, rval);
  1291.     END_RVAL(xdr_syscall, 0);
  1292. }
  1293.  
  1294. RSC_1str(func, condor_sysnum)
  1295. int (*func)();
  1296. int condor_sysnum;
  1297. {
  1298.     char str1[ MAXPATHLEN ], *s1 = str1;
  1299.     int rval;
  1300.  
  1301.     ASSERT(xdr_string(xdr_syscall, &s1, (u_int) MAXPATHLEN));
  1302.  
  1303.     rval = (*func)(s1);
  1304.  
  1305.     dprintf(D_SYSCALLS, "Shadow: %s(%s) = %d\n",
  1306.         CONDOR_SYSCALLNAME(condor_sysnum), s1, rval );
  1307.  
  1308.     PUT_RVAL(xdr_syscall, rval);
  1309.     END_RVAL(xdr_syscall, 0);
  1310. }
  1311.  
  1312. RSC_1str_1int(func, condor_sysnum)
  1313. int (*func)();
  1314. int condor_sysnum;
  1315. {
  1316.     char str1[ MAXPATHLEN ], *s1 = str1;
  1317.     int int2;
  1318.     int rval;
  1319.  
  1320.     ASSERT(xdr_string(xdr_syscall, &s1, (u_int) MAXPATHLEN));
  1321.     ASSERT(xdr_int(xdr_syscall, &int2));
  1322.  
  1323.     rval = (*func)(s1, int2);
  1324.  
  1325.     dprintf(D_SYSCALLS, "Shadow: %s(%s, 0%o) = %d\n",
  1326.             CONDOR_SYSCALLNAME(condor_sysnum), s1, int2, rval );
  1327.  
  1328.     PUT_RVAL(xdr_syscall, rval);
  1329.     END_RVAL(xdr_syscall, 0);
  1330. }
  1331.  
  1332. RSC_1str_2int(func, condor_sysnum)
  1333. int (*func)();
  1334. int condor_sysnum;
  1335. {
  1336.     char str1[ MAXPATHLEN ], *s1 = str1;
  1337.     int int2, int3;
  1338.     int rval;
  1339.  
  1340.     ASSERT(xdr_string(xdr_syscall, (char **)&s1, (u_int) MAXPATHLEN));
  1341.     ASSERT(xdr_int(xdr_syscall, &int2));
  1342.     ASSERT(xdr_int(xdr_syscall, &int3));
  1343.  
  1344.     rval = (*func)( s1, int2, int3 );
  1345.  
  1346.     dprintf(D_SYSCALLS, "Shadow: %s(%s, 0%o, 0%o) = %d\n",
  1347.         CONDOR_SYSCALLNAME(condor_sysnum), s1, int2, int3, rval);
  1348.  
  1349.     PUT_RVAL(xdr_syscall, rval);
  1350.     END_RVAL(xdr_syscall, 0);
  1351. }
  1352.  
  1353. RSC_2str(func, condor_sysnum)
  1354. int (*func)();
  1355. int condor_sysnum;
  1356. {
  1357.     char str1[ MAXPATHLEN ], *s1 = str1;
  1358.     char str2[ MAXPATHLEN ], *s2 = str2;
  1359.     int rval;
  1360.  
  1361.     ASSERT(xdr_string(xdr_syscall, (char **)&s1, (u_int) MAXPATHLEN));
  1362.     ASSERT(xdr_string(xdr_syscall, (char **)&s2, (u_int) MAXPATHLEN));
  1363.  
  1364.     rval = (*func)( s1, s2 );
  1365.  
  1366.     dprintf(D_SYSCALLS, "Shadow: %s(%s, %s) = %d\n",
  1367.             CONDOR_SYSCALLNAME(condor_sysnum), s1, s2, rval );
  1368.  
  1369.     PUT_RVAL(xdr_syscall, rval);
  1370.     END_RVAL(xdr_syscall, 0);
  1371. }
  1372.  
  1373. /*
  1374. **    System call handler for syscalls which take 1 integer
  1375. **    and return a buffer of size bufsiz.
  1376. */
  1377. RSC_1int_1Rbuf(func, condor_sysnum, bufsiz, xdrf)
  1378. int (*func)();
  1379. int condor_sysnum, bufsiz;
  1380. int (*xdrf)();
  1381. {
  1382.     int arg1;
  1383.     caddr_t buf;
  1384.     int rval;
  1385.  
  1386.     ASSERT(xdr_int(xdr_syscall, &arg1));
  1387.  
  1388.     MemToFree = buf = malloc( (unsigned)bufsiz );
  1389.  
  1390.     rval = (*func)( arg1, buf );
  1391.  
  1392.     dprintf(D_SYSCALLS, "Shadow: %s(%d, 0x%x) = %d\n",
  1393.             CONDOR_SYSCALLNAME(condor_sysnum), arg1, buf, rval);
  1394.  
  1395.     PUT_RVAL(xdr_syscall, rval);
  1396.     ASSERT((*xdrf)(xdr_syscall, buf));
  1397.     END_RVAL(xdr_syscall, 0);
  1398. }
  1399.  
  1400. /*
  1401. **    System call handler for syscalls which take 1 string
  1402. **    and return a buffer of size bufsiz.
  1403. */
  1404. RSC_1str_1Rbuf(func, condor_sysnum, bufsiz, xdrf)
  1405. int (*func)();
  1406. int condor_sysnum, bufsiz;
  1407. int (*xdrf)();
  1408. {
  1409.     char str1[ MAXPATHLEN ], *s1 = str1;
  1410.     caddr_t buf;
  1411.     int rval;
  1412.  
  1413.     ASSERT(xdr_string(xdr_syscall, (char **)&s1, (u_int) MAXPATHLEN));
  1414.  
  1415.     MemToFree = buf = malloc( (unsigned) bufsiz );
  1416.  
  1417.     rval = (*func)( s1, buf );
  1418.  
  1419.     dprintf(D_SYSCALLS, "Shadow: %s(%s, 0x%x) = %d\n",
  1420.             CONDOR_SYSCALLNAME(condor_sysnum), s1, buf, rval);
  1421.  
  1422.     PUT_RVAL(xdr_syscall, rval);
  1423.     ASSERT((*xdrf)(xdr_syscall, buf));
  1424.     END_RVAL(xdr_syscall, 0);
  1425. }
  1426.  
  1427. /*
  1428. **    Make sure that they are not trying to
  1429. **    close a reserved descriptor.
  1430. */
  1431. condor_close(d)
  1432. int d;
  1433. {
  1434.     if( (d >= MIN_RSRV_FD) && (d <= MAX_RSRV_FD) ||
  1435.                     d == MyPipe || d == LockFd ) {
  1436.         errno = EINVAL;
  1437.         return( -1 );
  1438.     }
  1439.  
  1440.     return( close(d) );
  1441. }
  1442.  
  1443. /*
  1444. **    Make sure that they are not trying to
  1445. **    dup to a reserved descriptor.
  1446. */
  1447. condor_dup2(oldd, newd)
  1448. int oldd, newd;
  1449. {
  1450.     if( (newd >= MIN_RSRV_FD) && (newd <= MAX_RSRV_FD) ||
  1451.                         newd == MyPipe || newd == LockFd || newd == LogPipe ) {
  1452.         errno = EINVAL;
  1453.         return( -1 );
  1454.     }
  1455.  
  1456.     return( dup2(oldd, newd) );
  1457. }
  1458.  
  1459. /*
  1460. **    We don't really want the shadow to exit here because the 
  1461. **    starter may want to make a new checkpoint file.  So, just
  1462. **    respond with an error-free return code and hang out; the
  1463. **    shadow will (should) go away when (if) the starter closes
  1464. **    the LogSock.
  1465. */
  1466. /* ARGSUSED */
  1467. condor_exit(status)
  1468. int status;
  1469. {
  1470.     return( 0 );
  1471. }
  1472.  
  1473. /*
  1474. **    getppid normally returns the parents id, right?  Well in
  1475. **    the CONDOR case, this job may be started and checkpointed many
  1476. **    times.  The parent will change each time.  Instead we will
  1477. **    treat it as though the parent process died and this process
  1478. **    was inherited by init.
  1479. */
  1480. condor_getppid()
  1481. {
  1482.     return( 1 );
  1483. }
  1484.  
  1485. /*
  1486. **    getpid should return the same number each time.  As indicated
  1487. **    above, this CONDOR job may be started and checkpointed several times
  1488. **    during its lifetime, so we will make it a function of the CONDOR
  1489. **    process id...
  1490. */
  1491. condor_getpid()
  1492. {
  1493.     extern PROC Proc;
  1494.  
  1495.     return( (Proc.id.cluster * 1000) + Proc.id.proc );
  1496. }
  1497.  
  1498. /*VARARGS*/
  1499. CONDOR_NotSupported()
  1500. {
  1501. #ifdef NOTDEF
  1502.     errno = ESYSNOTSUPP;
  1503.     return( -1 );
  1504. #endif NOTDEF
  1505.  
  1506.     errno = 0;
  1507.     PERM_ERR( "%s - system call not supported by Condor",
  1508.                                     CONDOR_SYSCALLNAME(condor_sysnum) );
  1509.     EXCEPT( "Unsupported system call %s (%d)",
  1510.                         CONDOR_SYSCALLNAME(condor_sysnum), condor_sysnum );
  1511. #ifdef LINT
  1512.     return -1;
  1513. #endif LINT
  1514. }
  1515.