[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[PATCH 3/7] Remove mkdirChain() from isys, use g_mkdir_with_parents()



Replace uses of mkdirChain() with g_mkdir_with_parents() and
remove the existing mkdirChain() code from isys/imount.*
---
 loader/driverdisk.c      |   15 +++++++++---
 loader/loader.c          |    6 +++-
 loader/method.c          |    6 +++-
 pyanaconda/isys/imount.c |   52 +--------------------------------------------
 pyanaconda/isys/imount.h |    1 -
 5 files changed, 21 insertions(+), 59 deletions(-)

diff --git a/loader/driverdisk.c b/loader/driverdisk.c
index 2688c82..9b4c710 100644
--- a/loader/driverdisk.c
+++ b/loader/driverdisk.c
@@ -265,9 +265,15 @@ static int loadDriverDisk(struct loaderData_s *loaderData, char *mntpt) {
     logMessage(DEBUGLVL, "Kernel version: %s", kernelver);
 
     sprintf(file, DD_RPMDIR_TEMPLATE, disknum);
-    mkdirChain(file);
-    mkdirChain(DD_MODULES);
-    mkdirChain(DD_FIRMWARE);
+
+    if (g_mkdir_with_parents(file, 0755) == -1)
+        logMessage(ERROR, "mkdir error on %s: %m", file);
+
+    if (g_mkdir_with_parents(DD_MODULES, 0755) == -1)
+        logMessage(ERROR, "mkdir error on %s: %m", DD_MODULES);
+
+    if (g_mkdir_with_parents(DD_FIRMWARE, 0755) == -1)
+        logMessage(ERROR, "mkdir error on %s: %m", DD_FIRMWARE);
 
     if (!FL_CMDLINE(flags)) {
         startNewt();
@@ -293,7 +299,8 @@ static int loadDriverDisk(struct loaderData_s *loaderData, char *mntpt) {
 
     /* ensure updates directory exists */
     sprintf(file, "/lib/modules/%s/updates", kernelver);
-    mkdirChain(file);
+    if (g_mkdir_with_parents(file, 0755) == -1)
+        logMessage(ERROR, "mkdir error on %s: %m", file);
 
     /* make sure driver update are referenced from system module dir
        but from a different subdir, initrd overlays use the main
diff --git a/loader/loader.c b/loader/loader.c
index 88d7a7a..50daeb0 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -2146,8 +2146,10 @@ int main(int argc, char ** argv) {
 
     /* make sure /tmp/updates exists so that magic in anaconda to */
     /* symlink rhpl/ will work                                    */
-    if (access("/tmp/updates", F_OK))
-        mkdirChain("/tmp/updates");
+    if (access("/tmp/updates", F_OK)) {
+        if (g_mkdir_with_parents("/tmp/updates", 0755) == -1)
+            logMessage(ERROR, "mkdir error on /tmp/updates: %m");
+    }
 
     add_fw_search_dir(&loaderData, "/tmp/updates/firmware");
     add_fw_search_dir(&loaderData, "/tmp/product/firmware");
diff --git a/loader/method.c b/loader/method.c
index 844048f..d84a2e8 100644
--- a/loader/method.c
+++ b/loader/method.c
@@ -313,8 +313,10 @@ int unpackCpioBall(char * ballPath, char * rootDir) {
     if (access(ballPath, R_OK))
         return 1;
 
-    if (access(rootDir, R_OK))
-        mkdirChain(rootDir);
+    if (access(rootDir, R_OK)) {
+        if (g_mkdir_with_parents(rootDir, 0755) == -1)
+            logMessage(ERROR, "mkdir error on %s: %m", rootDir);
+    }
 
     buf = (char *)malloc(PATH_MAX);
     cwd = getcwd(buf, PATH_MAX);
diff --git a/pyanaconda/isys/imount.c b/pyanaconda/isys/imount.c
index ed0f5a7..39265a0 100644
--- a/pyanaconda/isys/imount.c
+++ b/pyanaconda/isys/imount.c
@@ -27,14 +27,13 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <unistd.h>
+#include <glib.h>
 
 #include "imount.h"
 #include "log.h"
 
 #define _(foo) foo
 
-static int mkdirIfNone(char * directory);
-
 static int readFD(int fd, char **buf) {
     char *p;
     size_t size = 4096;
@@ -88,7 +87,7 @@ int mountCommandWrapper(int mode, char *dev, char *where, char *fs,
     case IMOUNT_MODE_MOUNT:
     case IMOUNT_MODE_BIND:
         cmd = "/bin/mount";
-        if (mkdirChain(where))
+        if (g_mkdir_with_parents(where, 0755))
             return IMOUNT_ERR_ERRNO;
         break;
     case IMOUNT_MODE_UMOUNT:
@@ -264,31 +263,6 @@ int doPwUmount(char *where, char **err) {
                                NULL, where, NULL, NULL, err);
 }
 
-int mkdirChain(char * origChain) {
-    char * chain;
-    char * chptr;
-
-    chain = alloca(strlen(origChain) + 1);
-    strcpy(chain, origChain);
-    chptr = chain;
-
-    while ((chptr = strchr(chptr, '/'))) {
-	*chptr = '\0';
-	if (mkdirIfNone(chain)) {
-	    *chptr = '/';
-	    return IMOUNT_ERR_ERRNO;
-	}
-
-	*chptr = '/';
-	chptr++;
-    }
-
-    if (mkdirIfNone(chain))
-	return IMOUNT_ERR_ERRNO;
-
-    return 0;
-}
-
 /* Returns true iff it is possible that the mount command that have returned
  * 'errno' might succeed at a later time (think e.g. not yet initialized USB
  * device, etc.) */
@@ -304,25 +278,3 @@ int mountMightSucceedLater(int mountRc)
     }
     return rc;
 }
-
-static int mkdirIfNone(char * directory) {
-    int rc, mkerr;
-    char * chptr;
-
-    /* If the file exists it *better* be a directory -- I'm not going to
-       actually check or anything */
-    if (!access(directory, X_OK)) return 0;
-
-    /* if the path is '/' we get ENOFILE not found" from mkdir, rather
-       then EEXIST which is weird */
-    for (chptr = directory; *chptr; chptr++)
-        if (*chptr != '/') break;
-    if (!*chptr) return 0;
-
-    rc = mkdir(directory, 0755);
-    mkerr = errno;
-
-    if (!rc || mkerr == EEXIST) return 0;
-
-    return IMOUNT_ERR_ERRNO;
-}
diff --git a/pyanaconda/isys/imount.h b/pyanaconda/isys/imount.h
index d1b7cf3..3ce6387 100644
--- a/pyanaconda/isys/imount.h
+++ b/pyanaconda/isys/imount.h
@@ -44,7 +44,6 @@
 int doBindMount(char* path, char *where, char **err);
 int doPwMount(char *dev, char *where, char *fs, char *options, char **err);
 int doPwUmount(char *where, char **err);
-int mkdirChain(char * origChain);
 int mountMightSucceedLater(int mountRc);
 
 #endif
-- 
1.7.2.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]