Skip to content

Commit

Permalink
Clear the slurmstepd environment before calling enroot
Browse files Browse the repository at this point in the history
  • Loading branch information
flx42 committed Jan 25, 2024
1 parent 125df53 commit e2de433
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions pyxis_slurmstepd.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,36 @@ static int enroot_new_log(void)
return (context.log_fd);
}

/* We do not want to inherit any environment variable from slurmstepd, except PATH */
static int slurm_clear_env(void)
{
int rv = -1;
const char *p;
char *saved_path = NULL;

/* It's unclear if the pointer returned by getenv(3) will always persist after clearenv(3), so make a copy. */
p = getenv("PATH");
if (p != NULL) {
saved_path = strdup(p);
if (saved_path == NULL)
goto fail;
}

if (clearenv() != 0)
goto fail;

if (saved_path != NULL) {
if (setenv("PATH", saved_path, 1) < 0)
goto fail;
}

rv = 0;

fail:
free(saved_path);
return (rv);
}

/*
* List of environment variables that should not be passed from the Slurm job to enroot.
*/
Expand Down Expand Up @@ -345,6 +375,9 @@ static int enroot_import_job_env(char **env)

static int enroot_set_env(void)
{
if (slurm_clear_env() < 0)
return (-1);

if (enroot_import_job_env(context.job.environ) < 0)
return (-1);

Expand Down

0 comments on commit e2de433

Please sign in to comment.