]> xenbits.xensource.com Git - libvirt.git/commitdiff
Fri Feb 20 16:49:53 IST 2007 Mark McLoughlin <markmc@redhat.com>
authorMark McLoughlin <markmc@redhat.com>
Tue, 20 Feb 2007 16:55:56 +0000 (16:55 +0000)
committerMark McLoughlin <markmc@redhat.com>
Tue, 20 Feb 2007 16:55:56 +0000 (16:55 +0000)
        * qemud/conf.c, qemud/qemud.c: only create config dirs
        when actually trying to write out config.

ChangeLog
qemud/conf.c
qemud/qemud.c

index 05032f9ccb0549c1ffcb632dc0519aff089947a4..47983c80ea1fa093585e6c87c8d39fb590c089cb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Fri Feb 20 16:49:53 IST 2007 Mark McLoughlin <markmc@redhat.com>
+
+       * qemud/conf.c, qemud/qemud.c: only create config dirs
+       when actually trying to write out config.
+
 Fri Feb 20 09:56:35 IST 2007 Mark McLoughlin <markmc@redhat.com>
 
        * qemud/bridge.c: change the fix for the alignment warning
index 7dd58e6aa80a88b6f1ff018dae26490b1095af66..b4f76f0893368fe4eab263939ae9915d8f81c1a1 100644 (file)
@@ -138,31 +138,32 @@ qemudMakeConfigPath(const char *configDir,
 }
 
 static int
-qemudEnsureConfigDir(struct qemud_server *server,
-                     const char *configDir) {
-    struct stat sb;
+qemudEnsureDir(const char *path)
+{
+    struct stat st;
+    char parent[PATH_MAX];
+    char *p;
+    int err;
 
-    /* XXX: needs to be recursive */
+    if (stat(path, &st) >= 0)
+        return 0;
 
-    if (stat(configDir, &sb) < 0) {
-        if (errno == ENOENT) {
-            if (mkdir(configDir, 0700) < 0) {
-                qemudReportError(server, VIR_ERR_INTERNAL_ERROR,
-                                 "cannot create config directory %s: %s",
-                                 configDir, strerror(errno));
-                return -1;
-            }
-        } else {
-            qemudReportError(server, VIR_ERR_INTERNAL_ERROR,
-                             "cannot stat config directory %s",
-                             configDir, strerror(errno));
-            return -1;
-        }
-    } else if (!S_ISDIR(sb.st_mode)) {
-        qemudReportError(server, VIR_ERR_INTERNAL_ERROR,
-                         "config directory %s is not a directory", configDir);
-        return -1;
-    }
+    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 = qemudEnsureDir(parent)))
+        return err;
+
+    if (mkdir(path, 0777) < 0 && errno != EEXIST)
+        return errno;
 
     return 0;
 }
@@ -1138,12 +1139,16 @@ static int qemudSaveConfig(struct qemud_server *server,
     char *xml;
     int fd = -1, ret = -1;
     int towrite;
+    int err;
 
     if (!(xml = qemudGenerateXML(server, vm, 0))) {
         return -1;
     }
 
-    if (qemudEnsureConfigDir(server, server->configDir) < 0) {
+    if ((err = qemudEnsureDir(server->configDir))) {
+        qemudReportError(server, VIR_ERR_INTERNAL_ERROR,
+                         "cannot create config directory %s: %s",
+                         server->configDir, strerror(err));
         goto cleanup;
     }
 
@@ -1268,12 +1273,16 @@ static int qemudSaveNetworkConfig(struct qemud_server *server,
     char *xml;
     int fd, ret = -1;
     int towrite;
+    int err;
 
     if (!(xml = qemudGenerateNetworkXML(server, network, 0))) {
         return -1;
     }
 
-    if (qemudEnsureConfigDir(server, server->networkConfigDir) < 0) {
+    if ((err = qemudEnsureDir(server->networkConfigDir))) {
+        qemudReportError(server, VIR_ERR_INTERNAL_ERROR,
+                         "cannot create config directory %s: %s",
+                         server->networkConfigDir, strerror(err));
         goto cleanup;
     }
 
index aeb7c1ebc23ce97816b3fa8e49d71e1bce1703bb..79ce4db92884edc566250970c9ad0ebe92b51857 100644 (file)
@@ -350,37 +350,6 @@ static int qemudListenUnix(struct qemud_server *server,
     return 0;
 }
 
-static int
-qemudEnsureDir(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 = qemudEnsureDir(parent)))
-        return err;
-
-    if (mkdir(path, 0777) < 0 && errno != EEXIST)
-        return errno;
-
-    return 0;
-}
-
 static int qemudInitPaths(int sys,
                           char *configDir,
                           char *networkConfigDir,
@@ -388,7 +357,6 @@ static int qemudInitPaths(int sys,
                           char *roSockname,
                           int maxlen) {
     uid_t uid;
-    int err;
 
     uid = geteuid();
 
@@ -432,18 +400,6 @@ static int qemudInitPaths(int sys,
             goto snprintf_error;
     }
 
-    if ((err = qemudEnsureDir(configDir))) {
-        qemudLog(QEMUD_ERR, "Failed to create directory '%s': %s",
-                 configDir, strerror(err));
-        return -1;
-    }
-
-    if ((err = qemudEnsureDir(networkConfigDir))) {
-        qemudLog(QEMUD_ERR, "Failed to create directory '%s': %s",
-                 networkConfigDir, strerror(err));
-        return -1;
-    }
-
     return 0;
 
  snprintf_error: