From nobody Wed May 15 18:27:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1618893887; cv=none; d=zohomail.com; s=zohoarc; b=JrrQBVWGg1/x1djYF/daiujH4rjm0JC4Zeh8IopSUkWfArJ5lHL1mSUMyYIuhXSTXbZY8mOtzAkQ89W0m/KZab4D6LzaYoVfn+KZbsIgjrbXCOdvDTbNUnVDlSqLhH7hWLfICTa81tb5eha8/RXV+UCHSqCGtLP2GAs6QohZ3Ek= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618893887; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eJqoIkEyigI8GVSDMDow1EXk4q5EPoDx09EAOlLD/58=; b=BXUAN8gg8Rj589JZ0tb0mbbD5mP3zZqcKZJHvW5cuGh5Lcszvf11XDzU+IKudhSdHPhOVUalTo1RhQAz3XnBlzxkxwnyVr9n91bauRHuMYO2qb3hslEkUkW03q0L6Rn9Ko7m2EuHpglPdkVGM8UmYqbukwMCL0drxs2xz52UEMc= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1618893887671411.2382455880787; Mon, 19 Apr 2021 21:44:47 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-521-KC7MZdGzOaWqCrPoFZqrNg-1; Tue, 20 Apr 2021 00:44:43 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5023518397A3; Tue, 20 Apr 2021 04:44:36 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 626755C1D0; Tue, 20 Apr 2021 04:44:35 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6E20B44A57; Tue, 20 Apr 2021 04:44:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13K4iURp015566 for ; Tue, 20 Apr 2021 00:44:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7FE69209F748; Tue, 20 Apr 2021 04:44:30 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 79D71209F743 for ; Tue, 20 Apr 2021 04:44:28 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2906F101A531 for ; Tue, 20 Apr 2021 04:44:28 +0000 (UTC) Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-248-BmFbEDjTM56sFV2eeeykAA-1; Tue, 20 Apr 2021 00:44:25 -0400 Received: by mail-pg1-f177.google.com with SMTP id z16so25759265pga.1 for ; Mon, 19 Apr 2021 21:44:25 -0700 (PDT) Received: from localhost ([103.142.141.204]) by smtp.gmail.com with ESMTPSA id n9sm5212958pgt.35.2021.04.19.21.44.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Apr 2021 21:44:24 -0700 (PDT) X-MC-Unique: KC7MZdGzOaWqCrPoFZqrNg-1 X-MC-Unique: BmFbEDjTM56sFV2eeeykAA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eJqoIkEyigI8GVSDMDow1EXk4q5EPoDx09EAOlLD/58=; b=esyIB90g54/+c1GZiTUkENpea1vgPvuIGMWlufYFba2HUe0KuYpJJ36TTvWjpHiAxb PtQMWuXILELFK36RuHJOd6vOu5UeNPobK5HvxKElNDKqjBrVsBePoD7zuUAc90fqmKJI DuKzW6nc0dH9X+uY21xDCOsEL8QMGCgunNACK7rJtozW3wSdghBJnQtweFKulTE7hxtQ cjqJI/z7d8btaC2VnNcg9Ly5UdjFABlwmvpxC+5/avTxjK6mQyn1JaBYlU80rc3TsByW xZ/mYfCqvi+nQoRf3Vkxiw3luG8Dt3IHzjAf/kX69g7Js9ZrsJtJlZETjbK1NHVVLwaW kprQ== X-Gm-Message-State: AOAM530mq2iRZse67lVYF37ifHcmAqLoj/OCRj6EPwWhtQryUujKGwAA 5R8sZSEm6fRqOXar12/IT2/ZIBWp9UoCGdsloes= X-Google-Smtp-Source: ABdhPJwQjUaJb9OR9ZHiNvg8i8J5WMTpnjQUh+ZIooG5ik54JahSjj7x0bNJI8RLMrPBt4mtLl+Qtg== X-Received: by 2002:a65:57cb:: with SMTP id q11mr15775604pgr.183.1618893864352; Mon, 19 Apr 2021 21:44:24 -0700 (PDT) From: Luke Yue To: libvir-list@redhat.com Subject: [PATCH 1/1] Replace AbsPath judgement method with g_path_is_absolute() Date: Tue, 20 Apr 2021 12:44:12 +0800 Message-Id: <20210420044412.42753-2-lukedyue@gmail.com> In-Reply-To: <20210420044412.42753-1-lukedyue@gmail.com> References: <20210420044412.42753-1-lukedyue@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The g_path_is_absolute() considers more situations than just a simply "path[0] =3D=3D '/'". Related issue: https://gitlab.com/libvirt/libvirt/-/issues/12 Signed-off-by: Luke Yue Reviewed-by: Michal Privoznik --- src/conf/backup_conf.c | 2 +- src/conf/snapshot_conf.c | 2 +- src/conf/storage_source_conf.c | 2 +- src/lxc/lxc_native.c | 2 +- src/qemu/qemu_block.c | 2 +- src/storage_file/storage_source.c | 2 +- src/util/vircommand.c | 2 +- src/vbox/vbox_snapshot_conf.c | 2 +- src/vmware/vmware_conf.c | 2 +- src/vmware/vmware_driver.c | 2 +- tests/virtestmock.c | 2 +- tools/virt-login-shell-helper.c | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/conf/backup_conf.c b/src/conf/backup_conf.c index 2de77a59c0..7f54a25ff6 100644 --- a/src/conf/backup_conf.c +++ b/src/conf/backup_conf.c @@ -262,7 +262,7 @@ virDomainBackupDefParse(xmlXPathContextPtr ctxt, } =20 if (def->server->transport =3D=3D VIR_STORAGE_NET_HOST_TRANS_UNIX = && - def->server->socket[0] !=3D '/') { + !g_path_is_absolute(def->server->socket)) { virReportError(VIR_ERR_XML_ERROR, _("backup socket path '%s' must be absolute"), def->server->socket); diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index 07c9ea7af7..df3f2a4c63 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -363,7 +363,7 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, def->file =3D g_steal_pointer(&memoryFile); =20 /* verify that memory path is absolute */ - if (def->file && def->file[0] !=3D '/') { + if (def->file && !g_path_is_absolute(def->file)) { virReportError(VIR_ERR_XML_ERROR, _("memory snapshot file path (%s) must be absolute"= ), def->file); diff --git a/src/conf/storage_source_conf.c b/src/conf/storage_source_conf.c index 05939181d6..5ca06fa30a 100644 --- a/src/conf/storage_source_conf.c +++ b/src/conf/storage_source_conf.c @@ -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] !=3D '/'; + return !g_path_is_absolute(src->path); =20 case VIR_STORAGE_TYPE_NETWORK: case VIR_STORAGE_TYPE_VOLUME: diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index 083fb50af7..4bdd960e23 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -261,7 +261,7 @@ lxcAddFstabLine(virDomainDef *def, lxcFstab *fstab) if (!options) return -1; =20 - if (fstab->dst[0] !=3D '/') { + if (!g_path_is_absolute(fstab->dst)) { dst =3D g_strdup_printf("/%s", fstab->dst); } else { dst =3D g_strdup(fstab->dst); diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index a972e1e368..c815daf1e6 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -427,7 +427,7 @@ qemuBlockStorageSourceGetURI(virStorageSource *src) if (src->volume) { uri->path =3D g_strdup_printf("/%s/%s", src->volume, src->path= ); } else { - uri->path =3D g_strdup_printf("%s%s", src->path[0] =3D=3D '/' = ? "" : "/", + uri->path =3D g_strdup_printf("%s%s", g_path_is_absolute(src->= path) ? "" : "/", src->path); } } diff --git a/src/storage_file/storage_source.c b/src/storage_file/storage_s= ource.c index 4246ede04b..c2bdc39f25 100644 --- a/src/storage_file/storage_source.c +++ b/src/storage_file/storage_source.c @@ -68,7 +68,7 @@ virStorageSourceBackinStoreStringIsFile(const char *backi= ng) static bool virStorageSourceBackinStoreStringIsRelative(const char *backing) { - if (backing[0] =3D=3D '/') + if (g_path_is_absolute(backing)) return false; =20 if (!virStorageSourceBackinStoreStringIsFile(backing)) diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 8117190076..7abb2e288f 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -629,7 +629,7 @@ virExec(virCommand *cmd) g_autofree gid_t *groups =3D NULL; int ngroups; =20 - if (cmd->args[0][0] !=3D '/') { + if (!g_path_is_absolute(cmd->args[0])) { if (!(binary =3D binarystr =3D virFindFileInPath(cmd->args[0]))) { virReportSystemError(ENOENT, _("Cannot find '%s' in path"), diff --git a/src/vbox/vbox_snapshot_conf.c b/src/vbox/vbox_snapshot_conf.c index 743ee72211..f7423f60fc 100644 --- a/src/vbox/vbox_snapshot_conf.c +++ b/src/vbox/vbox_snapshot_conf.c @@ -82,7 +82,7 @@ virVBoxSnapshotConfCreateVBoxSnapshotConfHardDiskPtr(xmlN= odePtr diskNode, _("Cannot parse 'location' attribute")); goto cleanup; } - if (location[0] !=3D '/') { + if (!g_path_is_absolute(location)) { /* The location is a relative path, so we must change it into an a= bsolute one. */ tmp =3D g_strdup_printf("%s%s", machineLocation, location); hardDisk->location =3D g_strdup(tmp); diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index 6b0d3f9610..af4461f2cb 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -154,7 +154,7 @@ vmwareLoadDomains(struct vmware_driver *driver) for (str =3D outbuf; (vmxPath =3D strtok_r(str, "\n", &saveptr)) !=3D = NULL; str =3D NULL) { =20 - if (vmxPath[0] !=3D '/') + if (!g_path_is_absolute(vmxPath)) continue; =20 if (virFileReadAll(vmxPath, 10000, &vmx) < 0) diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index 62f653e86f..3bd6d4d440 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -309,7 +309,7 @@ vmwareUpdateVMStatus(struct vmware_driver *driver, virD= omainObj *vm) for (str =3D outbuf; (parsedVmxPath =3D strtok_r(str, "\n", &saveptr))= !=3D NULL; str =3D NULL) { =20 - if (parsedVmxPath[0] !=3D '/') + if (!g_path_is_absolute(parsedVmxPath)) continue; =20 if (STREQ(parsedVmxPath, vmxAbsolutePath)) { diff --git a/tests/virtestmock.c b/tests/virtestmock.c index 776493f0c5..0073677b4d 100644 --- a/tests/virtestmock.c +++ b/tests/virtestmock.c @@ -104,7 +104,7 @@ checkPath(const char *path, char *relPath =3D NULL; char *crippledPath =3D NULL; =20 - if (path[0] !=3D '/') + if (!g_path_is_absolute(path)) relPath =3D g_strdup_printf("./%s", path); =20 /* Le sigh. virFileCanonicalizePath() expects @path to exist, otherwise diff --git a/tools/virt-login-shell-helper.c b/tools/virt-login-shell-helpe= r.c index 78e351867f..5c6e007b09 100644 --- a/tools/virt-login-shell-helper.c +++ b/tools/virt-login-shell-helper.c @@ -346,7 +346,7 @@ main(int argc, char **argv) * a leading '-' to indicate it is a login shell */ shcmd =3D shargv[0]; - if (shcmd[0] !=3D '/') { + if (!g_path_is_absolute(shcmd)) { virReportSystemError(errno, _("Shell '%s' should have absolute path"), shcmd); --=20 2.31.1