summaryrefslogtreecommitdiff
path: root/src/rc/runscript.c
diff options
context:
space:
mode:
authorChristian Ruppert <idl0r@gentoo.org>2011-05-23 20:15:15 +0200
committerWilliam Hubbs <williamh@gentoo.org>2011-05-23 14:23:15 -0500
commitd59e245bc7edc05e5d7a77df25717029b0710c55 (patch)
tree659d194bbcbc881cb6fc7a328e32608cd27ceaf6 /src/rc/runscript.c
parent74c8667497425746b3d2eaaf88cae1ac2bdf34f5 (diff)
downloadopenrc-d59e245bc7edc05e5d7a77df25717029b0710c55.tar.gz
openrc-d59e245bc7edc05e5d7a77df25717029b0710c55.tar.bz2
openrc-d59e245bc7edc05e5d7a77df25717029b0710c55.tar.xz
Fix dirname calls in runscript
runscript will try to get the dir and basename of a file/link in case it contains at least one slash. This patch gives a temporary copy of the path to the dirname() function since dirname() can modify its argument.
Diffstat (limited to 'src/rc/runscript.c')
-rw-r--r--src/rc/runscript.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/rc/runscript.c b/src/rc/runscript.c
index 0eca487..58eb609 100644
--- a/src/rc/runscript.c
+++ b/src/rc/runscript.c
@@ -1101,7 +1101,8 @@ runscript(int argc, char **argv)
bool doneone = false;
int retval, opt, depoptions = RC_DEP_TRACE;
RC_STRING *svc;
- char path[PATH_MAX], lnk[PATH_MAX], *dir, *save = NULL, pidstr[10];
+ char path[PATH_MAX], lnk[PATH_MAX], *dir, *save = NULL, *save2 = NULL;
+ char pidstr[10];
size_t l = 0, ll;
const char *file;
struct stat stbuf;
@@ -1133,7 +1134,8 @@ runscript(int argc, char **argv)
dir = dirname(path);
if (strchr(lnk, '/')) {
save = xstrdup(dir);
- dir = dirname(lnk);
+ save2 = xstrdup(lnk);
+ dir = dirname(save2);
if (strcmp(dir, save) == 0)
file = basename_c(argv[1]);
else
@@ -1149,6 +1151,7 @@ runscript(int argc, char **argv)
service = xstrdup(lnk);
}
free(save);
+ free(save2);
}
if (!service)
service = xstrdup(path);