Skip to content

Commit 1bb2763

Browse files
slptylerfanelli
authored andcommitted
init: override kernel's HOME and TERM envs
Starting 3ac0663, init.c is able to read the workload parameters from a configuration file. After this change, parameters passed as environment variables still take preference over the ones specified in the config file, to allow our callers to easily override them without altering said file. The problem with this approach is that the kernel unconditionally exports the HOME and TERM variables, so the ones in the config file are never applied. In this change, we always override HOME and TERM with the values in the config file, and we introduce KRUN_HOME and KRUN_TERM to allow our callers to still be able to override them using environment variables. Signed-off-by: Sergio Lopez <[email protected]>
1 parent 4f10987 commit 1bb2763

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

init/init.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,12 @@ static void config_parse_env(char *data, jsmntok_t *token)
257257
*env_val = '\0';
258258
env_val++;
259259

260-
setenv(env, env_val, 0);
260+
if ((strcmp(env, "HOME") == 0) ||
261+
(strcmp(env, "TERM") == 0)) {
262+
setenv(env, env_val, 1);
263+
} else {
264+
setenv(env, env_val, 0);
265+
}
261266
}
262267
}
263268

@@ -451,6 +456,8 @@ int main(int argc, char **argv)
451456
int sockfd;
452457
char localhost[] = "localhost\0";
453458
char *hostname;
459+
char *krun_home;
460+
char *krun_term;
454461
char *krun_init;
455462
char *config_workdir, *env_workdir;
456463
char *rlimits;
@@ -484,6 +491,16 @@ int main(int argc, char **argv)
484491

485492
config_parse_file(&config_argv, &config_workdir);
486493

494+
krun_home = getenv("KRUN_HOME");
495+
if (krun_home) {
496+
setenv("HOME", krun_home, 1);
497+
}
498+
499+
krun_term = getenv("KRUN_TERM");
500+
if (krun_term) {
501+
setenv("TERM", krun_term, 1);
502+
}
503+
487504
hostname = getenv("HOSTNAME");
488505
if (hostname) {
489506
sethostname(hostname, strlen(hostname));

0 commit comments

Comments
 (0)