changeset 9173:6d92d3b331ed

Fix mis-recognition of 'mcs' on QNX 6.
author Bruno Haible <bruno@clisp.org>
date Sun, 02 Sep 2007 11:13:02 +0000
parents fe9324e088ed
children 51c9c0c00a3f
files ChangeLog lib/csharpcomp.c m4/csharpcomp.m4
diffstat 3 files changed, 48 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2007-09-02  Bruno Haible  <bruno@clisp.org>
+
+	Fix mis-recognition of 'mcs' on QNX 6.
+	* m4/csharpcomp.m4 (gt_CSHARPCOMP): Test whether the "mcs --version"
+	output contains the string "Mono".
+	* lib/csharpcomp.c (compile_csharp_using_mono): Likewise.
+	Reported by <kraai@ftbfs.org> at <https://savannah.gnu.org/bugs/?18337>.
+
 2007-09-01  Bruno Haible  <bruno@clisp.org>
 
 	Fix collision between uniwidth/* and linebreak modules.
--- a/lib/csharpcomp.c
+++ b/lib/csharpcomp.c
@@ -182,16 +182,48 @@
   if (!mcs_tested)
     {
       /* Test for presence of mcs:
-	 "mcs --version >/dev/null 2>/dev/null"  */
+	 "mcs --version >/dev/null 2>/dev/null"
+	 and (to exclude an unrelated 'mcs' program on QNX 6)
+	 "mcs --version 2>/dev/null | grep Mono >/dev/null"  */
       char *argv[3];
+      pid_t child;
+      int fd[1];
       int exitstatus;
 
       argv[0] = "mcs";
       argv[1] = "--version";
       argv[2] = NULL;
-      exitstatus = execute ("mcs", "mcs", argv, false, false, true, true, true,
-			    false);
-      mcs_present = (exitstatus == 0);
+      child = create_pipe_in ("mcs", "mcs", argv, DEV_NULL, true, true, false,
+			      fd);
+      mcs_present = false;
+      if (child != -1)
+	{
+	  /* Read the subprocess output, and test whether it contains the
+	     string "Mono".  */
+	  char c[4];
+	  size_t count = 0;
+
+	  while (safe_read (fd[0], &c[count], 1) > 0)
+	    {
+	      count++;
+	      if (count == 4)
+		{
+		  if (memcmp (c, "Mono", 4) == 0)
+		    mcs_present = true;
+		  c[0] = c[1]; c[1] = c[2]; c[2] = c[3];
+		  count--;
+		}
+	    }
+
+	  close (fd[0]);
+
+	  /* Remove zombie process from process list, and retrieve exit
+	     status.  */
+	  exitstatus =
+	    wait_subprocess (child, "mcs", false, true, true, false);
+	  if (exitstatus != 0)
+	    mcs_present = false;
+	}
       mcs_tested = true;
     }
 
--- a/m4/csharpcomp.m4
+++ b/m4/csharpcomp.m4
@@ -1,5 +1,5 @@
-# csharpcomp.m4 serial 6 (gettext-0.15)
-dnl Copyright (C) 2003-2005 Free Software Foundation, Inc.
+# csharpcomp.m4 serial 7 (gettext-0.16.2)
+dnl Copyright (C) 2003-2005, 2007 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -43,7 +43,8 @@
         ;;
       mono)
         if test -n "$HAVE_MCS_IN_PATH" \
-           && mcs --version >/dev/null 2>/dev/null; then
+           && mcs --version >/dev/null 2>/dev/null \
+           && mcs --version 2>/dev/null | grep Mono >/dev/null; then
           HAVE_MCS=1
           ac_result="mcs"
           break