Skip to content

Commit 1077e0d

Browse files
committed
ccon: Set PATH from process.env for non-host execution
Because execvpe is using current PATH, not the one we're passing in via its argument. The exec_fd guards don't have a semantic impact, because we've already opened the file descriptor using the original PATH; they're just a performance optimization, because there's no need to iterate through env or call setenv for the host-executable case.
1 parent 1aeefd5 commit 1077e0d

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

ccon.c

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,17 +1080,41 @@ static int set_capabilities(json_t * process)
10801080

10811081
static void exec_container_process(json_t * config, int *socket, int *exec_fd)
10821082
{
1083-
json_t *process, *console;
1083+
json_t *process, *env, *value;
1084+
const char *env_var;
1085+
size_t path_len, i;
10841086

10851087
process = json_object_get(config, "process");
10861088
if (!process) {
10871089
LOG("process not defined, exiting\n");
10881090
exit(0);
10891091
}
10901092

1091-
console = json_object_get(config, "console");
1092-
exec_process(process, console
1093-
&& json_boolean_value(console), 1, socket, exec_fd);
1093+
if (!exec_fd || *exec_fd < 0) {
1094+
env = json_object_get(process, "env");
1095+
if (env) {
1096+
path_len = strlen("PATH=");
1097+
json_array_foreach(env, i, value) {
1098+
env_var = json_string_value(value);
1099+
if (!env_var) {
1100+
LOG("failed to extract process.capabilities[%d]\n", (int)i);
1101+
return;
1102+
}
1103+
if (strncmp("PATH=", env_var, path_len) == 0) {
1104+
if (setenv
1105+
("PATH", env_var + path_len, 1)) {
1106+
PERROR("setenv");
1107+
return;
1108+
}
1109+
break;
1110+
}
1111+
}
1112+
}
1113+
}
1114+
1115+
value = json_object_get(config, "console");
1116+
exec_process(process, value
1117+
&& json_boolean_value(value), 1, socket, exec_fd);
10941118
return;
10951119
}
10961120

0 commit comments

Comments
 (0)