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)
(val == NULL) || (*val == 0));
}
+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;
return -1;
}
+ /* set variable */
+
if (*s->dptr == '=')
{
s->dptr++;
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;
}
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 *);
#include <sys/wait.h>
#include <unistd.h>
-extern char **envlist;
-
int _mutt_system (const char *cmd, int flags)
{
int rc = -1;
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)