From 50cff8ebc8dd531452e54ca8c411a0c6649e1f8e Mon Sep 17 00:00:00 2001
From: Roy Marples <roy@marples.name>
Date: Tue, 29 Apr 2008 10:49:50 +0000
Subject: Tweak the last commit and fix a valgrind error.

---
 src/rc/runscript.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

(limited to 'src')

diff --git a/src/rc/runscript.c b/src/rc/runscript.c
index af140d62..7b87c27f 100644
--- a/src/rc/runscript.c
+++ b/src/rc/runscript.c
@@ -1108,7 +1108,7 @@ int runscript(int argc, char **argv)
 	char lnk[PATH_MAX];
 	size_t l = 0;
 	size_t ll;
-	char *dir, *save;
+	char *dir, *save = NULL;
 	const char *file;
 	int depoptions = RC_DEP_TRACE;
 	struct stat stbuf;
@@ -1145,8 +1145,7 @@ int runscript(int argc, char **argv)
 				file = basename_c(argv[1]);
 			else
 				file = basename_c(lnk);
-			free(save);
-			dir = dirname(path);
+			dir = save; 
 		} else
 			file = basename_c(argv[1]);
 		ll = strlen(dir) + strlen(file) + 2;
@@ -1156,6 +1155,7 @@ int runscript(int argc, char **argv)
 			free(service);
 			service = xstrdup(lnk);
 		}
+		free(save);
 	}
 	if (!service)
 		service = xstrdup(path);
@@ -1200,11 +1200,15 @@ int runscript(int argc, char **argv)
 	if (rc_conf_yesno("rc_parallel")) {
 		/* Get the longest service name */
 		services = rc_services_in_runlevel(NULL);
-		TAILQ_FOREACH(svc, services, entries) {
-			ll = strlen(svc->value);
-			if (ll > l)
-				l = ll;
-		}
+		if (services) {
+			TAILQ_FOREACH(svc, services, entries) {
+				ll = strlen(svc->value);
+				if (ll > l)
+					l = ll;
+			}
+			rc_stringlist_free(services);
+			services = NULL;
+		} else l = strlen(applet);
 
 		/* Make our prefix string */
 		prefix = xmalloc(sizeof(char) * l + 1);
@@ -1292,6 +1296,7 @@ int runscript(int argc, char **argv)
 			prefix = NULL;
 			svc_exec(optarg, NULL);
 			eprefix(save);
+			prefix = save;
 		} else if (strcmp(optarg, "ineed") == 0 ||
 			   strcmp(optarg, "iuse") == 0 ||
 			   strcmp(optarg, "needsme") == 0 ||
-- 
cgit v1.2.3