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]

Re: [OT] Wine + Cygwin: `script -e` exit status forwarding randomly return zero for non zero child process

Hi Qian,

On Sep  2 22:27, Qian Hong wrote:
> Dear list,
> Before the actual question, I wonder whether Wine specific issues are
> considered as off-topic here, and whether it is allowed here? Anyway,
> thanks for your great contribution on Cygwin!
> In the past few months, we were working on supporting Cygwin/MSYS2 on
> Wine (Wine Staging at this moment, we will upstream our patches
> lately). After fixing a couple of Wine Staging bugs [1], today
> Cygwin/MSYS2 works much better on Wine Staging than before.
> GCC/GDB/etc, including most part of toolchain, are now basically
> supported on Wine Staging 1.7.50.
> However, the remain bugs are difficult, so it would be great to have
> some help from Cygwin community to speed up the bug fix progress, many
> thanks for anyone interesting to join!
> ==== thanks for reading :) ====
> Now, here is one bug blocks me for two days:
> On Cygwin Windows, `script -e -c "exit 5"` will always return 5;
> On Cygwin Wine, `script -e -c "exit 5"` sometimes returns 5 while
> sometimes return zero. I tested with a 100-times-loop, 34 of them
> return zero, while 66 of them return 5.

Comparing the straces, two interesting facts are conspicuous:

- Independently of "good" or "bad", it's pretty clear that everything
  worked as expected as far as the child processes of the parent script
  are concerned.  In both cases, the 1st forked script process returns
  with the correct result:

  good (parent script pid 48, child script pid 50):

     4026 6468659 [main] script 50 pinfo::exit: Calling ExitProcess n 0x500,
    exitcode 0x500
    5079923 6473669 [waitproc] script 48 pinfo::maybe_set_exit_code_from_windows
    : pid 50, exit value - old 0x8000500, windows 0xDEADBEEF, cygwin 0x8000500

  bad (parent script pid 25, child script pid 38):

      215 2716087 [main] script 38 pinfo::exit: Calling ExitProcess n 0x500,
    exitcode 0x500
    2487909 2717274 [waitproc] script 25 pinfo::maybe_set_exit_code_from_windows
    : pid 38, exit value - old 0x8000500, windows 0xDEADBEEF, cygwin 0x8000500

- After the forked script returned, what happens in the parent is absolutly
  identical in both cases, up to a point during exit.  This point is reached
  with line 1573 in the "bad" case and line 1580 in the "good" case.  Then
  "something" happens:

  In the bad case the pty master thread gets an error condition returned
  from DisconnectNamedPipe:

    305 2754169 [ptym] script 25 fhandler_pty_master::pty_master_thread:
    DisconnectNamedPipe, Win32 error 6

  After that, the pty master thread exits in both cases and then, for
  some invisible reason, the "bad" process exits immediately, even
  though it's not really finished:

      170 2755070 [main] script 25 cygthread::terminate_thread: thread 'ptymf',
      id 0x3F, inuse 1, stack_ptr 0xC0B7D0
    --- Process 25 thread 63 exited with status 0x0
    --- Process 25 thread 61 exited with status 0x0
    --- Process 25 thread 12 exited with status 0x0
    --- Process 25 thread 11 exited with status 0x0
    --- Process 25 exited with status 0x0

   while the "good" guy performs the remaining cleanup tasks.  The last
   of the remaining cleanup tasks is calling ExitProcess with the right
   exit code:

     221 7249273 [main] script 48 pinfo::exit: Calling ExitProcess n 0x500,
     exitcode 0x5

   To me this looks like the "bad" script has been exited forcefully
   for some reason.

There's something else which occured to me while looking through both
straces:  Are you aware that Windows PIDs are *always* multiples of 4?

  PID 0, 4, 8, 12, 16, ...  exist
  PID 1, 2, 3, 5, 6, 7, ... don't.

Wine apparently doesn't follow this scheme.  I would treat that as a bug.
I can easily imagine applications which rely on the fact that PIDs are
always multiples of four and use the lower two bits for dubious purposes.
I'd suggest to change that in Wine for compatibility reasons.


Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

Attachment: pgpClXhFHb6GM.pgp
Description: PGP signature

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