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 Message-ID: <4377651F.9050400@t-online.de> Date: Sun, 13 Nov 2005 17:09:03 +0100 From: Christian Franke User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b) Gecko/20050217 MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: setsid() does not call FreeConsole() even if all files are closed Content-Type: multipart/mixed; boundary="------------090300000704050806020305" X-ID: G5IBsrZUZeQVtkm1kQLOt+K2zMvOvO2cEbgoZU+gDVHq8M2HlDamY3 X-TOI-MSGID: 6a70e124-36df-42bd-9359-db2bc30b2512 X-IsSubscribed: yes --------------090300000704050806020305 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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. If run without an argument, the output line is written to current console. It should be written to a new console, but AllocConsole() does nothing because the current console is still attached. If run with any argument, FreeConsole is called after setsid(). It should return FALSE, but returns TRUE (status=1). Then the output line is written to a new console. According to syscall.cc:setsid(), FreeConsole() should be called if a tty exists and no files are open. Diagnostic via strace doesn't help. The program works as expected if run via strace ... interesting?-) Thanks for any help Christian --------------090300000704050806020305 Content-Type: text/plain; name="testsetsid.cc" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="testsetsid.cc" #include #include #include main(int argc, char **argv) { if (fork()) return 0; fclose(stdin); fclose(stdout); fclose(stderr); setsid(); int status = -1; if (argc > 1) status = FreeConsole(); sleep(10); AllocConsole(); freopen("/dev/conout", "w", stdout); printf("Welcome back, status=%d\n", status); sleep(20); return 0; } --------------090300000704050806020305 Content-Type: text/plain; charset=us-ascii -- 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/ --------------090300000704050806020305--