[patch 3/9] Make iptables code use common utils

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

 



utils.c has grown some functions since the iptables code
was written - make use of virFileMakePath() and virFileBuildPath().

Signed-off-by: Mark McLoughlin <markmc@xxxxxxxxxx>

Index: libvirt/src/iptables.c
===================================================================
--- libvirt.orig/src/iptables.c	2008-01-04 09:46:19.000000000 +0000
+++ libvirt.orig/src/iptables.c	2008-01-04 09:46:19.000000000 +0000
@@ -44,6 +44,7 @@
 
 #include "internal.h"
 #include "iptables.h"
+#include "util.h"
 
 #define qemudLog(level, msg...) fprintf(stderr, msg)
 
@@ -135,60 +136,6 @@ writeRules(const char *path,
 
     return 0;
 }
-
-static int
-ensureDir(const char *path)
-{
-    struct stat st;
-    char parent[PATH_MAX];
-    char *p;
-    int err;
-
-    if (stat(path, &st) >= 0)
-        return 0;
-
-    strncpy(parent, path, PATH_MAX);
-    parent[PATH_MAX - 1] = '\0';
-
-    if (!(p = strrchr(parent, '/')))
-        return EINVAL;
-
-    if (p == parent)
-        return EPERM;
-
-    *p = '\0';
-
-    if ((err = ensureDir(parent)))
-        return err;
-
-    if (mkdir(path, 0700) < 0 && errno != EEXIST)
-        return errno;
-
-    return 0;
-}
-
-static int
-buildDir(const char *table,
-         char *path,
-         int maxlen)
-{
-    if (snprintf(path, maxlen, IPTABLES_DIR "/%s", table) >= maxlen)
-        return EINVAL;
-    else
-        return 0;
-}
-
-static int
-buildPath(const char *table,
-          const char *chain,
-          char *path,
-          int maxlen)
-{
-    if (snprintf(path, maxlen, IPTABLES_DIR "/%s/%s.chain", table, chain) >= maxlen)
-        return EINVAL;
-    else
-        return 0;
-}
 #endif /* IPTABLES_DIR */
 
 static void
@@ -235,7 +182,7 @@ iptRulesAppend(iptRules *rules,
     {
         int err;
 
-        if ((err = ensureDir(rules->dir)))
+        if ((err = virFileMakePath(rules->dir)))
             return err;
 
         if ((err = writeRules(rules->path, rules->rules, rules->nrules)))
@@ -332,10 +279,10 @@ iptRulesNew(const char *table,
     rules->nrules = 0;
 
 #ifdef IPTABLES_DIR
-    if (buildDir(table, rules->dir, sizeof(rules->dir)))
+    if (virFileBuildPath(IPTABLES_DIR, table, NULL, rules->dir, sizeof(rules->dir)) < 0)
         goto error;
 
-    if (buildPath(table, chain, rules->path, sizeof(rules->path)))
+    if (virFileBuildPath(rules->dir, chain, ".chain", rules->path, sizeof(rules->path)) < 0)
         goto error;
 #endif /* IPTABLES_DIR */
 

-- 

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]