]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
secret: Generate configDir during driver initialization
authorJohn Ferlan <jferlan@redhat.com>
Wed, 19 Apr 2017 20:40:45 +0000 (16:40 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Wed, 26 Apr 2017 17:27:15 +0000 (13:27 -0400)
Rather than waiting for the first save to fail, let's generate the
directory with the correct privs during initialization.

Signed-off-by: John Ferlan <jferlan@redhat.com>
src/secret/secret_driver.c

index 4c7fa1e80e67b40937e48fdf9a45fdc790b5385e..fc01e6d1b8fb46d312b638fb1e5a139c254f5929 100644 (file)
@@ -96,17 +96,6 @@ secretObjFromSecret(virSecretPtr secret)
 }
 
 
-static int
-secretEnsureDirectory(void)
-{
-    if (mkdir(driver->configDir, S_IRWXU) < 0 && errno != EEXIST) {
-        virReportSystemError(errno, _("cannot create '%s'"),
-                             driver->configDir);
-        return -1;
-    }
-    return 0;
-}
-
 /* Driver functions */
 
 static int
@@ -237,9 +226,6 @@ secretDefineXML(virConnectPtr conn,
         goto cleanup;
 
     if (!def->isephemeral) {
-        if (secretEnsureDirectory() < 0)
-            goto cleanup;
-
         if (backup && backup->isephemeral) {
             if (virSecretObjSaveData(obj) < 0)
                 goto restore_backup;
@@ -338,9 +324,6 @@ secretSetValue(virSecretPtr secret,
     if (virSecretSetValueEnsureACL(secret->conn, def) < 0)
         goto cleanup;
 
-    if (secretEnsureDirectory() < 0)
-        goto cleanup;
-
     if (virSecretObjSetValue(obj, value, value_size) < 0)
         goto cleanup;
 
@@ -481,6 +464,12 @@ secretStateInitialize(bool privileged,
         goto error;
     VIR_FREE(base);
 
+    if (virFileMakePathWithMode(driver->configDir, S_IRWXU) < 0) {
+        virReportSystemError(errno, _("cannot create config directory '%s'"),
+                             driver->configDir);
+        goto error;
+    }
+
     if (!(driver->secrets = virSecretObjListNew()))
         goto error;