Mail Archives: cygwin/2005/11/13/11:09:17
--------------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 <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;
}
--------------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--
- Raw text -