secret: Generate configDir during driver initialization

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>
This commit is contained in:
John Ferlan 2017-04-19 16:40:45 -04:00
parent 24d33d18ba
commit 6fcbdf7308

View 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;