On 2017-04-22 22:52:43 +0200, Vincent Lefevre wrote:
> I'm wondering. Is the call to setenv() useful any longer?
> I mean, GPG_TTY needs to be set only for child processes, not
> for Mutt itself. This would mean that
> 
>   setenv("GPG_TTY", tty, 0);
> 
> could be removed. And that setenv() should no longer be used,
> so that anything related to it could be removed. What about
> the attached patch?

For consistency, I think that the other execl() / execvp() should
be changed to execle() / execvpe(). Indeed, the Mutt manual says:

7. Managing the Environment

   You can alter the environment that Mutt passes on to its child
   processes using the "setenv" and "unsetenv" operators. (N.B. These
   follow Mutt-style syntax, not shell-style!) You can also query current
   environment values by prefixing a "?" character.
setenv TERM vt100
setenv ORGANIZATION "The Mutt Development Team"
unsetenv DISPLAY
setenv ?LESS

So, *any* process started by Mutt should be affected. New patch
attached.

-- 
Vincent Lefèvre <vinc...@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
diff -r 69df899cdfa9 configure.ac
--- a/configure.ac      Tue Apr 18 16:18:10 2017 -0700
+++ b/configure.ac      Sat Apr 22 23:00:32 2017 +0200
@@ -374,7 +374,7 @@
 
 AC_CHECK_FUNCS(fgetpos memmove setegid srand48 strerror)
 
-AC_REPLACE_FUNCS([setenv strcasecmp strdup strsep strtok_r wcscasecmp])
+AC_REPLACE_FUNCS([strcasecmp strdup strsep strtok_r wcscasecmp])
 AC_REPLACE_FUNCS([strcasestr mkdtemp])
 
 AC_CHECK_FUNC(getopt)
diff -r 69df899cdfa9 m4/gettext.m4
--- a/m4/gettext.m4     Tue Apr 18 16:18:10 2017 -0700
+++ b/m4/gettext.m4     Sat Apr 22 23:00:32 2017 +0200
@@ -318,7 +318,7 @@
    AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h stddef.h \
 stdlib.h string.h unistd.h sys/param.h])
    AC_CHECK_FUNCS([feof_unlocked fgets_unlocked getcwd getegid geteuid \
-getgid getuid mempcpy munmap putenv setenv setlocale stpcpy strchr strcasecmp \
+getgid getuid mempcpy munmap putenv setlocale stpcpy strchr strcasecmp \
 strdup strtoul tsearch __argz_count __argz_stringify __argz_next])
 
    MUTT_AM_ICONV
diff -r 69df899cdfa9 mutt_tunnel.c
--- a/mutt_tunnel.c     Tue Apr 18 16:18:10 2017 -0700
+++ b/mutt_tunnel.c     Sat Apr 22 23:00:32 2017 +0200
@@ -106,7 +106,7 @@
     /* Don't let the subprocess think it can use the controlling tty */
     setsid ();
 
-    execl (EXECSHELL, "sh", "-c", Tunnel, NULL);
+    execle (EXECSHELL, "sh", "-c", Tunnel, NULL, mutt_envlist ());
     _exit (127);
   }
   mutt_unblock_signals_system (1);
diff -r 69df899cdfa9 pgp.c
--- a/pgp.c     Tue Apr 18 16:18:10 2017 -0700
+++ b/pgp.c     Sat Apr 22 23:00:32 2017 +0200
@@ -114,10 +114,7 @@
     return 0;
 
   if ((tty = ttyname(0)))
-  {
-    setenv("GPG_TTY", tty, 0);
     mutt_envlist_set ("GPG_TTY", tty, 0);
-  }
 
   return 1;
 }
diff -r 69df899cdfa9 protos.h
--- a/protos.h  Tue Apr 18 16:18:10 2017 -0700
+++ b/protos.h  Sat Apr 22 23:00:32 2017 +0200
@@ -543,10 +543,6 @@
 
 /* prototypes for compatibility functions */
 
-#ifndef HAVE_SETENV
-int setenv (const char *, const char *, int);
-#endif
-
 #ifndef HAVE_STRCASECMP
 int strcasecmp (char *, char *);
 int strncasecmp (char *, char *, size_t);
diff -r 69df899cdfa9 sendlib.c
--- a/sendlib.c Tue Apr 18 16:18:10 2017 -0700
+++ b/sendlib.c Sat Apr 22 23:00:32 2017 +0200
@@ -2240,7 +2240,7 @@
          _exit (S_ERR);
       }
 
-      execvp (path, args);
+      execvpe (path, args, mutt_envlist ());
       _exit (S_ERR);
     }
     else if (pid == -1)
diff -r 69df899cdfa9 setenv.c
--- a/setenv.c  Tue Apr 18 16:18:10 2017 -0700
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-/*  Replacement for a missing setenv.
-**
-**  Written by Russ Allbery <r...@stanford.edu>
-**  This work is hereby placed in the public domain by its author.
-**
-**  Provides the same functionality as the standard library routine setenv
-**  for those platforms that don't have it.
-*/
-
-#include "config.h"
-
-#include <stdlib.h>
-#include <string.h>
-
-int
-setenv(const char *name, const char *value, int overwrite)
-{
-    char *envstring;
-
-    if (!overwrite && getenv(name) != NULL)
-        return 0;
-
-    /* Allocate memory for the environment string.  We intentionally don't
-       use concat here, or the xmalloc family of allocation routines, since
-       the intention is to provide a replacement for the standard library
-       function which sets errno and returns in the event of a memory
-       allocation failure. */
-    envstring = malloc(strlen(name) + 1 + strlen(value) + 1); /* 
__MEM_CHECKED__ */
-    if (envstring == NULL)
-        return -1;
-
-    /* Build the environment string and add it to the environment using
-       putenv.  Systems without putenv lose, but XPG4 requires it. */
-    strcpy(envstring, name);  /* __STRCPY_CHECKED__ */
-    strcat(envstring, "=");   /* __STRCAT_CHECKED__ */
-    strcat(envstring, value); /* __STRCAT_CHECKED__ */
-    return putenv(envstring);
-
-    /* Note that the memory allocated is not freed.  This is intentional;
-       many implementations of putenv assume that the string passed to
-       putenv will never be freed and don't make a copy of it.  Repeated use
-       of this function will therefore leak memory, since most
-       implementations of putenv also don't free strings removed from the
-       environment (due to being overwritten). */
-}

Reply via email to