This is the mail archive of the cygwin@cygwin.com 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]

ExitProcess() with negative argument -> zero exit status from wait*()


If a process exits by calling ExitProcess() with a negative argument,
then cygwin returns a zero exit status to the calling process.  This
seems wrong, and is different from the behavior of GetExitCodeProcess().

Consider the following two programs:

----------------------------------------
bash$ cat foo.c
/* exit with negative (broken) or positive status values */

#include <windows.h>

int
main(int argc, char **argv)
{
#ifdef BROKEN
  ExitProcess(-33);
#else
  ExitProcess(+33);
#endif
}
----------------------------------------
bash$ cat bar.c
/* run foo as a child process, and get the exit status */

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

int
main(int argc, char **argv)
{
  STARTUPINFO si;
  PROCESS_INFORMATION pi;
  DWORD rc;

  memset(&si, 0, sizeof(si));
  si.cb = sizeof(si);
  CreateProcess("foo.exe", NULL, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi);
  WaitForSingleObject(pi.hProcess, INFINITE);
  GetExitCodeProcess(pi.hProcess, &rc);

  printf("exit code = 0x%08X %d\n", rc, rc);
  return(0);
}
----------------------------------------

With a positive argument for ExitProcess(), everything works as expected:

bash$ gcc bar.c -o bar

bash$ gcc foo.c -o foo
bash$ ./foo; echo $?
33
bash$ ./bar
exit code = 0x00000021 33

However, when we switch to a negative argument, notice the broken behavior
of bash, while the program that uses GetExitCodeProcess() continues to work:

bash$ gcc -DBROKEN foo.c -o foo
bash$ ./foo; echo $?
0
bash$ ./bar
exit code = 0xFFFFFFDF -33

These are just examples: you can also observe the MSVC debugger doing
the right thing, and cygwin apps like "make" or tcsh doing the wrong thing.
It looks like the wait*() implementation is broken.

I realize that ExitStatus() takes a UINT as an argument, and I'd be happy
to just get back only the low order byte from cygwin, but it should at
least be nonzero in these examples, don't you think?

I will append output from cygcheck -s -v -r as recommended.

Bob Byrnes                        e-mail: byrnes@curl.com
Curl Corporation                  phone:  617-761-1238
400 Technology Square, 8th Floor  fax:    617-761-1201
Cambridge, MA  02139

----------------------------------------
tcsh> cygcheck -s -v -r

Cygwin Win95/NT Configuration Diagnostics
Current System Time: Mon Jun 03 22:39:30 2002

Windows 2000 Professional Ver 5.0 Build 2195 Service Pack 2

Path:	u:\byrnes\bin\CYGWIN_NT-5.0.1.i686
	u:\byrnes\bin\share
	C:\cygwin\usr\local\bin
	C:\cygwin\bin
	C:\cygwin\bin
	C:\cygwin\usr\sbin
	C:\cygwin\bin
	c:\Perl\bin
	c:\WINNT\system32
	c:\WINNT
	c:\WINNT\System32\Wbem
	c:\win32app\emacs-20.5
	c:\win32app\emacs-20.5\bin
	c:\ntreskit\
	C:\cygwin\bin
	C:\cygwin\usr\ucb
	C:\cygwin\usr\local\jdk\bin
	C:\cygwin\usr\local\news\bin
	C:\cygwin\usr\local\games
	C:\cygwin\usr\games
	.

SysDir: C:\WINNT\System32
WinDir: C:\WINNT

CYGWIN = `binmode tty nontsec'
HOME = `u:\byrnes'
MAKE_MODE = `unix'
PWD = `/u/byrnes/ExitProcess'
USER = `byrnes'

ALLUSERSPROFILE = `C:\WINNT\Profiles\All Users'
ARCH = `CYGWIN_NT-5.0.1.i686'
ARCHM = `i686'
ARCHR = `1.3.10(0.51/3/2)'
BASH_ENV = `.bashrc'
COMMONPROGRAMFILES = `C:\Program Files\Common Files'
COMPUTERNAME = `VOLTRON'
COMSPEC = `C:\WINNT\system32\cmd.exe'
CURL_INSTALL = `file:///scratch/byrnes/build/curl/dev/metal/install/3'
CURL_SOURCE = `file:///u:/byrnes/curl/dev/metal'
CVSROOT = `/projects/systems/cvs-root'
EDITOR = `vi'
ESHELL = `bash.exe'
GROUP = `Administrators'
HOMEDRIVE = `\\'
HOMEPATH = `byrnes.u\byrnes'
HOST = `VOLTRON'
HOSTTAPE = `kingpin'
HOSTTYPE = `i386'
LESS = `-s'
LOGNAME = `byrnes'
LOGONSERVER = `\\NTCURL'
LPDEST = `ratcatcher'
LS_COLORS = `no=00:fi=00:di=01;36:ex=01;32:ln=01;33:or=01;04;33:so=01;35:pi=01;04;35:cd=01;31:bd=01;04;31'
MACHTYPE = `i386'
MAIL = `/u/byrnes/.Mailbox'
MANPATH = `:/usr/ssl/man'
MORE = `-s'
NUMBER_OF_PROCESSORS = `1'
OS2LIBPATH = `C:\WINNT\system32\os2\dll;'
OS = `Windows_NT'
OSTYPE = `posix'
P4CLIENT = `byrnes-curl-metal'
P4CONFIG = `.p4conf'
P4DIFF = `diff'
PAGER = `less'
PATHEXT = `.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH'
PRINTER = `ratcatcher'
PROCESSOR_ARCHITECTURE = `x86'
PROCESSOR_IDENTIFIER = `x86 Family 6 Model 8 Stepping 1, GenuineIntel'
PROCESSOR_LEVEL = `6'
PROCESSOR_REVISION = `0801'
PROGRAMFILES = `C:\Program Files'
REMOTEHOST = `boris.curl.com'
SHELL = `/bin/tcsh'
SHLVL = `1'
SMS_LOCAL_DIR = `C:\WINNT'
SSH_CLIENT = `216.230.83.7 1283 22'
SSH_TTY = `/dev/tty0'
SYSTEMDRIVE = `C:'
SYSTEMROOT = `C:\WINNT'
TAPE = `/dev/nst0'
TERM = `xterm'
TZ = `EST5EDT4,M4.1.0/2,M10.5.0/2'
USERDOMAIN = `CURL'
USERNAME = `byrnes'
USERPROFILE = `C:\WINNT\Profiles\byrnes'
VENDOR = `intel'
VISUAL = `vi'
WINDIR = `C:\WINNT'

HKEY_CURRENT_USER\Software\Cygnus Solutions
HKEY_CURRENT_USER\Software\Cygnus Solutions\Cygwin
HKEY_CURRENT_USER\Software\Cygnus Solutions\Cygwin\mounts v2
HKEY_CURRENT_USER\Software\Cygnus Solutions\Cygwin\Program Options
HKEY_CURRENT_USER\Software\Cygnus Solutions\CYGWIN.DLL setup
HKEY_CURRENT_USER\Software\Cygnus Solutions\CYGWIN.DLL setup\b15.0
HKEY_CURRENT_USER\Software\Cygnus Solutions\CYGWIN.DLL setup\b15.0\mounts
HKEY_CURRENT_USER\Software\Cygnus Solutions\CYGWIN.DLL setup\b15.0\mounts\00
  (default) = `d:'
  unix = `/d'
  fbinary = 0x00000000
  fsilent = 0x00000000
HKEY_CURRENT_USER\Software\Cygnus Solutions\CYGWIN.DLL setup\b15.0\mounts\01
  (default) = `C:'
  unix = `/'
  fbinary = 0x00000000
  fsilent = 0x00000000
HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions
HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin
  (default) = `19'
HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2
  (default) = `/cygdrive'
  cygdrive flags = 0x0000003a
HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2\/
  (default) = `C:\cygwin'
  flags = 0x0000000a
HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2\/c
  (default) = `c:'
  flags = 0x0000001a
HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2\/d
  (default) = `d:'
  flags = 0x0000001a
HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2\/m
  (default) = `m:'
  flags = 0x0000001a
HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2\/projects
  (default) = `p:'
  flags = 0x0000001a
HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2\/releases
  (default) = `r:'
  flags = 0x0000001a
HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2\/software
  (default) = `s:'
  flags = 0x0000001a
HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2\/t
  (default) = `t:'
  flags = 0x0000001a
HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2\/u
  (default) = `u:'
  flags = 0x0000001a
HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2\/usr/bin
  (default) = `C:\cygwin/bin'
  flags = 0x0000000a
HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2\/usr/lib
  (default) = `C:\cygwin/lib'
  flags = 0x0000000a
HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\Program Options

a:  fd           N/A    N/A                    
c:  hd  NTFS    9766Mb  25% CP CS UN PA FC     SYSTEM
d:  hd  NTFS   43974Mb  11% CP CS UN PA FC     
e:  cd           N/A    N/A                    
m:  net NTFS    5744Mb  90% CP CS    PA        byrnes
p:  net NTFS    1011Mb  13% CP CS    PA        projects
r:  net NTFS    1011Mb  13% CP CS    PA        releases
s:  net NTFS   17233Mb  84% CP CS    PA        software
t:  net NTFS   26693Mb  43% CP CS UN PA FC     
u:  net NTFS     159Mb  55% CP CS    PA        u

C:\cygwin      /          system  binmode
c:             /c         system  binmode,exec
d:             /d         system  binmode,exec
m:             /m         system  binmode,exec
p:             /projects  system  binmode,exec
r:             /releases  system  binmode,exec
s:             /software  system  binmode,exec
t:             /t         system  binmode,exec
u:             /u         system  binmode,exec
C:\cygwin/bin  /usr/bin   system  binmode
C:\cygwin/lib  /usr/lib   system  binmode
.              /cygdrive  user    binmode,exec,noumount

Found: C:\cygwin\bin\bash.exe
Found: C:\cygwin\bin\cat.exe
Found: C:\cygwin\bin\cpp.exe
Found: C:\cygwin\bin\find.exe
Found: C:\cygwin\bin\gcc.exe
Found: C:\cygwin\bin\gdb.exe
Found: C:\cygwin\bin\ld.exe
Found: C:\cygwin\bin\ls.exe
Found: C:\cygwin\bin\make.exe
Found: C:\cygwin\bin\sh.exe

   56k 2000/12/03 C:\cygwin\bin\cygbz21.0.dll - os=4.0 img=1.0 sys=4.0
                  "cygbz21.0.dll" v0.0 ts=2000/11/20 18:53
  621k 2002/01/16 C:\cygwin\bin\cygcrypto.dll - os=4.0 img=1.0 sys=4.0
                  "cygcrypto.dll" v0.0 ts=2002/1/16 4:54
   45k 2001/04/25 C:\cygwin\bin\cygform5.dll - os=4.0 img=1.0 sys=4.0
                  "cygform5.dll" v0.0 ts=2001/4/25 1:28
   35k 2002/01/09 C:\cygwin\bin\cygform6.dll - os=4.0 img=1.0 sys=4.0
                  "cygform6.dll" v0.0 ts=2002/1/9 1:03
   19k 2002/02/20 C:\cygwin\bin\cyggdbm.dll - os=4.0 img=1.0 sys=4.0
                  "cyggdbm.dll" v0.0 ts=2002/2/19 22:05
   17k 2001/06/28 C:\cygwin\bin\cyghistory4.dll - os=4.0 img=1.0 sys=4.0
                  "cyghistory4.dll" v0.0 ts=2001/1/6 23:34
   20k 2002/01/13 C:\cygwin\bin\cyghistory5.dll - os=4.0 img=1.0 sys=4.0
                  "cyghistory5.dll" v0.0 ts=2002/1/12 20:27
   22k 2001/12/13 C:\cygwin\bin\cygintl-1.dll - os=4.0 img=1.0 sys=4.0
                  "cygintl-1.dll" v0.0 ts=2001/12/13 4:28
   21k 2001/06/20 C:\cygwin\bin\cygintl.dll - os=4.0 img=1.0 sys=4.0
                  "cygintl.dll" v0.0 ts=2001/6/20 13:09
   81k 2001/10/20 C:\cygwin\bin\cygitcl30.dll - os=4.0 img=1.0 sys=4.0
                  "cygitcl30.dll" v0.0 ts=2001/10/19 20:25
   35k 2001/10/20 C:\cygwin\bin\cygitk30.dll - os=4.0 img=1.0 sys=4.0
                  "cygitk30.dll" v0.0 ts=2001/10/19 20:25
   25k 2002/03/17 C:\cygwin\bin\cygltdl-3.dll - os=4.0 img=1.0 sys=4.0
                  "cygltdl-3.dll" v0.0 ts=2002/3/17 11:44
   26k 2001/04/25 C:\cygwin\bin\cygmenu5.dll - os=4.0 img=1.0 sys=4.0
                  "cygmenu5.dll" v0.0 ts=2001/4/25 1:27
   20k 2002/01/09 C:\cygwin\bin\cygmenu6.dll - os=4.0 img=1.0 sys=4.0
                  "cygmenu6.dll" v0.0 ts=2002/1/9 1:03
  156k 2001/04/25 C:\cygwin\bin\cygncurses++5.dll - os=4.0 img=1.0 sys=4.0
                  "cygncurses++5.dll" v0.0 ts=2001/4/25 1:29
  175k 2002/01/09 C:\cygwin\bin\cygncurses++6.dll - os=4.0 img=1.0 sys=4.0
                  "cygncurses++6.dll" v0.0 ts=2002/1/9 1:03
  226k 2001/04/25 C:\cygwin\bin\cygncurses5.dll - os=4.0 img=1.0 sys=4.0
                  "cygncurses5.dll" v0.0 ts=2001/4/25 1:17
  202k 2002/01/09 C:\cygwin\bin\cygncurses6.dll - os=4.0 img=1.0 sys=4.0
                  "cygncurses6.dll" v0.0 ts=2002/1/9 1:03
   15k 2001/04/25 C:\cygwin\bin\cygpanel5.dll - os=4.0 img=1.0 sys=4.0
                  "cygpanel5.dll" v0.0 ts=2001/4/25 1:27
   12k 2002/01/09 C:\cygwin\bin\cygpanel6.dll - os=4.0 img=1.0 sys=4.0
                  "cygpanel6.dll" v0.0 ts=2002/1/9 1:03
   40k 2001/11/21 C:\cygwin\bin\cygpcre.dll - os=4.0 img=1.0 sys=4.0
                  "cygpcre.dll" v0.0 ts=2001/11/21 17:15
   39k 2001/11/21 C:\cygwin\bin\cygpcreposix.dll - os=4.0 img=1.0 sys=4.0
                  "cygpcreposix.dll" v0.0 ts=2001/11/21 17:15
  108k 2001/06/28 C:\cygwin\bin\cygreadline4.dll - os=4.0 img=1.0 sys=4.0
                  "cygreadline4.dll" v0.0 ts=2001/1/6 23:34
  121k 2002/01/13 C:\cygwin\bin\cygreadline5.dll - os=4.0 img=1.0 sys=4.0
                  "cygreadline5.dll" v0.0 ts=2002/1/12 20:27
   66k 2001/11/20 C:\cygwin\bin\cygregex.dll - os=4.0 img=1.0 sys=4.0
                  "cygregex.dll" v0.0 ts=2001/11/20 9:44
  156k 2002/01/16 C:\cygwin\bin\cygssl.dll - os=4.0 img=1.0 sys=4.0
                  "cygssl.dll" v0.0 ts=2002/1/16 4:54
  390k 2001/10/20 C:\cygwin\bin\cygtcl80.dll - os=4.0 img=1.0 sys=4.0
                  "cygtcl80.dll" v0.0 ts=2001/10/19 20:24
    5k 2001/10/20 C:\cygwin\bin\cygtclpip80.dll - os=4.0 img=1.0 sys=4.0
   10k 2001/10/20 C:\cygwin\bin\cygtclreg80.dll - os=4.0 img=1.0 sys=4.0
                  "cygtclreg80.dll" v0.0 ts=2001/10/19 20:24
  623k 2001/10/20 C:\cygwin\bin\cygtk80.dll - os=4.0 img=1.0 sys=4.0
                  "cygtk80.dll" v0.0 ts=2001/10/19 20:25
   50k 2002/03/12 C:\cygwin\bin\cygz.dll - os=4.0 img=1.0 sys=4.0
                  "cygz.dll" v0.0 ts=2002/3/11 23:38
  751k 2002/02/25 C:\cygwin\bin\cygwin1.dll - os=4.0 img=1.0 sys=4.0
                  "cygwin1.dll" v0.0 ts=2002/2/25 11:14
    Cygwin DLL version info:
        DLL version: 1.3.10
        DLL epoch: 19
        DLL bad signal mask: 19005
        DLL old termios: 5
        DLL malloc env: 28
        API major: 0
        API minor: 51
        Shared data: 3
        DLL identifier: cygwin1
        Mount registry: 2
        Cygnus registry name: Cygnus Solutions
        Cygwin registry name: Cygwin
        Program options name: Program Options
        Cygwin mount registry name: mounts v2
        Cygdrive flags: cygdrive flags
        Cygdrive prefix: cygdrive prefix
        Cygdrive default prefix: 
        Build date: Mon Feb 25 11:14:34 EST 2002
        Shared id: cygwin1S3


Cygwin Package Information
Last downloaded files to: 
Last downloaded files from: à$?

Package             Version             
ash                 20020131-1          
autoconf            2.53-1              
autoconf-devel      2.52-4              
autoconf-stable     2.13-4              
automake            1.6a-1              
automake-devel      1.5b-1              
automake-stable     1.4p5-5             
bash                2.05a-3             
bc                  1.06-1              
binutils            20011002-1          
bison               1.34-1              
byacc               1.9-1               
bzip2               1.0.1-6             
clear               1.0-1               
cpio                2.4.2               
crypt               1.0-1               
ctags               5.2-1               
cygrunsrv           0.95-1              
cygutils            1.0.0-1             
cygwin              1.3.10-1            
diff                0.0                 
ed                  0.2-1               
file                3.37-1              
fileutils           4.1-1               
findutils           4.1                 
flex                2.5.4-1             
fortune             1.8-2               
gawk                3.0.4-1             
gcc                 2.95.3-5            
gdb                 20010428-3          
gdbm                1.8.0-4             
gettext             0.10.40-1           
grep                2.5-1               
groff               1.17.2-1            
gzip                1.3.2-1             
less                374-1               
libintl             0.10.38-3           
libintl1            0.10.40-1           
libncurses5         5.2-1               
libncurses6         5.2-8               
libreadline4        4.1-2               
libreadline5        4.2a-1              
libtool             20020202a-1         
libtool-devel       20020316-1          
libtool-stable      1.4.2-2             
login               1.4-3               
m4                  0.0                 
make                3.79.1-5            
man                 1.5g-2              
mingw-runtime       1.2-1               
mktemp              1.4-1               
ncurses             5.2-8               
newlib-man          20001118-1          
openssh             3.1p1-1             
openssl             0.9.6c-3            
openssl-devel       0.9.6c-2            
patch               2.5-3               
pcre                3.7-1               
pkgconfig           0.10.0-1            
popt                1.6.2-1             
readline            4.2a-1              
sed                 3.02-1              
sh-utils            2.0-2               
sharutils           4.2.1-2             
tar                 1.13.19-1           
tcsh                6.11.00-4           
termcap             20020403-1          
terminfo            5.2-1               
texinfo             4.1-1               
textutils           2.0.21-1            
time                1.7-1               
ttcp                19980512-1          
unzip               5.41-1              
vim                 6.1-2               
w32api              1.2-2               
which               1.5-1               
whois               4.5.17-1            
zip                 2.3-1               
zlib                1.1.4-1             

Use -h to see help about each section

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


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