Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 4032903

Browse files
authored
Merge pull request #281 from gnawux/default_PATH
setup default PATH if it is not in the specified env list
2 parents b635717 + 0ebf7d8 commit 4032903

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/exec.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ static int hyper_do_exec_cmd(struct hyper_exec *exec, int pipe, struct stdio_con
534534
// do the exec, no return
535535
static void hyper_exec_process(struct hyper_exec *exec, struct stdio_config *io)
536536
{
537+
bool defaultPath = false;
537538
if (sigprocmask(SIG_SETMASK, &orig_mask, NULL) < 0) {
538539
perror("sigprocmask restore mask failed");
539540
goto exit;
@@ -550,7 +551,8 @@ static void hyper_exec_process(struct hyper_exec *exec, struct stdio_config *io)
550551
}
551552

552553
// set the process env
553-
if (hyper_setup_env(exec->envs, exec->envs_num) < 0) {
554+
defaultPath = (exec->argv[0][0] != '/') && (strcmp(exec->container_id, HYPERSTART_EXEC_CONTAINER) != 0);
555+
if (hyper_setup_env(exec->envs, exec->envs_num, defaultPath) < 0) {
554556
fprintf(stderr, "setup env failed\n");
555557
goto exit;
556558
}

src/util.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,24 @@ char *read_cmdline(void)
3030
return NULL;
3131
}
3232

33-
int hyper_setup_env(struct env *envs, int num)
33+
int hyper_setup_env(struct env *envs, int num, bool setPATH)
3434
{
3535
int i, ret = 0;
3636
struct env *env;
37+
if (setPATH) {
38+
ret = setenv("PATH", "/usr/local/bin:/usr/bin:/bin:.", 1);
39+
if (ret < 0) {
40+
perror("fail to setup default PATH");
41+
ret = -1;
42+
}
43+
}
3744

3845
for (i = 0; i < num; i++) {
3946
env = &envs[i];
4047
if (setenv(env->env, env->value, 1) < 0) {
4148
perror("fail to setup env");
4249
ret = -1;
50+
continue;
4351
}
4452
}
4553

src/util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct env;
1818
#endif
1919

2020
char *read_cmdline(void);
21-
int hyper_setup_env(struct env *envs, int num);
21+
int hyper_setup_env(struct env *envs, int num, bool setPATH);
2222
int hyper_find_sd(char *addr, char **dev);
2323
int hyper_list_dir(char *path);
2424
int hyper_copy_dir(char *src, char *dst);

0 commit comments

Comments
 (0)