diff options
author | John Beppu | 2000-06-28 00:41:26 +0000 |
---|---|---|
committer | John Beppu | 2000-06-28 00:41:26 +0000 |
commit | 7cdc76dfbf3eb294ada708d79865ea582eb074af (patch) | |
tree | 9f8ac9f08e4078ced0a62b071bdb7d9fd8a062fc /applets | |
parent | d0edef3cbe37880b0dd402614413eb490b39c9e1 (diff) | |
download | busybox-7cdc76dfbf3eb294ada708d79865ea582eb074af.zip busybox-7cdc76dfbf3eb294ada708d79865ea582eb074af.tar.gz |
+ busybox --install [-s]
is functional (but disabled in busybox.def.h by default)
Someone email the guy who originally wanted this.
Diffstat (limited to 'applets')
-rw-r--r-- | applets/busybox.c | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/applets/busybox.c b/applets/busybox.c index e454bb6..2a68604 100644 --- a/applets/busybox.c +++ b/applets/busybox.c @@ -376,6 +376,31 @@ static char* install_dir[] = { /* abstract link() */ typedef int (*__link_f)(const char *, const char *); +/* + * Where in the filesystem is this busybox? + * [return] + * malloc'd string w/ full pathname of busybox's location + * NULL on failure + */ +static char *busybox_fullpath() +{ + pid_t pid; + char path[256]; + char proc[256]; + int len; + + pid = getpid(); + sprintf(proc, "/proc/%d/exe", pid); + len = readlink(proc, path, 256); + if (len != -1) { + path[len] = 0; + } else { + fprintf(stderr, "busybox : %s : %s\n", proc, strerror(errno)); + return NULL; + } + return strdup(path); +} + /* create (sym)links for each applet */ static int install_links(const char *busybox, int use_symbolic_links) { @@ -394,14 +419,13 @@ static int install_links(const char *busybox, int use_symbolic_links) install_dir[applets[i].location], applets[i].name ); -#if 0 +#if 1 rc |= Link(busybox, command); #else puts(command); #endif if (rc) { fprintf(stderr,"busybox : %s : %s\n", command, strerror(errno)); - break; } } return rc; @@ -427,6 +451,8 @@ int main(int argc, char **argv) */ if (argc > 1 && (strcmp(argv[1], "--install") == 0)) { int use_symbolic_links = 0; + int rc = 0; + char *busybox; /* to use symlinks, or not to use symlinks... */ if (argc > 2) { @@ -434,13 +460,16 @@ int main(int argc, char **argv) use_symbolic_links = 1; } } - /* - * FIXME : - * I need a clever unix trick that'll tell - * me where to find the currently running - * busybox binary - */ - return install_links("/bin/busybox", use_symbolic_links); + + /* link */ + busybox = busybox_fullpath(); + if (busybox) { + install_links(busybox, use_symbolic_links); + free(busybox); + } else { + rc = 1; + } + return rc; } #endif /* BB_FEATURE_INSTALLER */ |