This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

setsid() does not call FreeConsole() even if all files are closed


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.


+  #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, 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


#include <stdio.h>
#include <unistd.h>
#include <windows.h>

main(int argc, char **argv)
  if (fork())
    return 0;

  fclose(stdin); fclose(stdout); fclose(stderr);


  int status = -1;
  if (argc > 1)
    status = FreeConsole();


  freopen("/dev/conout", "w", stdout);
  printf("Welcome back, status=%d\n", status);

  return 0;

Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]