From 1c88ae1f613359beaa4acd8abf1157a9158bfe19 Mon Sep 17 00:00:00 2001 From: Claudio Matsuoka Date: Sun, 16 Mar 2008 12:47:37 -0300 Subject: [PATCH] Run-parts code cleanup and minor fixes Signed-off-by: Claudio Matsuoka --- Makefile | 4 +++- helpers.c | 18 +++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 007b5596..a126df6d 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ CFLAGS += -march=pentium-m #CFLAGS += -DDIRECTISA # Use built-in run-parts instead of /bin/run-parts -#CFLAGS += BUILTIN_RUNPARTS +CFLAGS += -DBUILTIN_RUNPARTS ifneq ($(USER), "user") CFLAGS += -DDEFUSER=\"$(USER)\" @@ -67,6 +67,8 @@ finit.o: finit.c Makefile finit-mod.o: finit-mod.c Makefile +helpers.o: helpers.c Makefile + dist: rm -Rf $(PKG) mkdir -p $(PKG)/contrib diff --git a/helpers.c b/helpers.c index 0572f455..8ecd45c3 100644 --- a/helpers.c +++ b/helpers.c @@ -117,24 +117,18 @@ int run_parts(char *dir, ...) char *args[NUM_ARGS]; va_list ap; - if ((d = opendir(dir)) == NULL) - return -1; - if (chdir(dir)) return -1; + if ((d = opendir(dir)) == NULL) + return -1; + va_start(ap, dir); while (argnum < NUM_ARGS && (args[argnum++] = va_arg(ap, char *))); va_end(ap); - while (1) { - if ((e = readdir(d)) == NULL) - break; - - if (e->d_type == DT_REG) { - if (stat(e->d_name, &st)) - continue; - + while ((e = readdir(d))) { + if (e->d_type == DT_REG && stat(e->d_name, &st) == 0) { if (st.st_mode & S_IXUSR) { ent[num++] = strdup(e->d_name); if (num >= NUM_SCRIPTS) @@ -143,6 +137,8 @@ int run_parts(char *dir, ...) } } + closedir(d); + if (num == 0) return 0;