Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ static int hyper_do_exec_cmd(struct hyper_exec *exec, int pipe, struct stdio_con
// do the exec, no return
static void hyper_exec_process(struct hyper_exec *exec, struct stdio_config *io)
{
bool defaultPath = false;
if (sigprocmask(SIG_SETMASK, &orig_mask, NULL) < 0) {
perror("sigprocmask restore mask failed");
goto exit;
Expand All @@ -550,7 +551,8 @@ static void hyper_exec_process(struct hyper_exec *exec, struct stdio_config *io)
}

// set the process env
if (hyper_setup_env(exec->envs, exec->envs_num) < 0) {
defaultPath = (exec->argv[0][0] != '/') && (strcmp(exec->container_id, HYPERSTART_EXEC_CONTAINER) != 0);
if (hyper_setup_env(exec->envs, exec->envs_num, defaultPath) < 0) {
fprintf(stderr, "setup env failed\n");
goto exit;
}
Expand Down
10 changes: 9 additions & 1 deletion src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,24 @@ char *read_cmdline(void)
return NULL;
}

int hyper_setup_env(struct env *envs, int num)
int hyper_setup_env(struct env *envs, int num, bool setPATH)
{
int i, ret = 0;
struct env *env;
if (setPATH) {
ret = setenv("PATH", "/usr/local/bin:/usr/bin:/bin:.", 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we also need /sbin and /usr/sbin?

Copy link
Member Author

@gnawux gnawux Mar 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good question, if the user is root, it's better to include them, otherwise sbin shouldn't be here. The problem is it is not easy to know who is the user at this position. That's part of what I said it is not as simple as I thought.

if (ret < 0) {
perror("fail to setup default PATH");
ret = -1;
}
}

for (i = 0; i < num; i++) {
env = &envs[i];
if (setenv(env->env, env->value, 1) < 0) {
perror("fail to setup env");
ret = -1;
continue;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct env;
#endif

char *read_cmdline(void);
int hyper_setup_env(struct env *envs, int num);
int hyper_setup_env(struct env *envs, int num, bool setPATH);
int hyper_find_sd(char *addr, char **dev);
int hyper_list_dir(char *path);
int hyper_copy_dir(char *src, char *dst);
Expand Down