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 Date: Sat, 25 Sep 2004 15:20:40 -0400 From: Christopher Faylor To: cygwin AT cygwin DOT com Subject: Re: Fw: 1.5.11 bug in WEXITSTATUS() macro (wait.h) Message-ID: <20040925192040.GE15889@trixie.casa.cgf.cx> Reply-To: cygwin AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com References: <00f001c4a32f$d724a570$0200000a AT donpedro> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <00f001c4a32f$d724a570$0200000a@donpedro> User-Agent: Mutt/1.4.1i On Sat, Sep 25, 2004 at 08:45:33PM +0200, Peter Dons Tychsen wrote: >The WEXITSTATUS is a bit buggy. (wait.h) > >The macro extracts information gained from a call to waitpid() (and others). >The information it extracts is the status of the completed process (8 bit >signed value). > >The problem is that the macro does not cast the value to a signed integer >(like other systems do), which can cause the value to be incorrectly >interpreted (breaks some programs). > >The following fails: > >// Wait for processes to complete >if(waitpid(pid, &status, 0) == pid) >{ > // Check return value for failure (-1) > if(WEXITSTATUS(status) == -1) > { > /* We will never get here, as the macro returns 255 if the process >exited with -1 */ > } >} Did you try this on linux? I wrote the following simple test case (tm), (R), (C) and it does not print a negative number. #include #include int main (int argc, char **argv) { int pid = fork (); int *zero = 0; int status; if (!pid) if (argc > 1) *zero = 1; // boom else exit (-1); if (waitpid(pid, &status, 0) == pid) { if (WEXITSTATUS(status) == -1) puts ("it is negative"); else puts ("it is not negative"); printf ("%d\n", WEXITSTATUS(status)); } exit(0); } The reason for this is that the definition of WEXITSTATUS on linux is this: #define __WEXITSTATUS(status) (((status) & 0xff00) >> 8) which would not return a negative number. The linux man page also has this to say: WEXITSTATUS(status) evaluates to the least significant eight bits of the return code of the child which terminated, which may have been set as the argument to a call to exit() or _exit() or as the argument for a return statement in the main program. This macro can only be evaluated if WIFEXITED returned true. So, it seems like if there is a problem with cygwin it is in the fact that there is no assurance that only eight bits are being returned. In short, I don't see how this could be a bug. -- Christopher Faylor spammer? -> aaaspam AT sourceware DOT org Cygwin Co-Project Leader aaaspam AT duffek DOT com TimeSys, Inc. -- 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/