This is the mail archive of the cygwin-developers@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

exec()'s behavior when ppid == 1


Chris,

When Windows spawns a Cygwin process A, A has ppid 1 and ppid_handle 0.
If process A execs B, Cygwin keeps A alive. If B then execs C, B stays 
alive too. When C terminates, B and A follow suit and Windows goes on its way.
So far so good.

Now suppose that A forks X and A terminates. Windows goes on its way
right away.
Meanwhile X (which now has ppid 1 but a non zero ppid_handle) execs B
and X is kept alive. If B execs C, B is also kept alive. When C 
terminates, B and X follow suit.

Q: Why does it help to keep X and B alive until C terminates?

Unfortunately Windows sockets are not always fully cleaned up until a
process terminates, and the current behavior breaks some features
of exim.

I have been running for a day with the one line patch below, which
seems to work without noxious side effects. 

Pierre

Index: spawn.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/spawn.cc,v
retrieving revision 1.121
diff -u -p -r1.121 spawn.cc
--- spawn.cc    19 May 2003 01:43:31 -0000     1.121
+++ spawn.cc    1 Jun 2003 20:55:46 -0000
@@ -802,7 +802,8 @@ spawn_guts (const char * prog_arg, const
            case WAIT_OBJECT_0 + 2:
              if (myself->ppid_handle)
                res |= EXIT_REPARENTING;
-             if (!my_parent_is_alive ())
+//PAH        if (!my_parent_is_alive ())
+             else
                {
                  nwait = 2;
                  sigproc_terminate ();




Further down one could possibly also change the
"if (res & EXIT_REPARENTING)" into 
"if (res & EXIT_REPARENTING && myself->ppid != 1) "
to avoid useless handle duplications.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]