diff options
author | William Hubbs <williamh@gentoo.org> | 2011-12-11 01:18:08 -0600 |
---|---|---|
committer | William Hubbs <williamh@gentoo.org> | 2011-12-11 01:18:08 -0600 |
commit | 5e01051c4eccf1fc52b32b060478a534d34769ed (patch) | |
tree | dcfb915b8986e62506f695cef7a38bdad854fe85 /src/rc | |
parent | 8ea1190486f9194bac9dfcb355021ebc8e8c15ce (diff) |
Allow init scripts to be executed with a relative path
This was a regression that was caused by the fix for
http://bugs.gentoo.org/show_bug.cgi?id=350910. I am reverting the commit
that we said fixed that bug and re-opening it.
Reported-By: Nathaniel <nathaniel@paust.us
X-Gentoo-Bug: 392457
X-Gentoo-Bug-URL: http://bugs.gentoo.org/show_bug.cgi?id=392457
Diffstat (limited to 'src/rc')
-rw-r--r-- | src/rc/runscript.c | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/src/rc/runscript.c b/src/rc/runscript.c index 33065004..b460cc3c 100644 --- a/src/rc/runscript.c +++ b/src/rc/runscript.c @@ -1100,7 +1100,8 @@ runscript(int argc, char **argv) bool doneone = false; int retval, opt, depoptions = RC_DEP_TRACE; RC_STRING *svc; - char *save = NULL; + char path[PATH_MAX], lnk[PATH_MAX]; + char *dir, *save = NULL, *saveLnk = NULL; char pidstr[10]; size_t l = 0, ll; struct stat stbuf; @@ -1119,7 +1120,40 @@ runscript(int argc, char **argv) atexit(cleanup); - service = xstrdup(argv[1]); + /* We need to work out the real full path to our service. + * This works fine, provided that we ONLY allow multiplexed services + * to exist in the same directory as the master link. + * Also, the master link as to be a real file in the init dir. */ + if (!realpath(argv[1], path)) { + fprintf(stderr, "realpath: %s\n", strerror(errno)); + exit(EXIT_FAILURE); + } + memset(lnk, 0, sizeof(lnk)); + if (readlink(argv[1], lnk, sizeof(lnk)-1)) { + dir = dirname(path); + if (strchr(lnk, '/')) { + save = xstrdup(dir); + saveLnk = xstrdup(lnk); + dir = dirname(saveLnk); + if (strcmp(dir, save) == 0) + file = basename_c(argv[1]); + else + file = basename_c(lnk); + dir = save; + } else + file = basename_c(argv[1]); + ll = strlen(dir) + strlen(file) + 2; + service = xmalloc(ll); + snprintf(service, ll, "%s/%s", dir, file); + if (stat(service, &stbuf) != 0) { + free(service); + service = xstrdup(lnk); + } + free(save); + free(saveLnk); + } + if (!service) + service = xstrdup(path); applet = basename_c(service); if (argc < 3) |