delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/11/13/13:14:30

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Date: Sun, 13 Nov 2005 13:14:22 -0500
From: Christopher Faylor <cgf-no-personal-reply-please AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: setsid() does not call FreeConsole() even if all files are closed
Message-ID: <20051113181422.GA16538@trixie.casa.cgf.cx>
Reply-To: cygwin AT cygwin DOT com
References: <4377651F DOT 9050400 AT t-online DOT de>
Mime-Version: 1.0
In-Reply-To: <4377651F.9050400@t-online.de>
User-Agent: Mutt/1.5.8i

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019