mcexec: store full path to executable

required so that a forked process can obtain exec reference in the
Linux kernel even if executable was specified with relative path
and fork was called after changing the current working directory
This commit is contained in:
Balazs Gerofi bgerofi@riken.jp
2014-12-03 15:14:26 +09:00
parent 8f30e16976
commit c1cf630a94

View File

@ -548,9 +548,24 @@ int load_elf_desc(char *filename, struct program_load_desc **desc_p,
free(exec_path);
}
exec_path = strdup(filename);
if (!exec_path) {
fprintf(stderr, "WARNING: strdup(filename) failed\n");
if (!strncmp("/", filename, 1)) {
exec_path = strdup(filename);
if (!exec_path) {
fprintf(stderr, "WARNING: strdup(filename) failed\n");
return ENOMEM;
}
}
else {
char *cwd = getcwd(NULL, 0);
exec_path = malloc(strlen(cwd) + strlen(filename) + 1);
if (!exec_path) {
fprintf(stderr, "Error: allocating exec_path\n");
return ENOMEM;
}
sprintf(exec_path, "%s/%s", cwd, filename);
free(cwd);
}
desc = load_elf(fp, &interp_path);