Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , 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 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 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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/