Skip to content

Commit

Permalink
Do not pass locale environment variables to the container
Browse files Browse the repository at this point in the history
Signed-off-by: Felix Abecassis <fabecassis@nvidia.com>
  • Loading branch information
flx42 committed Sep 12, 2022
1 parent c451d2c commit 96938bd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pyxis_slurmstepd.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,13 @@ static int read_proc_environ(pid_t pid, char **result, size_t *size)
return (rv);
}

static const char *container_deny_env[] = {
"LANG",
"LANGUAGE",
"LC_ALL",
NULL
};

static int spank_import_container_env(spank_t sp, pid_t pid)
{
int ret;
Expand All @@ -536,6 +543,15 @@ static int spank_import_container_env(spank_t sp, pid_t pid)
spank_err_t rc;
int rv = -1;

/* First, remove unwanted environment variables from the job */
for (int i = 0; container_deny_env[i] != NULL; ++i) {
rc = spank_unsetenv(sp, container_deny_env[i]);
if (rc != ESPANK_SUCCESS) {
slurm_error("pyxis: failed to unset %s: %s", container_deny_env[i], spank_strerror(rc));
goto fail;
}
}

ret = read_proc_environ(pid, &proc_environ, &size);
if (ret < 0) {
slurm_error("pyxis: couldn't read /proc/%d/environ", pid);
Expand Down
5 changes: 5 additions & 0 deletions tests/env.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ load ./common
grep -q '/tmp' <<< "${lines[-1]}" || grep -q 'tmpfs' <<< "${lines[-1]}"
}

@test "\$LANG special case" {
LANG=en_US.UTF-8 run_srun --container-image=ubuntu:22.04 --no-container-mount-home perl --version
! grep 'Setting locale failed' <<< "${output}"
}

@test "nvidia/cuda:10.2-base with \$NVIDIA_VISIBLE_DEVICES=0" {
if ! srun which nvidia-smi; then
skip "no NVIDIA GPUs"
Expand Down

0 comments on commit 96938bd

Please sign in to comment.