From 2ed21a363df5b9ab87e29fcab7e67d79b74c05f1 Mon Sep 17 00:00:00 2001 From: Anna Rift Date: Tue, 17 Dec 2024 09:12:36 -0800 Subject: [PATCH] Fix propagate_environment for chpl_append_to_buf changes Signed-off-by: Anna Rift --- .../slurm-gasnetrun_common.h | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h b/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h index 64b6b84a9b1c..f49b66636ec9 100644 --- a/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h +++ b/runtime/src/launch/slurm-gasnetrun_common/slurm-gasnetrun_common.h @@ -173,13 +173,21 @@ static void genNumLocalesOptions(FILE* slurmFile, sbatchVersion sbatch, } } -static void propagate_environment(char** buf) +// Append environment variables using chpl_append_to_cmd. +// charsWritten may be NULL, in which case it is ignored. +static void propagate_environment(char** buf, int* charsWritten) { + int ignoredCharsWritten; + if (!charsWritten) { + charsWritten = &ignoredCharsWritten; + } + // Indiscriminately propagate all environment variables. // We could do this more selectively, but we would be likely // to leave out something important. char *enviro_keys = chpl_get_enviro_keys(','); - if (enviro_keys) chpl_append_to_cmd(buf, " -E '%s'", enviro_keys); + if (enviro_keys) + chpl_append_to_cmd(buf, charsWritten, " -E '%s'", enviro_keys); } static char* chpl_launch_create_command(int argc, char* argv[], @@ -189,7 +197,6 @@ static char* chpl_launch_create_command(int argc, char* argv[], int i; int size; char* baseCommand = NULL; - char* envProp = NULL; char* command; FILE* slurmFile; char* projectString = getenv(launcherAccountEnvvar); @@ -298,8 +305,10 @@ static char* chpl_launch_create_command(int argc, char* argv[], CHPL_THIRD_PARTY, WRAP_TO_STR(LAUNCH_PATH), GASNETRUN_LAUNCHER, numLocales, numLocales); - propagate_environment(envProp); + char* envProp = NULL; + propagate_environment(&envProp, NULL); fprintf(slurmFile, "%s", envProp); + chpl_mem_free(envProp); fprintf(slurmFile, " %s %s", chpl_get_real_binary_wrapper(), chpl_get_real_binary_name()); @@ -337,7 +346,7 @@ static char* chpl_launch_create_command(int argc, char* argv[], chpl_append_to_cmd(&iCom, &len, " %s/%s/%s -n %d -N %d -c 0", CHPL_THIRD_PARTY, WRAP_TO_STR(LAUNCH_PATH), GASNETRUN_LAUNCHER, numLocales, numNodes); - propagate_environment(&iCom); + propagate_environment(&iCom, &len); chpl_append_to_cmd(&iCom, &len, " %s %s", chpl_get_real_binary_wrapper(), chpl_get_real_binary_name()); for (i=1; i