From patchwork Wed May 25 14:41:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 12861351 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 BAECBC433F5 for ; Wed, 25 May 2022 15:07:06 +0000 (UTC) Received: from localhost ([::1]:48348 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntsbJ-0005jF-Ob for qemu-devel@archiver.kernel.org; Wed, 25 May 2022 11:07:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43788) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntsGp-00039a-RJ for qemu-devel@nongnu.org; Wed, 25 May 2022 10:45:55 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:51367) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntsCn-00063l-JF for qemu-devel@nongnu.org; Wed, 25 May 2022 10:41:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653489704; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lXDFt/kv/PAlM1zbajSUp4pzp4N3dp+WErbFqzTdMdA=; b=eVXoa0ptkKX6DOCqRPkNs7UvU8fgp4hzjCYNfT8vMbHWi1eH4dQ94ULSzQ8jFCk316aCxN E9RT7cmy56WNjj0Uvk5xe5swwViNoc8n31Yb95m0JH8RxOCw4hsqd8CZqxz/17MalHILDG b7L7hLIH+xxPZi9DDTav1vkcKltBtbo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-445-Gg_U-d_ROCm_Rne3Q0_sRg-1; Wed, 25 May 2022 10:41:43 -0400 X-MC-Unique: Gg_U-d_ROCm_Rne3Q0_sRg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 268708001EA for ; Wed, 25 May 2022 14:41:43 +0000 (UTC) Received: from localhost (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id CAFD940CF8EF; Wed, 25 May 2022 14:41:42 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Konstantin Kostiuk , Markus Armbruster , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [PATCH v5 01/15] include: move qemu_*_exec_dir() to cutils Date: Wed, 25 May 2022 16:41:26 +0200 Message-Id: <20220525144140.591926-2-marcandre.lureau@redhat.com> In-Reply-To: <20220525144140.591926-1-marcandre.lureau@redhat.com> References: <20220525144140.591926-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau The function is required by get_relocated_path() (already in cutils), and used by qemu-ga and may be generally useful. Signed-off-by: Marc-André Lureau Reviewed-by: Markus Armbruster --- include/qemu/cutils.h | 7 ++ include/qemu/osdep.h | 8 -- qemu-io.c | 1 + storage-daemon/qemu-storage-daemon.c | 1 + tests/qtest/fuzz/fuzz.c | 1 + util/cutils.c | 108 +++++++++++++++++++++++++++ util/oslib-posix.c | 81 -------------------- util/oslib-win32.c | 36 --------- 8 files changed, 118 insertions(+), 125 deletions(-) diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h index 5c6572d444..40e10e19a7 100644 --- a/include/qemu/cutils.h +++ b/include/qemu/cutils.h @@ -193,6 +193,13 @@ int uleb128_decode_small(const uint8_t *in, uint32_t *n); */ int qemu_pstrcmp0(const char **str1, const char **str2); +/* Find program directory, and save it for later usage with + * qemu_get_exec_dir(). + * Try OS specific API first, if not working, parse from argv0. */ +void qemu_init_exec_dir(const char *argv0); + +/* Get the saved exec dir. */ +const char *qemu_get_exec_dir(void); /** * get_relocated_path: diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index a72e99db85..b1c161c035 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -557,14 +557,6 @@ void qemu_set_cloexec(int fd); */ char *qemu_get_local_state_dir(void); -/* Find program directory, and save it for later usage with - * qemu_get_exec_dir(). - * Try OS specific API first, if not working, parse from argv0. */ -void qemu_init_exec_dir(const char *argv0); - -/* Get the saved exec dir. */ -const char *qemu_get_exec_dir(void); - /** * qemu_getauxval: * @type: the auxiliary vector key to lookup diff --git a/qemu-io.c b/qemu-io.c index d70d3dd4fd..2bd7bfb650 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -16,6 +16,7 @@ #endif #include "qemu/help-texts.h" +#include "qemu/cutils.h" #include "qapi/error.h" #include "qemu-io.h" #include "qemu/error-report.h" diff --git a/storage-daemon/qemu-storage-daemon.c b/storage-daemon/qemu-storage-daemon.c index 9b8b17f52e..c104817cdd 100644 --- a/storage-daemon/qemu-storage-daemon.c +++ b/storage-daemon/qemu-storage-daemon.c @@ -44,6 +44,7 @@ #include "qemu/help-texts.h" #include "qemu-version.h" +#include "qemu/cutils.h" #include "qemu/config-file.h" #include "qemu/error-report.h" #include "qemu/help_option.h" diff --git a/tests/qtest/fuzz/fuzz.c b/tests/qtest/fuzz/fuzz.c index a7a5e14fa3..0ad4ba9e94 100644 --- a/tests/qtest/fuzz/fuzz.c +++ b/tests/qtest/fuzz/fuzz.c @@ -15,6 +15,7 @@ #include +#include "qemu/cutils.h" #include "qemu/datadir.h" #include "sysemu/sysemu.h" #include "sysemu/qtest.h" diff --git a/util/cutils.c b/util/cutils.c index b2777210e7..6cc7cc8cde 100644 --- a/util/cutils.c +++ b/util/cutils.c @@ -931,6 +931,114 @@ static inline const char *next_component(const char *dir, int *p_len) return dir; } +static const char *exec_dir; + +void qemu_init_exec_dir(const char *argv0) +{ +#ifdef G_OS_WIN32 + char *p; + char buf[MAX_PATH]; + DWORD len; + + if (exec_dir) { + return; + } + + len = GetModuleFileName(NULL, buf, sizeof(buf) - 1); + if (len == 0) { + return; + } + + buf[len] = 0; + p = buf + len - 1; + while (p != buf && *p != '\\') { + p--; + } + *p = 0; + if (access(buf, R_OK) == 0) { + exec_dir = g_strdup(buf); + } else { + exec_dir = CONFIG_BINDIR; + } +#else + char *p = NULL; + char buf[PATH_MAX]; + + if (exec_dir) { + return; + } + +#if defined(__linux__) + { + int len; + len = readlink("/proc/self/exe", buf, sizeof(buf) - 1); + if (len > 0) { + buf[len] = 0; + p = buf; + } + } +#elif defined(__FreeBSD__) \ + || (defined(__NetBSD__) && defined(KERN_PROC_PATHNAME)) + { +#if defined(__FreeBSD__) + static int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1}; +#else + static int mib[4] = {CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME}; +#endif + size_t len = sizeof(buf) - 1; + + *buf = '\0'; + if (!sysctl(mib, ARRAY_SIZE(mib), buf, &len, NULL, 0) && + *buf) { + buf[sizeof(buf) - 1] = '\0'; + p = buf; + } + } +#elif defined(__APPLE__) + { + char fpath[PATH_MAX]; + uint32_t len = sizeof(fpath); + if (_NSGetExecutablePath(fpath, &len) == 0) { + p = realpath(fpath, buf); + if (!p) { + return; + } + } + } +#elif defined(__HAIKU__) + { + image_info ii; + int32_t c = 0; + + *buf = '\0'; + while (get_next_image_info(0, &c, &ii) == B_OK) { + if (ii.type == B_APP_IMAGE) { + strncpy(buf, ii.name, sizeof(buf)); + buf[sizeof(buf) - 1] = 0; + p = buf; + break; + } + } + } +#endif + /* If we don't have any way of figuring out the actual executable + location then try argv[0]. */ + if (!p && argv0) { + p = realpath(argv0, buf); + } + if (p) { + exec_dir = g_path_get_dirname(p); + } else { + exec_dir = CONFIG_BINDIR; + } +#endif +} + +const char *qemu_get_exec_dir(void) +{ + return exec_dir; +} + char *get_relocated_path(const char *dir) { size_t prefix_len = strlen(CONFIG_PREFIX); diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 477990f39b..7ba4472760 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -283,87 +283,6 @@ void qemu_set_tty_echo(int fd, bool echo) tcsetattr(fd, TCSANOW, &tty); } -static const char *exec_dir; - -void qemu_init_exec_dir(const char *argv0) -{ - char *p = NULL; - char buf[PATH_MAX]; - - if (exec_dir) { - return; - } - -#if defined(__linux__) - { - int len; - len = readlink("/proc/self/exe", buf, sizeof(buf) - 1); - if (len > 0) { - buf[len] = 0; - p = buf; - } - } -#elif defined(__FreeBSD__) \ - || (defined(__NetBSD__) && defined(KERN_PROC_PATHNAME)) - { -#if defined(__FreeBSD__) - static int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1}; -#else - static int mib[4] = {CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME}; -#endif - size_t len = sizeof(buf) - 1; - - *buf = '\0'; - if (!sysctl(mib, ARRAY_SIZE(mib), buf, &len, NULL, 0) && - *buf) { - buf[sizeof(buf) - 1] = '\0'; - p = buf; - } - } -#elif defined(__APPLE__) - { - char fpath[PATH_MAX]; - uint32_t len = sizeof(fpath); - if (_NSGetExecutablePath(fpath, &len) == 0) { - p = realpath(fpath, buf); - if (!p) { - return; - } - } - } -#elif defined(__HAIKU__) - { - image_info ii; - int32_t c = 0; - - *buf = '\0'; - while (get_next_image_info(0, &c, &ii) == B_OK) { - if (ii.type == B_APP_IMAGE) { - strncpy(buf, ii.name, sizeof(buf)); - buf[sizeof(buf) - 1] = 0; - p = buf; - break; - } - } - } -#endif - /* If we don't have any way of figuring out the actual executable - location then try argv[0]. */ - if (!p && argv0) { - p = realpath(argv0, buf); - } - if (p) { - exec_dir = g_path_get_dirname(p); - } else { - exec_dir = CONFIG_BINDIR; - } -} - -const char *qemu_get_exec_dir(void) -{ - return exec_dir; -} - #ifdef CONFIG_LINUX static void sigbus_handler(int signal, siginfo_t *siginfo, void *ctx) #else /* CONFIG_LINUX */ diff --git a/util/oslib-win32.c b/util/oslib-win32.c index dafef4f157..6c818749d2 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -269,42 +269,6 @@ void qemu_set_tty_echo(int fd, bool echo) } } -static const char *exec_dir; - -void qemu_init_exec_dir(const char *argv0) -{ - - char *p; - char buf[MAX_PATH]; - DWORD len; - - if (exec_dir) { - return; - } - - len = GetModuleFileName(NULL, buf, sizeof(buf) - 1); - if (len == 0) { - return; - } - - buf[len] = 0; - p = buf + len - 1; - while (p != buf && *p != '\\') { - p--; - } - *p = 0; - if (access(buf, R_OK) == 0) { - exec_dir = g_strdup(buf); - } else { - exec_dir = CONFIG_BINDIR; - } -} - -const char *qemu_get_exec_dir(void) -{ - return exec_dir; -} - int getpagesize(void) { SYSTEM_INFO system_info; From patchwork Wed May 25 14:41:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 12861304 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 AB273C433F5 for ; Wed, 25 May 2022 14:55:42 +0000 (UTC) Received: from localhost ([::1]:50826 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntsQH-0004dP-ON for qemu-devel@archiver.kernel.org; Wed, 25 May 2022 10:55:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43740) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntsGp-00033c-Kc for qemu-devel@nongnu.org; Wed, 25 May 2022 10:45:55 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:38859) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntsCp-00063p-2Y for qemu-devel@nongnu.org; Wed, 25 May 2022 10:41:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653489706; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lwU0IIX84LupWziufp4z1foxxfyW5QXhf/iA8+wlBWQ=; b=c5YYKMUm4mda3wPk+xH4lnA1lV6Wp7IFzkS3/X5POHvcMuDhnUgPZmN8HcxhnjIMnLiQYQ cf3IepSv/MlKQXFxEM7acrw8WSEwopvu7GpmTHh5SeKs83PYBG1o0IU66Ivkgdol0T77Kk qhya4GswheJb9Vc2llbGB3Oh7/9/rvo= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-318-lqLcK3FFOdyo0IYWzNtQcg-1; Wed, 25 May 2022 10:41:44 -0400 X-MC-Unique: lqLcK3FFOdyo0IYWzNtQcg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7DA2F3C0D190 for ; Wed, 25 May 2022 14:41:44 +0000 (UTC) Received: from localhost (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F4DCC23DBF; Wed, 25 May 2022 14:41:44 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Konstantin Kostiuk , Markus Armbruster , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [PATCH v5 02/15] util/win32: simplify qemu_get_local_state_dir() Date: Wed, 25 May 2022 16:41:27 +0200 Message-Id: <20220525144140.591926-3-marcandre.lureau@redhat.com> In-Reply-To: <20220525144140.591926-1-marcandre.lureau@redhat.com> References: <20220525144140.591926-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau SHGetFolderPath() is a deprecated API: https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetfolderpatha It is a wrapper for SHGetKnownFolderPath() and CSIDL_COMMON_PATH is mapped to FOLDERID_ProgramData: https://docs.microsoft.com/en-us/windows/win32/shell/csidl g_get_system_data_dirs() is a suitable replacement, as it will have FOLDERID_ProgramData in the returned list. However, it follows the XDG Base Directory Specification, if `XDG_DATA_DIRS` is defined, it will be returned instead. Signed-off-by: Marc-André Lureau Reviewed-by: Stefan Weil --- util/oslib-win32.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/util/oslib-win32.c b/util/oslib-win32.c index 6c818749d2..5723d3eb4c 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -40,9 +40,6 @@ #include "qemu/error-report.h" #include -/* this must come after including "trace.h" */ -#include - static int get_allocation_granularity(void) { SYSTEM_INFO system_info; @@ -237,17 +234,11 @@ int qemu_get_thread_id(void) char * qemu_get_local_state_dir(void) { - HRESULT result; - char base_path[MAX_PATH+1] = ""; + const char * const *data_dirs = g_get_system_data_dirs(); - result = SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, - /* SHGFP_TYPE_CURRENT */ 0, base_path); - if (result != S_OK) { - /* misconfigured environment */ - g_critical("CSIDL_COMMON_APPDATA unavailable: %ld", (long)result); - abort(); - } - return g_strdup(base_path); + g_assert(data_dirs && data_dirs[0]); + + return g_strdup(data_dirs[0]); } void qemu_set_tty_echo(int fd, bool echo) From patchwork Wed May 25 14:41:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 12861349 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 79322C433F5 for ; Wed, 25 May 2022 15:03:39 +0000 (UTC) Received: from localhost ([::1]:39614 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntsXy-00083f-Av for qemu-devel@archiver.kernel.org; Wed, 25 May 2022 11:03:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43788) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntsGp-00039a-F5 for qemu-devel@nongnu.org; Wed, 25 May 2022 10:45:55 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:40324) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntsCq-000643-1X for qemu-devel@nongnu.org; Wed, 25 May 2022 10:41:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653489707; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jjhDG+PefqnF+nXEwx0/7YsWzgp6Vw19B0UKkz8Y6/o=; b=aEf+D+Fpu8jsOSNA9/wOc+PzG6ZeBqby2WmQ3/zkgH6cNUDQIj3gBO996DPpkuk0F2wMDb 1v07VZ7dfcnLp0c2Be4Nds7NOyTNlnRMm+zy209p2M8KZlGbCaGZ/9pVg0N1L0Xiyuzogj Tt5ZHwzmfRKIWMf6Ahs78he+Gf6+LEE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-534-TD08MBh7Pi2dHcu5lq4Uig-1; Wed, 25 May 2022 10:41:46 -0400 X-MC-Unique: TD08MBh7Pi2dHcu5lq4Uig-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BB63D85828B for ; Wed, 25 May 2022 14:41:45 +0000 (UTC) Received: from localhost (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 66EE0112131B; Wed, 25 May 2022 14:41:45 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Konstantin Kostiuk , Markus Armbruster , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [PATCH v5 03/15] tests: make libqmp buildable for win32 Date: Wed, 25 May 2022 16:41:28 +0200 Message-Id: <20220525144140.591926-4-marcandre.lureau@redhat.com> In-Reply-To: <20220525144140.591926-1-marcandre.lureau@redhat.com> References: <20220525144140.591926-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau Signed-off-by: Marc-André Lureau Reviewed-by: Thomas Huth --- tests/qtest/libqmp.h | 2 ++ tests/qtest/libqmp.c | 34 +++++++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/tests/qtest/libqmp.h b/tests/qtest/libqmp.h index 5cb7eeaa18..3445b753ff 100644 --- a/tests/qtest/libqmp.h +++ b/tests/qtest/libqmp.h @@ -21,8 +21,10 @@ #include "qapi/qmp/qdict.h" QDict *qmp_fd_receive(int fd); +#ifndef _WIN32 void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num, const char *fmt, va_list ap) G_GNUC_PRINTF(4, 0); +#endif void qmp_fd_vsend(int fd, const char *fmt, va_list ap) G_GNUC_PRINTF(2, 0); void qmp_fd_send(int fd, const char *fmt, ...) G_GNUC_PRINTF(2, 3); void qmp_fd_send_raw(int fd, const char *fmt, ...) G_GNUC_PRINTF(2, 3); diff --git a/tests/qtest/libqmp.c b/tests/qtest/libqmp.c index 0358b8313d..ade26c15f0 100644 --- a/tests/qtest/libqmp.c +++ b/tests/qtest/libqmp.c @@ -18,6 +18,11 @@ #include "libqmp.h" +#ifndef _WIN32 +#include +#endif + +#include "qemu/cutils.h" #include "qapi/error.h" #include "qapi/qmp/json-parser.h" #include "qapi/qmp/qjson.h" @@ -87,6 +92,7 @@ QDict *qmp_fd_receive(int fd) return qmp.response; } +#ifndef _WIN32 /* Sends a message and file descriptors to the socket. * It's needed for qmp-commands like getfd/add-fd */ static void socket_send_fds(int socket_fd, int *fds, size_t fds_num, @@ -120,17 +126,23 @@ static void socket_send_fds(int socket_fd, int *fds, size_t fds_num, } while (ret < 0 && errno == EINTR); g_assert_cmpint(ret, >, 0); } +#endif /** * Allow users to send a message without waiting for the reply, * in the case that they choose to discard all replies up until * a particular EVENT is received. */ -void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num, - const char *fmt, va_list ap) +static void +_qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num, + const char *fmt, va_list ap) { QObject *qobj; +#ifdef _WIN32 + assert(fds_num == 0); +#endif + /* Going through qobject ensures we escape strings properly */ qobj = qobject_from_vjsonf_nofail(fmt, ap); @@ -148,10 +160,14 @@ void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num, if (log) { fprintf(stderr, "%s", str->str); } + +#ifndef _WIN32 /* Send QMP request */ if (fds && fds_num > 0) { socket_send_fds(fd, fds, fds_num, str->str, str->len); - } else { + } else +#endif + { socket_send(fd, str->str, str->len); } @@ -160,15 +176,23 @@ void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num, } } +#ifndef _WIN32 +void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num, + const char *fmt, va_list ap) +{ + _qmp_fd_vsend_fds(fd, fds, fds_num, fmt, ap); +} +#endif + void qmp_fd_vsend(int fd, const char *fmt, va_list ap) { - qmp_fd_vsend_fds(fd, NULL, 0, fmt, ap); + _qmp_fd_vsend_fds(fd, NULL, 0, fmt, ap); } QDict *qmp_fdv(int fd, const char *fmt, va_list ap) { - qmp_fd_vsend_fds(fd, NULL, 0, fmt, ap); + _qmp_fd_vsend_fds(fd, NULL, 0, fmt, ap); return qmp_fd_receive(fd); } From patchwork Wed May 25 14:41:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 12861306 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 24E46C433FE for ; Wed, 25 May 2022 14:58:41 +0000 (UTC) Received: from localhost ([::1]:59222 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntsTA-00022e-9z for qemu-devel@archiver.kernel.org; Wed, 25 May 2022 10:58:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43796) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntsGo-0003Ex-MX for qemu-devel@nongnu.org; Wed, 25 May 2022 10:45:55 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:37519) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntsCr-00064P-5j for qemu-devel@nongnu.org; Wed, 25 May 2022 10:41:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653489708; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G3KkTArWcTemx/7HtGXNcyVHwh5TYE+TZivZFY4G1FM=; b=gIw/2NHqw4q2L7FTj4jrI7uzAgpo2SzwJp5g8WJlLYpfR2Q6h44tPT1PpgLEnMuCxD+jsf Cjk/sCHCR7hQbQ9lTVClO4JjfXQDI28+J/4BXMDdrVIio5PMjaq/hveBQ0l+jRmUFfs8a5 JAO96OnKjg1ZHluP/D1Wr/F8123AZpc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-582-edbMqzebO_6FfwuHtJsU6Q-1; Wed, 25 May 2022 10:41:47 -0400 X-MC-Unique: edbMqzebO_6FfwuHtJsU6Q-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 07A8F811E7A for ; Wed, 25 May 2022 14:41:47 +0000 (UTC) Received: from localhost (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id B584E40E6A57; Wed, 25 May 2022 14:41:46 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Konstantin Kostiuk , Markus Armbruster , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [PATCH v5 04/15] qga: flatten safe_open_or_create() Date: Wed, 25 May 2022 16:41:29 +0200 Message-Id: <20220525144140.591926-5-marcandre.lureau@redhat.com> In-Reply-To: <20220525144140.591926-1-marcandre.lureau@redhat.com> References: <20220525144140.591926-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau There is a bit too much nesting in the function, this can be simplified a bit to improve readability. This also helps with the following error handling changes. Signed-off-by: Marc-André Lureau Reviewed-by: Markus Armbruster --- qga/commands-posix.c | 120 +++++++++++++++++++++---------------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 69f209af87..8ee149e550 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -339,73 +339,73 @@ find_open_flag(const char *mode_str, Error **errp) static FILE * safe_open_or_create(const char *path, const char *mode, Error **errp) { - Error *local_err = NULL; int oflag; + int fd = -1; + FILE *f = NULL; + + oflag = find_open_flag(mode, errp); + if (oflag < 0) { + goto end; + } + + /* If the caller wants / allows creation of a new file, we implement it + * with a two step process: open() + (open() / fchmod()). + * + * First we insist on creating the file exclusively as a new file. If + * that succeeds, we're free to set any file-mode bits on it. (The + * motivation is that we want to set those file-mode bits independently + * of the current umask.) + * + * If the exclusive creation fails because the file already exists + * (EEXIST is not possible for any other reason), we just attempt to + * open the file, but in this case we won't be allowed to change the + * file-mode bits on the preexistent file. + * + * The pathname should never disappear between the two open()s in + * practice. If it happens, then someone very likely tried to race us. + * In this case just go ahead and report the ENOENT from the second + * open() to the caller. + * + * If the caller wants to open a preexistent file, then the first + * open() is decisive and its third argument is ignored, and the second + * open() and the fchmod() are never called. + */ + fd = open(path, oflag | ((oflag & O_CREAT) ? O_EXCL : 0), 0); + if (fd == -1 && errno == EEXIST) { + oflag &= ~(unsigned)O_CREAT; + fd = open(path, oflag); + } + if (fd == -1) { + error_setg_errno(errp, errno, + "failed to open file '%s' (mode: '%s')", + path, mode); + goto end; + } - oflag = find_open_flag(mode, &local_err); - if (local_err == NULL) { - int fd; - - /* If the caller wants / allows creation of a new file, we implement it - * with a two step process: open() + (open() / fchmod()). - * - * First we insist on creating the file exclusively as a new file. If - * that succeeds, we're free to set any file-mode bits on it. (The - * motivation is that we want to set those file-mode bits independently - * of the current umask.) - * - * If the exclusive creation fails because the file already exists - * (EEXIST is not possible for any other reason), we just attempt to - * open the file, but in this case we won't be allowed to change the - * file-mode bits on the preexistent file. - * - * The pathname should never disappear between the two open()s in - * practice. If it happens, then someone very likely tried to race us. - * In this case just go ahead and report the ENOENT from the second - * open() to the caller. - * - * If the caller wants to open a preexistent file, then the first - * open() is decisive and its third argument is ignored, and the second - * open() and the fchmod() are never called. - */ - fd = open(path, oflag | ((oflag & O_CREAT) ? O_EXCL : 0), 0); - if (fd == -1 && errno == EEXIST) { - oflag &= ~(unsigned)O_CREAT; - fd = open(path, oflag); - } + qemu_set_cloexec(fd); - if (fd == -1) { - error_setg_errno(&local_err, errno, "failed to open file '%s' " - "(mode: '%s')", path, mode); - } else { - qemu_set_cloexec(fd); + if ((oflag & O_CREAT) && fchmod(fd, DEFAULT_NEW_FILE_MODE) == -1) { + error_setg_errno(errp, errno, "failed to set permission " + "0%03o on new file '%s' (mode: '%s')", + (unsigned)DEFAULT_NEW_FILE_MODE, path, mode); + goto end; + } - if ((oflag & O_CREAT) && fchmod(fd, DEFAULT_NEW_FILE_MODE) == -1) { - error_setg_errno(&local_err, errno, "failed to set permission " - "0%03o on new file '%s' (mode: '%s')", - (unsigned)DEFAULT_NEW_FILE_MODE, path, mode); - } else { - FILE *f; - - f = fdopen(fd, mode); - if (f == NULL) { - error_setg_errno(&local_err, errno, "failed to associate " - "stdio stream with file descriptor %d, " - "file '%s' (mode: '%s')", fd, path, mode); - } else { - return f; - } - } + f = fdopen(fd, mode); + if (f == NULL) { + error_setg_errno(errp, errno, "failed to associate stdio stream with " + "file descriptor %d, file '%s' (mode: '%s')", + fd, path, mode); + } - close(fd); - if (oflag & O_CREAT) { - unlink(path); - } +end: + if (f == NULL && fd != -1) { + close(fd); + if (oflag & O_CREAT) { + unlink(path); } } - - error_propagate(errp, local_err); - return NULL; + return f; } int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode, From patchwork Wed May 25 14:41:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 12861372 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 C1E4EC433FE for ; Wed, 25 May 2022 15:17:04 +0000 (UTC) Received: from localhost ([::1]:34280 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntskx-0008Aw-ND for qemu-devel@archiver.kernel.org; Wed, 25 May 2022 11:17:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43788) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntsGo-00039a-MY for qemu-devel@nongnu.org; Wed, 25 May 2022 10:45:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:58287) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntsCv-000654-Ce for qemu-devel@nongnu.org; Wed, 25 May 2022 10:41:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653489712; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XpST3xr1kVKb7PaMJB8Emv+GgCBuZy2G3wWIf1G+QQo=; b=EMtyHmHQ9ZuhTMmhWRpJL+m8v81k/5AfrN+KZkxaI31IvcsGw+FbtNfpAO5MufauiXXFS7 skb4YSGst8WD2wA+EISU8SwYQRzKKnB9g3LpC1TQDwSIiS4lC/rnPguqaIRc4CGmkjQtMS Iz/Hi3QYW2ieCKGtD2VGajyjdwJBY7s= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-12-Qn3z7aFmMvOg1jl_DZ0vnw-1; Wed, 25 May 2022 10:41:51 -0400 X-MC-Unique: Qn3z7aFmMvOg1jl_DZ0vnw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2D2903C0ED45 for ; Wed, 25 May 2022 14:41:51 +0000 (UTC) Received: from localhost (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id D43DF40C1240; Wed, 25 May 2022 14:41:50 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Konstantin Kostiuk , Markus Armbruster , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [PATCH v5 05/15] qga: add qga_open_cloexec() helper Date: Wed, 25 May 2022 16:41:30 +0200 Message-Id: <20220525144140.591926-6-marcandre.lureau@redhat.com> In-Reply-To: <20220525144140.591926-1-marcandre.lureau@redhat.com> References: <20220525144140.591926-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau QGA calls qemu_open_old() in various places. Calling qemu_open() instead isn't a great alternative, as it has special "/dev/fdset" handling and depends on QEMU internal monitor data structures. Instead, provide a simple helper for QGA needs, with Error* support. The following patches will make use of it. Signed-off-by: Marc-André Lureau Reviewed-by: Markus Armbruster --- qga/cutils.h | 8 ++++++++ qga/cutils.c | 33 +++++++++++++++++++++++++++++++++ qga/meson.build | 1 + 3 files changed, 42 insertions(+) create mode 100644 qga/cutils.h create mode 100644 qga/cutils.c diff --git a/qga/cutils.h b/qga/cutils.h new file mode 100644 index 0000000000..f0f30a7d28 --- /dev/null +++ b/qga/cutils.h @@ -0,0 +1,8 @@ +#ifndef CUTILS_H_ +#define CUTILS_H_ + +#include "qemu/osdep.h" + +int qga_open_cloexec(const char *name, int flags, mode_t mode); + +#endif /* CUTILS_H_ */ diff --git a/qga/cutils.c b/qga/cutils.c new file mode 100644 index 0000000000..b8e142ef64 --- /dev/null +++ b/qga/cutils.c @@ -0,0 +1,33 @@ +/* + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ +#include "cutils.h" + +#include "qapi/error.h" + +/** + * qga_open_cloexec: + * @name: the pathname to open + * @flags: as in open() + * @mode: as in open() + * + * A wrapper for open() function which sets O_CLOEXEC. + * + * On error, -1 is returned. + */ +int qga_open_cloexec(const char *name, int flags, mode_t mode) +{ + int ret; + +#ifdef O_CLOEXEC + ret = open(name, flags | O_CLOEXEC, mode); +#else + ret = open(name, flags, mode); + if (ret >= 0) { + qemu_set_cloexec(ret); + } +#endif + + return ret; +} diff --git a/qga/meson.build b/qga/meson.build index 6d9f39bb32..35fe2229e9 100644 --- a/qga/meson.build +++ b/qga/meson.build @@ -65,6 +65,7 @@ qga_ss.add(files( 'commands.c', 'guest-agent-command-state.c', 'main.c', + 'cutils.c', )) qga_ss.add(when: 'CONFIG_POSIX', if_true: files( 'channel-posix.c', From patchwork Wed May 25 14:41:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 12861300 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 37901C433FE for ; Wed, 25 May 2022 14:50:36 +0000 (UTC) Received: from localhost ([::1]:42076 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntsLL-0006xi-9P for qemu-devel@archiver.kernel.org; Wed, 25 May 2022 10:50:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43788) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntsGo-00039a-86 for qemu-devel@nongnu.org; Wed, 25 May 2022 10:45:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:40097) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntsCy-00065S-St for qemu-devel@nongnu.org; Wed, 25 May 2022 10:41:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653489716; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2uBEOyQEPIiObuqR7RI/+MglbL2+EMq4kneJ+0UPmX4=; b=ZL0l0NQ2Ds6Wsx2qcRGUWAvXomNJTVPs5hLd2XyHt4hTlKIu1aFcfv0gqhdTK6ufYgNQMr 1uBh76EBylDEj8OwRMdEmUSJJ6yQWda0s3XBO8JbH/LfxMq+8ydkrNI1Cy+DJP+LP/y68Q PMwY7/9aBZCbGUiYS4d60n8Irjrs/uE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-437-V4UQG6GHOgSUgDzzaNojKw-1; Wed, 25 May 2022 10:41:53 -0400 X-MC-Unique: V4UQG6GHOgSUgDzzaNojKw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AFC35185A794 for ; Wed, 25 May 2022 14:41:52 +0000 (UTC) Received: from localhost (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 31D191121315; Wed, 25 May 2022 14:41:52 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Konstantin Kostiuk , Markus Armbruster , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [PATCH v5 06/15] qga: use qga_open_cloexec() for safe_open_or_create() Date: Wed, 25 May 2022 16:41:31 +0200 Message-Id: <20220525144140.591926-7-marcandre.lureau@redhat.com> In-Reply-To: <20220525144140.591926-1-marcandre.lureau@redhat.com> References: <20220525144140.591926-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau The function takes care of setting CLOEXEC. Signed-off-by: Marc-André Lureau Reviewed-by: Markus Armbruster --- qga/commands-posix.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 8ee149e550..88ccbf2fdf 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -27,6 +27,7 @@ #include "qemu/cutils.h" #include "commands-common.h" #include "block/nvme.h" +#include "cutils.h" #ifdef HAVE_UTMPX #include @@ -370,10 +371,10 @@ safe_open_or_create(const char *path, const char *mode, Error **errp) * open() is decisive and its third argument is ignored, and the second * open() and the fchmod() are never called. */ - fd = open(path, oflag | ((oflag & O_CREAT) ? O_EXCL : 0), 0); + fd = qga_open_cloexec(path, oflag | ((oflag & O_CREAT) ? O_EXCL : 0), 0); if (fd == -1 && errno == EEXIST) { oflag &= ~(unsigned)O_CREAT; - fd = open(path, oflag); + fd = qga_open_cloexec(path, oflag, 0); } if (fd == -1) { error_setg_errno(errp, errno, @@ -382,8 +383,6 @@ safe_open_or_create(const char *path, const char *mode, Error **errp) goto end; } - qemu_set_cloexec(fd); - if ((oflag & O_CREAT) && fchmod(fd, DEFAULT_NEW_FILE_MODE) == -1) { error_setg_errno(errp, errno, "failed to set permission " "0%03o on new file '%s' (mode: '%s')", From patchwork Wed May 25 14:41:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 12861371 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 1EE47C433EF for ; Wed, 25 May 2022 15:14:16 +0000 (UTC) Received: from localhost ([::1]:59582 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntsiF-0005qj-1P for qemu-devel@archiver.kernel.org; Wed, 25 May 2022 11:14:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43796) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntsGo-0003Ex-8T for qemu-devel@nongnu.org; Wed, 25 May 2022 10:45:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:57961) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntsCy-00065O-4e for qemu-devel@nongnu.org; Wed, 25 May 2022 10:41:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653489715; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JxY9MA5x6iqOBnouDVh/yzYbs9SpUuAnmlQWplmWNGw=; b=Pv1u1TXBhWULjEJLfsfna9YCNplpOCFJ/COZ+41bwJnQGsueixBCe78rp4uSDAEJzKpzmC PD3iHEE4FAmwjTR7fLS0RBAdZzeQqwKlsJj7/XUHOaLhGyP1ne4pFlK1hOQfsO0ehTgzH8 fjJg/NUxh/rJ4/u45ZmjLsEhq6BPys4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-31-DHNpZfYjMw2iUPbNW3q3LQ-1; Wed, 25 May 2022 10:41:54 -0400 X-MC-Unique: DHNpZfYjMw2iUPbNW3q3LQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DBE97185A794 for ; Wed, 25 May 2022 14:41:53 +0000 (UTC) Received: from localhost (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 934D240C1240; Wed, 25 May 2022 14:41:53 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Konstantin Kostiuk , Markus Armbruster , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [PATCH v5 07/15] qga: throw an Error in ga_channel_open() Date: Wed, 25 May 2022 16:41:32 +0200 Message-Id: <20220525144140.591926-8-marcandre.lureau@redhat.com> In-Reply-To: <20220525144140.591926-1-marcandre.lureau@redhat.com> References: <20220525144140.591926-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau Allow for a single point of error reporting, and further refactoring. Signed-off-by: Marc-André Lureau Reviewed-by: Markus Armbruster --- qga/channel-posix.c | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/qga/channel-posix.c b/qga/channel-posix.c index a996858e24..25fcc5cb1a 100644 --- a/qga/channel-posix.c +++ b/qga/channel-posix.c @@ -119,7 +119,7 @@ static int ga_channel_client_add(GAChannel *c, int fd) } static gboolean ga_channel_open(GAChannel *c, const gchar *path, - GAChannelMethod method, int fd) + GAChannelMethod method, int fd, Error **errp) { int ret; c->method = method; @@ -133,21 +133,20 @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, #endif ); if (fd == -1) { - g_critical("error opening channel: %s", strerror(errno)); + error_setg_errno(errp, errno, "error opening channel"); return false; } #ifdef CONFIG_SOLARIS ret = ioctl(fd, I_SETSIG, S_OUTPUT | S_INPUT | S_HIPRI); if (ret == -1) { - g_critical("error setting event mask for channel: %s", - strerror(errno)); + error_setg_errno(errp, errno, "error setting event mask for channel"); close(fd); return false; } #endif ret = ga_channel_client_add(c, fd); if (ret) { - g_critical("error adding channel to main loop"); + error_setg(errp, "error adding channel to main loop"); close(fd); return false; } @@ -159,7 +158,7 @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, assert(fd < 0); fd = qemu_open_old(path, O_RDWR | O_NOCTTY | O_NONBLOCK); if (fd == -1) { - g_critical("error opening channel: %s", strerror(errno)); + error_setg_errno(errp, errno, "error opening channel"); return false; } tcgetattr(fd, &tio); @@ -180,7 +179,7 @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, tcsetattr(fd, TCSANOW, &tio); ret = ga_channel_client_add(c, fd); if (ret) { - g_critical("error adding channel to main loop"); + error_setg(errp, "error adding channel to main loop"); close(fd); return false; } @@ -188,12 +187,8 @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, } case GA_CHANNEL_UNIX_LISTEN: { if (fd < 0) { - Error *local_err = NULL; - - fd = unix_listen(path, &local_err); - if (local_err != NULL) { - g_critical("%s", error_get_pretty(local_err)); - error_free(local_err); + fd = unix_listen(path, errp); + if (fd < 0) { return false; } } @@ -202,24 +197,19 @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, } case GA_CHANNEL_VSOCK_LISTEN: { if (fd < 0) { - Error *local_err = NULL; SocketAddress *addr; char *addr_str; addr_str = g_strdup_printf("vsock:%s", path); - addr = socket_parse(addr_str, &local_err); + addr = socket_parse(addr_str, errp); g_free(addr_str); - if (local_err != NULL) { - g_critical("%s", error_get_pretty(local_err)); - error_free(local_err); + if (!addr) { return false; } - fd = socket_listen(addr, 1, &local_err); + fd = socket_listen(addr, 1, errp); qapi_free_SocketAddress(addr); - if (local_err != NULL) { - g_critical("%s", error_get_pretty(local_err)); - error_free(local_err); + if (fd < 0) { return false; } } @@ -227,7 +217,7 @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, break; } default: - g_critical("error binding/listening to specified socket"); + error_setg(errp, "error binding/listening to specified socket"); return false; } @@ -272,12 +262,14 @@ GIOStatus ga_channel_read(GAChannel *c, gchar *buf, gsize size, gsize *count) GAChannel *ga_channel_new(GAChannelMethod method, const gchar *path, int listen_fd, GAChannelCallback cb, gpointer opaque) { + Error *err = NULL; GAChannel *c = g_new0(GAChannel, 1); c->event_cb = cb; c->user_data = opaque; - if (!ga_channel_open(c, path, method, listen_fd)) { - g_critical("error opening channel"); + if (!ga_channel_open(c, path, method, listen_fd, &err)) { + g_critical("%s", error_get_pretty(err)); + error_free(err); ga_channel_free(c); return NULL; } From patchwork Wed May 25 14:41:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 12861307 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 6A660C433F5 for ; Wed, 25 May 2022 14:58:42 +0000 (UTC) Received: from localhost ([::1]:59368 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntsTB-00028I-BG for qemu-devel@archiver.kernel.org; Wed, 25 May 2022 10:58:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43796) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntsGn-0003Ex-Rb for qemu-devel@nongnu.org; Wed, 25 May 2022 10:45:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:25323) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntsCz-00065X-8g for qemu-devel@nongnu.org; Wed, 25 May 2022 10:41:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653489716; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2txoi8kzLWAOR77xToALWlamClGyip6/Kibhx/lHuiE=; b=D+QObjo/TCb2c0pylIAUdkTfSskDPa1X8jcfuQl4r8Lwlp3V6jJHrFQ6xEVwCr2GE/ZJLM 5mzOfxu9HZTgdO+koiGCnqb+OYNjTX/0vfcGNSgtH8Ia+mdaCy7K607Ee3rSszuo9H2leP i1/usiXBUUqGjIIhyINL6Fn7o6zjfkM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-346-XQhbvHz_PsGXPzv5R8tOZQ-1; Wed, 25 May 2022 10:41:55 -0400 X-MC-Unique: XQhbvHz_PsGXPzv5R8tOZQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2EDB9811E7A for ; Wed, 25 May 2022 14:41:55 +0000 (UTC) Received: from localhost (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id B5718400F36; Wed, 25 May 2022 14:41:54 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Konstantin Kostiuk , Markus Armbruster , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [PATCH v5 08/15] qga: replace qemu_open_old() with qga_open_cloexec() Date: Wed, 25 May 2022 16:41:33 +0200 Message-Id: <20220525144140.591926-9-marcandre.lureau@redhat.com> In-Reply-To: <20220525144140.591926-1-marcandre.lureau@redhat.com> References: <20220525144140.591926-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau qemu_open_old() uses qemu_open_internal() which handles special "/dev/fdset/" path for monitor fd sets, set CLOEXEC, and uses Error reporting (and some O_DIRECT special error casing). The monitor fdset handling is unnecessary for qga, use qga_open_cloexec() instead. Signed-off-by: Marc-André Lureau Reviewed-by: Konstantin Kostiuk --- qga/channel-posix.c | 13 +++++++++---- qga/commands-posix.c | 8 ++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/qga/channel-posix.c b/qga/channel-posix.c index 25fcc5cb1a..6796a02cff 100644 --- a/qga/channel-posix.c +++ b/qga/channel-posix.c @@ -1,8 +1,10 @@ #include "qemu/osdep.h" +#include "qemu/cutils.h" #include #include "qapi/error.h" #include "qemu/sockets.h" #include "channel.h" +#include "cutils.h" #ifdef CONFIG_SOLARIS #include @@ -127,11 +129,14 @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, switch (c->method) { case GA_CHANNEL_VIRTIO_SERIAL: { assert(fd < 0); - fd = qemu_open_old(path, O_RDWR | O_NONBLOCK + fd = qga_open_cloexec( + path, #ifndef CONFIG_SOLARIS - | O_ASYNC + O_ASYNC | #endif - ); + O_RDWR | O_NONBLOCK, + 0 + ); if (fd == -1) { error_setg_errno(errp, errno, "error opening channel"); return false; @@ -156,7 +161,7 @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, struct termios tio; assert(fd < 0); - fd = qemu_open_old(path, O_RDWR | O_NOCTTY | O_NONBLOCK); + fd = qga_open_cloexec(path, O_RDWR | O_NOCTTY | O_NONBLOCK, 0); if (fd == -1) { error_setg_errno(errp, errno, "error opening channel"); return false; diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 88ccbf2fdf..ff2d21d394 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -1406,7 +1406,7 @@ static void get_nvme_smart(GuestDiskInfo *disk) | (((sizeof(log) >> 2) - 1) << 16) }; - fd = qemu_open_old(disk->name, O_RDONLY); + fd = qga_open_cloexec(disk->name, O_RDONLY, 0); if (fd == -1) { g_debug("Failed to open device: %s: %s", disk->name, g_strerror(errno)); return; @@ -1739,7 +1739,7 @@ int64_t qmp_guest_fsfreeze_freeze_list(bool has_mountpoints, } } - fd = qemu_open_old(mount->dirname, O_RDONLY); + fd = qga_open_cloexec(mount->dirname, O_RDONLY, 0); if (fd == -1) { error_setg_errno(errp, errno, "failed to open %s", mount->dirname); goto error; @@ -1806,7 +1806,7 @@ int64_t qmp_guest_fsfreeze_thaw(Error **errp) QTAILQ_FOREACH(mount, &mounts, next) { logged = false; - fd = qemu_open_old(mount->dirname, O_RDONLY); + fd = qga_open_cloexec(mount->dirname, O_RDONLY, 0); if (fd == -1) { continue; } @@ -1892,7 +1892,7 @@ qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp) QAPI_LIST_PREPEND(response->paths, result); - fd = qemu_open_old(mount->dirname, O_RDONLY); + fd = qga_open_cloexec(mount->dirname, O_RDONLY, 0); if (fd == -1) { result->error = g_strdup_printf("failed to open: %s", strerror(errno)); From patchwork Wed May 25 14:41:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 12861305 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 39A2DC433EF for ; Wed, 25 May 2022 14:58:33 +0000 (UTC) Received: from localhost ([::1]:58516 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntsT2-0001Z8-7r for qemu-devel@archiver.kernel.org; Wed, 25 May 2022 10:58:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43788) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntsGl-00039a-MG for qemu-devel@nongnu.org; Wed, 25 May 2022 10:45:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52685) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntsDA-00067r-4G for qemu-devel@nongnu.org; Wed, 25 May 2022 10:42:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653489727; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W+wrMyYVWWFGnPXi/rJyzvNkUQBqAEAKXc6ego1U/n4=; b=Irc4oxsaA44LxJRWYwU5Kye+JmqVqQ5dgbxNKJeawZAtdfZ39S01GxZ42TUdWbCapeSQMJ nq0cDETzUQTEqlom8scIik0guHv6mDf0DddPziHeR7gO8Y1FIvrr/ZizKyVJt5rDymmcV4 W4AnnX2tvXyF+n8+FPfFqBaWb3lvn/Y= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-446-T9617xrSPjKWyQQ38uq01g-1; Wed, 25 May 2022 10:41:56 -0400 X-MC-Unique: T9617xrSPjKWyQQ38uq01g-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6C81480418B for ; Wed, 25 May 2022 14:41:56 +0000 (UTC) Received: from localhost (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1940582872; Wed, 25 May 2022 14:41:55 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Konstantin Kostiuk , Markus Armbruster , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [PATCH v5 09/15] qga: make build_fs_mount_list() return a bool Date: Wed, 25 May 2022 16:41:34 +0200 Message-Id: <20220525144140.591926-10-marcandre.lureau@redhat.com> In-Reply-To: <20220525144140.591926-1-marcandre.lureau@redhat.com> References: <20220525144140.591926-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau Change build_fs_mount_list() to return bool, in accordance with the guidance under = Rules = in include/qapi/error.h Signed-off-by: Marc-André Lureau Suggested-by: Markus Armbruster --- qga/commands-posix.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index ff2d21d394..af93faae97 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -673,7 +673,7 @@ static int dev_major_minor(const char *devpath, /* * Walk the mount table and build a list of local file systems */ -static void build_fs_mount_list_from_mtab(FsMountList *mounts, Error **errp) +static bool build_fs_mount_list_from_mtab(FsMountList *mounts, Error **errp) { struct mntent *ment; FsMount *mount; @@ -684,7 +684,7 @@ static void build_fs_mount_list_from_mtab(FsMountList *mounts, Error **errp) fp = setmntent(mtab, "r"); if (!fp) { error_setg(errp, "failed to open mtab file: '%s'", mtab); - return; + return false; } while ((ment = getmntent(fp))) { @@ -714,6 +714,7 @@ static void build_fs_mount_list_from_mtab(FsMountList *mounts, Error **errp) } endmntent(fp); + return true; } static void decode_mntname(char *name, int len) @@ -738,7 +739,7 @@ static void decode_mntname(char *name, int len) } } -static void build_fs_mount_list(FsMountList *mounts, Error **errp) +static bool build_fs_mount_list(FsMountList *mounts, Error **errp) { FsMount *mount; char const *mountinfo = "/proc/self/mountinfo"; @@ -751,8 +752,7 @@ static void build_fs_mount_list(FsMountList *mounts, Error **errp) fp = fopen(mountinfo, "r"); if (!fp) { - build_fs_mount_list_from_mtab(mounts, errp); - return; + return build_fs_mount_list_from_mtab(mounts, errp); } while (getline(&line, &n, fp) != -1) { @@ -794,6 +794,7 @@ static void build_fs_mount_list(FsMountList *mounts, Error **errp) free(line); fclose(fp); + return true; } #endif @@ -1592,8 +1593,7 @@ GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error **errp) Error *local_err = NULL; QTAILQ_INIT(&mounts); - build_fs_mount_list(&mounts, &local_err); - if (local_err) { + if (!build_fs_mount_list(&mounts, &local_err)) { error_propagate(errp, local_err); return NULL; } @@ -1716,8 +1716,7 @@ int64_t qmp_guest_fsfreeze_freeze_list(bool has_mountpoints, } QTAILQ_INIT(&mounts); - build_fs_mount_list(&mounts, &local_err); - if (local_err) { + if (!build_fs_mount_list(&mounts, &local_err)) { error_propagate(errp, local_err); return -1; } @@ -1798,8 +1797,7 @@ int64_t qmp_guest_fsfreeze_thaw(Error **errp) Error *local_err = NULL; QTAILQ_INIT(&mounts); - build_fs_mount_list(&mounts, &local_err); - if (local_err) { + if (!build_fs_mount_list(&mounts, &local_err)) { error_propagate(errp, local_err); return 0; } @@ -1872,15 +1870,12 @@ qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp) FsMountList mounts; struct FsMount *mount; int fd; - Error *local_err = NULL; struct fstrim_range r; slog("guest-fstrim called"); QTAILQ_INIT(&mounts); - build_fs_mount_list(&mounts, &local_err); - if (local_err) { - error_propagate(errp, local_err); + if (!build_fs_mount_list(&mounts, errp)) { return NULL; } From patchwork Wed May 25 14:41:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 12861360 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 5249AC433EF for ; Wed, 25 May 2022 15:09:27 +0000 (UTC) Received: from localhost ([::1]:54110 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntsda-0001n6-Bz for qemu-devel@archiver.kernel.org; Wed, 25 May 2022 11:09:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43788) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntsGn-00039a-PH for qemu-devel@nongnu.org; Wed, 25 May 2022 10:45:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:29875) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntsD1-00066C-Sb for qemu-devel@nongnu.org; Wed, 25 May 2022 10:42:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653489719; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Dfx+q3Dn0Ils4WrtLZG0dAJwyOvO8aRP4o4o6IbtNzs=; b=hQNDx3H9HWsDR2CkaIXTtLlt+oEVb3bfOGqj+4LWhCHV1RO0sKT8ZzvF8ZdVQpuBqfDlTR NibJ92SYag4mPjURnzqvriod7KnOUGsgBW+ALNUl7by25ZkiEikyhLt3YrnbnNgBLaDPtL cISqq8LFa+cDSfz1oXHJwK1/zPBlJxY= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-518-86-MzcfgMUyQbJ-7DRAwIQ-1; Wed, 25 May 2022 10:41:58 -0400 X-MC-Unique: 86-MzcfgMUyQbJ-7DRAwIQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D18CE3802B8B for ; Wed, 25 May 2022 14:41:57 +0000 (UTC) Received: from localhost (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 74D701121315; Wed, 25 May 2022 14:41:57 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Konstantin Kostiuk , Markus Armbruster , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [PATCH v5 10/15] test/qga: use G_TEST_DIR to locate os-release test file Date: Wed, 25 May 2022 16:41:35 +0200 Message-Id: <20220525144140.591926-11-marcandre.lureau@redhat.com> In-Reply-To: <20220525144140.591926-1-marcandre.lureau@redhat.com> References: <20220525144140.591926-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau This a more accurate way to lookup the test data, and will allow to move the test in a subproject. Signed-off-by: Marc-André Lureau Reviewed-by: Konstantin Kostiuk --- tests/unit/test-qga.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/unit/test-qga.c b/tests/unit/test-qga.c index d6df1ee92e..ab0b12a2dd 100644 --- a/tests/unit/test-qga.c +++ b/tests/unit/test-qga.c @@ -914,15 +914,14 @@ static void test_qga_guest_get_osinfo(gconstpointer data) { TestFixture fixture; const gchar *str; - gchar *cwd, *env[2]; - QDict *ret, *val; + QDict *ret = NULL; + char *env[2]; + QDict *val; - cwd = g_get_current_dir(); env[0] = g_strdup_printf( - "QGA_OS_RELEASE=%s%ctests%cdata%ctest-qga-os-release", - cwd, G_DIR_SEPARATOR, G_DIR_SEPARATOR, G_DIR_SEPARATOR); + "QGA_OS_RELEASE=%s%c..%cdata%ctest-qga-os-release", + g_test_get_dir(G_TEST_DIST), G_DIR_SEPARATOR, G_DIR_SEPARATOR, G_DIR_SEPARATOR); env[1] = NULL; - g_free(cwd); fixture_setup(&fixture, NULL, env); ret = qmp_fd(fixture.fd, "{'execute': 'guest-get-osinfo'}"); From patchwork Wed May 25 14:41:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 12861301 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 EC363C433EF for ; Wed, 25 May 2022 14:50:46 +0000 (UTC) Received: from localhost ([::1]:42332 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntsLV-00078t-PV for qemu-devel@archiver.kernel.org; Wed, 25 May 2022 10:50:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43740) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntsGn-00033c-RM for qemu-devel@nongnu.org; Wed, 25 May 2022 10:45:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:29506) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntsD3-00066R-7r for qemu-devel@nongnu.org; Wed, 25 May 2022 10:42:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653489720; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BuMkuLbO3FE4e8SShPa84Ul5IHRCRshPWDNr/z6aoG4=; b=VEzVebZwGN8+h1ACvJNGKbxTLGB3zhWPBfmgV1yEU0iKrkCOp1qAMWZMm/NjI2ISBjbcbD B7ut/iunmqoRvZYnsa31IWupMBA340TprfCvWMQcXBMLPRbqf9vKjqWRsM77MW/MBR41jz yIJFNaToMvzTwXBu/HDhvV4hB0P7Whc= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-423-1cGm5I83OTC-iOJkF-2DtA-1; Wed, 25 May 2022 10:41:59 -0400 X-MC-Unique: 1cGm5I83OTC-iOJkF-2DtA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1C52B1C0CE6A for ; Wed, 25 May 2022 14:41:59 +0000 (UTC) Received: from localhost (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id B476C112131B; Wed, 25 May 2022 14:41:58 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Konstantin Kostiuk , Markus Armbruster , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [PATCH v5 11/15] qga/wixl: prefer variables over environment Date: Wed, 25 May 2022 16:41:36 +0200 Message-Id: <20220525144140.591926-12-marcandre.lureau@redhat.com> In-Reply-To: <20220525144140.591926-1-marcandre.lureau@redhat.com> References: <20220525144140.591926-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau No need to setup an environment or to check if the variable is undefined manually. Signed-off-by: Marc-André Lureau Reviewed-by: Konstantin Kostiuk --- qga/installer/qemu-ga.wxs | 30 +++++++++--------------------- qga/meson.build | 9 ++++----- 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/qga/installer/qemu-ga.wxs b/qga/installer/qemu-ga.wxs index 0950e8c6be..8a19aa1656 100644 --- a/qga/installer/qemu-ga.wxs +++ b/qga/installer/qemu-ga.wxs @@ -1,17 +1,5 @@ - - - - - - - - - - - - @@ -43,20 +31,20 @@ Name="QEMU guest agent" Id="*" UpgradeCode="{EB6B8302-C06E-4BEC-ADAC-932C68A3A98D}" - Manufacturer="$(env.QEMU_GA_MANUFACTURER)" - Version="$(env.QEMU_GA_VERSION)" + Manufacturer="$(var.QEMU_GA_MANUFACTURER)" + Version="$(var.QEMU_GA_VERSION)" Language="1033"> NOT VersionNT64 - + - + - + - + @@ -133,9 +121,9 @@ + Key="Software\$(var.QEMU_GA_MANUFACTURER)\$(var.QEMU_GA_DISTRO)\Tools\QemuGA"> - + diff --git a/qga/meson.build b/qga/meson.build index 35fe2229e9..31370405f9 100644 --- a/qga/meson.build +++ b/qga/meson.build @@ -122,15 +122,14 @@ if targetos == 'windows' output: 'qemu-ga-@0@.msi'.format(host_arch), depends: deps, command: [ - find_program('env'), - 'QEMU_GA_VERSION=' + config_host['QEMU_GA_VERSION'], - 'QEMU_GA_MANUFACTURER=' + config_host['QEMU_GA_MANUFACTURER'], - 'QEMU_GA_DISTRO=' + config_host['QEMU_GA_DISTRO'], - 'BUILD_DIR=' + meson.build_root(), wixl, '-o', '@OUTPUT0@', '@INPUT0@', qemu_ga_msi_arch[cpu], qemu_ga_msi_vss, + '-D', 'BUILD_DIR=' + meson.build_root(), '-D', 'Mingw_bin=' + config_host['QEMU_GA_MSI_MINGW_BIN_PATH'], + '-D', 'QEMU_GA_VERSION=' + config_host['QEMU_GA_VERSION'], + '-D', 'QEMU_GA_MANUFACTURER=' + config_host['QEMU_GA_MANUFACTURER'], + '-D', 'QEMU_GA_DISTRO=' + config_host['QEMU_GA_DISTRO'], ]) all_qga += [qga_msi] alias_target('msi', qga_msi) From patchwork Wed May 25 14:41:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 12861350 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 868EDC433F5 for ; Wed, 25 May 2022 15:06:37 +0000 (UTC) Received: from localhost ([::1]:47196 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntsaq-0004y1-Ig for qemu-devel@archiver.kernel.org; Wed, 25 May 2022 11:06:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43788) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntsGm-00039a-Cj for qemu-devel@nongnu.org; Wed, 25 May 2022 10:45:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:46888) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntsD4-00066e-KW for qemu-devel@nongnu.org; Wed, 25 May 2022 10:42:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653489722; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xHa+MKmmyBQTjsqTAkhCU6sL+AVzFTPDl677BcvCVPg=; b=A+zkp29iLIBubvDhDvuwf3NT6KtZecDoTukfZcpwHwKw30QoRDX+KIe4ZGkqt7F5cw0dJL XnlNAuYK9CcQ5m30IK0Lo7nwz15hjuw9TtiCim4HhCf5nCC7K0XaWMLzgJfWTdWOf0pEwY z5zOJfrTwoWFnUa06a9zN4yl7rumh1A= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-594-VTuuwc1QM9aMFqR62S_LEw-1; Wed, 25 May 2022 10:42:00 -0400 X-MC-Unique: VTuuwc1QM9aMFqR62S_LEw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3B086801E6B for ; Wed, 25 May 2022 14:42:00 +0000 (UTC) Received: from localhost (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id E520740D0160; Wed, 25 May 2022 14:41:59 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Konstantin Kostiuk , Markus Armbruster , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [PATCH v5 12/15] qga/wixl: require Mingw_bin Date: Wed, 25 May 2022 16:41:37 +0200 Message-Id: <20220525144140.591926-13-marcandre.lureau@redhat.com> In-Reply-To: <20220525144140.591926-1-marcandre.lureau@redhat.com> References: <20220525144140.591926-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau No clear reason to make guesses here. Signed-off-by: Marc-André Lureau Reviewed-by: Konstantin Kostiuk --- qga/installer/qemu-ga.wxs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/qga/installer/qemu-ga.wxs b/qga/installer/qemu-ga.wxs index 8a19aa1656..651db6e51c 100644 --- a/qga/installer/qemu-ga.wxs +++ b/qga/installer/qemu-ga.wxs @@ -4,15 +4,6 @@ - - - - - - - - - From patchwork Wed May 25 14:41:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 12861348 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 6F2B8C433EF for ; Wed, 25 May 2022 15:03:04 +0000 (UTC) Received: from localhost ([::1]:38878 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntsXP-0007YK-CP for qemu-devel@archiver.kernel.org; Wed, 25 May 2022 11:03:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43796) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntsGl-0003Ex-MC for qemu-devel@nongnu.org; Wed, 25 May 2022 10:45:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:43232) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntsD5-00066s-Jf for qemu-devel@nongnu.org; Wed, 25 May 2022 10:42:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653489723; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=v3LVImncM88Cgi5k/8KLgFb4Y+UE9CZITjEiSgR1j/I=; b=Ujzm10jgXBO19uNXfq8q+snp+xIFUpCgCWCKk0oDEPFjpAujS9sa3DiT4acUbtAAPqYM/T pzLUi5cKthD1nfP1LYjmH5uuRV+QJogBm2CfpUJpMyNBEPXIxPrORHnNpdHr5+S1ffgEKe xnrXdaP6eifhsHuU7iJdLO5lSbVrksc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-462-r2B4cpl2O5WUTi7kdVLF7A-1; Wed, 25 May 2022 10:42:01 -0400 X-MC-Unique: r2B4cpl2O5WUTi7kdVLF7A-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6872B8001EA for ; Wed, 25 May 2022 14:42:01 +0000 (UTC) Received: from localhost (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1E2901730C; Wed, 25 May 2022 14:42:00 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Konstantin Kostiuk , Markus Armbruster , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [PATCH v5 13/15] qga/wixl: simplify some pre-processing Date: Wed, 25 May 2022 16:41:38 +0200 Message-Id: <20220525144140.591926-14-marcandre.lureau@redhat.com> In-Reply-To: <20220525144140.591926-1-marcandre.lureau@redhat.com> References: <20220525144140.591926-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau Sadly, wixl doesn't have 'elif'. Signed-off-by: Marc-André Lureau Reviewed-by: Konstantin Kostiuk --- qga/installer/qemu-ga.wxs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/qga/installer/qemu-ga.wxs b/qga/installer/qemu-ga.wxs index 651db6e51c..e5b0958e18 100644 --- a/qga/installer/qemu-ga.wxs +++ b/qga/installer/qemu-ga.wxs @@ -1,21 +1,15 @@ - - - - - - - - - - - - - + + + + + + + X-Patchwork-Id: 12861299 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 A9D66C433F5 for ; Wed, 25 May 2022 14:50:34 +0000 (UTC) Received: from localhost ([::1]:42050 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntsLJ-0006wl-FQ for qemu-devel@archiver.kernel.org; Wed, 25 May 2022 10:50:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43796) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntsGj-0003Ex-Ko for qemu-devel@nongnu.org; Wed, 25 May 2022 10:45:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:58427) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntsD6-00067F-Mo for qemu-devel@nongnu.org; Wed, 25 May 2022 10:42:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653489724; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5JbYi6GhW0Xl9ocEi87oDn66jtx/NaHWH8zGMO2MaiY=; b=Nw3dizgaQpKf3ynLI4xQsElTzWTMdHZc80+tZ3ZA02i9T0gcVGYFNV1GiplSdsPMmXqboO ew7uKrDsPKCbVdXXbH+ordStK6pDb6NZgqpiRBYo/Fcwt6HWb5ekloyh0KrV1z0c6d+8n3 R/48fG98+lpzujZ6bgM4YKZmMfdLF+Q= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-126-EEOM1bYbPoad7cQKSBuPMQ-1; Wed, 25 May 2022 10:42:03 -0400 X-MC-Unique: EEOM1bYbPoad7cQKSBuPMQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BA4B0811E83 for ; Wed, 25 May 2022 14:42:02 +0000 (UTC) Received: from localhost (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6ACE8400F38; Wed, 25 May 2022 14:42:02 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Konstantin Kostiuk , Markus Armbruster , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [PATCH v5 14/15] qga/wixl: replace QEMU_GA_MSI_MINGW_BIN_PATH with glib bindir Date: Wed, 25 May 2022 16:41:39 +0200 Message-Id: <20220525144140.591926-15-marcandre.lureau@redhat.com> In-Reply-To: <20220525144140.591926-1-marcandre.lureau@redhat.com> References: <20220525144140.591926-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau Use more conventional variables to set the location of pre-built DLL/bin. Signed-off-by: Marc-André Lureau Reviewed-by: Konstantin Kostiuk --- configure | 9 ++++++--- meson.build | 5 ++++- qga/installer/qemu-ga.wxs | 24 ++++++++++++------------ qga/meson.build | 2 +- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/configure b/configure index 180ee688dc..f2baf2f526 100755 --- a/configure +++ b/configure @@ -1495,6 +1495,11 @@ for i in $glib_modules; do fi done +glib_bindir="$($pkg_config --variable=bindir glib-2.0)" +if test -z "$glib_bindir" ; then + glib_bindir="$($pkg_config --variable=prefix glib-2.0)"/bin +fi + # This workaround is required due to a bug in pkg-config file for glib as it # doesn't define GLIB_STATIC_COMPILATION for pkg-config --static @@ -1860,8 +1865,6 @@ if test "$QEMU_GA_VERSION" = ""; then QEMU_GA_VERSION=$(cat $source_path/VERSION) fi -QEMU_GA_MSI_MINGW_BIN_PATH="$($pkg_config --variable=prefix glib-2.0)/bin" - # Mac OS X ships with a broken assembler roms= if { test "$cpu" = "i386" || test "$cpu" = "x86_64"; } && \ @@ -1948,7 +1951,6 @@ if test "$debug_tcg" = "yes" ; then fi if test "$mingw32" = "yes" ; then echo "CONFIG_WIN32=y" >> $config_host_mak - echo "QEMU_GA_MSI_MINGW_BIN_PATH=${QEMU_GA_MSI_MINGW_BIN_PATH}" >> $config_host_mak echo "QEMU_GA_MANUFACTURER=${QEMU_GA_MANUFACTURER}" >> $config_host_mak echo "QEMU_GA_DISTRO=${QEMU_GA_DISTRO}" >> $config_host_mak echo "QEMU_GA_VERSION=${QEMU_GA_VERSION}" >> $config_host_mak @@ -2020,6 +2022,7 @@ echo "QEMU_CXXFLAGS=$QEMU_CXXFLAGS" >> $config_host_mak echo "QEMU_OBJCFLAGS=$QEMU_OBJCFLAGS" >> $config_host_mak echo "GLIB_CFLAGS=$glib_cflags" >> $config_host_mak echo "GLIB_LIBS=$glib_libs" >> $config_host_mak +echo "GLIB_BINDIR=$glib_bindir" >> $config_host_mak echo "GLIB_VERSION=$(pkg-config --modversion glib-2.0)" >> $config_host_mak echo "QEMU_LDFLAGS=$QEMU_LDFLAGS" >> $config_host_mak echo "LD_I386_EMULATION=$ld_i386_emulation" >> $config_host_mak diff --git a/meson.build b/meson.build index 9ebc00f032..8830b4dc1a 100644 --- a/meson.build +++ b/meson.build @@ -466,7 +466,10 @@ add_project_arguments(config_host['GLIB_CFLAGS'].split(), native: false, language: ['c', 'cpp', 'objc']) glib = declare_dependency(compile_args: config_host['GLIB_CFLAGS'].split(), link_args: config_host['GLIB_LIBS'].split(), - version: config_host['GLIB_VERSION']) + version: config_host['GLIB_VERSION'], + variables: { + 'bindir': config_host['GLIB_BINDIR'], + }) # override glib dep with the configure results (for subprojects) meson.override_dependency('glib-2.0', glib) diff --git a/qga/installer/qemu-ga.wxs b/qga/installer/qemu-ga.wxs index e5b0958e18..813d1c6ca6 100644 --- a/qga/installer/qemu-ga.wxs +++ b/qga/installer/qemu-ga.wxs @@ -58,7 +58,7 @@ - + @@ -69,40 +69,40 @@ - + - + - + - + - + - + - + - + - + - + - + X-Patchwork-Id: 12861303 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 AED16C433EF for ; Wed, 25 May 2022 14:55:31 +0000 (UTC) Received: from localhost ([::1]:50688 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntsQ4-0004Xe-U9 for qemu-devel@archiver.kernel.org; Wed, 25 May 2022 10:55:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43740) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntsGl-00033c-Ls for qemu-devel@nongnu.org; Wed, 25 May 2022 10:45:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:60488) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntsD8-00067Z-MG for qemu-devel@nongnu.org; Wed, 25 May 2022 10:42:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653489726; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5rZ9W7B5RI7Rp1xHh7Suqtb9Q7cqxrJIoPN6QF+yuNI=; b=KpxNoeHBBjCDF57C7nptG5STaLcFjl5JtZiTkwu17UNS7+1FVM1dhZctb2g8s4plTWmerx qnY14qLB6oU42/MGcSrLgQ45sfOSCHn/DF8lwALwOp77jShuVhEX+GIi2VLk1hzPriHksI bdk31BXCqGCbDu5YV55S/YdhRTPI/eU= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-490-6OZduiGePkOGkQPG7D-YfA-1; Wed, 25 May 2022 10:42:04 -0400 X-MC-Unique: 6OZduiGePkOGkQPG7D-YfA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 63A9A1C0F686 for ; Wed, 25 May 2022 14:42:04 +0000 (UTC) Received: from localhost (unknown [10.39.192.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id C3C16400F38; Wed, 25 May 2022 14:42:03 +0000 (UTC) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Konstantin Kostiuk , Markus Armbruster , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Subject: [PATCH v5 15/15] test/qga: use g_auto wherever sensible Date: Wed, 25 May 2022 16:41:40 +0200 Message-Id: <20220525144140.591926-16-marcandre.lureau@redhat.com> In-Reply-To: <20220525144140.591926-1-marcandre.lureau@redhat.com> References: <20220525144140.591926-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Marc-André Lureau Signed-off-by: Marc-André Lureau Reviewed-by: Konstantin Kostiuk --- tests/unit/test-qga.c | 121 +++++++++++++++--------------------------- 1 file changed, 43 insertions(+), 78 deletions(-) diff --git a/tests/unit/test-qga.c b/tests/unit/test-qga.c index ab0b12a2dd..530317044b 100644 --- a/tests/unit/test-qga.c +++ b/tests/unit/test-qga.c @@ -52,7 +52,10 @@ fixture_setup(TestFixture *fixture, gconstpointer data, gchar **envp) { const gchar *extra_arg = data; GError *error = NULL; - gchar *cwd, *path, *cmd, **argv = NULL; + g_autofree char *cwd = NULL; + g_autofree char *path = NULL; + g_autofree char *cmd = NULL; + g_auto(GStrv) argv = NULL; fixture->loop = g_main_loop_new(NULL, FALSE); @@ -78,17 +81,12 @@ fixture_setup(TestFixture *fixture, gconstpointer data, gchar **envp) fixture->fd = connect_qga(path); g_assert_cmpint(fixture->fd, !=, -1); - - g_strfreev(argv); - g_free(cmd); - g_free(cwd); - g_free(path); } static void fixture_tear_down(TestFixture *fixture, gconstpointer data) { - gchar *tmp; + g_autofree char *tmp = NULL; kill(fixture->pid, SIGTERM); @@ -107,7 +105,6 @@ fixture_tear_down(TestFixture *fixture, gconstpointer data) tmp = g_build_filename(fixture->test_dir, "sock", NULL); g_unlink(tmp); - g_free(tmp); g_rmdir(fixture->test_dir); g_free(fixture->test_dir); @@ -122,7 +119,7 @@ static void qmp_assertion_message_error(const char *domain, QDict *dict) { const char *class, *desc; - char *s; + g_autofree char *s = NULL; QDict *error; error = qdict_get_qdict(dict, "error"); @@ -131,7 +128,6 @@ static void qmp_assertion_message_error(const char *domain, s = g_strdup_printf("assertion failed %s: %s %s", expr, class, desc); g_assertion_message(domain, file, line, func, s); - g_free(s); } #define qmp_assert_no_error(err) do { \ @@ -146,7 +142,7 @@ static void test_qga_sync_delimited(gconstpointer fix) const TestFixture *fixture = fix; guint32 v, r = g_test_rand_int(); unsigned char c; - QDict *ret; + g_autoptr(QDict) ret = NULL; qmp_fd_send_raw(fixture->fd, "\xff"); qmp_fd_send(fixture->fd, @@ -180,15 +176,13 @@ static void test_qga_sync_delimited(gconstpointer fix) v = qdict_get_int(ret, "return"); g_assert_cmpint(r, ==, v); - - qobject_unref(ret); } static void test_qga_sync(gconstpointer fix) { const TestFixture *fixture = fix; guint32 v, r = g_test_rand_int(); - QDict *ret; + g_autoptr(QDict) ret = NULL; /* * TODO guest-sync is inherently limited: we cannot distinguish @@ -210,33 +204,27 @@ static void test_qga_sync(gconstpointer fix) v = qdict_get_int(ret, "return"); g_assert_cmpint(r, ==, v); - - qobject_unref(ret); } static void test_qga_ping(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret; + g_autoptr(QDict) ret = NULL; ret = qmp_fd(fixture->fd, "{'execute': 'guest-ping'}"); g_assert_nonnull(ret); qmp_assert_no_error(ret); - - qobject_unref(ret); } static void test_qga_id(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret; + g_autoptr(QDict) ret = NULL; ret = qmp_fd(fixture->fd, "{'execute': 'guest-ping', 'id': 1}"); g_assert_nonnull(ret); qmp_assert_no_error(ret); g_assert_cmpint(qdict_get_int(ret, "id"), ==, 1); - - qobject_unref(ret); } static void test_qga_invalid_oob(gconstpointer fix) @@ -253,7 +241,8 @@ static void test_qga_invalid_oob(gconstpointer fix) static void test_qga_invalid_args(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret, *error; + g_autoptr(QDict) ret = NULL; + QDict *error; const gchar *class, *desc; ret = qmp_fd(fixture->fd, "{'execute': 'guest-ping', " @@ -266,14 +255,13 @@ static void test_qga_invalid_args(gconstpointer fix) g_assert_cmpstr(class, ==, "GenericError"); g_assert_cmpstr(desc, ==, "Parameter 'foo' is unexpected"); - - qobject_unref(ret); } static void test_qga_invalid_cmd(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret, *error; + g_autoptr(QDict) ret = NULL; + QDict *error; const gchar *class, *desc; ret = qmp_fd(fixture->fd, "{'execute': 'guest-invalid-cmd'}"); @@ -285,14 +273,13 @@ static void test_qga_invalid_cmd(gconstpointer fix) g_assert_cmpstr(class, ==, "CommandNotFound"); g_assert_cmpint(strlen(desc), >, 0); - - qobject_unref(ret); } static void test_qga_info(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret, *val; + g_autoptr(QDict) ret = NULL; + QDict *val; const gchar *version; ret = qmp_fd(fixture->fd, "{'execute': 'guest-info'}"); @@ -302,14 +289,12 @@ static void test_qga_info(gconstpointer fix) val = qdict_get_qdict(ret, "return"); version = qdict_get_try_str(val, "version"); g_assert_cmpstr(version, ==, QEMU_VERSION); - - qobject_unref(ret); } static void test_qga_get_vcpus(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret; + g_autoptr(QDict) ret = NULL; QList *list; const QListEntry *entry; @@ -322,14 +307,12 @@ static void test_qga_get_vcpus(gconstpointer fix) entry = qlist_first(list); g_assert(qdict_haskey(qobject_to(QDict, entry->value), "online")); g_assert(qdict_haskey(qobject_to(QDict, entry->value), "logical-id")); - - qobject_unref(ret); } static void test_qga_get_fsinfo(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret; + g_autoptr(QDict) ret = NULL; QList *list; const QListEntry *entry; @@ -346,14 +329,13 @@ static void test_qga_get_fsinfo(gconstpointer fix) g_assert(qdict_haskey(qobject_to(QDict, entry->value), "type")); g_assert(qdict_haskey(qobject_to(QDict, entry->value), "disk")); } - - qobject_unref(ret); } static void test_qga_get_memory_block_info(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret, *val; + g_autoptr(QDict) ret = NULL; + QDict *val; int64_t size; ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-memory-block-info'}"); @@ -366,14 +348,12 @@ static void test_qga_get_memory_block_info(gconstpointer fix) size = qdict_get_int(val, "size"); g_assert_cmpint(size, >, 0); } - - qobject_unref(ret); } static void test_qga_get_memory_blocks(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret; + g_autoptr(QDict) ret = NULL; QList *list; const QListEntry *entry; @@ -391,14 +371,12 @@ static void test_qga_get_memory_blocks(gconstpointer fix) g_assert(qdict_haskey(qobject_to(QDict, entry->value), "online")); } } - - qobject_unref(ret); } static void test_qga_network_get_interfaces(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret; + g_autoptr(QDict) ret = NULL; QList *list; const QListEntry *entry; @@ -410,8 +388,6 @@ static void test_qga_network_get_interfaces(gconstpointer fix) list = qdict_get_qlist(ret, "return"); entry = qlist_first(list); g_assert(qdict_haskey(qobject_to(QDict, entry->value), "name")); - - qobject_unref(ret); } static void test_qga_file_ops(gconstpointer fix) @@ -642,7 +618,7 @@ static void test_qga_file_write_read(gconstpointer fix) static void test_qga_get_time(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret; + g_autoptr(QDict) ret = NULL; int64_t time; ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-time'}"); @@ -651,8 +627,6 @@ static void test_qga_get_time(gconstpointer fix) time = qdict_get_int(ret, "return"); g_assert_cmpint(time, >, 0); - - qobject_unref(ret); } static void test_qga_blacklist(gconstpointer data) @@ -693,18 +667,22 @@ static void test_qga_blacklist(gconstpointer data) static void test_qga_config(gconstpointer data) { GError *error = NULL; - char *cwd, *cmd, *out, *err, *str, **strv, **argv = NULL; + g_autofree char *out = NULL; + g_autofree char *err = NULL; + g_autofree char *cwd = NULL; + g_autofree char *cmd = NULL; + g_auto(GStrv) argv = NULL; + g_auto(GStrv) strv = NULL; + g_autoptr(GKeyFile) kf = NULL; + char *str; char *env[2]; int status; gsize n; - GKeyFile *kf; cwd = g_get_current_dir(); cmd = g_strdup_printf("%s%cqga%cqemu-ga -D", cwd, G_DIR_SEPARATOR, G_DIR_SEPARATOR); - g_free(cwd); g_shell_parse_argv(cmd, NULL, &argv, &error); - g_free(cmd); g_assert_no_error(error); env[0] = g_strdup_printf("QGA_CONF=tests%cdata%ctest-qga-config", @@ -712,7 +690,6 @@ static void test_qga_config(gconstpointer data) env[1] = NULL; g_spawn_sync(NULL, argv, env, 0, NULL, NULL, &out, &err, &status, &error); - g_strfreev(argv); g_assert_no_error(error); g_assert_cmpstr(err, ==, ""); @@ -759,18 +736,14 @@ static void test_qga_config(gconstpointer data) g_assert_true(g_strv_contains((const char * const *)strv, "guest-get-time")); g_assert_no_error(error); - g_strfreev(strv); - g_free(out); - g_free(err); g_free(env[0]); - g_key_file_free(kf); } static void test_qga_fsfreeze_status(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret; + g_autoptr(QDict) ret = NULL; const gchar *status; ret = qmp_fd(fixture->fd, "{'execute': 'guest-fsfreeze-status'}"); @@ -779,16 +752,15 @@ static void test_qga_fsfreeze_status(gconstpointer fix) status = qdict_get_try_str(ret, "return"); g_assert_cmpstr(status, ==, "thawed"); - - qobject_unref(ret); } static void test_qga_guest_exec(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret, *val; + g_autoptr(QDict) ret = NULL; + QDict *val; const gchar *out; - guchar *decoded; + g_autofree guchar *decoded = NULL; int64_t pid, now, exitcode; gsize len; bool exited; @@ -827,14 +799,13 @@ static void test_qga_guest_exec(gconstpointer fix) decoded = g_base64_decode(out, &len); g_assert_cmpint(len, ==, 12); g_assert_cmpstr((char *)decoded, ==, "\" test_str \""); - g_free(decoded); - qobject_unref(ret); } static void test_qga_guest_exec_invalid(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret, *error; + g_autoptr(QDict) ret = NULL; + QDict *error; const gchar *class, *desc; /* invalid command */ @@ -859,13 +830,13 @@ static void test_qga_guest_exec_invalid(gconstpointer fix) desc = qdict_get_str(error, "desc"); g_assert_cmpstr(class, ==, "GenericError"); g_assert_cmpint(strlen(desc), >, 0); - qobject_unref(ret); } static void test_qga_guest_get_host_name(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret, *val; + g_autoptr(QDict) ret = NULL; + QDict *val; ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-host-name'}"); g_assert_nonnull(ret); @@ -873,14 +844,13 @@ static void test_qga_guest_get_host_name(gconstpointer fix) val = qdict_get_qdict(ret, "return"); g_assert(qdict_haskey(val, "host-name")); - - qobject_unref(ret); } static void test_qga_guest_get_timezone(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret, *val; + g_autoptr(QDict) ret = NULL; + QDict *val; ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-timezone'}"); g_assert_nonnull(ret); @@ -889,14 +859,12 @@ static void test_qga_guest_get_timezone(gconstpointer fix) /* Make sure there's at least offset */ val = qdict_get_qdict(ret, "return"); g_assert(qdict_haskey(val, "offset")); - - qobject_unref(ret); } static void test_qga_guest_get_users(gconstpointer fix) { const TestFixture *fixture = fix; - QDict *ret; + g_autoptr(QDict) ret = NULL; QList *val; ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-users'}"); @@ -906,15 +874,13 @@ static void test_qga_guest_get_users(gconstpointer fix) /* There is not much to test here */ val = qdict_get_qlist(ret, "return"); g_assert_nonnull(val); - - qobject_unref(ret); } static void test_qga_guest_get_osinfo(gconstpointer data) { TestFixture fixture; const gchar *str; - QDict *ret = NULL; + g_autoptr(QDict) ret = NULL; char *env[2]; QDict *val; @@ -958,7 +924,6 @@ static void test_qga_guest_get_osinfo(gconstpointer data) g_assert_nonnull(str); g_assert_cmpstr(str, ==, "unit-test"); - qobject_unref(ret); g_free(env[0]); fixture_tear_down(&fixture, NULL); }