delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2010/12/06/18:07:48

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=0.7 required=5.0 tests=AWL,BAYES_20,SARE_HEAD_DATE_LONG1,T_RP_MATCHES_RCVD
X-Spam-Check-By: sourceware.org
Date: Mon, 6 Dec 2010 23:07:01 +0000 (GMT Standard Time)
From: Arthur Norman <acn1 AT cam DOT ac DOT uk>
To: cygwin AT cygwin DOT com
Subject: Program repeatedly restarts when its console is closed
Message-ID: <alpine.WNT.2.00.1012062305080.2572@panamint>
User-Agent: Alpine 2.00 (WNT 1167 2008-08-23)
MIME-Version: 1.0
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
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

At the end of this message is a short program. It is linked as a 
windows-mode executable so when it is launched it does not have a console. 
It then allocates one and uses it. The expected behaviour is that when I 
run it a fresh DOS-style console appears and I can type a few chars in and 
they get echoed.

This happens happily. EXCEPT that if before typing in 5 chars I close the 
console either via its file/close menu or by clicking the little "x" at the 
right of its title bar and IF I launched the program from cygwin using 
execv/execve (as the cygwin bash shell does) the application console winow 
closess but the program is instantly relauched. I see this with both the 32 
& 64-bit versions of the non-cygwin compilatets - ie replace 
x86_64-w64-mingw32-gcc with just "gcc -mno-cygwin" has the same behaviour.

If instead of launching the binary via cygwin's execv I launch it direct 
from a plain old DOS shell then closing the console window causes the 
program to terminate in the way I expected.

It is not clear to me whether this is an issue of the mingw bits not 
handling things and exiting badly or of the cygwin execv behaving 
improperly. Eg it I write a very short program that goes basically
execv("./bad0",...) and compile that using cygwin but then run that 
executable from a normal DOS shell I get the hydra-like behaviour where 
when I cut of a console a fresh one instantly re-grows, even though 
launching bad0 directly does not suffer that way. So if mingw people can 
confirm that this is a problem on the cygwin side the issue can be 
forwarded that way...

When I posted this for mingw64 people to comment on the response I got 
back was
"This indicates the problem to be with Cygwin.  Have you asked them?  I
know that Cygwin doesn't have control of the exec-ed "native" program
but it may be trapping the signals and causing the primary program to
not end so that it reopens the console making it appear to be
"restarting"."


Many thanks,

{I am on Windows 7 64-bit with the x86_64 compiler versions that cygwin 
installs for me, but I have tried the bad0 executable on a windows 2000 
(virtual) machine and observe the same bad effects in the 32-bit version 
there, so actually this is not just a 64-bit issue and not just a Windows 7 
one).

              Arthur


===========================================================
/*
  * x86_64-w64-mingw32-gcc -mno-cygwin bad0.c \
  *     -Wl,--subsystem=windows -o bad0
  * ./bad0
  */

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

int main(int argc, char *argv[])
{
     int i;
     if (AllocConsole())
     {   freopen("CONIN$", "r", stdin);
         freopen("CONOUT$", "w", stdout);
         freopen("CONOUT$", "w", stderr);
     }
     for (i=0; i<5; i++)
     {   int c = getchar();
         printf("char %d is %#x\n", i, c);
         fflush(stdout);
     }
     return 0;
}
=============================================================

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


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