Bruno Haible wrote:
> KO Myung-Hun wrote:
>>> If you set gl_cv_func_popen_works to 'no', it will activate the workaround
>>> in lib/popen.c. Does this workaround work? Does 'test-[p]open' succeed?
>>
>> Do you mean 'test-popen'? Then it works.
> 
> Good. Then lib/popen.c does not need to be extended.
> 

Both test-open and test-popen works.

>>> If yes, we'll also need an edit to doc/posix-functions/popen.texi.
>>>
>>
>> Part of 'Portability problems fixed by Gnulib:'?
> 
> Yes. Where it lists Cygwin as relevant platform, please list also OS/2 with
> kLIBC.
> 

Done.

>>>>    else
>>>> +    dnl On OS/2 kLIBC, the following test hangs on. So set to no here.
>>>> +    case "$host_os" in os2*) gl_cv_func_popen_works=no;; esac
>>>>      AC_CACHE_CHECK([whether popen works with closed stdin],
>>>>        [gl_cv_func_popen_works],
>>>>        [
>>>>
>>>
>>> Can you put the 'gl_cv_func_popen_works=no' into the AC_CACHE_CHECK?
>>> And produce the value 'guessing no', since the test is not being run.
>>> Rationale: We want 'configure' to print
>>>   checking whether popen works with closed stdin... guessing no
>>> not
>>>   checking whether popen works with closed stdin... (cached) no
>>
>> If the test is run, 'configure' is blocked until pressing Ctrl-C or
>> Ctrl-Break. Or do you mean modification of the test source codes to
>> return an error if OS/2?
> 
> I mean, in the third argument of AC_CACHE_CHECK, which is a set of
> shell statements, add the
>   case "$host_os" in os2*)
> there, before the test program gets created. Similar to the first
> AC_CACHE_CHECK in m4/fenv-environment.m4.
> 
> Bruno
> 

Done.


-- 
KO Myung-Hun

Korean OS/2 User Community : https://www.os2.kr/
From 2632ec684fb7c4d25678ad70bf171db5d1110f95 Mon Sep 17 00:00:00 2001
From: KO Myung-Hun <komh78@gmail.com>
Date: Mon, 10 Feb 2025 20:35:00 +0900
Subject: [PATCH v2] popen: set gl_cv_func_popen_works to "guessing no" on OS/2

On OS/2, popen() does not work with closed stdios. And configure hangs
on with the test.

* doc/posix-functions/popen.texi (Portability problems fixed by Gnulib):
List OS/2 kLIBC case.
* m4/popen.m4 (gl_FUNC_POPEN): Set gl_cv_func_popen_works to
"guessing no" on OS/2.
---
 doc/posix-functions/popen.texi |  3 ++
 m4/popen.m4                    | 58 +++++++++++++++++++---------------
 2 files changed, 36 insertions(+), 25 deletions(-)

diff --git a/doc/posix-functions/popen.texi b/doc/posix-functions/popen.texi
index c5e4067baa..c1d1f59f9c 100644
--- a/doc/posix-functions/popen.texi
+++ b/doc/posix-functions/popen.texi
@@ -16,6 +16,9 @@ MSVC 14.
 Some platforms start the child with closed stdin or stdout if the
 standard descriptors were closed in the parent:
 Cygwin 1.5.x.
+@item
+Some platforms hang on if this function is called with closed stdin or stdout:
+OS/2 kLIBC.
 @end itemize
 
 Portability problems not fixed by Gnulib:
diff --git a/m4/popen.m4 b/m4/popen.m4
index a68c1e606f..a0f2ee7812 100644
--- a/m4/popen.m4
+++ b/m4/popen.m4
@@ -1,5 +1,5 @@
 # popen.m4
-# serial 7
+# serial 8
 dnl Copyright (C) 2009-2025 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -17,30 +17,38 @@ AC_DEFUN([gl_FUNC_POPEN],
     AC_CACHE_CHECK([whether popen works with closed stdin],
       [gl_cv_func_popen_works],
       [
-        AC_RUN_IFELSE(
-          [AC_LANG_PROGRAM(
-             [[#include <stdio.h>]],
-             [[int result = 0;
-               FILE *child;
-               fclose (stdin);
-               fclose (stdout);
-               child = popen ("echo a", "r");
-               if (fgetc (child) != 'a')
-                 result |= 1;
-               if (pclose (child) != 0)
-                 result |= 2;
-               return result;
-             ]])],
-          [gl_cv_func_popen_works=yes],
-          [gl_cv_func_popen_works=no],
-          [case "$host_os" in
-                                # For now, only cygwin 1.5 or older is known to be broken.
-             cygwin*)           gl_cv_func_popen_works="guessing no" ;;
-                                # Guess yes on native Windows.
-             mingw* | windows*) gl_cv_func_popen_works="guessing yes" ;;
-             *)                 gl_cv_func_popen_works="guessing yes" ;;
-           esac
-          ])
+        case "$host_os" in
+          os2*)
+            # On OS/2 kLIBC, popen() with closed stdios hangs on.
+            gl_cv_func_popen_works="guessing no"
+            ;;
+          *)
+            AC_RUN_IFELSE(
+              [AC_LANG_PROGRAM(
+                 [[#include <stdio.h>]],
+                 [[int result = 0;
+                   FILE *child;
+                   fclose (stdin);
+                   fclose (stdout);
+                   child = popen ("echo a", "r");
+                   if (fgetc (child) != 'a')
+                     result |= 1;
+                   if (pclose (child) != 0)
+                     result |= 2;
+                   return result;
+                 ]])],
+              [gl_cv_func_popen_works=yes],
+              [gl_cv_func_popen_works=no],
+              [case "$host_os" in
+                                    # For now, only cygwin 1.5 or older is known to be broken.
+                 cygwin*)           gl_cv_func_popen_works="guessing no" ;;
+                                    # Guess yes on native Windows.
+                 mingw* | windows*) gl_cv_func_popen_works="guessing yes" ;;
+                 *)                 gl_cv_func_popen_works="guessing yes" ;;
+               esac
+              ])
+            ;;
+        esac
       ])
     case "$gl_cv_func_popen_works" in
       *yes) ;;
-- 
2.42.0

Reply via email to