From: Kevin McCarthy Date: Sat, 18 Mar 2017 20:48:02 +0000 (-0700) Subject: Pass envlist to filter children too. (closes #3922) X-Git-Tag: mutt-1-8-1-rel~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a41b3a452729460b730661bac7c5a9c5afa38407;p=mutt Pass envlist to filter children too. (closes #3922) The new setenv patch neglected to pass the envlist for filters too. Unfortunately, the filter code was already set up to pass COLUMNS to children, so it needed to be changed to add this to the envlist instead. Factor out mutt_envlist_set() from the parse_setenv() function, which the filter code can then use to set COLUMNS after forking. --- diff --git a/filter.c b/filter.c index 0e94d249..a10dcd2a 100644 --- a/filter.c +++ b/filter.c @@ -122,10 +122,10 @@ mutt_create_filter_fd (const char *cmd, FILE **in, FILE **out, FILE **err, if (MuttIndexWindow && (MuttIndexWindow->cols > 0)) { snprintf (columns, sizeof (columns), "%d", MuttIndexWindow->cols); - setenv ("COLUMNS", columns, 1); + mutt_envlist_set ("COLUMNS", columns); } - execl (EXECSHELL, "sh", "-c", cmd, NULL); + execle (EXECSHELL, "sh", "-c", cmd, NULL, mutt_envlist ()); _exit (127); } else if (thepid == -1) diff --git a/init.c b/init.c index 7c0f179a..7e027c66 100644 --- a/init.c +++ b/init.c @@ -1845,11 +1845,57 @@ static int check_charset (struct option_t *opt, const char *val) return rc; } +char **mutt_envlist (void) +{ + return envlist; +} + +/* Helper function for parse_setenv(). + * It's broken out because some other parts of mutt (filter.c) need + * to set/overwrite environment variables in envlist before execing. + */ +void mutt_envlist_set (const char *name, const char *value) +{ + char **envp = envlist; + char work[LONG_STRING]; + int count, len; + + len = mutt_strlen (name); + + /* Look for current slot to overwrite */ + count = 0; + while (envp && *envp) + { + if (!mutt_strncmp (name, *envp, len) && (*envp)[len] == '=') + { + FREE (envp); /* __FREE_CHECKED__ */ + break; + } + envp++; + count++; + } + + /* Format var=value string */ + snprintf (work, sizeof(work), "%s=%s", NONULL (name), NONULL (value)); + + /* If slot found, overwrite */ + if (*envp) + *envp = safe_strdup (work); + + /* If not found, add new slot */ + else + { + *envp = safe_strdup (work); + count++; + safe_realloc (&envlist, sizeof(char *) * (count + 1)); + envlist[count] = NULL; + } +} + static int parse_setenv(BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err) { int query, unset, len; - char work[LONG_STRING]; - char **save, **envp = envlist; + char *name, **save, **envp = envlist; int count = 0; query = 0; @@ -1924,6 +1970,8 @@ static int parse_setenv(BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err) return -1; } + /* set variable */ + if (*s->dptr == '=') { s->dptr++; @@ -1936,38 +1984,10 @@ static int parse_setenv(BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err) return -1; } - /* Look for current slot to overwrite */ - count = 0; - while (envp && *envp) - { - if (!mutt_strncmp (tmp->data, *envp, len) && (*envp)[len] == '=') - { - FREE (envp); /* __FREE_CHECKED__ */ - break; - } - envp++; - count++; - } - - /* Format var=value string */ - strfcpy (work, tmp->data, sizeof(work)); - len = strlen (work); - work[len++] = '='; + name = safe_strdup (tmp->data); mutt_extract_token (tmp, s, 0); - strfcpy (&work[len], tmp->data, sizeof(work)-len); - - /* If slot found, overwrite */ - if (*envp) - *envp = safe_strdup (work); - - /* If not found, add new slot */ - else - { - *envp = safe_strdup (work); - count++; - safe_realloc (&envlist, sizeof(char *) * (count + 1)); - envlist[count] = NULL; - } + mutt_envlist_set (name, tmp->data); + FREE (&name); return 0; } diff --git a/protos.h b/protos.h index c43b49cd..37bfe6df 100644 --- a/protos.h +++ b/protos.h @@ -185,6 +185,8 @@ void mutt_display_sanitize (char *); void mutt_edit_content_type (HEADER *, BODY *, FILE *); void mutt_edit_file (const char *, const char *); void mutt_edit_headers (const char *, const char *, HEADER *, char *, size_t); +char **mutt_envlist (void); +void mutt_envlist_set (const char *name, const char *value); int mutt_filter_unprintable (char **); int mutt_label_message (HEADER *); void mutt_make_label_hash (CONTEXT *); diff --git a/system.c b/system.c index 97dc2a8e..a0aa4dac 100644 --- a/system.c +++ b/system.c @@ -32,8 +32,6 @@ #include #include -extern char **envlist; - int _mutt_system (const char *cmd, int flags) { int rc = -1; @@ -116,7 +114,7 @@ int _mutt_system (const char *cmd, int flags) sigaction (SIGTSTP, &act, NULL); sigaction (SIGCONT, &act, NULL); - execle (EXECSHELL, "sh", "-c", cmd, NULL, envlist); + execle (EXECSHELL, "sh", "-c", cmd, NULL, mutt_envlist ()); _exit (127); /* execl error */ } else if (thepid != -1)