diff --git a/src/common/env.c b/src/common/env.c index 2847a85a3a81802aec13a3f29b4020f0aa9f6fc2..f208e39d4d751e55b03c410055c83fc0e2b83b1e 100644 --- a/src/common/env.c +++ b/src/common/env.c @@ -282,39 +282,25 @@ setenvfs(const char *fmt, ...) return rc; } -int -setenvf(char ***envp, const char *name, const char *fmt, ...) +int setenvf(char ***envp, const char *name, const char *fmt, ...) { - char **ep = NULL; - char *str = NULL; + char *str = NULL, *value; va_list ap; int rc; - char *buf, *bufcpy; - buf = xmalloc(ENV_BUFSIZE); + value = xmalloc(ENV_BUFSIZE); va_start(ap, fmt); - vsnprintf (buf, ENV_BUFSIZE, fmt, ap); + vsnprintf (value, ENV_BUFSIZE, fmt, ap); va_end(ap); - bufcpy = xstrdup(buf); - xfree(buf); - xstrfmtcat (str, "%s=%s", name, bufcpy); - xfree(bufcpy); if (envp && *envp) { - ep = _find_name_in_env (*envp, name); - - if (*ep != NULL) - xfree (*ep); - else - ep = _extend_env (envp); - - *ep = str; - - return (0); + rc = env_array_overwrite(envp, name, value); } else { + xstrfmtcat(str, "%s=%s", name, value); rc = putenv(str); - return rc; } + xfree(value); + return rc; } /* diff --git a/src/common/env.h b/src/common/env.h index b8795e2de25c19e4be46fab8547d12fe41d7215b..e39f791ae19b97fdfe89b7e2ada7ffe15500cf2e 100644 --- a/src/common/env.h +++ b/src/common/env.h @@ -79,11 +79,14 @@ typedef struct env_options { } env_t; -int envcount (char **env); -int setenvfs(const char *fmt, ...); -int setenvf(char ***envp, const char *name, const char *fmt, ...); -void unsetenvp(char **env, const char *name); +/* NOTE: These functions operate on the job's current environment + * if env is NULL, otherwise they operate on the argument array */ +int envcount (char **env); char * getenvp(char **env, const char *name); +int setenvf(char ***envp, const char *name, const char *fmt, ...); +int setenvfs(const char *fmt, ...); +void unsetenvp(char **env, const char *name); + int setup_env(env_t *env, bool preserve_env); /**********************************************************************