1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-22 17:34:18 +03:00

Replace AbsPath judgement method with g_path_is_absolute()

The g_path_is_absolute() considers more situations
than just a simply "path[0] == '/'".

Related issue: https://gitlab.com/libvirt/libvirt/-/issues/12

Signed-off-by: Luke Yue <lukedyue@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Luke Yue 2021-04-20 12:44:12 +08:00 committed by Michal Privoznik
parent 1c34211c22
commit 6e91cbfdad
18 changed files with 20 additions and 19 deletions

View File

@ -262,7 +262,7 @@ virDomainBackupDefParse(xmlXPathContextPtr ctxt,
}
if (def->server->transport == VIR_STORAGE_NET_HOST_TRANS_UNIX &&
def->server->socket[0] != '/') {
!g_path_is_absolute(def->server->socket)) {
virReportError(VIR_ERR_XML_ERROR,
_("backup socket path '%s' must be absolute"),
def->server->socket);

View File

@ -363,7 +363,7 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
def->file = g_steal_pointer(&memoryFile);
/* verify that memory path is absolute */
if (def->file && def->file[0] != '/') {
if (def->file && !g_path_is_absolute(def->file)) {
virReportError(VIR_ERR_XML_ERROR,
_("memory snapshot file path (%s) must be absolute"),
def->file);

View File

@ -1213,7 +1213,7 @@ virStorageSourceIsRelative(virStorageSource *src)
case VIR_STORAGE_TYPE_FILE:
case VIR_STORAGE_TYPE_BLOCK:
case VIR_STORAGE_TYPE_DIR:
return src->path[0] != '/';
return !g_path_is_absolute(src->path);
case VIR_STORAGE_TYPE_NETWORK:
case VIR_STORAGE_TYPE_VOLUME:

View File

@ -818,7 +818,7 @@ xenParseSxprChar(const char *value,
prefix = value;
if (value[0] == '/') {
if (g_path_is_absolute(value)) {
def->source->type = VIR_DOMAIN_CHR_TYPE_DEV;
def->source->data.file.path = g_strdup(value);
} else {

View File

@ -383,7 +383,7 @@ virCgroup *virLXCCgroupCreate(virDomainDef *def,
if (!machineName)
return NULL;
if (def->resource->partition[0] != '/') {
if (!g_path_is_absolute(def->resource->partition)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Resource partition '%s' must start with '/'"),
def->resource->partition);

View File

@ -261,7 +261,7 @@ lxcAddFstabLine(virDomainDef *def, lxcFstab *fstab)
if (!options)
return -1;
if (fstab->dst[0] != '/') {
if (!g_path_is_absolute(fstab->dst)) {
dst = g_strdup_printf("/%s", fstab->dst);
} else {
dst = g_strdup(fstab->dst);

View File

@ -427,7 +427,8 @@ qemuBlockStorageSourceGetURI(virStorageSource *src)
if (src->volume) {
uri->path = g_strdup_printf("/%s/%s", src->volume, src->path);
} else {
uri->path = g_strdup_printf("%s%s", src->path[0] == '/' ? "" : "/",
uri->path = g_strdup_printf("%s%s",
g_path_is_absolute(src->path) ? "" : "/",
src->path);
}
}

View File

@ -927,7 +927,7 @@ qemuInitCgroup(virDomainObj *vm,
vm->def->resource = res;
}
if (vm->def->resource->partition[0] != '/') {
if (!g_path_is_absolute(vm->def->resource->partition)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Resource partition '%s' must start with '/'"),
vm->def->resource->partition);

View File

@ -1009,7 +1009,7 @@ qemuBuildNetworkDriveStr(virStorageSource *src,
!src->hosts->name) ||
(src->hosts->transport == VIR_STORAGE_NET_HOST_TRANS_UNIX &&
src->hosts->socket &&
src->hosts->socket[0] != '/'))) {
!g_path_is_absolute(src->hosts->socket)))) {
virBufferAddLit(&buf, "nbd:");

View File

@ -68,7 +68,7 @@ virStorageSourceBackinStoreStringIsFile(const char *backing)
static bool
virStorageSourceBackinStoreStringIsRelative(const char *backing)
{
if (backing[0] == '/')
if (g_path_is_absolute(backing))
return false;
if (!virStorageSourceBackinStoreStringIsFile(backing))

View File

@ -92,7 +92,7 @@ virStorageSourceParseBackingURI(virStorageSource *src,
path = "";
/* possibly skip the leading slash */
if (path[0] == '/')
if (g_path_is_absolute(path))
path++;
/* NBD allows empty export name (path) */

View File

@ -953,7 +953,7 @@ virCgroupNewPartition(const char *path,
*group = NULL;
if (path[0] != '/') {
if (!g_path_is_absolute(path)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Partition path '%s' must start with '/'"),
path);
@ -1307,7 +1307,7 @@ virCgroupNewMachineSystemd(const char *name,
}
}
if (!path || STREQ(path, "/") || path[0] != '/') {
if (!path || STREQ(path, "/") || !g_path_is_absolute(path)) {
VIR_DEBUG("Systemd didn't setup its controller, path=%s",
NULLSTR(path));
return -2;

View File

@ -629,7 +629,7 @@ virExec(virCommand *cmd)
g_autofree gid_t *groups = NULL;
int ngroups;
if (cmd->args[0][0] != '/') {
if (!g_path_is_absolute(cmd->args[0])) {
if (!(binary = binarystr = virFindFileInPath(cmd->args[0]))) {
virReportSystemError(ENOENT,
_("Cannot find '%s' in path"),

View File

@ -82,7 +82,7 @@ virVBoxSnapshotConfCreateVBoxSnapshotConfHardDiskPtr(xmlNodePtr diskNode,
_("Cannot parse <HardDisk> 'location' attribute"));
goto cleanup;
}
if (location[0] != '/') {
if (!g_path_is_absolute(location)) {
/* The location is a relative path, so we must change it into an absolute one. */
tmp = g_strdup_printf("%s%s", machineLocation, location);
hardDisk->location = g_strdup(tmp);

View File

@ -154,7 +154,7 @@ vmwareLoadDomains(struct vmware_driver *driver)
for (str = outbuf; (vmxPath = strtok_r(str, "\n", &saveptr)) != NULL;
str = NULL) {
if (vmxPath[0] != '/')
if (!g_path_is_absolute(vmxPath))
continue;
if (virFileReadAll(vmxPath, 10000, &vmx) < 0)

View File

@ -309,7 +309,7 @@ vmwareUpdateVMStatus(struct vmware_driver *driver, virDomainObj *vm)
for (str = outbuf; (parsedVmxPath = strtok_r(str, "\n", &saveptr)) != NULL;
str = NULL) {
if (parsedVmxPath[0] != '/')
if (!g_path_is_absolute(parsedVmxPath))
continue;
if (STREQ(parsedVmxPath, vmxAbsolutePath)) {

View File

@ -104,7 +104,7 @@ checkPath(const char *path,
char *relPath = NULL;
char *crippledPath = NULL;
if (path[0] != '/')
if (!g_path_is_absolute(path))
relPath = g_strdup_printf("./%s", path);
/* Le sigh. virFileCanonicalizePath() expects @path to exist, otherwise

View File

@ -346,7 +346,7 @@ main(int argc, char **argv)
* a leading '-' to indicate it is a login shell
*/
shcmd = shargv[0];
if (shcmd[0] != '/') {
if (!g_path_is_absolute(shcmd)) {
virReportSystemError(errno,
_("Shell '%s' should have absolute path"),
shcmd);