OSDN Git Service

* spawn.cc (spawn_guts): Catch potential error from pinfo.remember. Change
authorcgf <cgf>
Fri, 26 Sep 2003 02:23:33 +0000 (02:23 +0000)
committercgf <cgf>
Fri, 26 Sep 2003 02:23:33 +0000 (02:23 +0000)
debug messages to make sense.  Pass correct value to pinfo constructor.  Ensure
cleanup after errors.  Always reimpersonate after errors.

winsup/cygwin/ChangeLog
winsup/cygwin/spawn.cc

index ea53ae5..12804d0 100644 (file)
@@ -1,3 +1,11 @@
+2003-09-25  Pierre Humblet <pierre.humblet@ieee.org>
+           Christopher Faylor  <cgf@redhat.com>
+
+       * spawn.cc (spawn_guts): Catch potential error from pinfo.remember.
+       Change debug messages to make sense.  Pass correct value to pinfo
+       constructor.  Ensure cleanup after errors.  Always reimpersonate after
+       errors.
+
 2003-09-25  Christopher Faylor  <cgf@redhat.com>
 
        * spawn.cc (spawn_guts): Move system signal handling stuff after
index b339660..8d2ab2d 100644 (file)
@@ -711,7 +711,7 @@ spawn_guts (const char * prog_arg, const char *const *argv,
 
   /* Restore impersonation. In case of _P_OVERLAY this isn't
      allowed since it would overwrite child data. */
-  if (mode != _P_OVERLAY)
+  if (mode != _P_OVERLAY || !rc)
       cygheap->user.reimpersonate ();
 
   MALLOC_CHECK;
@@ -734,7 +734,7 @@ spawn_guts (const char * prog_arg, const char *const *argv,
 
   /* FIXME: There is a small race here */
 
-  DWORD res;
+  int res;
   pthread_cleanup cleanup;
   pthread_cleanup_push (do_cleanup, (void *) &cleanup);
   if (mode == _P_SYSTEM)
@@ -788,16 +788,24 @@ spawn_guts (const char * prog_arg, const char *const *argv,
     {
       myself->set_has_pgid_children ();
       ProtectHandle (pi.hThread);
-      pinfo child (cygpid, 1);
+      pinfo child (cygpid, PID_IN_USE);
       if (!child)
        {
+         syscall_printf ("pinfo failed");
          set_errno (EAGAIN);
-         syscall_printf ("-1 = spawnve (), process table full");
-         return -1;
+         res = -1;
+         goto out;
        }
       child->dwProcessId = pi.dwProcessId;
       child->hProcess = pi.hProcess;
-      child.remember ();
+      if (!child.remember ())
+       {
+         syscall_printf ("process table full");
+         set_errno (EAGAIN);
+         res = -1;
+         goto out;
+       }
+
       strcpy (child->progname, real_path);
       /* FIXME: This introduces an unreferenced, open handle into the child.
         The purpose is to keep the pid shared memory open so that all of
@@ -919,6 +927,7 @@ spawn_guts (const char * prog_arg, const char *const *argv,
       break;
     }
 
+out:
   pthread_cleanup_pop (1);
   return (int) res;
 }