*** Makefile.in.orig	Sun Nov  7 05:09:57 1993
--- Makefile.in	Sun Nov  7 23:36:51 1993
***************
*** 47,53 ****
  
  # Which flavor of remote job execution support to use.
  # The code is found in `remote-$(REMOTE).c'.
! REMOTE = @REMOTE@
  
  # If you are using the GNU C library, or have the GNU getopt functions in
  # your C library, you can comment these out.
--- 47,54 ----
  
  # Which flavor of remote job execution support to use.
  # The code is found in `remote-$(REMOTE).c'.
! #REMOTE = @REMOTE@
! REMOTE = cstms
  
  # If you are using the GNU C library, or have the GNU getopt functions in
  # your C library, you can comment these out.
***************
*** 75,80 ****
--- 76,86 ----
  # Any extra object files your system needs.
  extras = @LIBOBJS@
  
+ CFLAGS += -I$(includedir)/customs
+   
+   # Any extra object files your system needs.
+ LOADLIBES += -L$(libdir) -lcustoms
+ 
  # Common prefix for machine-independent installed files.
  prefix = /usr/local
  # Common prefix for machine-dependent installed files.
***************
*** 99,107 ****
  # The value should be either `true' or `false'.
  # On many systems, the getloadavg function (used to implement the `-l'
  # switch) will not work unless make is installed setgid kmem.
! install_setgid = @NEED_SETGID@
  # Install make setgid to this group so it can read /dev/kmem.
  group = @KMEM_GROUP@
  
  # Program to install `make'.
  INSTALL_PROGRAM = @INSTALL_PROGRAM@
--- 105,117 ----
  # The value should be either `true' or `false'.
  # On many systems, the getloadavg function (used to implement the `-l'
  # switch) will not work unless make is installed setgid kmem.
! #install_setgid = @NEED_SETGID@
! install_setgid = false
  # Install make setgid to this group so it can read /dev/kmem.
  group = @KMEM_GROUP@
+ # Install make suid root so it can use customs securely
+ install_setuid = true
+ user = root
  
  # Program to install `make'.
  INSTALL_PROGRAM = @INSTALL_PROGRAM@
***************
*** 170,176 ****
  MAKE = make
  
  glob/libglob.a: FORCE config.h
! 	cd glob; $(MAKE) CC='$(CC)' CFLAGS='$(CFLAGS) -I..' \
  			 CPPFLAGS='$(CPPFLAGS) -DHAVE_CONFIG_H' \
  			 RANLIB='$(RANLIB)' \
  			 libglob.a
--- 180,186 ----
  MAKE = make
  
  glob/libglob.a: FORCE config.h
! 	cd glob; $(MAKE) CC='$(CC)' CFLAGS='-I.. $(CFLAGS)' \
  			 CPPFLAGS='$(CPPFLAGS) -DHAVE_CONFIG_H' \
  			 RANLIB='$(RANLIB)' \
  			 libglob.a
***************
*** 192,197 ****
--- 202,216 ----
  
  $(bindir)/$(instname): make
  	$(INSTALL_PROGRAM) make $@.new
+ 	@if $(install_setuid); then \
+ 	   if chown $(user) $@.new && chmod u+s $@.new; then \
+ 	     echo "chgrp $(user) $@.new && chmod u+s $@.new"; \
+ 	   else \
+ 	     echo "$@ needs to be owned by user $(user) and setuid;"; \
+ 	     echo "otherwise remote job execution will probably not work."; \
+ 	     echo "You will need special priveleges to install $@."; \
+ 	   fi; \
+ 	 else true; fi
  	@if $(install_setgid); then \
  	   if chgrp $(group) $@.new && chmod g+s $@.new; then \
  	     echo "chgrp $(group) $@.new && chmod g+s $@.new"; \
*** job.c.orig	Thu Oct 14 12:08:36 1993
--- job.c	Sun Nov  7 23:35:38 1993
***************
*** 619,625 ****
        if (start_remote_job (argv, child->environment,
  			    child->good_stdin ? 0 : bad_stdin,
  			    &is_remote, &id, &used_stdin))
! 	goto error;
        else
  	{
  	  if (child->good_stdin && !used_stdin)
--- 619,630 ----
        if (start_remote_job (argv, child->environment,
  			    child->good_stdin ? 0 : bad_stdin,
  			    &is_remote, &id, &used_stdin))
! 	/* Don't just give up here, since remote execution with customs
! 	 * may fail for all kinds of accidental reasons even after
! 	 * start_remote_job_p() has agreed to export the job.
! 	 * No big deal, just run the thing locally. */
! 	/* goto error; */
! 	goto start_local;
        else
  	{
  	  if (child->good_stdin && !used_stdin)
***************
*** 633,638 ****
--- 638,644 ----
      }
    else
      {
+  start_local:;
        /* Fork the child process.  */
  
  #ifdef	 POSIX
*** remote-cstms.c.orig	Thu Feb  4 10:31:53 1993
--- remote-cstms.c	Sun Nov  7 23:35:39 1993
***************
*** 27,33 ****
  #include <sys/time.h>
  #include <netdb.h>
  
- #define __STRICT_BSD__		/* Don't make conflicting declarations.  */
  #include "customs.h"
  
  
--- 27,32 ----
***************
*** 88,93 ****
--- 87,98 ----
    if (inited < 0)
      return 0;
  
+   /* the first job should run locally, or, if the -l flag is given, we use
+      that as clue as to how many local jobs should be scheduled locally */
+   if (max_load_average < 0 && job_slots_used == 0
+       || job_slots_used < max_load_average)
+      return 0;
+ 
    status = Customs_Host (EXPORT_SAME, &permit);
    if (status != RPC_SUCCESS)
      {
***************
*** 116,121 ****
--- 121,127 ----
  {
    extern int vfork (), execve ();
    char waybill[MAX_DATA_SIZE], msg[128];
+   struct hostent *host;
    struct timeval timeout;
    struct sockaddr_in sin;
    int len;
***************
*** 151,158 ****
    /* Modify the waybill as if the remote child had done `child_access ()'.  */
    {
      WayBill *wb = (WayBill *) waybill;
!     wb->euid = wb->ruid;
!     wb->rgid = wb->rgid;
    }
  
    /* Send the request to the server, timing out in 20 seconds.  */
--- 157,164 ----
    /* Modify the waybill as if the remote child had done `child_access ()'.  */
    {
      WayBill *wb = (WayBill *) waybill;
!     wb->ruid = wb->euid;
!     wb->rgid = wb->egid;
    }
  
    /* Send the request to the server, timing out in 20 seconds.  */
***************
*** 165,188 ****
  		     len, (Rpc_Opaque) waybill,
  		     sizeof(msg), (Rpc_Opaque) msg,
  		     1, &timeout);
    if (status != RPC_SUCCESS)
      {
        (void) close (retsock);
        (void) close (sock);
!       error ("exporting: %s", Rpc_ErrorMessage (status));
        return 1;
      }
    else if (msg[0] != 'O' || msg[1] != 'k' || msg[2] != '\0')
      {
        (void) close (retsock);
        (void) close (sock);
!       error ("CUSTOMS_IMPORT: %s", msg);
        return 1;
      }
    else if (debug_flag)
      {
!       struct hostent *host = gethostbyaddr (&permit.addr, sizeof (permit.addr),
! 					    AF_INET);
        printf ("Job exported to %s ID %u\n",
  	      host == 0 ? inet_ntoa (permit.addr) : host->h_name,
  	      permit.id);
--- 171,200 ----
  		     len, (Rpc_Opaque) waybill,
  		     sizeof(msg), (Rpc_Opaque) msg,
  		     1, &timeout);
+ 
    if (status != RPC_SUCCESS)
      {
+       host = gethostbyaddr (&permit.addr, sizeof (permit.addr), AF_INET);
        (void) close (retsock);
        (void) close (sock);
!       error ("exporting to %s: %s",
! 	     host == 0 ? inet_ntoa (permit.addr) : host->h_name,
!              Rpc_ErrorMessage (status));
        return 1;
      }
    else if (msg[0] != 'O' || msg[1] != 'k' || msg[2] != '\0')
      {
+       host = gethostbyaddr (&permit.addr, sizeof (permit.addr), AF_INET);
        (void) close (retsock);
        (void) close (sock);
!       error ("exporting to %s: %s",
! 	     host == 0 ? inet_ntoa (permit.addr) : host->h_name,
! 	     msg);
        return 1;
      }
    else if (debug_flag)
      {
!       host = gethostbyaddr (&permit.addr, sizeof (permit.addr), AF_INET);
        printf ("Job exported to %s ID %u\n",
  	      host == 0 ? inet_ntoa (permit.addr) : host->h_name,
  	      permit.id);
***************
*** 226,231 ****
--- 238,244 ----
    (void) close (sock);
    *is_remote = 0;
    *id_ptr = pid;
+   *used_stdin = 1;
    return 0;
  }
  
