[PATCH 12/14] secret: Generate configDir during driver initialization

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

 



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@xxxxxxxxxx>
---
 src/secret/secret_driver.c | 23 ++++++-----------------
 1 file changed, 6 insertions(+), 17 deletions(-)

diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c
index 2d4091d..8ddae57 100644
--- a/src/secret/secret_driver.c
+++ b/src/secret/secret_driver.c
@@ -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
@@ -238,9 +227,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;
@@ -341,9 +327,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;
 
@@ -488,6 +471,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;
 
-- 
2.9.3

--
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]
  Powered by Linux