Remove dead setenv, unsetenv replacement code.
authorThomas Munro <tmunro@postgresql.org>
Thu, 4 Aug 2022 21:38:36 +0000 (09:38 +1200)
committerThomas Munro <tmunro@postgresql.org>
Thu, 4 Aug 2022 21:38:36 +0000 (09:38 +1200)
setenv() and unsetenv() are in SUSv3 and targeted Unix systems have
them.  We still need special code for these on Windows, but that doesn't
require a configure probe.

This marks the first time we require a SUSv3 (POSIX.1-2001) facility
(rather than SUSv2).  The replacement code removed here was not needed
on any targeted system or any known non-EOL'd Unix system, and was
therefore dead and untested.

No need for vestigial HAVE_SETENV and HAVE_UNSETENV macros, because we
provide a replacement for Windows, and we didn't previously test the
macros.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Greg Stark <stark@mit.edu>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/CA+hUKGJ3LHeP9w5Fgzdr4G8AnEtJ=z=p6hGDEm4qYGEUX5B6fQ@mail.gmail.com

configure
configure.ac
src/include/pg_config.h.in
src/include/port.h
src/port/setenv.c [deleted file]
src/port/unsetenv.c [deleted file]
src/tools/msvc/Solution.pm

index 8ae573da25253f0a2194d4fb3d904a1f6f99364f..e98dfa29ce53c4b4366f4ee803e40294a58e8df2 100755 (executable)
--- a/configure
+++ b/configure
@@ -16841,49 +16841,6 @@ esac
 $as_echo "$as_me: On $host_os we will use our strtof wrapper." >&6;}
 fi
 
-case $host_os in
-        # Windows uses a specialised env handler
-        mingw*)
-
-$as_echo "#define HAVE_SETENV 1" >>confdefs.h
-
-
-$as_echo "#define HAVE_UNSETENV 1" >>confdefs.h
-
-                ac_cv_func_setenv=yes
-                ac_cv_func_unsetenv=yes
-                ;;
-        *)
-                ac_fn_c_check_func "$LINENO" "setenv" "ac_cv_func_setenv"
-if test "x$ac_cv_func_setenv" = xyes; then :
-  $as_echo "#define HAVE_SETENV 1" >>confdefs.h
-
-else
-  case " $LIBOBJS " in
-  *" setenv.$ac_objext "* ) ;;
-  *) LIBOBJS="$LIBOBJS setenv.$ac_objext"
- ;;
-esac
-
-fi
-
-ac_fn_c_check_func "$LINENO" "unsetenv" "ac_cv_func_unsetenv"
-if test "x$ac_cv_func_unsetenv" = xyes; then :
-  $as_echo "#define HAVE_UNSETENV 1" >>confdefs.h
-
-else
-  case " $LIBOBJS " in
-  *" unsetenv.$ac_objext "* ) ;;
-  *) LIBOBJS="$LIBOBJS unsetenv.$ac_objext"
- ;;
-esac
-
-fi
-
-
-                ;;
-esac
-
 # System's version of getaddrinfo(), if any, may be used only if we found
 # a definition for struct addrinfo; see notes in src/include/getaddrinfo.h.
 # We use only our own getaddrinfo.c on Windows, but it's time to revisit that.
index 7f8a20d97b682b17f9f3a375eeb49add48de178c..d551cb2acd10f40f07bbe534ec21e6711396b02a 100644 (file)
@@ -1898,19 +1898,6 @@ if test "$PORTNAME" = "win32" -o "$PORTNAME" = "cygwin"; then
    AC_MSG_NOTICE([On $host_os we will use our strtof wrapper.])
 fi
 
-case $host_os in
-        # Windows uses a specialised env handler
-        mingw*)
-                AC_DEFINE(HAVE_SETENV, 1, [Define to 1 because replacement version used.])
-                AC_DEFINE(HAVE_UNSETENV, 1, [Define to 1 because replacement version used.])
-                ac_cv_func_setenv=yes
-                ac_cv_func_unsetenv=yes
-                ;;
-        *)
-                AC_REPLACE_FUNCS([setenv unsetenv])
-                ;;
-esac
-
 # System's version of getaddrinfo(), if any, may be used only if we found
 # a definition for struct addrinfo; see notes in src/include/getaddrinfo.h.
 # We use only our own getaddrinfo.c on Windows, but it's time to revisit that.
index f3f132e2058d80a80ac986e5c5d00b610f80b2f8..b6ee575681c91caf6427b0cd49b0ef185d6b36b0 100644 (file)
 /* Define to 1 if you have the <security/pam_appl.h> header file. */
 #undef HAVE_SECURITY_PAM_APPL_H
 
-/* Define to 1 if you have the `setenv' function. */
-#undef HAVE_SETENV
-
 /* Define to 1 if you have the `setproctitle' function. */
 #undef HAVE_SETPROCTITLE
 
 /* Define to 1 if you have the <unistd.h> header file. */
 #undef HAVE_UNISTD_H
 
-/* Define to 1 if you have the `unsetenv' function. */
-#undef HAVE_UNSETENV
-
 /* Define to 1 if you have the `uselocale' function. */
 #undef HAVE_USELOCALE
 
index cec785f8a5d3ebd643630678e1fd1cf6722f7ceb..85c9b38f4eeb11c368002eb67c82f7fd9300e42f 100644 (file)
@@ -448,14 +448,6 @@ extern size_t strlcpy(char *dst, const char *src, size_t siz);
 extern size_t strnlen(const char *str, size_t maxlen);
 #endif
 
-#ifndef HAVE_SETENV
-extern int setenv(const char *name, const char *value, int overwrite);
-#endif
-
-#ifndef HAVE_UNSETENV
-extern int unsetenv(const char *name);
-#endif
-
 /* thread.c */
 #ifndef WIN32
 extern bool pg_get_user_name(uid_t user_id, char *buffer, size_t buflen);
diff --git a/src/port/setenv.c b/src/port/setenv.c
deleted file mode 100644 (file)
index d13c882..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * setenv.c
- *   setenv() emulation for machines without it
- *
- * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- *
- * IDENTIFICATION
- *   src/port/setenv.c
- *
- *-------------------------------------------------------------------------
- */
-
-#include "c.h"
-
-
-int
-setenv(const char *name, const char *value, int overwrite)
-{
-   char       *envstr;
-
-   /* Error conditions, per POSIX */
-   if (name == NULL || name[0] == '\0' || strchr(name, '=') != NULL ||
-       value == NULL)
-   {
-       errno = EINVAL;
-       return -1;
-   }
-
-   /* No work if variable exists and we're not to replace it */
-   if (overwrite == 0 && getenv(name) != NULL)
-       return 0;
-
-   /*
-    * Add or replace the value using putenv().  This will leak memory if the
-    * same variable is repeatedly redefined, but there's little we can do
-    * about that when sitting atop putenv().
-    */
-   envstr = (char *) malloc(strlen(name) + strlen(value) + 2);
-   if (!envstr)                /* not much we can do if no memory */
-       return -1;
-
-   sprintf(envstr, "%s=%s", name, value);
-
-   return putenv(envstr);
-}
diff --git a/src/port/unsetenv.c b/src/port/unsetenv.c
deleted file mode 100644 (file)
index 62b806d..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * unsetenv.c
- *   unsetenv() emulation for machines without it
- *
- * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- *
- * IDENTIFICATION
- *   src/port/unsetenv.c
- *
- *-------------------------------------------------------------------------
- */
-
-#include "c.h"
-
-
-int
-unsetenv(const char *name)
-{
-   char       *envstr;
-
-   /* Error conditions, per POSIX */
-   if (name == NULL || name[0] == '\0' || strchr(name, '=') != NULL)
-   {
-       errno = EINVAL;
-       return -1;
-   }
-
-   if (getenv(name) == NULL)
-       return 0;               /* no work */
-
-   /*
-    * The technique embodied here works if libc follows the Single Unix Spec
-    * and actually uses the storage passed to putenv() to hold the environ
-    * entry.  When we clobber the entry in the second step we are ensuring
-    * that we zap the actual environ member.  However, there are some libc
-    * implementations (notably recent BSDs) that do not obey SUS but copy the
-    * presented string.  This method fails on such platforms.  Hopefully all
-    * such platforms have unsetenv() and thus won't be using this hack. See:
-    * http://www.greenend.org.uk/rjk/2008/putenv.html
-    *
-    * Note that repeatedly setting and unsetting a var using this code will
-    * leak memory.
-    */
-
-   envstr = (char *) malloc(strlen(name) + 2);
-   if (!envstr)                /* not much we can do if no memory */
-       return -1;
-
-   /* Override the existing setting by forcibly defining the var */
-   sprintf(envstr, "%s=", name);
-   if (putenv(envstr))
-       return -1;
-
-   /* Now we can clobber the variable definition this way: */
-   strcpy(envstr, "=");
-
-   /*
-    * This last putenv cleans up if we have multiple zero-length names as a
-    * result of unsetting multiple things.
-    */
-   return putenv(envstr);
-}
index 2a7d9f1f9ef10d0c5a5016ecf49ad8947bcc966a..5301e01e833461f46f4573eeea23067d726192e1 100644 (file)
@@ -343,7 +343,6 @@ sub GenerateFiles
        HAVE_RL_RESET_SCREEN_SIZE                => undef,
        HAVE_RL_VARIABLE_BIND                    => undef,
        HAVE_SECURITY_PAM_APPL_H                 => undef,
-       HAVE_SETENV                              => undef,
        HAVE_SETPROCTITLE                        => undef,
        HAVE_SETPROCTITLE_FAST                   => undef,
        HAVE_SOCKLEN_T                           => 1,
@@ -402,7 +401,6 @@ sub GenerateFiles
        HAVE_UINT8                               => undef,
        HAVE_UNION_SEMUN                         => undef,
        HAVE_UNISTD_H                            => 1,
-       HAVE_UNSETENV                            => undef,
        HAVE_USELOCALE                           => undef,
        HAVE_UUID_BSD                            => undef,
        HAVE_UUID_E2FS                           => undef,