diff options
| author | Paul Eggert | 2020-01-18 20:54:29 -0800 |
|---|---|---|
| committer | Paul Eggert | 2020-01-18 20:55:09 -0800 |
| commit | 35a1a007bb7506c72ee6d9757a79014c679e7bae (patch) | |
| tree | 256bdc2f880c3e34bdeb99d8b675a0610602bc66 | |
| parent | 52baaca152135e3b67edb13df392ae9047af015c (diff) | |
| download | emacs-35a1a007bb7506c72ee6d9757a79014c679e7bae.tar.gz emacs-35a1a007bb7506c72ee6d9757a79014c679e7bae.zip | |
Remove Gnulib putenv code
It’s not needed, since Emacs always uses the system putenv and all
platforms have putenv. This improves on the fix for Bug#19874.
Suggested by Bruno Haible.
* admin/merge-gnulib (GNULIB_MODULES): Remove putenv.
* configure.ac: Remove workarounds for Gnulib putenv module.
* lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate.
* lib/putenv.c, m4/putenv.m4: Remove.
| -rwxr-xr-x | admin/merge-gnulib | 2 | ||||
| -rw-r--r-- | configure.ac | 5 | ||||
| -rw-r--r-- | lib/gnulib.mk.in | 12 | ||||
| -rw-r--r-- | lib/putenv.c | 194 | ||||
| -rw-r--r-- | m4/gnulib-comp.m4 | 9 | ||||
| -rw-r--r-- | m4/putenv.m4 | 60 |
6 files changed, 1 insertions, 281 deletions
diff --git a/admin/merge-gnulib b/admin/merge-gnulib index 3dee0b72b32..48c81e61e2a 100755 --- a/admin/merge-gnulib +++ b/admin/merge-gnulib | |||
| @@ -38,7 +38,7 @@ GNULIB_MODULES=' | |||
| 38 | getloadavg getopt-gnu gettime gettimeofday gitlog-to-changelog | 38 | getloadavg getopt-gnu gettime gettimeofday gitlog-to-changelog |
| 39 | ieee754-h ignore-value intprops largefile lstat | 39 | ieee754-h ignore-value intprops largefile lstat |
| 40 | manywarnings memmem-simple mempcpy memrchr minmax mkostemp mktime nstrftime | 40 | manywarnings memmem-simple mempcpy memrchr minmax mkostemp mktime nstrftime |
| 41 | pathmax pipe2 pselect pthread_sigmask putenv | 41 | pathmax pipe2 pselect pthread_sigmask |
| 42 | qcopy-acl readlink readlinkat regex | 42 | qcopy-acl readlink readlinkat regex |
| 43 | sig2str socklen stat-time std-gnu11 stdalign stddef stdio | 43 | sig2str socklen stat-time std-gnu11 stdalign stddef stdio |
| 44 | stpcpy strnlen strtoimax symlink sys_stat sys_time | 44 | stpcpy strnlen strtoimax symlink sys_stat sys_time |
diff --git a/configure.ac b/configure.ac index 8a13b36e942..d7b4d0352cc 100644 --- a/configure.ac +++ b/configure.ac | |||
| @@ -882,11 +882,6 @@ for func in $ac_func_list; do | |||
| 882 | test $func = pthread_sigmask || AS_VAR_APPEND([funcs], [" $func"]) | 882 | test $func = pthread_sigmask || AS_VAR_APPEND([funcs], [" $func"]) |
| 883 | done | 883 | done |
| 884 | ac_func_list=$funcs | 884 | ac_func_list=$funcs |
| 885 | # Use the system putenv even if it lacks GNU features, as we don't need them, | ||
| 886 | # and the gnulib replacement runs afoul of a FreeBSD 10.1 bug; see Bug#19874. | ||
| 887 | AC_CHECK_FUNCS_ONCE([putenv]) | ||
| 888 | AC_DEFUN([gl_FUNC_PUTENV], | ||
| 889 | [test "$ac_cv_func_putenv" = yes || REPLACE_PUTENV=1]) | ||
| 890 | # Emacs does not use the wchar or wctype-h modules. | 885 | # Emacs does not use the wchar or wctype-h modules. |
| 891 | AC_DEFUN([gt_TYPE_WINT_T], | 886 | AC_DEFUN([gt_TYPE_WINT_T], |
| 892 | [GNULIB_OVERRIDES_WINT_T=0 | 887 | [GNULIB_OVERRIDES_WINT_T=0 |
diff --git a/lib/gnulib.mk.in b/lib/gnulib.mk.in index ed80f88a874..1c8085b1a41 100644 --- a/lib/gnulib.mk.in +++ b/lib/gnulib.mk.in | |||
| @@ -127,7 +127,6 @@ | |||
| 127 | # pipe2 \ | 127 | # pipe2 \ |
| 128 | # pselect \ | 128 | # pselect \ |
| 129 | # pthread_sigmask \ | 129 | # pthread_sigmask \ |
| 130 | # putenv \ | ||
| 131 | # qcopy-acl \ | 130 | # qcopy-acl \ |
| 132 | # readlink \ | 131 | # readlink \ |
| 133 | # readlinkat \ | 132 | # readlinkat \ |
| @@ -2162,17 +2161,6 @@ EXTRA_libgnu_a_SOURCES += pthread_sigmask.c | |||
| 2162 | endif | 2161 | endif |
| 2163 | ## end gnulib module pthread_sigmask | 2162 | ## end gnulib module pthread_sigmask |
| 2164 | 2163 | ||
| 2165 | ## begin gnulib module putenv | ||
| 2166 | ifeq (,$(OMIT_GNULIB_MODULE_putenv)) | ||
| 2167 | |||
| 2168 | |||
| 2169 | EXTRA_DIST += putenv.c | ||
| 2170 | |||
| 2171 | EXTRA_libgnu_a_SOURCES += putenv.c | ||
| 2172 | |||
| 2173 | endif | ||
| 2174 | ## end gnulib module putenv | ||
| 2175 | |||
| 2176 | ## begin gnulib module qcopy-acl | 2164 | ## begin gnulib module qcopy-acl |
| 2177 | ifeq (,$(OMIT_GNULIB_MODULE_qcopy-acl)) | 2165 | ifeq (,$(OMIT_GNULIB_MODULE_qcopy-acl)) |
| 2178 | 2166 | ||
diff --git a/lib/putenv.c b/lib/putenv.c deleted file mode 100644 index 9e862e63d3d..00000000000 --- a/lib/putenv.c +++ /dev/null | |||
| @@ -1,194 +0,0 @@ | |||
| 1 | /* Copyright (C) 1991, 1994, 1997-1998, 2000, 2003-2020 Free Software | ||
| 2 | Foundation, Inc. | ||
| 3 | |||
| 4 | NOTE: The canonical source of this file is maintained with the GNU C | ||
| 5 | Library. Bugs can be reported to bug-glibc@prep.ai.mit.edu. | ||
| 6 | |||
| 7 | This program is free software: you can redistribute it and/or modify it | ||
| 8 | under the terms of the GNU General Public License as published by the | ||
| 9 | Free Software Foundation; either version 3 of the License, or any | ||
| 10 | later version. | ||
| 11 | |||
| 12 | This program is distributed in the hope that it will be useful, | ||
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | GNU General Public License for more details. | ||
| 16 | |||
| 17 | You should have received a copy of the GNU General Public License | ||
| 18 | along with this program. If not, see <https://www.gnu.org/licenses/>. */ | ||
| 19 | |||
| 20 | #include <config.h> | ||
| 21 | |||
| 22 | /* Specification. */ | ||
| 23 | #include <stdlib.h> | ||
| 24 | |||
| 25 | #include <stddef.h> | ||
| 26 | |||
| 27 | /* Include errno.h *after* sys/types.h to work around header problems | ||
| 28 | on AIX 3.2.5. */ | ||
| 29 | #include <errno.h> | ||
| 30 | #ifndef __set_errno | ||
| 31 | # define __set_errno(ev) ((errno) = (ev)) | ||
| 32 | #endif | ||
| 33 | |||
| 34 | #include <string.h> | ||
| 35 | #include <unistd.h> | ||
| 36 | |||
| 37 | #if defined _WIN32 && ! defined __CYGWIN__ | ||
| 38 | # define WIN32_LEAN_AND_MEAN | ||
| 39 | # include <windows.h> | ||
| 40 | #endif | ||
| 41 | |||
| 42 | #if _LIBC | ||
| 43 | # if HAVE_GNU_LD | ||
| 44 | # define environ __environ | ||
| 45 | # else | ||
| 46 | extern char **environ; | ||
| 47 | # endif | ||
| 48 | #endif | ||
| 49 | |||
| 50 | #if _LIBC | ||
| 51 | /* This lock protects against simultaneous modifications of 'environ'. */ | ||
| 52 | # include <bits/libc-lock.h> | ||
| 53 | __libc_lock_define_initialized (static, envlock) | ||
| 54 | # define LOCK __libc_lock_lock (envlock) | ||
| 55 | # define UNLOCK __libc_lock_unlock (envlock) | ||
| 56 | #else | ||
| 57 | # define LOCK | ||
| 58 | # define UNLOCK | ||
| 59 | #endif | ||
| 60 | |||
| 61 | static int | ||
| 62 | _unsetenv (const char *name) | ||
| 63 | { | ||
| 64 | size_t len; | ||
| 65 | #if !HAVE_DECL__PUTENV | ||
| 66 | char **ep; | ||
| 67 | #endif | ||
| 68 | |||
| 69 | if (name == NULL || *name == '\0' || strchr (name, '=') != NULL) | ||
| 70 | { | ||
| 71 | __set_errno (EINVAL); | ||
| 72 | return -1; | ||
| 73 | } | ||
| 74 | |||
| 75 | len = strlen (name); | ||
| 76 | |||
| 77 | #if HAVE_DECL__PUTENV | ||
| 78 | { | ||
| 79 | int putenv_result, putenv_errno; | ||
| 80 | char *name_ = malloc (len + 2); | ||
| 81 | memcpy (name_, name, len); | ||
| 82 | name_[len] = '='; | ||
| 83 | name_[len + 1] = 0; | ||
| 84 | putenv_result = _putenv (name_); | ||
| 85 | putenv_errno = errno; | ||
| 86 | free (name_); | ||
| 87 | __set_errno (putenv_errno); | ||
| 88 | return putenv_result; | ||
| 89 | } | ||
| 90 | #else | ||
| 91 | |||
| 92 | LOCK; | ||
| 93 | |||
| 94 | ep = environ; | ||
| 95 | while (*ep != NULL) | ||
| 96 | if (!strncmp (*ep, name, len) && (*ep)[len] == '=') | ||
| 97 | { | ||
| 98 | /* Found it. Remove this pointer by moving later ones back. */ | ||
| 99 | char **dp = ep; | ||
| 100 | |||
| 101 | do | ||
| 102 | dp[0] = dp[1]; | ||
| 103 | while (*dp++); | ||
| 104 | /* Continue the loop in case NAME appears again. */ | ||
| 105 | } | ||
| 106 | else | ||
| 107 | ++ep; | ||
| 108 | |||
| 109 | UNLOCK; | ||
| 110 | |||
| 111 | return 0; | ||
| 112 | #endif | ||
| 113 | } | ||
| 114 | |||
| 115 | |||
| 116 | /* Put STRING, which is of the form "NAME=VALUE", in the environment. | ||
| 117 | If STRING contains no '=', then remove STRING from the environment. */ | ||
| 118 | int | ||
| 119 | putenv (char *string) | ||
| 120 | { | ||
| 121 | const char *name_end = strchr (string, '='); | ||
| 122 | char **ep; | ||
| 123 | |||
| 124 | if (name_end == NULL) | ||
| 125 | { | ||
| 126 | /* Remove the variable from the environment. */ | ||
| 127 | return _unsetenv (string); | ||
| 128 | } | ||
| 129 | |||
| 130 | #if HAVE_DECL__PUTENV | ||
| 131 | /* Rely on _putenv to allocate the new environment. If other | ||
| 132 | parts of the application use _putenv, the !HAVE_DECL__PUTENV code | ||
| 133 | would fight over who owns the environ vector, causing a crash. */ | ||
| 134 | if (name_end[1]) | ||
| 135 | return _putenv (string); | ||
| 136 | else | ||
| 137 | { | ||
| 138 | /* _putenv ("NAME=") unsets NAME, so invoke _putenv ("NAME= ") | ||
| 139 | to allocate the environ vector and then replace the new | ||
| 140 | entry with "NAME=". */ | ||
| 141 | int putenv_result, putenv_errno; | ||
| 142 | char *name_x = malloc (name_end - string + sizeof "= "); | ||
| 143 | if (!name_x) | ||
| 144 | return -1; | ||
| 145 | memcpy (name_x, string, name_end - string + 1); | ||
| 146 | name_x[name_end - string + 1] = ' '; | ||
| 147 | name_x[name_end - string + 2] = 0; | ||
| 148 | putenv_result = _putenv (name_x); | ||
| 149 | putenv_errno = errno; | ||
| 150 | for (ep = environ; *ep; ep++) | ||
| 151 | if (strcmp (*ep, name_x) == 0) | ||
| 152 | { | ||
| 153 | *ep = string; | ||
| 154 | break; | ||
| 155 | } | ||
| 156 | # if defined _WIN32 && ! defined __CYGWIN__ | ||
| 157 | if (putenv_result == 0) | ||
| 158 | { | ||
| 159 | /* _putenv propagated "NAME= " into the subprocess environment; | ||
| 160 | fix that by calling SetEnvironmentVariable directly. */ | ||
| 161 | name_x[name_end - string] = 0; | ||
| 162 | putenv_result = SetEnvironmentVariable (name_x, "") ? 0 : -1; | ||
| 163 | putenv_errno = ENOMEM; /* ENOMEM is the only way to fail. */ | ||
| 164 | } | ||
| 165 | # endif | ||
| 166 | free (name_x); | ||
| 167 | __set_errno (putenv_errno); | ||
| 168 | return putenv_result; | ||
| 169 | } | ||
| 170 | #else | ||
| 171 | for (ep = environ; *ep; ep++) | ||
| 172 | if (strncmp (*ep, string, name_end - string) == 0 | ||
| 173 | && (*ep)[name_end - string] == '=') | ||
| 174 | break; | ||
| 175 | |||
| 176 | if (*ep) | ||
| 177 | *ep = string; | ||
| 178 | else | ||
| 179 | { | ||
| 180 | static char **last_environ = NULL; | ||
| 181 | size_t size = ep - environ; | ||
| 182 | char **new_environ = malloc ((size + 2) * sizeof *new_environ); | ||
| 183 | if (! new_environ) | ||
| 184 | return -1; | ||
| 185 | new_environ[0] = string; | ||
| 186 | memcpy (new_environ + 1, environ, (size + 1) * sizeof *new_environ); | ||
| 187 | free (last_environ); | ||
| 188 | last_environ = new_environ; | ||
| 189 | environ = new_environ; | ||
| 190 | } | ||
| 191 | |||
| 192 | return 0; | ||
| 193 | #endif | ||
| 194 | } | ||
diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4 index cb3b89dd72f..48d8030f539 100644 --- a/m4/gnulib-comp.m4 +++ b/m4/gnulib-comp.m4 | |||
| @@ -133,7 +133,6 @@ AC_DEFUN([gl_EARLY], | |||
| 133 | # Code from module pipe2: | 133 | # Code from module pipe2: |
| 134 | # Code from module pselect: | 134 | # Code from module pselect: |
| 135 | # Code from module pthread_sigmask: | 135 | # Code from module pthread_sigmask: |
| 136 | # Code from module putenv: | ||
| 137 | # Code from module qcopy-acl: | 136 | # Code from module qcopy-acl: |
| 138 | # Code from module readlink: | 137 | # Code from module readlink: |
| 139 | # Code from module readlinkat: | 138 | # Code from module readlinkat: |
| @@ -368,12 +367,6 @@ AC_DEFUN([gl_INIT], | |||
| 368 | gl_PREREQ_PTHREAD_SIGMASK | 367 | gl_PREREQ_PTHREAD_SIGMASK |
| 369 | fi | 368 | fi |
| 370 | gl_SIGNAL_MODULE_INDICATOR([pthread_sigmask]) | 369 | gl_SIGNAL_MODULE_INDICATOR([pthread_sigmask]) |
| 371 | gl_FUNC_PUTENV | ||
| 372 | if test $REPLACE_PUTENV = 1; then | ||
| 373 | AC_LIBOBJ([putenv]) | ||
| 374 | gl_PREREQ_PUTENV | ||
| 375 | fi | ||
| 376 | gl_STDLIB_MODULE_INDICATOR([putenv]) | ||
| 377 | gl_FUNC_READLINK | 370 | gl_FUNC_READLINK |
| 378 | if test $HAVE_READLINK = 0 || test $REPLACE_READLINK = 1; then | 371 | if test $HAVE_READLINK = 0 || test $REPLACE_READLINK = 1; then |
| 379 | AC_LIBOBJ([readlink]) | 372 | AC_LIBOBJ([readlink]) |
| @@ -973,7 +966,6 @@ AC_DEFUN([gl_FILE_LIST], [ | |||
| 973 | lib/pipe2.c | 966 | lib/pipe2.c |
| 974 | lib/pselect.c | 967 | lib/pselect.c |
| 975 | lib/pthread_sigmask.c | 968 | lib/pthread_sigmask.c |
| 976 | lib/putenv.c | ||
| 977 | lib/qcopy-acl.c | 969 | lib/qcopy-acl.c |
| 978 | lib/readlink.c | 970 | lib/readlink.c |
| 979 | lib/readlinkat.c | 971 | lib/readlinkat.c |
| @@ -1112,7 +1104,6 @@ AC_DEFUN([gl_FILE_LIST], [ | |||
| 1112 | m4/pipe2.m4 | 1104 | m4/pipe2.m4 |
| 1113 | m4/pselect.m4 | 1105 | m4/pselect.m4 |
| 1114 | m4/pthread_sigmask.m4 | 1106 | m4/pthread_sigmask.m4 |
| 1115 | m4/putenv.m4 | ||
| 1116 | m4/readlink.m4 | 1107 | m4/readlink.m4 |
| 1117 | m4/readlinkat.m4 | 1108 | m4/readlinkat.m4 |
| 1118 | m4/regex.m4 | 1109 | m4/regex.m4 |
diff --git a/m4/putenv.m4 b/m4/putenv.m4 deleted file mode 100644 index e38f8c56940..00000000000 --- a/m4/putenv.m4 +++ /dev/null | |||
| @@ -1,60 +0,0 @@ | |||
| 1 | # putenv.m4 serial 24 | ||
| 2 | dnl Copyright (C) 2002-2020 Free Software Foundation, Inc. | ||
| 3 | dnl This file is free software; the Free Software Foundation | ||
| 4 | dnl gives unlimited permission to copy and/or distribute it, | ||
| 5 | dnl with or without modifications, as long as this notice is preserved. | ||
| 6 | |||
| 7 | dnl From Jim Meyering. | ||
| 8 | dnl | ||
| 9 | dnl Check whether putenv ("FOO") removes FOO from the environment. | ||
| 10 | dnl The putenv in libc on at least SunOS 4.1.4 does *not* do that. | ||
| 11 | |||
| 12 | AC_DEFUN([gl_FUNC_PUTENV], | ||
| 13 | [ | ||
| 14 | AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) | ||
| 15 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | ||
| 16 | AC_CACHE_CHECK([for putenv compatible with GNU and SVID], | ||
| 17 | [gl_cv_func_svid_putenv], | ||
| 18 | [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],[[ | ||
| 19 | /* Put it in env. */ | ||
| 20 | if (putenv ("CONFTEST_putenv=val")) | ||
| 21 | return 1; | ||
| 22 | |||
| 23 | /* Try to remove it. */ | ||
| 24 | if (putenv ("CONFTEST_putenv")) | ||
| 25 | return 2; | ||
| 26 | |||
| 27 | /* Make sure it was deleted. */ | ||
| 28 | if (getenv ("CONFTEST_putenv") != 0) | ||
| 29 | return 3; | ||
| 30 | |||
| 31 | return 0; | ||
| 32 | ]])], | ||
| 33 | gl_cv_func_svid_putenv=yes, | ||
| 34 | gl_cv_func_svid_putenv=no, | ||
| 35 | dnl When crosscompiling, assume putenv is broken. | ||
| 36 | [case "$host_os" in | ||
| 37 | # Guess yes on glibc systems. | ||
| 38 | *-gnu* | gnu*) gl_cv_func_svid_putenv="guessing yes" ;; | ||
| 39 | # Guess yes on musl systems. | ||
| 40 | *-musl*) gl_cv_func_svid_putenv="guessing yes" ;; | ||
| 41 | # Guess no on native Windows. | ||
| 42 | mingw*) gl_cv_func_svid_putenv="guessing no" ;; | ||
| 43 | # If we don't know, obey --enable-cross-guesses. | ||
| 44 | *) gl_cv_func_svid_putenv="$gl_cross_guess_normal" ;; | ||
| 45 | esac | ||
| 46 | ]) | ||
| 47 | ]) | ||
| 48 | case "$gl_cv_func_svid_putenv" in | ||
| 49 | *yes) ;; | ||
| 50 | *) | ||
| 51 | REPLACE_PUTENV=1 | ||
| 52 | ;; | ||
| 53 | esac | ||
| 54 | ]) | ||
| 55 | |||
| 56 | # Prerequisites of lib/putenv.c. | ||
| 57 | AC_DEFUN([gl_PREREQ_PUTENV], | ||
| 58 | [ | ||
| 59 | AC_CHECK_DECLS([_putenv]) | ||
| 60 | ]) | ||