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

[PATCH 8/8] 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.*

Added a wrapper function for g_mkdir_with_parents() usage.
---
 loader/driverdisk.c      |   12 +++++++---
 loader/loader.c          |   14 ++++++------
 loader/unpack.c          |   26 +++++++++++++++++-----
 loader/unpack.h          |    1 +
 pyanaconda/isys/imount.c |   52 +--------------------------------------------
 pyanaconda/isys/imount.h |    1 -
 6 files changed, 38 insertions(+), 68 deletions(-)

diff --git a/loader/driverdisk.c b/loader/driverdisk.c
index 91dbd51..28fe612 100644
--- a/loader/driverdisk.c
+++ b/loader/driverdisk.c
@@ -54,6 +54,7 @@
 #include "urlinstall.h"
 
 #include "rpmextract.h"
+#include "unpack.h"
 
 #include "../pyanaconda/isys/isys.h"
 #include "../pyanaconda/isys/imount.h"
@@ -243,9 +244,11 @@ 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 (unpack_mkpath(file) != ARCHIVE_OK ||
+        unpack_mkpath(DD_MODULES) != ARCHIVE_OK ||
+        unpack_mkpath(DD_FIRMWARE) != ARCHIVE_OK)
+        goto loadDriverDiscException;
 
     if (!FL_CMDLINE(flags)) {
         startNewt();
@@ -271,7 +274,8 @@ static int loadDriverDisk(struct loaderData_s *loaderData, char *mntpt) {
 
     /* ensure updates directory exists */
     sprintf(file, "/lib/modules/%s/updates", kernelver);
-    mkdirChain(file);
+    if (unpack_mkpath(file) != ARCHIVE_OK)
+        goto loadDriverDiscException;
 
     /* 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..05cb784 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -90,6 +90,7 @@
 #include "ibft.h"
 #include "net.h"
 #include "readvars.h"
+#include "unpack.h"
 
 #include <selinux/selinux.h>
 #include "selinux.h"
@@ -2146,17 +2147,16 @@ 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 (unpack_mkpath("/tmp/updates") == ARCHIVE_OK) {
+        add_fw_search_dir(&loaderData, "/tmp/updates/firmware");
+        add_to_path_env("PYTHONPATH", "/tmp/updates");
+        add_to_path_env("LD_LIBRARY_PATH", "/tmp/updates");
+        add_to_path_env("PATH", "/tmp/updates");
+    }
 
-    add_fw_search_dir(&loaderData, "/tmp/updates/firmware");
     add_fw_search_dir(&loaderData, "/tmp/product/firmware");
-
-    add_to_path_env("PYTHONPATH", "/tmp/updates");
     add_to_path_env("PYTHONPATH", "/tmp/product");
-    add_to_path_env("LD_LIBRARY_PATH", "/tmp/updates");
     add_to_path_env("LD_LIBRARY_PATH", "/tmp/product");
-    add_to_path_env("PATH", "/tmp/updates");
     add_to_path_env("PATH", "/tmp/product");
 
     stop_fw_loader(&loaderData);
diff --git a/loader/unpack.c b/loader/unpack.c
index f3fa205..c7b47e8 100644
--- a/loader/unpack.c
+++ b/loader/unpack.c
@@ -29,6 +29,24 @@
 #include "../pyanaconda/isys/log.h"
 
 /*
+ * Wrapper for g_mkdir_with_parents()
+ */
+int unpack_mkpath(char *path) {
+    if (path == NULL)
+        return ARCHIVE_FATAL;
+
+    if (access(path, R_OK|W_OK|X_OK)) {
+        if (g_mkdir_with_parents(path, 0755) == -1) {
+            logMessage(ERROR, "unable to mkdir %s (%s:%d): %m",
+                       path, __func__, __LINE__);
+            return ARCHIVE_FATAL;
+        }
+    }
+
+    return ARCHIVE_OK;
+}
+
+/*
  * Initialize libarchive object for unpacking an archive file.
  * Args:
  *     struct archive **a      The archive object to use.
@@ -69,12 +87,8 @@ int unpack_members_and_finish(struct archive *a, char *dest) {
     }
 
     if (dest != NULL) {
-        if (access(dest, R_OK|W_OK|X_OK)) {
-            if (g_mkdir_with_parents(dest, 0755) == -1) {
-                logMessage(ERROR, "unable to mkdir %s (%s:%d): %m",
-                           dest, __func__, __LINE__);
-                return ARCHIVE_FATAL;
-            }
+        if (unpack_mkpath(dest) != ARCHIVE_OK) {
+            return ARCHIVE_FATAL;
         } else if (chdir(dest) == -1) {
             logMessage(ERROR, "unable to chdir %s (%s:%d): %m",
                        dest, __func__, __LINE__);
diff --git a/loader/unpack.h b/loader/unpack.h
index 0ce1fac..ebc67bb 100644
--- a/loader/unpack.h
+++ b/loader/unpack.h
@@ -24,6 +24,7 @@
 
 #include <archive.h>
 
+int unpack_mkpath(char *);
 int unpack_init(struct archive **);
 int unpack_members_and_finish(struct archive *, char *);
 int unpack_archive_file(char *, char *);
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.3.2


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