mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
Fix return value semantic of virFileMakePath
Some callers expected virFileMakePath to set errno, some expected it to return an errno value. Unify this to return 0 on success and -1 on error. Set errno to report detailed error information. Also optimize virFileMakePath if stat fails with an errno different from ENOENT.
This commit is contained in:
parent
c7694e3e50
commit
e123e1ee6b
@ -9989,7 +9989,7 @@ int virDomainSaveXML(const char *configDir,
|
|||||||
if ((configFile = virDomainConfigFile(configDir, def->name)) == NULL)
|
if ((configFile = virDomainConfigFile(configDir, def->name)) == NULL)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virFileMakePath(configDir)) {
|
if (virFileMakePath(configDir) < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("cannot create config directory '%s'"),
|
_("cannot create config directory '%s'"),
|
||||||
configDir);
|
configDir);
|
||||||
|
@ -1114,13 +1114,12 @@ int virNetworkSaveXML(const char *configDir,
|
|||||||
char *configFile = NULL;
|
char *configFile = NULL;
|
||||||
int fd = -1, ret = -1;
|
int fd = -1, ret = -1;
|
||||||
size_t towrite;
|
size_t towrite;
|
||||||
int err;
|
|
||||||
|
|
||||||
if ((configFile = virNetworkConfigFile(configDir, def->name)) == NULL)
|
if ((configFile = virNetworkConfigFile(configDir, def->name)) == NULL)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((err = virFileMakePath(configDir))) {
|
if (virFileMakePath(configDir) < 0) {
|
||||||
virReportSystemError(err,
|
virReportSystemError(errno,
|
||||||
_("cannot create config directory '%s'"),
|
_("cannot create config directory '%s'"),
|
||||||
configDir);
|
configDir);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -2184,13 +2184,12 @@ int virNWFilterSaveXML(const char *configDir,
|
|||||||
char *configFile = NULL;
|
char *configFile = NULL;
|
||||||
int fd = -1, ret = -1;
|
int fd = -1, ret = -1;
|
||||||
size_t towrite;
|
size_t towrite;
|
||||||
int err;
|
|
||||||
|
|
||||||
if ((configFile = virNWFilterConfigFile(configDir, def->name)) == NULL)
|
if ((configFile = virNWFilterConfigFile(configDir, def->name)) == NULL)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((err = virFileMakePath(configDir))) {
|
if (virFileMakePath(configDir) < 0) {
|
||||||
virReportSystemError(err,
|
virReportSystemError(errno,
|
||||||
_("cannot create config directory '%s'"),
|
_("cannot create config directory '%s'"),
|
||||||
configDir);
|
configDir);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -2574,10 +2573,8 @@ virNWFilterObjSaveDef(virNWFilterDriverStatePtr driver,
|
|||||||
ssize_t towrite;
|
ssize_t towrite;
|
||||||
|
|
||||||
if (!nwfilter->configFile) {
|
if (!nwfilter->configFile) {
|
||||||
int err;
|
if (virFileMakePath(driver->configDir) < 0) {
|
||||||
|
virReportSystemError(errno,
|
||||||
if ((err = virFileMakePath(driver->configDir))) {
|
|
||||||
virReportSystemError(err,
|
|
||||||
_("cannot create config directory %s"),
|
_("cannot create config directory %s"),
|
||||||
driver->configDir);
|
driver->configDir);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1512,10 +1512,8 @@ virStoragePoolObjSaveDef(virStorageDriverStatePtr driver,
|
|||||||
ssize_t towrite;
|
ssize_t towrite;
|
||||||
|
|
||||||
if (!pool->configFile) {
|
if (!pool->configFile) {
|
||||||
int err;
|
if (virFileMakePath(driver->configDir) < 0) {
|
||||||
|
virReportSystemError(errno,
|
||||||
if ((err = virFileMakePath(driver->configDir))) {
|
|
||||||
virReportSystemError(err,
|
|
||||||
_("cannot create config directory %s"),
|
_("cannot create config directory %s"),
|
||||||
driver->configDir);
|
driver->configDir);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -914,25 +914,25 @@ libxlStartup(int privileged) {
|
|||||||
"%s", LIBXL_SAVE_DIR) == -1)
|
"%s", LIBXL_SAVE_DIR) == -1)
|
||||||
goto out_of_memory;
|
goto out_of_memory;
|
||||||
|
|
||||||
if (virFileMakePath(libxl_driver->logDir) != 0) {
|
if (virFileMakePath(libxl_driver->logDir) < 0) {
|
||||||
char ebuf[1024];
|
char ebuf[1024];
|
||||||
VIR_ERROR(_("Failed to create log dir '%s': %s"),
|
VIR_ERROR(_("Failed to create log dir '%s': %s"),
|
||||||
libxl_driver->logDir, virStrerror(errno, ebuf, sizeof ebuf));
|
libxl_driver->logDir, virStrerror(errno, ebuf, sizeof ebuf));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (virFileMakePath(libxl_driver->stateDir) != 0) {
|
if (virFileMakePath(libxl_driver->stateDir) < 0) {
|
||||||
char ebuf[1024];
|
char ebuf[1024];
|
||||||
VIR_ERROR(_("Failed to create state dir '%s': %s"),
|
VIR_ERROR(_("Failed to create state dir '%s': %s"),
|
||||||
libxl_driver->stateDir, virStrerror(errno, ebuf, sizeof ebuf));
|
libxl_driver->stateDir, virStrerror(errno, ebuf, sizeof ebuf));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (virFileMakePath(libxl_driver->libDir) != 0) {
|
if (virFileMakePath(libxl_driver->libDir) < 0) {
|
||||||
char ebuf[1024];
|
char ebuf[1024];
|
||||||
VIR_ERROR(_("Failed to create lib dir '%s': %s"),
|
VIR_ERROR(_("Failed to create lib dir '%s': %s"),
|
||||||
libxl_driver->libDir, virStrerror(errno, ebuf, sizeof ebuf));
|
libxl_driver->libDir, virStrerror(errno, ebuf, sizeof ebuf));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (virFileMakePath(libxl_driver->saveDir) != 0) {
|
if (virFileMakePath(libxl_driver->saveDir) < 0) {
|
||||||
char ebuf[1024];
|
char ebuf[1024];
|
||||||
VIR_ERROR(_("Failed to create save dir '%s': %s"),
|
VIR_ERROR(_("Failed to create save dir '%s': %s"),
|
||||||
libxl_driver->saveDir, virStrerror(errno, ebuf, sizeof ebuf));
|
libxl_driver->saveDir, virStrerror(errno, ebuf, sizeof ebuf));
|
||||||
@ -3389,10 +3389,8 @@ libxlDomainSetAutostart(virDomainPtr dom, int autostart)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (autostart) {
|
if (autostart) {
|
||||||
int err;
|
if (virFileMakePath(driver->autostartDir) < 0) {
|
||||||
|
virReportSystemError(errno,
|
||||||
if ((err = virFileMakePath(driver->autostartDir))) {
|
|
||||||
virReportSystemError(err,
|
|
||||||
_("cannot create autostart directory %s"),
|
_("cannot create autostart directory %s"),
|
||||||
driver->autostartDir);
|
driver->autostartDir);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -308,7 +308,7 @@ static int lxcContainerChildMountSort(const void *a, const void *b)
|
|||||||
|
|
||||||
static int lxcContainerPivotRoot(virDomainFSDefPtr root)
|
static int lxcContainerPivotRoot(virDomainFSDefPtr root)
|
||||||
{
|
{
|
||||||
int rc, ret;
|
int ret;
|
||||||
char *oldroot = NULL, *newroot = NULL;
|
char *oldroot = NULL, *newroot = NULL;
|
||||||
|
|
||||||
ret = -1;
|
ret = -1;
|
||||||
@ -325,8 +325,8 @@ static int lxcContainerPivotRoot(virDomainFSDefPtr root)
|
|||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rc = virFileMakePath(oldroot)) != 0) {
|
if (virFileMakePath(oldroot) < 0) {
|
||||||
virReportSystemError(rc,
|
virReportSystemError(errno,
|
||||||
_("Failed to create %s"),
|
_("Failed to create %s"),
|
||||||
oldroot);
|
oldroot);
|
||||||
goto err;
|
goto err;
|
||||||
@ -347,8 +347,8 @@ static int lxcContainerPivotRoot(virDomainFSDefPtr root)
|
|||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rc = virFileMakePath(newroot)) != 0) {
|
if (virFileMakePath(newroot) < 0) {
|
||||||
virReportSystemError(rc,
|
virReportSystemError(errno,
|
||||||
_("Failed to create %s"),
|
_("Failed to create %s"),
|
||||||
newroot);
|
newroot);
|
||||||
goto err;
|
goto err;
|
||||||
@ -415,7 +415,7 @@ static int lxcContainerMountBasicFS(virDomainFSDefPtr root)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0 ; i < ARRAY_CARDINALITY(mnts) ; i++) {
|
for (i = 0 ; i < ARRAY_CARDINALITY(mnts) ; i++) {
|
||||||
if (virFileMakePath(mnts[i].dst) != 0) {
|
if (virFileMakePath(mnts[i].dst) < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Failed to mkdir %s"),
|
_("Failed to mkdir %s"),
|
||||||
mnts[i].src);
|
mnts[i].src);
|
||||||
@ -429,8 +429,8 @@ static int lxcContainerMountBasicFS(virDomainFSDefPtr root)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rc = virFileMakePath("/dev/pts") != 0)) {
|
if (virFileMakePath("/dev/pts") < 0) {
|
||||||
virReportSystemError(rc, "%s",
|
virReportSystemError(errno, "%s",
|
||||||
_("Cannot create /dev/pts"));
|
_("Cannot create /dev/pts"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -531,7 +531,7 @@ static int lxcContainerMountNewFS(virDomainDefPtr vmDef)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virFileMakePath(vmDef->fss[i]->dst) != 0) {
|
if (virFileMakePath(vmDef->fss[i]->dst) < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Failed to create %s"),
|
_("Failed to create %s"),
|
||||||
vmDef->fss[i]->dst);
|
vmDef->fss[i]->dst);
|
||||||
|
@ -690,7 +690,7 @@ lxcControllerRun(virDomainDefPtr def,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virFileMakePath(devpts) != 0) {
|
if (virFileMakePath(devpts) < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Failed to make path %s"),
|
_("Failed to make path %s"),
|
||||||
devpts);
|
devpts);
|
||||||
|
@ -1502,8 +1502,8 @@ static int lxcVmStart(virConnectPtr conn,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((r = virFileMakePath(driver->logDir)) != 0) {
|
if (virFileMakePath(driver->logDir) < 0) {
|
||||||
virReportSystemError(r,
|
virReportSystemError(errno,
|
||||||
_("Cannot create log directory '%s'"),
|
_("Cannot create log directory '%s'"),
|
||||||
driver->logDir);
|
driver->logDir);
|
||||||
return -1;
|
return -1;
|
||||||
@ -2539,10 +2539,8 @@ static int lxcDomainSetAutostart(virDomainPtr dom,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (autostart) {
|
if (autostart) {
|
||||||
int err;
|
if (virFileMakePath(driver->autostartDir) < 0) {
|
||||||
|
virReportSystemError(errno,
|
||||||
if ((err = virFileMakePath(driver->autostartDir))) {
|
|
||||||
virReportSystemError(err,
|
|
||||||
_("Cannot create autostart directory %s"),
|
_("Cannot create autostart directory %s"),
|
||||||
driver->autostartDir);
|
driver->autostartDir);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -692,17 +692,16 @@ networkStartDhcpDaemon(virNetworkObjPtr network)
|
|||||||
virCommandPtr cmd = NULL;
|
virCommandPtr cmd = NULL;
|
||||||
char *pidfile = NULL;
|
char *pidfile = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int err;
|
|
||||||
dnsmasqContext *dctx = NULL;
|
dnsmasqContext *dctx = NULL;
|
||||||
|
|
||||||
if ((err = virFileMakePath(NETWORK_PID_DIR)) != 0) {
|
if (virFileMakePath(NETWORK_PID_DIR) < 0) {
|
||||||
virReportSystemError(err,
|
virReportSystemError(errno,
|
||||||
_("cannot create directory %s"),
|
_("cannot create directory %s"),
|
||||||
NETWORK_PID_DIR);
|
NETWORK_PID_DIR);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if ((err = virFileMakePath(NETWORK_STATE_DIR)) != 0) {
|
if (virFileMakePath(NETWORK_STATE_DIR) < 0) {
|
||||||
virReportSystemError(err,
|
virReportSystemError(errno,
|
||||||
_("cannot create directory %s"),
|
_("cannot create directory %s"),
|
||||||
NETWORK_STATE_DIR);
|
NETWORK_STATE_DIR);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -713,8 +712,8 @@ networkStartDhcpDaemon(virNetworkObjPtr network)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = virFileMakePath(DNSMASQ_STATE_DIR)) != 0) {
|
if (virFileMakePath(DNSMASQ_STATE_DIR) < 0) {
|
||||||
virReportSystemError(err,
|
virReportSystemError(errno,
|
||||||
_("cannot create directory %s"),
|
_("cannot create directory %s"),
|
||||||
DNSMASQ_STATE_DIR);
|
DNSMASQ_STATE_DIR);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -764,7 +763,7 @@ networkStartRadvd(virNetworkObjPtr network)
|
|||||||
char *configstr = NULL;
|
char *configstr = NULL;
|
||||||
char *configfile = NULL;
|
char *configfile = NULL;
|
||||||
virCommandPtr cmd = NULL;
|
virCommandPtr cmd = NULL;
|
||||||
int ret = -1, err, ii;
|
int ret = -1, ii;
|
||||||
virNetworkIpDefPtr ipdef;
|
virNetworkIpDefPtr ipdef;
|
||||||
|
|
||||||
network->radvdPid = -1;
|
network->radvdPid = -1;
|
||||||
@ -777,14 +776,14 @@ networkStartRadvd(virNetworkObjPtr network)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = virFileMakePath(NETWORK_PID_DIR)) != 0) {
|
if (virFileMakePath(NETWORK_PID_DIR) < 0) {
|
||||||
virReportSystemError(err,
|
virReportSystemError(errno,
|
||||||
_("cannot create directory %s"),
|
_("cannot create directory %s"),
|
||||||
NETWORK_PID_DIR);
|
NETWORK_PID_DIR);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if ((err = virFileMakePath(RADVD_STATE_DIR)) != 0) {
|
if (virFileMakePath(RADVD_STATE_DIR) < 0) {
|
||||||
virReportSystemError(err,
|
virReportSystemError(errno,
|
||||||
_("cannot create directory %s"),
|
_("cannot create directory %s"),
|
||||||
RADVD_STATE_DIR);
|
RADVD_STATE_DIR);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -2526,7 +2525,7 @@ static int networkSetAutostart(virNetworkPtr net,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (autostart) {
|
if (autostart) {
|
||||||
if (virFileMakePath(driver->networkAutostartDir)) {
|
if (virFileMakePath(driver->networkAutostartDir) < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("cannot create autostart directory '%s'"),
|
_("cannot create autostart directory '%s'"),
|
||||||
driver->networkAutostartDir);
|
driver->networkAutostartDir);
|
||||||
|
@ -469,37 +469,37 @@ qemudStartup(int privileged) {
|
|||||||
goto out_of_memory;
|
goto out_of_memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virFileMakePath(qemu_driver->stateDir) != 0) {
|
if (virFileMakePath(qemu_driver->stateDir) < 0) {
|
||||||
char ebuf[1024];
|
char ebuf[1024];
|
||||||
VIR_ERROR(_("Failed to create state dir '%s': %s"),
|
VIR_ERROR(_("Failed to create state dir '%s': %s"),
|
||||||
qemu_driver->stateDir, virStrerror(errno, ebuf, sizeof ebuf));
|
qemu_driver->stateDir, virStrerror(errno, ebuf, sizeof ebuf));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (virFileMakePath(qemu_driver->libDir) != 0) {
|
if (virFileMakePath(qemu_driver->libDir) < 0) {
|
||||||
char ebuf[1024];
|
char ebuf[1024];
|
||||||
VIR_ERROR(_("Failed to create lib dir '%s': %s"),
|
VIR_ERROR(_("Failed to create lib dir '%s': %s"),
|
||||||
qemu_driver->libDir, virStrerror(errno, ebuf, sizeof ebuf));
|
qemu_driver->libDir, virStrerror(errno, ebuf, sizeof ebuf));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (virFileMakePath(qemu_driver->cacheDir) != 0) {
|
if (virFileMakePath(qemu_driver->cacheDir) < 0) {
|
||||||
char ebuf[1024];
|
char ebuf[1024];
|
||||||
VIR_ERROR(_("Failed to create cache dir '%s': %s"),
|
VIR_ERROR(_("Failed to create cache dir '%s': %s"),
|
||||||
qemu_driver->cacheDir, virStrerror(errno, ebuf, sizeof ebuf));
|
qemu_driver->cacheDir, virStrerror(errno, ebuf, sizeof ebuf));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (virFileMakePath(qemu_driver->saveDir) != 0) {
|
if (virFileMakePath(qemu_driver->saveDir) < 0) {
|
||||||
char ebuf[1024];
|
char ebuf[1024];
|
||||||
VIR_ERROR(_("Failed to create save dir '%s': %s"),
|
VIR_ERROR(_("Failed to create save dir '%s': %s"),
|
||||||
qemu_driver->saveDir, virStrerror(errno, ebuf, sizeof ebuf));
|
qemu_driver->saveDir, virStrerror(errno, ebuf, sizeof ebuf));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (virFileMakePath(qemu_driver->snapshotDir) != 0) {
|
if (virFileMakePath(qemu_driver->snapshotDir) < 0) {
|
||||||
char ebuf[1024];
|
char ebuf[1024];
|
||||||
VIR_ERROR(_("Failed to create save dir '%s': %s"),
|
VIR_ERROR(_("Failed to create save dir '%s': %s"),
|
||||||
qemu_driver->snapshotDir, virStrerror(errno, ebuf, sizeof ebuf));
|
qemu_driver->snapshotDir, virStrerror(errno, ebuf, sizeof ebuf));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (virFileMakePath(qemu_driver->autoDumpPath) != 0) {
|
if (virFileMakePath(qemu_driver->autoDumpPath) < 0) {
|
||||||
char ebuf[1024];
|
char ebuf[1024];
|
||||||
VIR_ERROR(_("Failed to create dump dir '%s': %s"),
|
VIR_ERROR(_("Failed to create dump dir '%s': %s"),
|
||||||
qemu_driver->autoDumpPath, virStrerror(errno, ebuf, sizeof ebuf));
|
qemu_driver->autoDumpPath, virStrerror(errno, ebuf, sizeof ebuf));
|
||||||
@ -586,8 +586,8 @@ qemudStartup(int privileged) {
|
|||||||
if (virAsprintf(&mempath, "%s/libvirt/qemu", qemu_driver->hugetlbfs_mount) < 0)
|
if (virAsprintf(&mempath, "%s/libvirt/qemu", qemu_driver->hugetlbfs_mount) < 0)
|
||||||
goto out_of_memory;
|
goto out_of_memory;
|
||||||
|
|
||||||
if ((rc = virFileMakePath(mempath)) != 0) {
|
if (virFileMakePath(mempath) < 0) {
|
||||||
virReportSystemError(rc,
|
virReportSystemError(errno,
|
||||||
_("unable to create hugepage path %s"), mempath);
|
_("unable to create hugepage path %s"), mempath);
|
||||||
VIR_FREE(mempath);
|
VIR_FREE(mempath);
|
||||||
goto error;
|
goto error;
|
||||||
@ -5021,10 +5021,8 @@ static int qemudDomainSetAutostart(virDomainPtr dom,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (autostart) {
|
if (autostart) {
|
||||||
int err;
|
if (virFileMakePath(driver->autostartDir) < 0) {
|
||||||
|
virReportSystemError(errno,
|
||||||
if ((err = virFileMakePath(driver->autostartDir))) {
|
|
||||||
virReportSystemError(err,
|
|
||||||
_("cannot create autostart directory %s"),
|
_("cannot create autostart directory %s"),
|
||||||
driver->autostartDir);
|
driver->autostartDir);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -7489,7 +7487,6 @@ static int qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm,
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
char *snapDir = NULL;
|
char *snapDir = NULL;
|
||||||
char *snapFile = NULL;
|
char *snapFile = NULL;
|
||||||
int err;
|
|
||||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||||
|
|
||||||
virUUIDFormat(vm->def->uuid, uuidstr);
|
virUUIDFormat(vm->def->uuid, uuidstr);
|
||||||
@ -7503,9 +7500,8 @@ static int qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm,
|
|||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
err = virFileMakePath(snapDir);
|
if (virFileMakePath(snapDir) < 0) {
|
||||||
if (err != 0) {
|
virReportSystemError(errno, _("cannot create snapshot directory '%s'"),
|
||||||
virReportSystemError(err, _("cannot create snapshot directory '%s'"),
|
|
||||||
snapDir);
|
snapDir);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -2448,7 +2448,7 @@ int qemuProcessStart(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virFileMakePath(driver->logDir) != 0) {
|
if (virFileMakePath(driver->logDir) < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("cannot create log directory %s"),
|
_("cannot create log directory %s"),
|
||||||
driver->logDir);
|
driver->logDir);
|
||||||
|
@ -559,8 +559,8 @@ virStorageBackendFileSystemBuild(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
/* assure all directories in the path prior to the final dir
|
/* assure all directories in the path prior to the final dir
|
||||||
* exist, with default uid/gid/mode. */
|
* exist, with default uid/gid/mode. */
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
if ((err = virFileMakePath(parent)) != 0) {
|
if (virFileMakePath(parent) < 0) {
|
||||||
virReportSystemError(err, _("cannot create path '%s'"),
|
virReportSystemError(errno, _("cannot create path '%s'"),
|
||||||
parent);
|
parent);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -1019,10 +1019,8 @@ storagePoolSetAutostart(virStoragePoolPtr obj,
|
|||||||
|
|
||||||
if (pool->autostart != autostart) {
|
if (pool->autostart != autostart) {
|
||||||
if (autostart) {
|
if (autostart) {
|
||||||
int err;
|
if (virFileMakePath(driver->autostartDir) < 0) {
|
||||||
|
virReportSystemError(errno,
|
||||||
if ((err = virFileMakePath(driver->autostartDir))) {
|
|
||||||
virReportSystemError(err,
|
|
||||||
_("cannot create autostart directory %s"),
|
_("cannot create autostart directory %s"),
|
||||||
driver->autostartDir);
|
driver->autostartDir);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -420,7 +420,7 @@ umlStartup(int privileged)
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virFileMakePath(uml_driver->monitorDir) != 0) {
|
if (virFileMakePath(uml_driver->monitorDir) < 0) {
|
||||||
char ebuf[1024];
|
char ebuf[1024];
|
||||||
VIR_ERROR(_("Failed to create monitor directory %s: %s"),
|
VIR_ERROR(_("Failed to create monitor directory %s: %s"),
|
||||||
uml_driver->monitorDir, virStrerror(errno, ebuf, sizeof ebuf));
|
uml_driver->monitorDir, virStrerror(errno, ebuf, sizeof ebuf));
|
||||||
@ -839,7 +839,7 @@ static int umlStartVMDaemon(virConnectPtr conn,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virFileMakePath(driver->logDir) != 0) {
|
if (virFileMakePath(driver->logDir) < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("cannot create log directory %s"),
|
_("cannot create log directory %s"),
|
||||||
driver->logDir);
|
driver->logDir);
|
||||||
@ -2004,10 +2004,8 @@ static int umlDomainSetAutostart(virDomainPtr dom,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (autostart) {
|
if (autostart) {
|
||||||
int err;
|
if (virFileMakePath(driver->autostartDir) < 0) {
|
||||||
|
virReportSystemError(errno,
|
||||||
if ((err = virFileMakePath(driver->autostartDir))) {
|
|
||||||
virReportSystemError(err,
|
|
||||||
_("cannot create autostart directory %s"),
|
_("cannot create autostart directory %s"),
|
||||||
driver->autostartDir);
|
driver->autostartDir);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -523,11 +523,10 @@ dnsmasqAddHost(dnsmasqContext *ctx,
|
|||||||
int
|
int
|
||||||
dnsmasqSave(const dnsmasqContext *ctx)
|
dnsmasqSave(const dnsmasqContext *ctx)
|
||||||
{
|
{
|
||||||
int err;
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if ((err = virFileMakePath(ctx->config_dir))) {
|
if (virFileMakePath(ctx->config_dir) < 0) {
|
||||||
virReportSystemError(err, _("cannot create config directory '%s'"),
|
virReportSystemError(errno, _("cannot create config directory '%s'"),
|
||||||
ctx->config_dir);
|
ctx->config_dir);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1010,66 +1010,79 @@ int virDirCreate(const char *path ATTRIBUTE_UNUSED,
|
|||||||
}
|
}
|
||||||
#endif /* WIN32 */
|
#endif /* WIN32 */
|
||||||
|
|
||||||
static int virFileMakePathHelper(char *path) {
|
static int virFileMakePathHelper(char *path)
|
||||||
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
char *p = NULL;
|
char *p = NULL;
|
||||||
int err;
|
|
||||||
|
|
||||||
if (stat(path, &st) >= 0)
|
if (stat(path, &st) >= 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
else if (errno != ENOENT)
|
||||||
|
return -1;
|
||||||
|
|
||||||
if ((p = strrchr(path, '/')) == NULL)
|
if ((p = strrchr(path, '/')) == NULL) {
|
||||||
return EINVAL;
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (p != path) {
|
if (p != path) {
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
err = virFileMakePathHelper(path);
|
|
||||||
|
if (virFileMakePathHelper(path) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
*p = '/';
|
*p = '/';
|
||||||
if (err != 0)
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mkdir(path, 0777) < 0 && errno != EEXIST) {
|
if (mkdir(path, 0777) < 0 && errno != EEXIST)
|
||||||
return errno;
|
return -1;
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the given directory with mode 0777 if it's not already existing.
|
||||||
|
*
|
||||||
|
* Returns 0 on success, or -1 if an error occurred (in which case, errno
|
||||||
|
* is set appropriately).
|
||||||
|
*/
|
||||||
int virFileMakePath(const char *path)
|
int virFileMakePath(const char *path)
|
||||||
{
|
{
|
||||||
|
int ret = -1;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
char *parent = NULL;
|
char *parent = NULL;
|
||||||
char *p;
|
char *p;
|
||||||
int err = 0;
|
|
||||||
|
|
||||||
if (stat(path, &st) >= 0)
|
if (stat(path, &st) >= 0)
|
||||||
|
return 0;
|
||||||
|
else if (errno != ENOENT)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((parent = strdup(path)) == NULL) {
|
if ((parent = strdup(path)) == NULL) {
|
||||||
err = ENOMEM;
|
errno = ENOMEM;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((p = strrchr(parent, '/')) == NULL) {
|
if ((p = strrchr(parent, '/')) == NULL) {
|
||||||
err = EINVAL;
|
errno = EINVAL;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p != parent) {
|
if (p != parent) {
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
if ((err = virFileMakePathHelper(parent)) != 0) {
|
|
||||||
|
if (virFileMakePathHelper(parent) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (mkdir(path, 0777) < 0 && errno != EEXIST) {
|
if (mkdir(path, 0777) < 0 && errno != EEXIST)
|
||||||
err = errno;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(parent);
|
VIR_FREE(parent);
|
||||||
return err;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Build up a fully qualified path for a config file to be
|
/* Build up a fully qualified path for a config file to be
|
||||||
@ -1182,8 +1195,10 @@ int virFileWritePid(const char *dir,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rc = virFileMakePath(dir)))
|
if (virFileMakePath(dir) < 0) {
|
||||||
|
rc = errno;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
if (!(pidfile = virFilePid(dir, name))) {
|
if (!(pidfile = virFilePid(dir, name))) {
|
||||||
rc = ENOMEM;
|
rc = ENOMEM;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user