Calling RegisterServiceProcess from setsid ?

Christopher Faylor
Sat Jun 7 15:12:00 GMT 2003

On Fri, Jun 06, 2003 at 07:46:46PM -0400, Pierre A. Humblet wrote:
>I think I have figured out most of what's happening in what
>I reported on Wednesday.
>The outcomes depend on the way the program is written because
>of a Cygwin feature (don't know if design or accident).
>-exim closes 0/1/2 then setsids
>-sshd setsids then closes 0/1/2 (actually sets them to /dev/null) 
>-inetd sets 0 to /dev/null, setsids, then closes 0/1/2 
>-cron setsids but doesn't close anything (that's why
>   Ronald Landheer-Cieslak is reporting problem on the list)
>Programs that close 0/1/2 and setsid (in any order) always survive 
>  log offs, whether started from cygwin.bat or from rxvt.
>Programs that setsid and then close 0/1/2 do survive log offs when 
>  started from cygwin.bat, but not from rxvt.
>I think the last two observations come from the facts that 
>setsid calls FreeConsole when fhandler_console::open_fhs == 0; it also
>  sets myself->ctty to -1.
>fhandler_console::close calls FreeConsole when fhandler_console::open_fhs
>  becomes 0, and myself->ctty != TTY_CONSOLE (e.g. when called after setsid).
>However fhandler_tty_slave::close never calls FreeConsole, even when
>  it is called after setsid and fhandler_console::open_fhs becomes 0.
>  I don't know if it's by design, but it surely makes a difference.

I guess fhandler_tty_slave::close could call FreeConsole too when the
last tty is closed and setsid has been previously called.

I'll check in a change to do this.


RCS file: /cvs/src/src/winsup/cygwin/,v
retrieving revision 1.96
diff -u -p -r1.96
---	20 Apr 2003 01:36:15 -0000	1.96
+++	7 Jun 2003 15:10:39 -0000
@@ -583,7 +583,8 @@ fhandler_tty_slave::close ()
   if (!output_done_event)
-      fhandler_console::open_fhs--;
+      if (!--fhandler_console::open_fhs && myself->ctty == -1)
+	FreeConsole ();
       termios_printf ("decremented open_fhs %d", fhandler_console::open_fhs);
   return fhandler_tty_common::close ();

More information about the Cygwin-developers mailing list