This is the mail archive of the
cygwin
mailing list for the Cygwin project.
setsid() does not call FreeConsole() even if all files are closed
- From: Christian Franke <Christian dot Franke at t-online dot de>
- To: cygwin at cygwin dot com
- Date: Sun, 13 Nov 2005 17:09:03 +0100
- Subject: setsid() does not call FreeConsole() even if all files are closed
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
#include <stdio.h>
#include <unistd.h>
#include <windows.h>
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;
}
--
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/