[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] getopt: handle POSIXLY_CORRECT set but not exported
From: |
Eric Blake |
Subject: |
[PATCH] getopt: handle POSIXLY_CORRECT set but not exported |
Date: |
Tue, 7 Sep 2010 15:58:45 -0600 |
* m4/getopt.m4 (gl_GETOPT_CHECK_HEADERS): Restore pre-existing
export state of POSIXLY_CORRECT.
Reported by Dustin J. Mitchell.
Signed-off-by: Eric Blake <address@hidden>
---
>> Maybe the test whether the value of ENVIRON["POSIXLY_CORRECT"] is empty or
>> non-empty can be moved into the awk script. I'm not very familiar with awk
>> programming.
>
>Like so:
In complete patch form. I'll be pushing this soon, after more
testing completes.
ChangeLog | 7 +++++++
m4/getopt.m4 | 23 ++++++++++++++++++-----
2 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 4d27d6a..f3a5ffb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2010-09-07 Eric Blake <address@hidden>
+
+ getopt: handle POSIXLY_CORRECT set but not exported
+ * m4/getopt.m4 (gl_GETOPT_CHECK_HEADERS): Restore pre-existing
+ export state of POSIXLY_CORRECT, due to bash set -o posix.
+ Reported by Dustin J. Mitchell.
+
2010-09-05 Bruno Haible <address@hidden>
gnulib-tool: Highlight the changed options.
diff --git a/m4/getopt.m4 b/m4/getopt.m4
index caa5df4..35b5732 100644
--- a/m4/getopt.m4
+++ b/m4/getopt.m4
@@ -1,4 +1,4 @@
-# getopt.m4 serial 29
+# getopt.m4 serial 30
dnl Copyright (C) 2002-2006, 2008-2010 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -50,6 +50,7 @@ AC_DEFUN([gl_GETOPT_IFELSE],
AC_DEFUN([gl_GETOPT_CHECK_HEADERS],
[
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+ AC_REQUIRE([AC_PROG_AWK]) dnl for a decent awk
dnl Persuade Solaris <unistd.h> to declare optarg, optind, opterr, optopt.
AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
@@ -213,7 +214,17 @@ main ()
# optstring is necessary for programs like m4 that have POSIX-mandated
# semantics for supporting options interspersed with files.
# Also, since getopt_long is a GNU extension, we require optind=0.
- gl_had_POSIXLY_CORRECT=${POSIXLY_CORRECT:+yes}
+ # Bash mixes 'set -o posix' with a non-exported POSIXLY_CORRECT;
+ # so take care to revert to the correct (non-)export state.
+dnl GNU Coding Standards currently allow awk but not env; besides, env
+dnl is ambiguous with environment values that contain newlines.
+ gl_awk_probe='BEGIN { for (v in ENVIRON)
+ if (v == "POSIXLY_CORRECT") print "x" }'
+ case ${POSIXLY_CORRECT:+x}`$AWK "$gl_awk_probe" </dev/null` in
+ xx) gl_had_POSIXLY_CORRECT=exported ;;
+ x) gl_had_POSIXLY_CORRECT=yes ;;
+ *) gl_had_POSIXLY_CORRECT= ;;
+ esac
POSIXLY_CORRECT=1
export POSIXLY_CORRECT
AC_RUN_IFELSE(
@@ -278,9 +289,11 @@ main ()
*) gl_cv_func_getopt_gnu=yes;;
esac
])
- if test "$gl_had_POSIXLY_CORRECT" != yes; then
- AS_UNSET([POSIXLY_CORRECT])
- fi
+ case $gl_had_POSIXLY_CORRECT in
+ exported) ;;
+ yes) AS_UNSET([POSIXLY_CORRECT]); POSIXLY_CORRECT=1 ;;
+ *) AS_UNSET([POSIXLY_CORRECT]) ;;
+ esac
])
if test "$gl_cv_func_getopt_gnu" = "no"; then
gl_replace_getopt=yes
--
1.7.2.2
- Re: POSIXLY_CORRECT not correctly unset in getopt.m4?, (continued)
- Re: POSIXLY_CORRECT not correctly unset in getopt.m4?, Eric Blake, 2010/09/07
- [PATCH] docs: mention bash vs. POSIXLY_CORRECT, Eric Blake, 2010/09/07
- Re: POSIXLY_CORRECT not correctly unset in getopt.m4?, Bruno Haible, 2010/09/07
- Re: POSIXLY_CORRECT not correctly unset in getopt.m4?, Eric Blake, 2010/09/07
- Re: POSIXLY_CORRECT not correctly unset in getopt.m4?, Ralf Wildenhues, 2010/09/07
- Re: POSIXLY_CORRECT not correctly unset in getopt.m4?, Eric Blake, 2010/09/07
- Re: POSIXLY_CORRECT not correctly unset in getopt.m4?, Ralf Wildenhues, 2010/09/07
- Re: POSIXLY_CORRECT not correctly unset in getopt.m4?, Eric Blake, 2010/09/07
- Re: POSIXLY_CORRECT not correctly unset in getopt.m4?, Eric Blake, 2010/09/07
- Re: POSIXLY_CORRECT not correctly unset in getopt.m4?, Eric Blake, 2010/09/07
- [PATCH] getopt: handle POSIXLY_CORRECT set but not exported,
Eric Blake <=
- Re: [PATCH] getopt: handle POSIXLY_CORRECT set but not exported, Dustin J. Mitchell, 2010/09/07
- Re: POSIXLY_CORRECT not correctly unset in getopt.m4?, Paolo Bonzini, 2010/09/08
- Re: POSIXLY_CORRECT not correctly unset in getopt.m4?, Bruno Haible, 2010/09/08
- Re: POSIXLY_CORRECT not correctly unset in getopt.m4?, Paolo Bonzini, 2010/09/08
- Re: POSIXLY_CORRECT not correctly unset in getopt.m4?, Eric Blake, 2010/09/08
Re: POSIXLY_CORRECT not correctly unset in getopt.m4?, Eric Blake, 2010/09/07