]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Replace AbsPath judgement method with g_path_is_absolute()
authorLuke Yue <lukedyue@gmail.com>
Tue, 20 Apr 2021 04:44:12 +0000 (12:44 +0800)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 21 Apr 2021 08:02:09 +0000 (10:02 +0200)
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>
18 files changed:
src/conf/backup_conf.c
src/conf/snapshot_conf.c
src/conf/storage_source_conf.c
src/libxl/xen_common.c
src/lxc/lxc_cgroup.c
src/lxc/lxc_native.c
src/qemu/qemu_block.c
src/qemu/qemu_cgroup.c
src/qemu/qemu_command.c
src/storage_file/storage_source.c
src/storage_file/storage_source_backingstore.c
src/util/vircgroup.c
src/util/vircommand.c
src/vbox/vbox_snapshot_conf.c
src/vmware/vmware_conf.c
src/vmware/vmware_driver.c
tests/virtestmock.c
tools/virt-login-shell-helper.c

index 2de77a59c0ec0d68203b2aa4860398b099176990..7f54a25ff6dead5276c27f275f182f8e55e3145c 100644 (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);
index 07c9ea7af726e14783b8c0272ec0adfdeab8150c..df3f2a4c635c9cbafa9a34c36d848a41d17b22cb 100644 (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);
index 05939181d6d092de1fa208bf1185657d69734406..5ca06fa30ad01585575d7c4e4a0e1c47552f7b97 100644 (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:
index 6fa69fbdf0c9613d79174503125b2aa4c8e2d555..4e09c6b1a26bc297627fb1f171794d3d16b900f0 100644 (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 {
index 1861ccf4db53c938a3a0174d90621263d4098a12..736b2000ff86aef5db393c3abbb282b96d0b042b 100644 (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);
index 083fb50af77d8804910f7a0c691d7b1f236f2329..4bdd960e2353c82e260724b98c1f7d853edec528 100644 (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);
index a972e1e3687f3c75c25d229de555abce2cbd1220..89f20eb1d2d9cfdafad3fd263271f7308ea8cf44 100644 (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);
         }
     }
index 717ce32bf28b28f47cc5ccdbf8d30213c3aef885..0e8835fb8641b823ba49e2dd9c1d8bdbe5925584 100644 (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);
index 2f69a79bc0977f1aa0335ef9fbcfd53dc84c1839..2ceff155124ef6b8cf5ecaea367982563286b7ff 100644 (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:");
 
index 4246ede04b6916f35689268b4764c66eab233b36..c2bdc39f25a39087e97a77d77507fe4dc777d3f8 100644 (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))
index 9021b9da0c556c8525ba2d33b94656e5b0a16908..e48ae725ab60de62e1f7784324bacd06010c4b6e 100644 (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) */
index 37dde2a5ed9afd4a9655195138e282bbaa467048..65a81e8d6f8c0b28485c96400e3336c231fe2fee 100644 (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;
index 81171900765f52ac614b8e0df84856bda04f3f56..7abb2e288f69176b01f38f5301450e43c99520a1 100644 (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"),
index 743ee722115b163f7e0ac6c7e07fc75c8abb853a..f7423f60fc32802eac15de0a41bf771d3abe997c 100644 (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);
index 6b0d3f96108cf2efb6da4e9164ec5f37aef73624..af4461f2cbc5447d1be1b6da918fff816aba6daa 100644 (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)
index 62f653e86fb802d094cbee386fbc2a86ecc5d929..3bd6d4d4404f08586aca5dbc02e06727a54d12fa 100644 (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)) {
index 776493f0c5de2ec6b79e455525a9f04522682236..0073677b4d8c70e77b3d0596d98c8246d69f8f0f 100644 (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
index 78e351867f94bacd891d8c5e98b01818f1ec8c0b..5c6e007b0907d98a5a536f8654011811002eafd2 100644 (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);