Add makepath() to avoid forking mkdir

Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
This commit is contained in:
Claudio Matsuoka
2008-02-05 10:48:19 -02:00
parent 145da5712c
commit 7c3e97c18b
2 changed files with 23 additions and 12 deletions
+22 -3
View File
@@ -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) {