mcexec: add a path prefix for interpreter search
- When the interpreter is not found, add a prefix to the path and retry search. - the prefix is specified by a environment variable MCEXEC_ALT_ROOT. - If the MCEXEC_ALT_ROOT does not exist, /usr/linux-k1om-4.7/linux-k1om is used as a prefix.
This commit is contained in:
@ -81,6 +81,7 @@ struct kernel_termios {
|
||||
int main_loop(int fd, int cpu, pthread_mutex_t *lock);
|
||||
|
||||
static int fd;
|
||||
static char *altroot;
|
||||
|
||||
struct program_load_desc *load_elf(FILE *fp, char **interp_pathp)
|
||||
{
|
||||
@ -176,6 +177,31 @@ struct program_load_desc *load_elf(FILE *fp, char **interp_pathp)
|
||||
return desc;
|
||||
}
|
||||
|
||||
char *search_file(char *orgpath, int mode)
|
||||
{
|
||||
int error;
|
||||
static char modpath[PATH_MAX];
|
||||
int n;
|
||||
|
||||
error = access(orgpath, mode);
|
||||
if (!error) {
|
||||
return orgpath;
|
||||
}
|
||||
|
||||
n = snprintf(modpath, sizeof(modpath), "%s/%s", altroot, orgpath);
|
||||
if (n >= sizeof(modpath)) {
|
||||
__eprintf("modified path too long: %s/%s\n", altroot, orgpath);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
error = access(modpath, mode);
|
||||
if (!error) {
|
||||
return modpath;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct program_load_desc *load_interp(struct program_load_desc *desc0, FILE *fp)
|
||||
{
|
||||
Elf64_Ehdr hdr;
|
||||
@ -464,12 +490,18 @@ int main(int argc, char **argv)
|
||||
pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
FILE *interp = NULL;
|
||||
char *interp_path;
|
||||
char *path;
|
||||
|
||||
#ifdef USE_SYSCALL_MOD_CALL
|
||||
__glob_argc = argc;
|
||||
__glob_argv = argv;
|
||||
#endif
|
||||
|
||||
altroot = getenv("MCEXEC_ALT_ROOT");
|
||||
if (!altroot) {
|
||||
altroot = "/usr/linux-k1om-4.7/linux-k1om";
|
||||
}
|
||||
|
||||
strcpy(dev, "/dev/mcos0");
|
||||
if(argv[1]){
|
||||
for(p = argv[1]; *p && *p >= '0' && *p <= '9'; p++);
|
||||
@ -501,9 +533,15 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (interp_path) {
|
||||
interp = fopen(interp_path, "rb");
|
||||
path = search_file(interp_path, X_OK);
|
||||
if (!path) {
|
||||
fprintf(stderr, "Error: interp not found: %s\n", interp_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
interp = fopen(path, "rb");
|
||||
if (!interp) {
|
||||
fprintf(stderr, "Error: Failed to open %s\n", interp_path);
|
||||
fprintf(stderr, "Error: Failed to open %s\n", path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user