X-Spam-Check-By: sourceware.org To: cygwin AT cygwin DOT com Subject: problems with exit codes on 64-bit Windows XP Pro x64 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Date: Mon, 06 Feb 2006 14:37:00 -0800 Message-ID: <1004.1139265420@gemini> From: Kevin Layer X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com I'm running the latest cygwin (1.5.19, see cygcheck below). My application is a native Windows app (64 and 32-bit). It includes no cygwin libraries and is not compiled with cygwin's gcc. When I execute cygwin programs from my app, however, the return value obtained from cygwin programs is always 0. More precisely, I spawn a particular cygwin program, say `make' or `sh', with CreateProcess(). When the program exits GetExitCodeProcess() always sets the exit status to 0, no matter what the real exit status was. Attached are 2 programs, exit1.c and bug.c. Compile with: cl bug.c bufferoverflowu.lib cl exit1.c bufferoverflowu.lib [cl is MS C/C++ version 14, found in the SDK.] Then, running on 64-bit windows: ./bug exit1 result = 0 Doing the experimentn on 32-bit Windows gets the output result = 1 Below are the files. Is this a known issue? Any chance of a fix? -- Kevin Layer layer AT Franz DOT COM http://www.franz.com/ Franz Inc., 555 12th St., Suite 1450, Oakland, CA 94607, USA Phone: (510) 452-2000 FAX: (510) 452-0182 --=-=-= Content-Type: text/x-c Content-Disposition: attachment; filename=exit1.c Content-Description: exit1.c /* demonstrate a bug in capturing the exit code from shell */ #include #include #include #include #include #include #define _POSIX_ #include #include #include main (int argc, char *argv[]) { exit(1); } --=-=-= Content-Type: text/x-c Content-Disposition: attachment; filename=bug.c Content-Description: bug.c /* demonstrate a bug in capturing the exit code from shell */ #include #include #include #include #include #include #define _POSIX_ #include #include #include main (int argc, char *argv[]) { int docommand(char *), res; if (argc > 1) { res = docommand(argv[1]); printf("result = %d\n", res); } else { printf("no command!\n"); } } char *make_command_line(char *cmdline) { char buf[1024]; sprintf(buf, "sh -c \"%s\"", cmdline); return strdup(buf); } int docommand(char *cmdline) { STARTUPINFO startup_info; PROCESS_INFORMATION process_info; SECURITY_ATTRIBUTES security; char *newcmdline; DWORD status; HANDLE output_write = 0; HANDLE erroroutput_write = 0; HANDLE input_read = 0; HANDLE current_process; memset(&startup_info, 0, sizeof(startup_info)); startup_info.cb = sizeof(startup_info); security.nLength = sizeof(security); security.lpSecurityDescriptor = 0; security.bInheritHandle = FALSE; startup_info.dwFlags = STARTF_USESTDHANDLES; current_process = GetCurrentProcess(); newcmdline=make_command_line(cmdline); if (!DuplicateHandle(current_process, GetStdHandle(STD_INPUT_HANDLE), current_process, &input_read, 0, TRUE, /* inherit this one */ DUPLICATE_SAME_ACCESS)) input_read = 0; startup_info.hStdInput = input_read; if (!DuplicateHandle(current_process, GetStdHandle(STD_OUTPUT_HANDLE), current_process, &output_write, 0, TRUE, /* inherit this one */ DUPLICATE_SAME_ACCESS)) output_write = 0; startup_info.hStdOutput = output_write; if (!DuplicateHandle(current_process, GetStdHandle(STD_ERROR_HANDLE), current_process, &erroroutput_write, 0, TRUE, /* inherit this one */ DUPLICATE_SAME_ACCESS)) erroroutput_write = 0; startup_info.hStdError = erroroutput_write; if ((startup_info.hStdInput == 0) && (startup_info.hStdOutput == 0) && (startup_info.hStdError == 0)) { /* clear this bit */ startup_info.dwFlags &= ~STARTF_USESTDHANDLES; } if (!CreateProcess(0, newcmdline, 0, 0, 1, /* inherit handles */ 0x214, 0, 0, &startup_info, &process_info)) { printf("CreateProces(%s) failed. error code %ld\n", cmdline, GetLastError()); free(newcmdline); return 1; } free(newcmdline); ResumeThread(process_info.hThread); CloseHandle(process_info.hThread); /* Wait for the process to exit */ WaitForSingleObject(process_info.hProcess, INFINITE); if(!GetExitCodeProcess(process_info.hProcess, &status)) { printf("GetExitCodeProcess failed! error %ld\n", GetLastError()); exit(1); } CloseHandle(process_info.hProcess); return status; } --=-=-= Content-Type: text/x-news Content-Disposition: attachment; filename=cygcheck.txt Content-Description: cygcheck.txt Cygwin Configuration Diagnostics Current System Time: Mon Feb 06 14:09:14 2006 Windows XP Professional Ver 5.1 Build 2600 Running under WOW64 on AMD64 Running in Terminal Service session Path: . c:\bin c:\cygwin\bin c:\cygwin\usr\X11R6\bin C:\WINDOWS\system32 C:\WINDOWS C:\WINDOWS\System32\Wbem C:\Program Files\Microsoft Platform SDK\Bin\. C:\Program Files\Microsoft Platform SDK\Bin\WinNT\. c:\Program Files\Debugging Tools for Windows 64-bit c:\Program Files\Microsoft Platform SDK\bin\win64\x86\AMD64 Output from C:\cygwin\bin\id.exe (nontsec) UID: 11003(layer) GID: 10513(Domain Users) 544(Administrators) 545(Users) 10512(Domain Admins) 10513(Domain Users) Output from C:\cygwin\bin\id.exe (ntsec) UID: 11003(layer) GID: 10513(Domain Users) 544(Administrators) 545(Users) 10512(Domain Admins) 10513(Domain Users) SysDir: C:\WINDOWS\system32 WinDir: C:\WINDOWS PWD = '/c/acl80/src/cl/src' CYGWIN = 'nontsec' HOME = '/c' Use '-r' to scan registry c: hd NTFS 238464Mb 4% CP CS UN PA FC d: cd N/A N/A e: cd N/A N/A f: fd N/A N/A g: fd N/A N/A h: fd N/A N/A i: fd N/A N/A y: net NTFS 28040Mb 76% CP CS PA layer z: net NTFS 8350Mb 87% CP CS PA pc z: /z system textmode y: /y system textmode C:\cygwin/lib /usr/lib system textmode C:\cygwin/bin /usr/bin system textmode c: /c system textmode C:\cygwin / system textmode . /cygdrive system textmode,cygdrive Found: c:\cygwin\bin\awk.exe Found: c:\cygwin\bin\bash.exe Found: c:\cygwin\bin\cat.exe Found: c:\cygwin\bin\cp.exe Not Found: cpp (good!) Not Found: crontab Found: c:\cygwin\bin\find.exe Not Found: gcc Not Found: gdb Found: c:\cygwin\bin\grep.exe Found: c:\cygwin\bin\kill.exe Found: c:\Program Files\Debugging Tools for Windows 64-bit\kill.exe Not Found: ld Found: c:\cygwin\bin\ls.exe Found: c:\cygwin\bin\make.exe Found: c:\cygwin\bin\mv.exe Found: c:\cygwin\bin\patch.exe Found: c:\cygwin\bin\perl.exe Found: c:\cygwin\bin\rm.exe Found: c:\cygwin\bin\sed.exe Found: c:\cygwin\bin\ssh.exe Found: c:\cygwin\bin\sh.exe Found: c:\cygwin\bin\tar.exe Found: c:\cygwin\bin\test.exe Not Found: vi Found: c:\cygwin\bin\vim.exe 56k 2005/07/09 c:\cygwin\bin\cygbz2-1.dll 7k 2005/11/20 c:\cygwin\bin\cygcharset-1.dll 16k 2005/10/11 c:\cygwin\bin\cygcompface-0.dll 7k 2003/10/19 c:\cygwin\bin\cygcrypt-0.dll 1108k 2005/10/17 c:\cygwin\bin\cygcrypto-0.9.7.dll 1047k 2005/10/11 c:\cygwin\bin\cygcrypto-0.9.8.dll 895k 2004/04/28 c:\cygwin\bin\cygdb-4.2.dll 965k 2005/05/14 c:\cygwin\bin\cygdb-4.3.dll 1156k 2004/04/28 c:\cygwin\bin\cygdb_cxx-4.2.dll 1240k 2005/05/14 c:\cygwin\bin\cygdb_cxx-4.3.dll 174k 2004/10/14 c:\cygwin\bin\cygexpat-0.dll 129k 2004/03/11 c:\cygwin\bin\cygfontconfig-1.dll 40k 2005/09/29 c:\cygwin\bin\cygform-8.dll 45k 2001/04/25 c:\cygwin\bin\cygform5.dll 35k 2002/01/09 c:\cygwin\bin\cygform6.dll 48k 2003/08/09 c:\cygwin\bin\cygform7.dll 375k 2005/09/06 c:\cygwin\bin\cygfreetype-6.dll 28k 2003/07/20 c:\cygwin\bin\cyggdbm-3.dll 30k 2003/08/11 c:\cygwin\bin\cyggdbm-4.dll 19k 2003/03/22 c:\cygwin\bin\cyggdbm.dll 15k 2003/07/20 c:\cygwin\bin\cyggdbm_compat-3.dll 15k 2003/08/11 c:\cygwin\bin\cyggdbm_compat-4.dll 158k 2004/10/16 c:\cygwin\bin\cyggmp-3.dll 288k 2004/10/16 c:\cygwin\bin\cyggmpxx-3.dll 17k 2001/06/28 c:\cygwin\bin\cyghistory4.dll 29k 2003/08/10 c:\cygwin\bin\cyghistory5.dll 24k 2006/01/28 c:\cygwin\bin\cyghistory6.dll 947k 2005/11/20 c:\cygwin\bin\cygiconv-2.dll 22k 2001/12/13 c:\cygwin\bin\cygintl-1.dll 37k 2003/08/10 c:\cygwin\bin\cygintl-2.dll 31k 2005/11/20 c:\cygwin\bin\cygintl-3.dll 21k 2001/06/20 c:\cygwin\bin\cygintl.dll 132k 2003/08/11 c:\cygwin\bin\cygjpeg-62.dll 41k 2005/08/29 c:\cygwin\bin\cyglber-2-2-7.dll 176k 2005/08/29 c:\cygwin\bin\cygldap-2-2-7.dll 188k 2005/08/29 c:\cygwin\bin\cygldap_r-2-2-7.dll 48k 2005/11/19 c:\cygwin\bin\cygmagic-1.dll 21k 2005/09/29 c:\cygwin\bin\cygmenu-8.dll 26k 2001/04/25 c:\cygwin\bin\cygmenu5.dll 20k 2002/01/09 c:\cygwin\bin\cygmenu6.dll 29k 2003/08/09 c:\cygwin\bin\cygmenu7.dll 21k 2004/10/22 c:\cygwin\bin\cygminires.dll 71k 2004/10/16 c:\cygwin\bin\cygmp-3.dll 95k 2004/10/16 c:\cygwin\bin\cygmpfr-0.dll 67k 2005/09/29 c:\cygwin\bin\cygncurses++-8.dll 156k 2001/04/25 c:\cygwin\bin\cygncurses++5.dll 175k 2002/01/09 c:\cygwin\bin\cygncurses++6.dll 226k 2005/09/29 c:\cygwin\bin\cygncurses-8.dll 226k 2001/04/25 c:\cygwin\bin\cygncurses5.dll 202k 2002/01/09 c:\cygwin\bin\cygncurses6.dll 224k 2003/08/09 c:\cygwin\bin\cygncurses7.dll 11k 2005/09/29 c:\cygwin\bin\cygpanel-8.dll 15k 2001/04/25 c:\cygwin\bin\cygpanel5.dll 12k 2002/01/09 c:\cygwin\bin\cygpanel6.dll 19k 2003/08/09 c:\cygwin\bin\cygpanel7.dll 176k 2005/09/06 c:\cygwin\bin\cygpcre-0.dll 299k 2005/09/06 c:\cygwin\bin\cygpcrecpp-0.dll 6k 2005/09/06 c:\cygwin\bin\cygpcreposix-0.dll 1249k 2005/12/30 c:\cygwin\bin\cygperl5_8.dll 230k 2005/07/11 c:\cygwin\bin\cygpng12.dll 22k 2002/06/09 c:\cygwin\bin\cygpopt-0.dll 94k 2005/11/08 c:\cygwin\bin\cygpq.dll 108k 2001/06/28 c:\cygwin\bin\cygreadline4.dll 148k 2003/08/10 c:\cygwin\bin\cygreadline5.dll 152k 2006/01/28 c:\cygwin\bin\cygreadline6.dll 78k 2004/10/13 c:\cygwin\bin\cygsasl2-2.dll 231k 2005/10/17 c:\cygwin\bin\cygssl-0.9.7.dll 215k 2005/10/11 c:\cygwin\bin\cygssl-0.9.8.dll 304k 2005/07/10 c:\cygwin\bin\cygtiff-5.dll 282k 2003/08/11 c:\cygwin\bin\cygtiff4.dll 281k 2005/07/10 c:\cygwin\bin\cygtiffxx-5.dll 27k 2005/10/23 c:\cygwin\bin\cygungif-4.dll 65k 2005/08/23 c:\cygwin\bin\cygz.dll 1763k 2006/01/20 c:\cygwin\bin\cygwin1.dll Cygwin DLL version info: DLL version: 1.5.19 DLL epoch: 19 DLL bad signal mask: 19005 DLL old termios: 5 DLL malloc env: 28 API major: 0 API minor: 150 Shared data: 4 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: Fri Jan 20 13:28:43 EST 2006 CVS tag: cr-0x5ef Shared id: cygwin1S4 243k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygdps-1.dll 26k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygdpstk-1.dll 21k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygfontenc-1.dll 36k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygFS-6.dll 358k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygGL-1.dll 438k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygGLU-1.dll 75k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygICE-6.dll 9k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygoldX-6.dll 1413k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygOSMesa-4.dll 20k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygpsres-1.dll 30k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygSM-6.dll 877k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygX11-6.dll 254k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygXaw-6.dll 356k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygXaw-7.dll 363k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygXaw-8.dll 275k 2004/01/13 c:\cygwin\usr\X11R6\bin\cygXaw3d-7.dll 9k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygXcomposite-1.dll 30k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygXcursor-1.dll 9k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygXdamage-1.dll 7k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygXevie-1.dll 49k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygXext-6.dll 16k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygXfixes-3.dll 56k 2004/03/11 c:\cygwin\usr\X11R6\bin\cygXft-1.dll 63k 2004/03/23 c:\cygwin\usr\X11R6\bin\cygXft-2.dll 27k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygXi-6.dll 125k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygxkbfile-1.dll 12k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygxkbui-1.dll 76k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygXmu-6.dll 11k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygXmuu-1.dll 26k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygXp-6.dll 52k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygXpm-4.dll 12k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygXrandr-2.dll 28k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygXrender-1.dll 8k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygXRes-1.dll 40k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygxrx-6.dll 25k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygxrxnest-6.dll 282k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygXt-6.dll 27k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygXTrap-6.dll 17k 2005/02/23 c:\cygwin\usr\X11R6\bin\cygXtst-6.dll No Cygwin services found. Cygwin Package Information Package Version _update-info-dir 00352-1 alternatives 1.3.20a-2 ash 20040127-3 base-files 3.7-1 base-passwd 2.2-1 bash 3.0-14 bash-completion 20050721-1 bzip2 1.0.3-1 compface 1.5.2-1 coreutils 5.93-3 crypt 1.1-1 ctags 5.5-4 cvs 1.11.17-1 cvsutils 0.2.3-1 cygrunsrv 1.12-1 cygutils 1.2.9-1 cygwin 1.5.19-4 cygwin-doc 1.4-3 diffutils 2.8.7-1 ed 0.2-1 editrights 1.01-1 emacs 21.2-13 emacs-el 21.2-13 emacs-X11 21.2-13 expat 1.95.8-1 file 4.16-1 findutils 4.2.27-1 fontconfig 2.2.2-1 freetype2 2.1.9-1 gawk 3.1.5-2 gdbm 1.8.3-7 gettext 0.14.5-1 gmp 4.1.4-2 grep 2.5.1a-2 groff 1.18.1-2 gzip 1.3.5-1 inetutils 1.3.2-35 less 381-1 libbz2_1 1.0.3-1 libcharset1 1.9.2-2 libdb4.2 4.2.52-1 libdb4.3 4.3.28-1 libfontconfig1 2.2.2-1 libfreetype26 2.1.9-1 libgdbm 1.8.0-5 libgdbm-devel 1.8.3-7 libgdbm3 1.8.3-3 libgdbm4 1.8.3-7 libiconv 1.9.2-2 libiconv2 1.9.2-2 libintl 0.10.38-3 libintl1 0.10.40-1 libintl2 0.12.1-3 libintl3 0.14.5-1 libjpeg62 6b-11 libncurses5 5.2-1 libncurses6 5.2-8 libncurses7 5.3-4 libncurses8 5.4-4 libopenldap2_2_7 2.2.26-2 libpcre0 6.3-1 libpng12 1.2.8-2 libpopt0 1.6.4-4 libreadline4 4.1-2 libreadline5 4.3-5 libreadline6 5.1-2 libsasl2 2.1.19-3 libtiff4 3.6.0-5 libtiff5 3.7.3-1 libungif 4.1.4-1 libungif4 4.1.4-1 libXft 2.1.6-1 libXft1 1.0.0-1 libXft2 2.1.6-1 login 1.9-7 make 3.80-1 man 1.5p-1 minires 1.00-1 mktemp 1.5-3 ncftp 3.1.7-1 ncurses 5.4-4 openssh 4.3p1-1 openssl 0.9.8a-1 openssl097 0.9.7i-1 patch 2.5.8-8 patchutils 0.2.31-1 pcre 6.3-1 pcre-devel 6.3-1 pcre-doc 6.3-1 perl 5.8.7-5 perl-libwin32 0.26-1 postgresql 8.0.4-1 run 1.1.6-1 sed 4.1.4-1 tar 1.15.1-3 tcsh 6.14.00-5 termcap 20050421-1 terminfo 5.4_20041009-1 texinfo 4.8-1 time 1.7-1 unzip 5.50-5 vim 6.4-4 wget 1.10.2-1 which 1.7-1 whois 4.7.11-1 X-startup-scripts 1.0.11-1 Xaw3d 1.5D-5 xemacs 21.4.18-2 xemacs-sumo 2005-12-08-1 xorg-x11-base 6.8.2.0-1 xorg-x11-bin 6.8.2.0-1 xorg-x11-bin-dlls 6.8.2.0-1 xorg-x11-bin-lndir 6.8.2.0-1 xorg-x11-etc 6.8.2.0-1 xorg-x11-fenc 6.8.1.0-2 xorg-x11-fnts 6.8.1.0-3 xorg-x11-libs-data 6.8.2.0-1 xorg-x11-xwin 6.8.2.0-4 xterm 202-1 zip 2.3-6 zlib 1.2.3-1 Use -h to see help about each section --=-=-= 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/ --=-=-=--