delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/11/13/11:09:17

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
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 <Christian DOT Franke AT t-online DOT de>
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
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 <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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019