Fix WIN32 wait() return value macros to be accurate, particularly
authorBruce Momjian <bruce@momjian.us>
Sun, 30 Jul 2006 01:45:21 +0000 (01:45 +0000)
committerBruce Momjian <bruce@momjian.us>
Sun, 30 Jul 2006 01:45:21 +0000 (01:45 +0000)
because they are used for testing the return value from system().
(WIN32 doesn't overlay the return code with other failure conditions
like Unix does, so they are just simple macros.)

Fix regression checks to properly handle diff failures on Win32 using
the new macros.

src/include/port/win32.h
src/test/regress/pg_regress.c

index 2d8320a386a2abec30b4c5527679916369d9f9fd..3708ede6abda1347239c657e961a8ab60d2bf653 100644 (file)
@@ -109,12 +109,17 @@ int                       semop(int semId, struct sembuf * sops, int flag);
 
 
 /*
- * Signal stuff
+ *     Signal stuff
+ *     WIN32 doesn't have wait(), so the return value for children
+ *     is simply the return value specified by the child, without
+ *     any additional information on whether the child terminated
+ *     on its own or via a signal.  These macros are also used
+ *     to interpret the return value of system().
  */
-#define WEXITSTATUS(w) (((w) >> 8) & 0xff)
-#define WIFEXITED(w)   (((w) & 0xff) == 0)
-#define WIFSIGNALED(w) (((w) & 0x7f) > 0 && (((w) & 0x7f) < 0x7f))
-#define WTERMSIG(w)            ((w) & 0x7f)
+#define WEXITSTATUS(w) (w)
+#define WIFEXITED(w)   (true)
+#define WIFSIGNALED(w) (false)
+#define WTERMSIG(w)            (0)
 
 #define sigmask(sig) ( 1 << ((sig)-1) )
 
index b80531a22af7ce69b1304ef81f7ff882346e7bb7..07c07c0096e96e5ef27012b3afc0bed3104cf5f1 100644 (file)
@@ -799,29 +799,32 @@ make_directory(const char *dir)
 }
 
 /*
- * Run a "diff" command and check that it didn't crash
+ * Run a "diff" command and also check that it didn't crash
  */
-static void
-run_diff(const char *cmd)
+static int
+run_diff(const char *cmd, const char *filename)
 {
        int r;
 
        r = system(cmd);
-       /*
-        * XXX FIXME: it appears that include/port/win32.h's definitions of
-        * WIFEXITED and related macros may be wrong.  They certainly don't
-        * work for inspecting the results of system().  For the moment,
-        * hard-wire the check on Windows.
-        */
-#ifndef WIN32
        if (!WIFEXITED(r) || WEXITSTATUS(r) > 1)
-#else
-       if (r != 0 && r != 1)
-#endif
        {
                fprintf(stderr, _("diff command failed with status %d: %s\n"), r, cmd);
                exit_nicely(2);
        }
+#ifdef WIN32
+       /*
+        *      On WIN32, if the 'diff' command cannot be found, system() returns
+        *      1, but produces nothing to stdout, so we check for that here.
+        */
+       if (WEXITSTATUS(r) == 1 && file_size(filename) <= 0)
+       {
+               fprintf(stderr, _("diff command not found: %s\n"), cmd);
+               exit_nicely(2);
+       }
+#endif
+       
+       return WEXITSTATUS(r);
 }
 
 /*
@@ -844,7 +847,7 @@ results_differ(const char *testname)
        int best_line_count;
        int i;
        int l;
-
+       
        /* Check in resultmap if we should be looking at a different file */
        expectname = testname;
        for (rm = resultmap; rm != NULL; rm = rm->next)
@@ -872,12 +875,10 @@ results_differ(const char *testname)
        snprintf(cmd, sizeof(cmd),
                         SYSTEMQUOTE "diff %s \"%s\" \"%s\" > \"%s\"" SYSTEMQUOTE,
                         basic_diff_opts, expectfile, resultsfile, diff);
-       run_diff(cmd);
 
        /* Is the diff file empty? */
-       if (file_size(diff) == 0)
+       if (run_diff(cmd, diff) == 0)
        {
-               /* No diff = no changes = good */
                unlink(diff);
                return false;
        }
@@ -896,11 +897,9 @@ results_differ(const char *testname)
                snprintf(cmd, sizeof(cmd),
                                 SYSTEMQUOTE "diff %s \"%s\" \"%s\" > \"%s\"" SYSTEMQUOTE,
                                 basic_diff_opts, expectfile, resultsfile, diff);
-               run_diff(cmd);
 
-               if (file_size(diff) == 0)
+               if (run_diff(cmd, diff) == 0)
                {
-                       /* No diff = no changes = good */
                        unlink(diff);
                        return false;
                }
@@ -921,7 +920,7 @@ results_differ(const char *testname)
        snprintf(cmd, sizeof(cmd),
                         SYSTEMQUOTE "diff %s \"%s\" \"%s\" >> \"%s\"" SYSTEMQUOTE,
                         pretty_diff_opts, best_expect_file, resultsfile, difffilename);
-       run_diff(cmd);
+       run_diff(cmd, difffilename);
 
        /* And append a separator */
        difffile = fopen(difffilename, "a");