diff options
author | Lauri Leukkunen <lle@rahina.org> | 2006-12-26 11:57:41 +0200 |
---|---|---|
committer | Lauri Leukkunen <lleukkun@leka.rahina.org> | 2006-12-26 11:57:41 +0200 |
commit | 2c10ab33f9e7c6332ab83cc16ac180418e202304 (patch) | |
tree | 5831b2af0d1c11d6e5f80e2720892e9909247829 /preload | |
parent | 2880c5f37943937cbfed46d7f3efee27a82a57d4 (diff) |
* add a mapping cache, speeds things up enormously, almost to SB1 level
* fix a lot of subtle mis-behaviour by returning the untouched path in
cases where no mapping took place.
* mkdtemp can't use mapping at the moment, this should be revisited in
the future.
* add a few more mappings to default.lua, mainly autotools related
* main.lua fills in sane defaults for missing values in rules, makes
the rules files way cleaner and less verbose to write.
Diffstat (limited to 'preload')
-rw-r--r-- | preload/libsb2.c | 63 | ||||
-rw-r--r-- | preload/sb_alien.c | 66 |
2 files changed, 75 insertions, 54 deletions
diff --git a/preload/libsb2.c b/preload/libsb2.c index 9c6d24e..300aa52 100644 --- a/preload/libsb2.c +++ b/preload/libsb2.c @@ -85,7 +85,7 @@ * if ( amount /../ > amount /other/ ) ) remove extra /../ */ -#define narrow_chroot_path(path, fakechroot_path, fakechroot_ptr) \ +#define narrow_chroot_path(path, fakechroot_path) \ { \ if ((path) != NULL && *((char *)(path)) != '\0') { \ fakechroot_path = scratchbox_path(__FUNCTION__, path); \ @@ -120,11 +120,6 @@ } \ } -/* some useful prototypes */ - -int ld_so_run_app(char *file, char **argv, char *const *envp); -int run_app(char *file, char **argv, char *const *envp); -int run_cputransparency(char *file, char **argv, char *const *envp); #ifndef __GLIBC__ extern char **environ; @@ -1742,7 +1737,7 @@ int ftw64 (const char *dir, int (*fn)(const char *file, const struct stat64 *sb, /* #include <unistd.h> */ char * get_current_dir_name (void) { char *cwd, *oldptr, *newptr; - char *fakechroot_path, *fakechroot_ptr; + char *fakechroot_path; if (next_get_current_dir_name == NULL) fakechroot_init(); @@ -1750,7 +1745,7 @@ char * get_current_dir_name (void) { return NULL; } oldptr = cwd; - narrow_chroot_path(cwd, fakechroot_path, fakechroot_ptr); + narrow_chroot_path(cwd, fakechroot_path); if (cwd == NULL) { return NULL; } @@ -1769,14 +1764,14 @@ char * get_current_dir_name (void) { char * getcwd (char *buf, size_t size) { char *cwd; - char *fakechroot_path, *fakechroot_ptr; + char *fakechroot_path; if (next_getcwd == NULL) fakechroot_init(); if ((cwd = next_getcwd(buf, size)) == NULL) { return NULL; } - narrow_chroot_path(cwd, fakechroot_path, fakechroot_ptr); + narrow_chroot_path(cwd, fakechroot_path); return cwd; } @@ -1785,14 +1780,14 @@ char * getcwd (char *buf, size_t size) char * getwd (char *buf) { char *cwd; - char *fakechroot_path, *fakechroot_ptr; + char *fakechroot_path; if (next_getwd == NULL) fakechroot_init(); if ((cwd = next_getwd(buf)) == NULL) { return NULL; } - narrow_chroot_path(cwd, fakechroot_path, fakechroot_ptr); + narrow_chroot_path(cwd, fakechroot_path); return cwd; } @@ -1814,8 +1809,8 @@ int glob (const char *pattern, int flags, int (*errfunc) (const char *, int), gl { int rc; unsigned int i; - char tmp[FAKECHROOT_MAXPATH], *tmpptr; - char *fakechroot_path, *fakechroot_ptr; + char tmp[FAKECHROOT_MAXPATH]; + char *fakechroot_path; expand_chroot_path(pattern, fakechroot_path); @@ -1840,8 +1835,8 @@ int glob64 (const char *pattern, int flags, int (*errfunc) (const char *, int), { int rc; unsigned int i; - char tmp[FAKECHROOT_MAXPATH], *tmpptr; - char *fakechroot_path, *fakechroot_ptr; + char tmp[FAKECHROOT_MAXPATH]; + char *fakechroot_path; if (next_glob64 == NULL) fakechroot_init(); expand_chroot_path(pattern, fakechroot_path); @@ -2033,25 +2028,26 @@ int mkdir (const char *pathname, mode_t mode) char *mkdtemp (char *template) { char tmp[FAKECHROOT_MAXPATH], *oldtemplate, *ptr; - char *fakechroot_path, *fakechroot_ptr; + char *fakechroot_path; - oldtemplate = template; +// oldtemplate = template; - expand_chroot_path(template, fakechroot_path); +// expand_chroot_path(template, fakechroot_path); if (next_mkdtemp == NULL) fakechroot_init(); if (next_mkdtemp(template) == NULL) { return NULL; } - ptr = tmp; - strcpy(ptr, template); - narrow_chroot_path(ptr, fakechroot_path, fakechroot_ptr); - if (ptr == NULL) { - return NULL; - } - strcpy(oldtemplate, ptr); - return oldtemplate; +// ptr = tmp; +// strcpy(ptr, template); +// narrow_chroot_path(ptr, fakechroot_path); +// if (ptr == NULL) { +// return NULL; +// } +// strcpy(oldtemplate, ptr); +// DBGOUT("before returning from mkdtemp\n"); + return template; } #endif @@ -2085,7 +2081,7 @@ int mkstemp (char *template) { char tmp[FAKECHROOT_MAXPATH], *oldtemplate, *ptr; int fd; - char *fakechroot_path, *fakechroot_ptr; + char *fakechroot_path; oldtemplate = template; @@ -2098,7 +2094,7 @@ int mkstemp (char *template) } ptr = tmp; strcpy(ptr, template); - narrow_chroot_path(ptr, fakechroot_path, fakechroot_ptr); + narrow_chroot_path(ptr, fakechroot_path); if (ptr != NULL) { strcpy(oldtemplate, ptr); } @@ -2111,7 +2107,7 @@ int mkstemp64 (char *template) { char tmp[FAKECHROOT_MAXPATH], *oldtemplate, *ptr; int fd; - char *fakechroot_path, *fakechroot_ptr; + char *fakechroot_path; oldtemplate = template; @@ -2124,7 +2120,7 @@ int mkstemp64 (char *template) } ptr = tmp; strcpy(ptr, template); - narrow_chroot_path(ptr, fakechroot_path, fakechroot_ptr); + narrow_chroot_path(ptr, fakechroot_path); if (ptr != NULL) { strcpy(oldtemplate, ptr); } @@ -2258,12 +2254,12 @@ int readlink (const char *path, char *buf, READLINK_TYPE_ARG3) char *realpath (const char *name, char *resolved) { char *ptr; - char *fakechroot_path, *fakechroot_ptr; + char *fakechroot_path; if (next_realpath == NULL) fakechroot_init(); if ((ptr = next_realpath(name, resolved)) != NULL) { - narrow_chroot_path(ptr, fakechroot_path, fakechroot_ptr); + narrow_chroot_path(ptr, fakechroot_path); } return ptr; } @@ -2497,7 +2493,6 @@ int utimes (const char *filename, const struct timeval tv[2]) int uname(struct utsname *buf) { - char **t; if (next_uname == NULL) fakechroot_init(); if (next_uname(buf) < 0) { diff --git a/preload/sb_alien.c b/preload/sb_alien.c index 425978e..bedffb0 100644 --- a/preload/sb_alien.c +++ b/preload/sb_alien.c @@ -13,9 +13,6 @@ #define LD_LIB_PATH "/scratchbox/sarge/lib/:/scratchbox/sarge/lib/tls:/scratchbox/sarge/usr/lib" #define LD_SO "/scratchbox/sarge/lib/ld-linux.so.2" -extern int (*next_execve) (const char *filename, char *const argv [], char *const envp[]); - - static int endswith(char *haystack, char *needle) { return strcmp(&haystack[strlen(haystack)-strlen(needle)], needle)==0; @@ -115,46 +112,75 @@ char **post_args(char *fname) return padded_list(ret); } - int run_cputransparency(char *file, char **argv, char *const *envp) { - char **my_argv, **p; - char **my_envp; - char *tmp = NULL; - int i = 0; - - my_argv = (char **)calloc(elem_count(argv) + 4 + 1, sizeof(char *)); - my_envp = (char **)calloc(elem_count(envp) + 1, sizeof(char *)); + char *cputransp_bin, *target_root; + char *basec, *bname; - tmp = getenv("SBOX_CPUTRANSPARENCY_METHOD"); - if (!tmp) { + cputransp_bin = getenv("SBOX_CPUTRANSPARENCY_METHOD"); + if (!cputransp_bin) { fprintf(stderr, "SBOX_CPUTRANSPARENCY_METHOD not set, unable to execute the target binary\n"); return -1; } - my_argv[i++] = strdup(tmp); - my_argv[i++] = "-L"; - tmp = getenv("SBOX_TARGET_ROOT"); - if (!tmp) { + target_root = getenv("SBOX_TARGET_ROOT"); + if (!target_root) { fprintf(stderr, "SBOX_TARGET_ROOT not set, unable to execute the target binary\n"); return -1; } - my_argv[i++] = strdup(tmp); + + basec = strdup(cputransp_bin); + bname = basename(basec); + + if (strstr(bname, "qemu")) { + free(basec); + return run_qemu(cputransp_bin, target_root, file, argv, envp); + } else if (strstr(bname, "sbrsh")) { + free(basec); + return run_sbrsh(cputransp_bin, target_root, file, argv, envp); + } + + free(basec); + fprintf(stderr, "run_cputransparency() error: Unknown cputransparency method: [%s]\n", cputransp_bin); + return -1; +} + +int run_sbrsh(char *sbrsh_bin, char *target_root, char *file, char **argv, char *const *envp) +{ + return -1; +} + +int run_qemu(char *qemu_bin, char *target_root, char *file, char **argv, char *const *envp) +{ + char **my_argv, **p; + char **my_envp; + int i = 0; + //DBGOUT("about to run qemu: %s %s %s %s\n", qemu_bin, target_root, file, argv[0]); + my_argv = (char **)calloc(elem_count(argv) + 4 + 1, sizeof(char *)); + my_envp = (char **)calloc(elem_count((char **)envp) + 1, sizeof(char *)); + + my_argv[i++] = qemu_bin; + my_argv[i++] = "-L"; + + my_argv[i++] = target_root; my_argv[i++] = file; for (p=&argv[1]; *p; p++) { + //DBGOUT("processing args: [%s]\n", *p); my_argv[i++] = *p; } my_argv[i] = NULL; i = 0; for (p=(char **)envp; *p; p++) { - /* DBGOUT("ENV: [%s]\n", *p); */ + //DBGOUT("ENV: [%s]\n", *p); my_envp[i++] = *p; } my_envp[i] = NULL; - + //DBGOUT("just before running it [%s][%s]\n", my_argv[0], my_argv[1]); return next_execve(my_argv[0], my_argv, envp); + //DBGOUT("after running it\n"); + return -1; } int run_app(char *file, char **argv, char *const *envp) |