diff --git a/doc/man/man1/sbatch.1 b/doc/man/man1/sbatch.1 index 8f846c7103042264f8370dbc620e84cb10541495..aa8b91c07981ee5e23233777e4c82b3197dbbfa1 100644 --- a/doc/man/man1/sbatch.1 +++ b/doc/man/man1/sbatch.1 @@ -384,9 +384,7 @@ assumed. Export environment variables defined in <\fIfilename\fR> or read from <\fIfd\fR> to the job's execution environment. The content is one or more environment variable definitions of the form NAME=value, each separated by a null character. This allows the use -of special characters in environment definitions.(Note: primarily for use -with Moab. outside of Moab, variables in the user's working environment -may supercede the variables specified in the file.) +of special characters in environment definitions. .TP \fB\-F\fR, \fB\-\-nodefile\fR=<\fInode file\fR> diff --git a/src/common/env.c b/src/common/env.c index 19e32418cdd8c25f30823c4d761487ae19c1363f..dd7876f32899b4f65e11e80042e75e0ae1fb56d8 100644 --- a/src/common/env.c +++ b/src/common/env.c @@ -81,6 +81,7 @@ strong_alias(env_array_append, slurm_env_array_append); strong_alias(env_array_append_fmt, slurm_env_array_append_fmt); strong_alias(env_array_overwrite, slurm_env_array_overwrite); strong_alias(env_array_overwrite_fmt, slurm_env_array_overwrite_fmt); +strong_alias(env_unset_environment, slurm_env_unset_environment); #define ENV_BUFSIZE (256 * 1024) @@ -1526,6 +1527,33 @@ void env_array_set_environment(char **env_array) } } +/* + * Unset all of the environment variables in a user's current + * environment. + * + * (Note: becuae the environ array is decrementing with each + * unsetenv, only increment the ptr on a failure to unset.) + */ +void env_unset_environment(void) +{ + extern char **environ; + + int rc = 0; + char **ptr; + char name[256], *value; + + value = xmalloc(ENV_BUFSIZE); + for (ptr = (char **)environ; *ptr != NULL; ) { + if ((_env_array_entry_splitter(*ptr, name, sizeof(name), + value, ENV_BUFSIZE)) && + (unsetenv(name) != -1)) + rc = 1; + else + ptr++; + } + xfree(value); +} + /* * Merge all of the environment variables in src_array into the * array dest_array. Any variables already found in dest_array diff --git a/src/common/env.h b/src/common/env.h index e2e5478bbf7bb39a4ac0275a5b28a861c7d9b077..53531f7fbd7ac34c4cad96df1cb6abedbf0892c9 100644 --- a/src/common/env.h +++ b/src/common/env.h @@ -180,6 +180,12 @@ env_array_for_step(char ***dest, */ char **env_array_create(void); +/* + * Unset all of the environment variables in a user's current + * environment. + */ +void env_unset_environment(void); + /* * Merge all of the environment variables in src_array into the * array dest_array. Any variables already found in dest_array diff --git a/src/sbatch/sbatch.c b/src/sbatch/sbatch.c index 440a10a4a9a658b628f7640c2f7fabb6e3dd3301..07d23510ef34896c225531f25f0c40bc8ffabfd7 100644 --- a/src/sbatch/sbatch.c +++ b/src/sbatch/sbatch.c @@ -137,6 +137,13 @@ int main(int argc, char *argv[]) (void) _set_rlimit_env(); } + /* + * if the environment is coming from a file, the + * environment at execution startup, must be unset. + */ + if (opt.export_file != NULL) + env_unset_environment(); + _set_prio_process_env(); _set_spank_env(); _set_submit_dir_env();