This is the mail archive of the cygwin 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]

Re: setsid() does not call FreeConsole() even if all files are closed


On Sun, Nov 13, 2005 at 05:09:03PM +0100, Christian Franke wrote:
>Hi,
>
>when starting a daemon from the console, the console will not close 
>before the daemon finishes.
>
>Try, e.g:
>
>$ /usr/sbin/syslogd
>$ exit
>
>Shell exits, but console window persists until syslogd is terminated.
>
>Workaround:
>
>  setsid();
>+  #ifdef __CYGWIN__
>+  FreeConsole();
>+  #endif
>
>
>The attached program demonstrates the issue.

The attached program demonstrates the assumption that only
stdin/stdout/stderr are open when the program is started.  A shell could
conceivably keep other fds open.

Try applying the below patch to gain the behavior that you want.

cgf

--- testsetsid.cc.orig	2005-11-13 12:34:28.000000000 -0500
+++ testsetsid.cc	2005-11-13 13:10:30.000000000 -0500
@@ -6,8 +6,10 @@ main(int argc, char **argv)
 {
   if (fork())
     return 0;
+  int nfds = getdtablesize ();
 
-  fclose(stdin); fclose(stdout); fclose(stderr);
+  for (int i = 0; i < nfds; i++)
+    close (i);
 
   setsid();
 

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


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