From patchwork Sun Mar 30 16:03:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hongbo X-Patchwork-Id: 14032947 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 88CAEC28B20 for ; Sun, 30 Mar 2025 16:04:15 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.931630.1333824 (Exim 4.92) (envelope-from ) id 1tyv8c-0002PO-OV; Sun, 30 Mar 2025 16:03:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 931630.1333824; Sun, 30 Mar 2025 16:03:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tyv8c-0002PH-M1; Sun, 30 Mar 2025 16:03:54 +0000 Received: by outflank-mailman (input) for mailman id 931630; Sun, 30 Mar 2025 16:03:53 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tyv8b-0002PB-L2 for xen-devel@lists.xenproject.org; Sun, 30 Mar 2025 16:03:53 +0000 Received: from mout.mail.com (mout.mail.com [74.208.4.200]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8fa6b1dd-0d80-11f0-9ffb-bf95429c2676; Sun, 30 Mar 2025 18:03:48 +0200 (CEST) Received: from localhost.localdomain ([202.81.229.170]) by smtp.mail.com (mrgmxus005 [74.208.5.15]) with ESMTPSA (Nemesis) id 0LtZ5O-1t0Sma0jDA-015jgB; Sun, 30 Mar 2025 18:03:44 +0200 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 8fa6b1dd-0d80-11f0-9ffb-bf95429c2676 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mail.com; s=s1089575; t=1743350624; x=1743955424; i=hehongbo@mail.com; bh=oF78OOmsAcJMdi0rEz2e/GUg/u4gORsyRl/Ou+Gu0Ig=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-Id:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=DmxkQ81XoPPQlP10i5Vl0AQ3qwsAoBPzLQ3ULX2aV2Qv3tqqgNFAh9zAsGcE/bUh nGJ0OdCtRasJzw4tTTRO+5lMFStBFcM3MEoxpHFOQc59jVaX4TebkT7bsjKnHP3XQ 7JSkgLVP6U+4+ec6x+f/zJ79fJigt5AJDpOeAWyYMvvEOh08EE61gZ0FNZNjKEILQ zk3TN/G9h33f4lOmrUtP4w4d23ZT0WJtGqjERgh8XxmpdQFaqCtNHkI3tZnQKG850 VirzGFJi/XR/kzTkelJfzQG18d2yrcGqpQLSsThocPloR78QJxLNVd5V0yXOyGoW8 zH5Q9Yrmkz02URJQzw== X-UI-Sender-Class: f2cb72be-343f-493d-8ec3-b1efb8d6185a From: Hongbo To: xen-devel@lists.xenproject.org Cc: Hongbo , Anthony PERARD , Juergen Gross Subject: [XEN PATCH v2 1/1] tools/libxl: search PATH for QEMU if `QEMU_XEN_PATH` is not absolute Date: Mon, 31 Mar 2025 00:03:04 +0800 Message-Id: <20250330160304.20899-1-hehongbo@mail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241223031753.13709-1-hehongbo@mail.com> References: <20241223031753.13709-1-hehongbo@mail.com> MIME-Version: 1.0 X-Provags-ID: V03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kqoYnWJuW5HlESLRo BunO5CbzBr7m0G2IAD5cVhtY3gNg4ZHMfSNDaWAbsl6m08NYHLX66Gaf4P87VerKWSZ+VzraI cDudx9PKyDiglBwcW5ZgF5zbeD0QU7uJ7pBLG9W7Mo33EQqHtyi/ppQI2S8RFId26QlXqpte5 I0S1axGJR3krATrNMLbERMG1gpIsnFGsTJSf5HXVcY8rlbpm8Tk2BKC9rPNX8plqZ6/vMOQSZ kyPn424WJqz51vVC19V5bOqDsQD44WD7VDgOaNGnVgJoH0NFcKURzqA9B/aKxiL5EkRCGw8zx nDMrMrnCZfscpys8MKg+LM3+f8i2kZ4mKNRtTAMc7gYwdlDMyqKldQEorR2thZm9qjjPfR23r rgbKQGrXio2dUnOhGB5xIMc1CZ1cH7bDhXBu/Hl8oaywtUPGB7u7ze3XmcZ1h8e91X5Re1Ol5 t8R6wuqo/WLIhd5y4JoGl+0gOilaL2K9wnoo1d0MJ1le3eJZ+E3q5OSWaMzNbzFhzbZ3cY6Wi LOXzGeUZeTQ/jHK/4wQNyEosep18nvbTz6Es63dWnz8mnBp3nY23fF5SBkeM6kfCoF86FJDKl Xa8ryHeE5ijIMt5pT1Ji3Qu1IvZDpG7JSHtW9W/tpVc7rWOOIL8p7X7CVpF5IfGyVaYv53tiV joAppR3nZ2Va6i9MUlE3AGqEdZnY= `QEMU_XEN_PATH` will be configured as `qemu-system-i386` with no clue where, if `--with-system-qemu` is set without giving a path (as matched in the case `yes` but not `*`). However, the existence of the executable is checked by `access()`, that will not look for anywhere in $PATH but the current directory. And since it is possible for `qemu-system-i386` (or any other configured values) to be executed from PATH later, we'd better find that in PATH and return the full path for the caller to check against. Signed-off-by: Hongbo --- v2: - Identify absolute/relative paths with their first char (being `/` or not). - Put the case inside a block `{}` to address `clang` warnings about the new variable. - Avoid unnecessary string duplications. - Parity of using `{}` block on both sides of `if` statements. - Use `libxl__abs_path()` to get absolute paths. Updated the patch as requested. Also, I just realized that there is a `libxl__abs_path()` (occurred just above my patched hunk), and I should utilize that instead of doing the `%s/%s` `snprintf` thing myself. Let me know if further changes are needed. Best regards, Hongbo --- CC: Anthony PERARD CC: Juergen Gross --- tools/libs/light/libxl_dm.c | 38 +++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) -- 2.39.5 (Apple Git-154) diff --git a/tools/libs/light/libxl_dm.c b/tools/libs/light/libxl_dm.c index b193a5dc37..8f0bbd5d64 100644 --- a/tools/libs/light/libxl_dm.c +++ b/tools/libs/light/libxl_dm.c @@ -331,9 +331,43 @@ const char *libxl__domain_device_model(libxl__gc *gc, case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL: dm = libxl__abs_path(gc, "qemu-dm", libxl__private_bindir_path()); break; - case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN: - dm = qemu_xen_path(gc); + case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN: { + const char *configured_dm = qemu_xen_path(gc); + if (configured_dm[0] == '/') + { + dm = configured_dm; + } + else + { + const char *path_env = getenv("PATH"); + if (!path_env) + { + dm = configured_dm; + } + else + { + char *path_dup = libxl__strdup(gc, path_env); + char *saveptr; + + char *path = strtok_r(path_dup, ":", &saveptr); + dm = NULL; + while (path) + { + char *candidate = libxl__abs_path(gc, configured_dm, path); + if (access(candidate, X_OK) == 0) + { + dm = candidate; + break; + } + path = strtok_r(NULL, ":", &saveptr); + } + + if (!dm) + dm = configured_dm; + } + } break; + } default: LOG(ERROR, "invalid device model version %d", info->device_model_version);