From 7c3e97c18bf2e7ea2f82a33fa8cae17d30bd0deb Mon Sep 17 00:00:00 2001 From: Claudio Matsuoka Date: Tue, 5 Feb 2008 10:48:19 -0200 Subject: [PATCH] Add makepath() to avoid forking mkdir Signed-off-by: Claudio Matsuoka --- Makefile | 10 +--------- finit-mod.c | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 8baffb83..9b56c52e 100644 --- a/Makefile +++ b/Makefile @@ -9,15 +9,7 @@ LIBS = all: finit finit-mod finit-mdv -finit: finit.o - $(LD) $(LDFLAGS) -o $@ $+ $(LIBS) - strip $@ - -finit-mod: finit-mod.o - $(LD) $(LDFLAGS) -o $@ $+ $(LIBS) - strip $@ - -finit-mdv: finit-mdv.o +%: %.o $(LD) $(LDFLAGS) -o $@ $+ $(LIBS) strip $@ diff --git a/finit-mod.c b/finit-mod.c index 5df58148..fe204a85 100644 --- a/finit-mod.c +++ b/finit-mod.c @@ -27,7 +27,9 @@ THE SOFTWARE. Changelog from the original Eeepc fastinit: - Use mknod() instead of close(creat()) call to create empty file - +- Fix random seed initialization +- Don't try to handle signal 0 +- Implement makepath() to avoid system("mkdir -p") */ @@ -61,6 +63,23 @@ Changelog from the original Eeepc fastinit: #define touch(x) mknod((x), S_IFREG|0644, 0) +int makepath(char *p) +{ + char *x, path[PATH_MAX]; + int ret; + + x = path; + + do { + do { *x++ = *p++; } while (*p && *p != '/'); + ret = mkdir(path, 0777); + } while (*p && (*p != '/' || *(p + 1))); /* ignore trailing slash */ + + return ret; +} + + + void shutdown(int); void signal_handler(int); void chld_handler(int); @@ -145,8 +164,8 @@ int main() /* * Network stuff */ - system("mkdir -p /dev/shm/network"); - system("mkdir -p /dev/shm/resolvconf/interface"); + makepath("/dev/shm/network"); + makepath("/dev/shm/resolvconf/interface"); if ((dir = opendir("/etc/resolvconf/run/interface")) != NULL) { while ((d = readdir(dir)) != NULL) {