2013-02-24 17:25:55 +00:00
|
|
|
/* Installed as lib.start.so, this bootstraps a working busybox and uses
|
|
|
|
* it to run lib.runshell.so. */
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
void chopdir (char *s) {
|
|
|
|
char *p=strrchr(s, '/');
|
|
|
|
if (p == NULL) {
|
|
|
|
fprintf(stderr, "cannot find directory in %s", s);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
p[0] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
main () {
|
|
|
|
char buf[1024];
|
|
|
|
char *p;
|
|
|
|
struct stat st_buf;
|
|
|
|
|
|
|
|
/* Get something like /data/data/ga.androidterm/lib/lib.start.so */
|
|
|
|
int n=readlink("/proc/self/exe", buf, 1023);
|
|
|
|
if (n < 1) {
|
|
|
|
fprintf(stderr, "failed to find own name");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
buf[n] = '\0';
|
|
|
|
|
|
|
|
/* Change directory to something like /data/data/ga.androidterm */
|
|
|
|
chopdir(buf);
|
|
|
|
chopdir(buf);
|
|
|
|
if (chdir(buf) != 0) {
|
|
|
|
perror("chdir");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2013-03-01 04:06:32 +00:00
|
|
|
if (stat("lib/lib.busybox.so", &st_buf) != 0) {
|
2013-03-05 16:02:44 +00:00
|
|
|
/* TODO my lib dir should be in LD_LIBRARY_PATH; check that */
|
2013-03-01 04:06:32 +00:00
|
|
|
fprintf(stderr, "Falling back to hardcoded app location; cannot find expected files in %s\n", buf);
|
|
|
|
if (chdir("/data/data/ga.androidterm") != 0) {
|
|
|
|
perror("chdir");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-23 17:54:49 +00:00
|
|
|
/* If this is the first run, set up busybox symlink,
|
|
|
|
* which allows busybox to run. */
|
2013-02-24 18:10:09 +00:00
|
|
|
if (stat("busybox", &st_buf) != 0) {
|
2013-05-23 17:54:49 +00:00
|
|
|
if (symlink("lib/lib.busybox.so", "busybox") != 0) {
|
|
|
|
/* Just in case! */
|
|
|
|
if (link("lib/lib.busybox.so", "busybox") != 0) {
|
|
|
|
perror("link busybox");
|
|
|
|
exit(1);
|
|
|
|
}
|
2013-02-24 17:25:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-24 18:10:09 +00:00
|
|
|
execl("./busybox", "./busybox", "sh", "lib/lib.runshell.so", NULL);
|
2013-02-24 17:25:55 +00:00
|
|
|
perror("error running busybox sh");
|
|
|
|
}
|