Cygwin 3.1.2: Every call of exec(2) in the session starts to create a console window after some TTY outputs from programs compiled with "-mwindows"

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Cygwin 3.1.2: Every call of exec(2) in the session starts to create a console window after some TTY outputs from programs compiled with "-mwindows"

Koichi Murase
Hi, I updated Cygwin from 3.0.7 to 3.1.2 and have two problems.  This
is the report for one of them.  (For the other one, read(2)
occasionally fails on the new cygwin console for some settings, but
I'm still trying to pin down the issue.)

Cygwin Version:

  Cygwin 3.1.2 x86_64 on Windows 10.  I also confirmed that the
  problem is not fixed with the latest commit 85aff2830 of
  newlib-cygwin.  Note that Cygwin 3.0.7 doesn't have this problem.


Brief Description:

  As in the subject, this problem is caused after some TTY outputs from
  programs compiled with "-mwindows".  For example, after running the
  command "mintty.exe --version" in a terminal, every "exec" called in
  the processes in the same session starts to create a console window
  which will be closed instantaneously.  As results, the display is
  always flashing when some scripts are running, the shell scripts
  becomes very slow, some of user inputs to the terminal go to the
  created window and get lost, and CPU usage extremely increases.
  This problem was not present in Cygwin 3.0.7.


Repeat-By:

  The following is one example to reproduce it:

  1. Open Cygwin Terminal (mintty)
  2. Run "mintty --version"
  3. Run some shell scripts, e.g., "for i in {0..99}; do date; done | uniq -c"


Details:

* The terminal

  This phenomena is not reproduced with every terminal.  For example,
  it is reproduced with xterm, lxterminal and mintty, but not with the
  cygwin console (which can be started, e.g., by directly calling
  C:\cygwin64\bin\bash.exe from Windows) and GNU Screen.  It appears
  that it is caused when the terminal process that holds the PTY
  master also has GUI windows.

* The trigger command

  This phenomena is started when a program with
  IMAGE_SUBSYSTEM_WINDOWS_GUI in its PE header (which can be created,
  for example, by passing the option "-mwindows" to "gcc") outputs
  something to TTY.  One example for such a program is "mintty
  --version".  But this is not a specific problem to "mintty".  The
  simplest example "test1.exe" that causes the phenomena can be
  created by the following command:

  $ echo 'main(){puts("A");}' | gcc -xc - -mwindows -o test1.exe

  The above program looks useless, but of course it is a reduced case
  just to reproduce the phenomena.  Actually, in one of my programs, I
  need to output something to TTY in some case, and need to create a
  GUI window (based on Windows API) in the other cases.  Specifically,
  my program is basically a GUI program (terminal emulator) and does
  not want to show a console window when it is launched from, e.g.,
  Explorer, so I need to specify "-mwindows" to tell Windows not to
  create a console.  But when my program is called inside terminal
  with a special option, it runs in a TUI mode, so still I want to
  output something to TTY when some conditions are satisfied.

* exec?

  A new console window appears to be created when a new program is
  loaded with "exec".  A console window is not generated when a
  subshell is created in the shell (which implies "fork" does not create
  a console window) while the command "exec some-command" in the shell
  creates a new console window.


Takashi: Thank you very much for your hard work on recent PTY issues!
Today I checked cygwin-patches mailing list to check possible related
fixes and found your recent patch on "disable_pcon", which is the very
feature I wanted for testing my terminal application with the legacy
console mode.  Thank you!


Best regards,

Koichi

--
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

Reply | Threaded
Open this post in threaded view
|

Re: Cygwin 3.1.2: Every call of exec(2) in the session starts to create a console window after some TTY outputs from programs compiled with "-mwindows"

marco atzeri-4
Am 20.01.2020 um 07:13 schrieb Koichi Murase:

> Hi, I updated Cygwin from 3.0.7 to 3.1.2 and have two problems.  This
> is the report for one of them.  (For the other one, read(2)
> occasionally fails on the new cygwin console for some settings, but
> I'm still trying to pin down the issue.)
>
> Cygwin Version:
>
>    Cygwin 3.1.2 x86_64 on Windows 10.  I also confirmed that the
>    problem is not fixed with the latest commit 85aff2830 of
>    newlib-cygwin.  Note that Cygwin 3.0.7 doesn't have this problem.
>
>
> Brief Description:
>
>    As in the subject, this problem is caused after some TTY outputs from
>    programs compiled with "-mwindows".  For example, after running the
>    command "mintty.exe --version" in a terminal, every "exec" called in
>    the processes in the same session starts to create a console window
>    which will be closed instantaneously.  As results, the display is
>    always flashing when some scripts are running, the shell scripts
>    becomes very slow, some of user inputs to the terminal go to the
>    created window and get lost, and CPU usage extremely increases.
>    This problem was not present in Cygwin 3.0.7.
>
>
> Repeat-By:
>
>    The following is one example to reproduce it:
>
>    1. Open Cygwin Terminal (mintty)
>    2. Run "mintty --version"
>    3. Run some shell scripts, e.g., "for i in {0..99}; do date; done | uniq -c"
>

I can not replicate with latest snapshot

$ uname -a
CYGWIN_NT-10.0 LAPTOP-82F08ILC 3.1.2s(0.340/5/3) 2020-01-14 16:33 x86_64
Cygwin

$ mintty --version
mintty 3.1.0 (x86_64-pc-cygwin)
...

$ for i in {0..99}; do date; done | uniq -c
       6 Mon, Jan 20, 2020  8:15:49 AM
      18 Mon, Jan 20, 2020  8:15:50 AM
      19 Mon, Jan 20, 2020  8:15:51 AM
      16 Mon, Jan 20, 2020  8:15:52 AM
      20 Mon, Jan 20, 2020  8:15:53 AM
      21 Mon, Jan 20, 2020  8:15:54 AM


--
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

Reply | Threaded
Open this post in threaded view
|

Re: Cygwin 3.1.2: Every call of exec(2) in the session starts to create a console window after some TTY outputs from programs compiled with "-mwindows"

Koichi Murase
2020年1月20日(月) 15:17 Marco Atzeri <[hidden email]>:

>
> I can not replicate with latest snapshot
>
> $ uname -a
> CYGWIN_NT-10.0 LAPTOP-82F08ILC 3.1.2s(0.340/5/3) 2020-01-14 16:33 x86_64
> Cygwin
>
> $ mintty --version
> mintty 3.1.0 (x86_64-pc-cygwin)
> ...
>
> $ for i in {0..99}; do date; done | uniq -c
>        6 Mon, Jan 20, 2020  8:15:49 AM
>       18 Mon, Jan 20, 2020  8:15:50 AM
>       19 Mon, Jan 20, 2020  8:15:51 AM
>       16 Mon, Jan 20, 2020  8:15:52 AM
>       20 Mon, Jan 20, 2020  8:15:53 AM
>       21 Mon, Jan 20, 2020  8:15:54 AM

Thank you for the information.  I found that the locale also matters.
The problem is not yet fixed in the snapshot and also the latest
commit of the git repository.


Repeat-By:

  I update the steps to reproduce the problem:

  1. Open Cygwin Terminal
  2. Run the following commands

    $ LANG=ja_JP.UTF-8
    $ mintty --version
    $ for a in {0..99}; do date; done | uniq -c


Locale:

  I found that the problem is reproduced when LANG=ja_JP.UTF-8.  I
  tried LANG=C and LANG=en_US.UTF-8, but the problem was not present
  with these locales.  I tried several locales as follows.  It appears
  it is related to multi-byte character sets, and also the problem
  does not occur if UTF-8 is not specified.

  * Not reproduced with: en_US.UTF-8, en_GB.UTF-8, de_DE.UTF-8,
    fr_FR.UTF-8, ru_RU.UTF-8, ja_JP

  * Reproduced with: ja_JP.UTF-8, ja_JP.utf8, zh_CN.UTF-8,
    zh_TW.UTF-8, ko_KR.UTF-8

  Next I tried to find out which locale category causes the problem,
  but the problem is not reproduced by just specifying a locale for
  one locale category.  I tried the following, but none reproduced the
  problem.

    $ LANG=en_US.UTF-8 LC_CTYPE=ja_JP.UTF-8; mintty --version
    $ for a in {0..99}; do date; done | uniq -c
    $ LANG=en_US.UTF-8 LC_COLLATE=ja_JP.UTF-8; mintty --version
    $ for a in {0..99}; do date; done | uniq -c
    $ LANG=en_US.UTF-8 LC_MESSAGES=ja_JP.UTF-8; mintty --version
    $ for a in {0..99}; do date; done | uniq -c
    $ LANG=en_US.UTF-8 LC_NUMERIC=ja_JP.UTF-8; mintty --version
    $ for a in {0..99}; do date; done | uniq -c
    $ LANG=en_US.UTF-8 LC_TIME=ja_JP.UTF-8; mintty --version
    $ for a in {0..99}; do date; done | uniq -c
    $ LANG=en_US.UTF-8 LC_MONETARY=ja_JP.UTF-8; mintty --version
    $ for a in {0..99}; do date; done | uniq -c

  Other interesting observations are

  1. To reproduce the problem, LANG needs not be set to
    ja_JP.UTF-8 when "mintty --version" runs, i.e., it can be
    reproduced with:

    $ mintty --version
    $ LANG=ja_JP.UTF-8
    $ for a in {0..99}; do date; done | uniq -c

  2. Once the exec starts to create a console window, the problem
    persists even after resetting LANG to a non-problematic one:

    $ mintty --version
    $ LANG=en_US.UTF-8
    $ for a in {0..99}; do date; done | uniq -c
    <No problems>
    $ LANG=ja_JP.UTF-8
    $ for a in {0..99}; do date; done | uniq -c
    <Many flashing console windows>
    $ LANG=en_US.UTF-8
    $ for a in {0..99}; do date; done | uniq -c
    <Still there are many console windows>


Cygwin Versions:

  In my environments, it is reproduced with the latest snapshot as
  well.  I also tried the latest version of the git repository, but
  the problem has not yet fixed.  I tried the following versions, but
  with all the versions the same problem occurs:

  1. Cygwin 3.1.2

  $ uname -a
  CYGWIN_NT-10.0 letsnote2019 3.1.2(0.340/5/3) 2019-12-21 15:25 x86_64
  Cygwin

  2. Snapshot 2020-01-14 from https://cygwin.com/snapshots/

  $ uname -a
  CYGWIN_NT-10.0 letsnote2019 3.1.2s(0.340/5/3) 2020-01-14 16:33 x86_64
  Cygwin

  3. Commit 85aff2830 from git://sourceware.org/git/newlib-cygwin.git

  $ uname -a
  CYGWIN_NT-10.0 letsnote2019 3.1.2(0.340/5/3) 2020-01-19 15:12 x86_64
  Cygwin

  4. Commit 4261a8f5c from git://sourceware.org/git/newlib-cygwin.git

  $ uname -a
  CYGWIN_NT-10.0 letsnote2019 3.1.2(0.340/5/3) 2020-01-21 00:57 x86_64
  Cygwin

  Also, this is not a specific problem of one computer because I tried
  with two laptops and both reproduce the same problem.


Best,

Koichi

--
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

Reply | Threaded
Open this post in threaded view
|

Re: Cygwin 3.1.2: Every call of exec(2) in the session starts to create a console window after some TTY outputs from programs compiled with "-mwindows"

Takashi Yano
On Tue, 21 Jan 2020 10:30:48 +0800
Koichi Murase wrote:

> 2020年1月20日(月) 15:17 Marco Atzeri:
> >
> > I can not replicate with latest snapshot
> >
> > $ uname -a
> > CYGWIN_NT-10.0 LAPTOP-82F08ILC 3.1.2s(0.340/5/3) 2020-01-14 16:33 x86_64
> > Cygwin
> >
> > $ mintty --version
> > mintty 3.1.0 (x86_64-pc-cygwin)
> > ...
> >
> > $ for i in {0..99}; do date; done | uniq -c
> >        6 Mon, Jan 20, 2020  8:15:49 AM
> >       18 Mon, Jan 20, 2020  8:15:50 AM
> >       19 Mon, Jan 20, 2020  8:15:51 AM
> >       16 Mon, Jan 20, 2020  8:15:52 AM
> >       20 Mon, Jan 20, 2020  8:15:53 AM
> >       21 Mon, Jan 20, 2020  8:15:54 AM
>
> Thank you for the information.  I found that the locale also matters.
> The problem is not yet fixed in the snapshot and also the latest
> commit of the git repository.
>
>
> Repeat-By:
>
>   I update the steps to reproduce the problem:
>
>   1. Open Cygwin Terminal
>   2. Run the following commands
>
>     $ LANG=ja_JP.UTF-8
>     $ mintty --version
>     $ for a in {0..99}; do date; done | uniq -c
>
>
> Locale:
>
>   I found that the problem is reproduced when LANG=ja_JP.UTF-8.  I
>   tried LANG=C and LANG=en_US.UTF-8, but the problem was not present
>   with these locales.  I tried several locales as follows.  It appears
>   it is related to multi-byte character sets, and also the problem
>   does not occur if UTF-8 is not specified.
>
>   * Not reproduced with: en_US.UTF-8, en_GB.UTF-8, de_DE.UTF-8,
>     fr_FR.UTF-8, ru_RU.UTF-8, ja_JP
>
>   * Reproduced with: ja_JP.UTF-8, ja_JP.utf8, zh_CN.UTF-8,
>     zh_TW.UTF-8, ko_KR.UTF-8
>
>   Next I tried to find out which locale category causes the problem,
>   but the problem is not reproduced by just specifying a locale for
>   one locale category.  I tried the following, but none reproduced the
>   problem.
>
>     $ LANG=en_US.UTF-8 LC_CTYPE=ja_JP.UTF-8; mintty --version
>     $ for a in {0..99}; do date; done | uniq -c
>     $ LANG=en_US.UTF-8 LC_COLLATE=ja_JP.UTF-8; mintty --version
>     $ for a in {0..99}; do date; done | uniq -c
>     $ LANG=en_US.UTF-8 LC_MESSAGES=ja_JP.UTF-8; mintty --version
>     $ for a in {0..99}; do date; done | uniq -c
>     $ LANG=en_US.UTF-8 LC_NUMERIC=ja_JP.UTF-8; mintty --version
>     $ for a in {0..99}; do date; done | uniq -c
>     $ LANG=en_US.UTF-8 LC_TIME=ja_JP.UTF-8; mintty --version
>     $ for a in {0..99}; do date; done | uniq -c
>     $ LANG=en_US.UTF-8 LC_MONETARY=ja_JP.UTF-8; mintty --version
>     $ for a in {0..99}; do date; done | uniq -c
>
>   Other interesting observations are
>
>   1. To reproduce the problem, LANG needs not be set to
>     ja_JP.UTF-8 when "mintty --version" runs, i.e., it can be
>     reproduced with:
>
>     $ mintty --version
>     $ LANG=ja_JP.UTF-8
>     $ for a in {0..99}; do date; done | uniq -c
>
>   2. Once the exec starts to create a console window, the problem
>     persists even after resetting LANG to a non-problematic one:
>
>     $ mintty --version
>     $ LANG=en_US.UTF-8
>     $ for a in {0..99}; do date; done | uniq -c
>     <No problems>
>     $ LANG=ja_JP.UTF-8
>     $ for a in {0..99}; do date; done | uniq -c
>     <Many flashing console windows>
>     $ LANG=en_US.UTF-8
>     $ for a in {0..99}; do date; done | uniq -c
>     <Still there are many console windows>
>
>
> Cygwin Versions:
>
>   In my environments, it is reproduced with the latest snapshot as
>   well.  I also tried the latest version of the git repository, but
>   the problem has not yet fixed.  I tried the following versions, but
>   with all the versions the same problem occurs:
>
>   1. Cygwin 3.1.2
>
>   $ uname -a
>   CYGWIN_NT-10.0 letsnote2019 3.1.2(0.340/5/3) 2019-12-21 15:25 x86_64
>   Cygwin
>
>   2. Snapshot 2020-01-14 from https://cygwin.com/snapshots/
>
>   $ uname -a
>   CYGWIN_NT-10.0 letsnote2019 3.1.2s(0.340/5/3) 2020-01-14 16:33 x86_64
>   Cygwin
>
>   3. Commit 85aff2830 from git://sourceware.org/git/newlib-cygwin.git
>
>   $ uname -a
>   CYGWIN_NT-10.0 letsnote2019 3.1.2(0.340/5/3) 2020-01-19 15:12 x86_64
>   Cygwin
>
>   4. Commit 4261a8f5c from git://sourceware.org/git/newlib-cygwin.git
>
>   $ uname -a
>   CYGWIN_NT-10.0 letsnote2019 3.1.2(0.340/5/3) 2020-01-21 00:57 x86_64
>   Cygwin
>
>   Also, this is not a specific problem of one computer because I tried
>   with two laptops and both reproduce the same problem.

Thanks for the report. I could reproduce the problem under LANG=ja_JP.UTF-8.
I have almost caught the culprit. Please wait for a while.

--
Takashi Yano <[hidden email]>

--
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

Reply | Threaded
Open this post in threaded view
|

Cygwin 3.3.0: The programs compiled with "-mwindows" cannot read more than one byte from noncanonical mode TTY

Koichi Murase
2020年1月21日(火) 10:47 Takashi Yano <[hidden email]>:
> Thanks for the report. I could reproduce the problem under LANG=ja_JP.UTF-8.
> I have almost caught the culprit. Please wait for a while.

Thank you for the patch fixing the problem. I cherry-picked the patch
and tried it, but there is another problem.

Description:

  The programs compiled with "-mwindows" cannot read more than one
  character from PTY in a non-canonical mode in .  There was no
  problem before the patch "Cygwin: pty: Fix reopening slave in
  push_to_pcon_screenbuffer().".

Repeat-By:

  1. Open Cygwin Terminal (mintty)

  2. Compile the attached program with the following commands.

    $ g++ -o minimal2-con.exe minimal2.cpp
    $ g++ -mwindows -o minimal2-win.exe minimal2.cpp

  3. The expected behavior can be checked with `minimal2-con'.  After
    executing the command, please type some five characters.  The
    string `[RECV]' will be printed five times, and then the program
    will exit.

    $ ./minimal2-con
    [RECV][RECV][RECV][RECV][RECV]
    $

  4. However, with the compile option "-mwindows", we can only see one
    `[RECV]', and the program will hang.

    $ ./minimal2-win
    [RECV]


Best,

Koichi


--
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

minimal2.cpp (1024 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Cygwin 3.3.0: The programs compiled with "-mwindows" cannot read more than one byte from noncanonical mode TTY

Takashi Yano
On Thu, 23 Jan 2020 18:49:04 +0800
Koichi Murase wrote:

> 2020年1月21日(火) 10:47 Takashi Yano <[hidden email]>:
> > Thanks for the report. I could reproduce the problem under LANG=ja_JP.UTF-8.
> > I have almost caught the culprit. Please wait for a while.
>
> Thank you for the patch fixing the problem. I cherry-picked the patch
> and tried it, but there is another problem.
>
> Description:
>
>   The programs compiled with "-mwindows" cannot read more than one
>   character from PTY in a non-canonical mode in .  There was no
>   problem before the patch "Cygwin: pty: Fix reopening slave in
>   push_to_pcon_screenbuffer().".
>
> Repeat-By:
>
>   1. Open Cygwin Terminal (mintty)
>
>   2. Compile the attached program with the following commands.
>
>     $ g++ -o minimal2-con.exe minimal2.cpp
>     $ g++ -mwindows -o minimal2-win.exe minimal2.cpp
>
>   3. The expected behavior can be checked with `minimal2-con'.  After
>     executing the command, please type some five characters.  The
>     string `[RECV]' will be printed five times, and then the program
>     will exit.
>
>     $ ./minimal2-con
>     [RECV][RECV][RECV][RECV][RECV]
>     $
>
>   4. However, with the compile option "-mwindows", we can only see one
>     `[RECV]', and the program will hang.
>
>     $ ./minimal2-win
>     [RECV]

Thanks for the report again. Apparently, close() before reopening slave
which I added just in case was superfluous. I will submit a patch for
this issue.

--
Takashi Yano <[hidden email]>

--
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