From nobody Mon Feb 9 11:43:59 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1665590935; cv=none; d=zohomail.com; s=zohoarc; b=EFe4t8ZK3PgvwhaOaIXnRj2zXTBGDTx6nBxNyA0BT1I4jQLUyP5heQnW9gvBn6NIEdnNJtGggcn6JWfwMzk7OuW/FpGzVoy7t70mnaH5n8b5+XD4OWqrC+S8wd8FU8Ogt8A4oxhx4WddNRgTSQZhksWw+IAj+V0QPik/pR3+phA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665590935; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6KR8vlqJRcmecgBUCD195hRbO9PvQLssXSaePlqkxvw=; b=XPoyNssKwO2ZARXJ2+1jCFqkwn+zUOCHsZXIYEHgj9dPs0cnXTdSF3LWt2K7bgP6g+b/c7WhRzdzTFwMk42IbTiOkFSKtVATMeHt4tzo/d/gHitSdU8E+1CMvwZce/boAX+9jWoTokZ4/e8XrOu42CoJggvcnFVfZ76j8+cOvfs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16655909350151021.4144614578194; Wed, 12 Oct 2022 09:08:55 -0700 (PDT) Received: from localhost ([::1]:56170 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oieHt-0006Ag-RJ for importer@patchew.org; Wed, 12 Oct 2022 12:08:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54136) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oieEG-0003B9-GW for qemu-devel@nongnu.org; Wed, 12 Oct 2022 12:05:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:37440) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oieE4-0005V2-VX for qemu-devel@nongnu.org; Wed, 12 Oct 2022 12:05:02 -0400 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-619-hGseXee8O1CCLR8pjYn62w-1; Wed, 12 Oct 2022 12:04:52 -0400 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 40E8F299E75B; Wed, 12 Oct 2022 16:04:52 +0000 (UTC) Received: from localhost (unknown [10.39.208.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 568174EA4A; Wed, 12 Oct 2022 16:04:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665590695; 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=6KR8vlqJRcmecgBUCD195hRbO9PvQLssXSaePlqkxvw=; b=GE/KnP8tDWy8rVkTNhmbuALKjsQISExiN43A+i5lKZY6DsjQ+vBKZI92/2fNWzh45br8iK w8wOjeCahO97kBk7vwXFVduSgSI39EqIWXN1r+x0+DWjCRVcfsCC8YtU81cSKM1Pd1uzEl /C8oEkzDCBUzCRRkkWi3vKJHYFSEHYI= X-MC-Unique: hGseXee8O1CCLR8pjYn62w-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Stefan Weil , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PULL 1/7] win32: set threads name Date: Wed, 12 Oct 2022 20:04:38 +0400 Message-Id: <20221012160444.3762795-2-marcandre.lureau@redhat.com> In-Reply-To: <20221012160444.3762795-1-marcandre.lureau@redhat.com> References: <20221012160444.3762795-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1665590936345100001 From: Marc-Andr=C3=A9 Lureau As described in: https://learn.microsoft.com/en-us/visualstudio/debugger/how-to-set-a-thread= -name-in-native-code?view=3Dvs-2022 SetThreadDescription() is available since Windows 10, version 1607 and in some versions only by "Run Time Dynamic Linking". Its declaration is not yet in mingw, so we lookup the function the same way glib does. Tested with Visual Studio Community 2022 debugger. Signed-off-by: Marc-Andr=C3=A9 Lureau Acked-by: Richard Henderson --- util/qemu-thread-win32.c | 54 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c index a2d5a6e825..b9a467d7db 100644 --- a/util/qemu-thread-win32.c +++ b/util/qemu-thread-win32.c @@ -19,12 +19,39 @@ =20 static bool name_threads; =20 +typedef HRESULT (WINAPI *pSetThreadDescription) (HANDLE hThread, + PCWSTR lpThreadDescriptio= n); +static pSetThreadDescription SetThreadDescriptionFunc; +static HMODULE kernel32_module; + +static bool load_set_thread_description(void) +{ + static gsize _init_once =3D 0; + + if (g_once_init_enter(&_init_once)) { + kernel32_module =3D LoadLibrary("kernel32.dll"); + if (kernel32_module) { + SetThreadDescriptionFunc =3D + (pSetThreadDescription)GetProcAddress(kernel32_module, + "SetThreadDescriptio= n"); + if (!SetThreadDescriptionFunc) { + FreeLibrary(kernel32_module); + } + } + g_once_init_leave(&_init_once, 1); + } + + return !!SetThreadDescriptionFunc; +} + void qemu_thread_naming(bool enable) { - /* But note we don't actually name them on Windows yet */ name_threads =3D enable; =20 - fprintf(stderr, "qemu: thread naming not supported on this host\n"); + if (enable && !load_set_thread_description()) { + fprintf(stderr, "qemu: thread naming not supported on this host\n"= ); + name_threads =3D false; + } } =20 static void error_exit(int err, const char *msg) @@ -400,6 +427,25 @@ void *qemu_thread_join(QemuThread *thread) return ret; } =20 +static bool set_thread_description(HANDLE h, const char *name) +{ + HRESULT hr; + g_autofree wchar_t *namew =3D NULL; + + if (!load_set_thread_description()) { + return false; + } + + namew =3D g_utf8_to_utf16(name, -1, NULL, NULL, NULL); + if (!namew) { + return false; + } + + hr =3D SetThreadDescriptionFunc(h, namew); + + return SUCCEEDED(hr); +} + void qemu_thread_create(QemuThread *thread, const char *name, void *(*start_routine)(void *), void *arg, int mode) @@ -423,7 +469,11 @@ void qemu_thread_create(QemuThread *thread, const char= *name, if (!hThread) { error_exit(GetLastError(), __func__); } + if (name_threads && name && !set_thread_description(hThread, name)) { + fprintf(stderr, "qemu: failed to set thread description: %s\n", na= me); + } CloseHandle(hThread); + thread->data =3D data; } =20 --=20 2.37.3 From nobody Mon Feb 9 11:43:59 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1665591794; cv=none; d=zohomail.com; s=zohoarc; b=FAAE/x5iXunzabs118h7pEz1MooV6SHf7zA6quKzGvRByDdZeKKW71+wb4AGIkcbvTlJW+7oyxRIT3v9GaEDtVH6h21np2DFnMqGnkVFzW8G4e9tGnlgh1CsV/vlzbeFmP8eU2sJNVo/ZO6YgblChTs+eV3BBam3wTsND3F7b7Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665591794; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=PiH6T6gMly3jr1v1LsPfDdUntrgXMzzWBurcO7SULak=; b=Gkwj8EbX/v2UJ/RwM16ULvnWJ6yGczQPNfHQfcz1v9+eos6/Iw7Z25O6hUh7QfHcsXrVAZCBBCGKub5QxbhvWft1F/gcZD46YGZnggoNpaP6/tuw2HSIxE4IJUvM5rZWXsLeAft+1dgHsctVUHaL09aA06z07V3AVtogehj5cUc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1665591794380605.1653782573006; Wed, 12 Oct 2022 09:23:14 -0700 (PDT) Received: from localhost ([::1]:35900 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oieVk-0005Eg-Cn for importer@patchew.org; Wed, 12 Oct 2022 12:23:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54134) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oieEH-0003B8-R1 for qemu-devel@nongnu.org; Wed, 12 Oct 2022 12:05:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:37671) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oieE8-0005VR-Ki for qemu-devel@nongnu.org; Wed, 12 Oct 2022 12:05:06 -0400 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-563-Kq9cBApLPkmV7zgaL52M1Q-1; Wed, 12 Oct 2022 12:04:56 -0400 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 49C4C85A5A6; Wed, 12 Oct 2022 16:04:56 +0000 (UTC) Received: from localhost (unknown [10.39.208.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 812A6404CD9B; Wed, 12 Oct 2022 16:04:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665590700; 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=PiH6T6gMly3jr1v1LsPfDdUntrgXMzzWBurcO7SULak=; b=GTGDo71eW7GDz0GMTyNbY83DGL824euRCnxlTy8//He3bj3bfUwboqM4Bk2woekPpn+imq 2wApUVyKPTmMY5iiNmM3r772ZVFQoxqfIsviZkzT1HXbiWG8ORQshvDhU5iZut+GDJRrNR BAN5WqKm+loR/JC6uqiojoMd/y/Jm5E= X-MC-Unique: Kq9cBApLPkmV7zgaL52M1Q-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Stefan Weil , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PULL 2/7] osdep: make readv_writev() work with partial read/write Date: Wed, 12 Oct 2022 20:04:39 +0400 Message-Id: <20221012160444.3762795-3-marcandre.lureau@redhat.com> In-Reply-To: <20221012160444.3762795-1-marcandre.lureau@redhat.com> References: <20221012160444.3762795-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1665591795105100001 From: Marc-Andr=C3=A9 Lureau With a pipe or other reasons, read/write may return less than the requested bytes. This happens with the test-io-channel-command test on Windows. glib spawn code uses a binary pipe of 4096 bytes, and the first read returns that much (although more are requested), for some unclear reason... Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Daniel P. Berrang=C3=A9 Message-Id: <20221006113657.2656108-2-marcandre.lureau@redhat.com> --- util/osdep.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/util/osdep.c b/util/osdep.c index 60fcbbaebe..746d5f7d71 100644 --- a/util/osdep.c +++ b/util/osdep.c @@ -538,18 +538,22 @@ int socket_init(void) =20 =20 #ifndef CONFIG_IOVEC -/* helper function for iov_send_recv() */ static ssize_t readv_writev(int fd, const struct iovec *iov, int iov_cnt, bool do_write) { unsigned i =3D 0; ssize_t ret =3D 0; + ssize_t off =3D 0; while (i < iov_cnt) { ssize_t r =3D do_write - ? write(fd, iov[i].iov_base, iov[i].iov_len) - : read(fd, iov[i].iov_base, iov[i].iov_len); + ? write(fd, iov[i].iov_base + off, iov[i].iov_len - off) + : read(fd, iov[i].iov_base + off, iov[i].iov_len - off); if (r > 0) { ret +=3D r; + off +=3D r; + if (off < iov[i].iov_len) { + continue; + } } else if (!r) { break; } else if (errno =3D=3D EINTR) { @@ -562,6 +566,7 @@ readv_writev(int fd, const struct iovec *iov, int iov_c= nt, bool do_write) } break; } + off =3D 0; i++; } return ret; --=20 2.37.3 From nobody Mon Feb 9 11:43:59 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1665591738; cv=none; d=zohomail.com; s=zohoarc; b=QxTrbVDpSORoYzGeP/PZdSJ21CuyenU2yn+PcjL/5Ik8WR+h5a5ot+cyRRISxnHfFOPbbOfiUOs1zlJdEW5o0LAcXEzqNifdV0nTx3U+FkK1qYK86mzDD1Tm76YLYQefkcUSpErEHufU5ZUQSXWvlXCyUruqdys2XEa39ZHCZ5w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665591738; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=k4PKj4wwLVipahbwgyxDEoKO+wr2/j8Ozv4HRqeDjXs=; b=hzl+UKsU2eVbkAGzdnMDxwtF5VhHjog1XsDiRX9uMcWe2ZZ8WVlqoxItPXQg1PzRsnX+NYEAZhpxvjGPFogLwzEYv+lO4+8erES5IJZdtQbyiXKYCsKrcfnaviU2q2vhm6RotiQjcMT4c+deG7Odkr0YXl5o0LjHTIuXulenmRc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1665591738297386.0501824918574; Wed, 12 Oct 2022 09:22:18 -0700 (PDT) Received: from localhost ([::1]:43674 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oieUr-0003Bk-7H for importer@patchew.org; Wed, 12 Oct 2022 12:22:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47060) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oieEO-0003F7-Aq for qemu-devel@nongnu.org; Wed, 12 Oct 2022 12:05:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:59693) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oieEG-0005gD-6F for qemu-devel@nongnu.org; Wed, 12 Oct 2022 12:05:15 -0400 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-13-JVbB42TnNcm8rOxP4-L92w-1; Wed, 12 Oct 2022 12:05:00 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 09939185A792; Wed, 12 Oct 2022 16:05:00 +0000 (UTC) Received: from localhost (unknown [10.39.208.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3FA8C2028DC1; Wed, 12 Oct 2022 16:04:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665590704; 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=k4PKj4wwLVipahbwgyxDEoKO+wr2/j8Ozv4HRqeDjXs=; b=aHK2m9fH0UuqFvGS1GQL/QDdP89w8wsV+FZn5GKKA7er4yMIxdscGK7+bMNj619vDPJok1 Utt3PuzUe3fbej0QoOcj755UWdi8mn1gxEwXvPtjLZQAn3Hn0l5QdiIEx24ekpJnLGqJs0 Ih+NukE2mEXEDxKNEXlvAeYDTQoa2L4= X-MC-Unique: JVbB42TnNcm8rOxP4-L92w-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Stefan Weil , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PULL 3/7] util: make do_send_recv work with partial send/recv Date: Wed, 12 Oct 2022 20:04:40 +0400 Message-Id: <20221012160444.3762795-4-marcandre.lureau@redhat.com> In-Reply-To: <20221012160444.3762795-1-marcandre.lureau@redhat.com> References: <20221012160444.3762795-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1665591738885100001 From: Marc-Andr=C3=A9 Lureau According to msdn documentation and Linux man pages, send() should try to send as much as possible in blocking mode, while recv() may return earlier with a smaller available amount, we should try to continue send/recv from there. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Daniel P. Berrang=C3=A9 Message-Id: <20221006113657.2656108-3-marcandre.lureau@redhat.com> --- util/iov.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/util/iov.c b/util/iov.c index 22d6996cce..b4be580022 100644 --- a/util/iov.c +++ b/util/iov.c @@ -111,12 +111,17 @@ do_send_recv(int sockfd, struct iovec *iov, unsigned = iov_cnt, bool do_send) /*XXX Note: windows has WSASend() and WSARecv() */ unsigned i =3D 0; ssize_t ret =3D 0; + ssize_t off =3D 0; while (i < iov_cnt) { ssize_t r =3D do_send - ? send(sockfd, iov[i].iov_base, iov[i].iov_len, 0) - : recv(sockfd, iov[i].iov_base, iov[i].iov_len, 0); + ? send(sockfd, iov[i].iov_base + off, iov[i].iov_len - off, 0) + : recv(sockfd, iov[i].iov_base + off, iov[i].iov_len - off, 0); if (r > 0) { ret +=3D r; + off +=3D r; + if (off < iov[i].iov_len) { + continue; + } } else if (!r) { break; } else if (errno =3D=3D EINTR) { @@ -129,6 +134,7 @@ do_send_recv(int sockfd, struct iovec *iov, unsigned io= v_cnt, bool do_send) } break; } + off =3D 0; i++; } return ret; --=20 2.37.3 From nobody Mon Feb 9 11:43:59 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1665591199; cv=none; d=zohomail.com; s=zohoarc; b=Q6w9Hnwa7L0qyjDquIC4zsf/S1+ZlsHxpogg0MdiT3DVAkHVTv+Eh7HqyO81i2qAHIWF53u50f+OkQ2YJtpwSxiOIf/23Y2awMr8zQArtd6FJ7x4fGUt1Ej5kHigBpzpjZ7Nnek/7n4i8/du2zCSizViXtjuzUBpF+ahrD3gHI8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665591199; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qk30fyQ0Le155PMM91BRCjq1NfaJf0UNUST6CUuyfFE=; b=MORugSVzT5GUqTtX7m7zId5PUVL+/carBdsMuN5Mn5secWeyooSXUn9oEZRpHJK/MTuypypS3f5Su/Nr2vIO7+obKeb41hsyMh4uGJStaSd6XwQpVVp6Bk86RqKtw7G3sawCYpfX3gmpe3gCHtmHBt2nIu/eb/qQUndRBi2OT48= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 166559119938557.75176242509576; Wed, 12 Oct 2022 09:13:19 -0700 (PDT) Received: from localhost ([::1]:50778 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oieMA-0003sb-3f for importer@patchew.org; Wed, 12 Oct 2022 12:13:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47064) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oieET-0003KO-D0 for qemu-devel@nongnu.org; Wed, 12 Oct 2022 12:05:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:52128) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oieEM-0005gz-49 for qemu-devel@nongnu.org; Wed, 12 Oct 2022 12:05:21 -0400 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-251-GomwmYcgO8i0iDOIVf2Jmw-1; Wed, 12 Oct 2022 12:05:05 -0400 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 A3C36811E75; Wed, 12 Oct 2022 16:05:04 +0000 (UTC) Received: from localhost (unknown [10.39.208.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8CA4A404CD9B; Wed, 12 Oct 2022 16:05:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665590713; 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=qk30fyQ0Le155PMM91BRCjq1NfaJf0UNUST6CUuyfFE=; b=YXwadHNVtRuDFrRdfrTL8eB4Hb0jpTe59ktpip7mVMjv7XH4ly8Y/DYT5YsOAATU9Prxqv RjB0IImUhpkHw7VqpE0H4nbnl3QId0IMKc1WYI8x5XGKPTyVM/vQoUK2uHS26mTIHaXmrs 7NTLbrzcvjQweVVvZDElslzwvsyudkg= X-MC-Unique: GomwmYcgO8i0iDOIVf2Jmw-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Stefan Weil , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PULL 4/7] tests/channel-helper: set blocking in main thread Date: Wed, 12 Oct 2022 20:04:41 +0400 Message-Id: <20221012160444.3762795-5-marcandre.lureau@redhat.com> In-Reply-To: <20221012160444.3762795-1-marcandre.lureau@redhat.com> References: <20221012160444.3762795-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1665591199775100001 From: Marc-Andr=C3=A9 Lureau The /io/channel/command/echo tests run the reader side and the writer side with the same underlying command channel. Setting the blocking mode of the fd/handles while the other end is already reading/writing may create issues (deadlock in win32 when earlier attempt of this series were using SetNamedPipeHandleState). Let's just do it before spawning the threads to avoid further concurrency issues. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Daniel P. Berrang=C3=A9 Message-Id: <20221006113657.2656108-4-marcandre.lureau@redhat.com> --- tests/unit/io-channel-helpers.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/unit/io-channel-helpers.c b/tests/unit/io-channel-helper= s.c index ff156ed3c4..c0799c21c2 100644 --- a/tests/unit/io-channel-helpers.c +++ b/tests/unit/io-channel-helpers.c @@ -25,7 +25,6 @@ struct QIOChannelTest { QIOChannel *src; QIOChannel *dst; - bool blocking; size_t len; size_t niov; char *input; @@ -42,8 +41,6 @@ static gpointer test_io_thread_writer(gpointer opaque) { QIOChannelTest *data =3D opaque; =20 - qio_channel_set_blocking(data->src, data->blocking, NULL); - qio_channel_writev_all(data->src, data->inputv, data->niov, @@ -58,8 +55,6 @@ static gpointer test_io_thread_reader(gpointer opaque) { QIOChannelTest *data =3D opaque; =20 - qio_channel_set_blocking(data->dst, data->blocking, NULL); - qio_channel_readv_all(data->dst, data->outputv, data->niov, @@ -113,7 +108,9 @@ void qio_channel_test_run_threads(QIOChannelTest *test, =20 test->src =3D src; test->dst =3D dst; - test->blocking =3D blocking; + + qio_channel_set_blocking(test->dst, blocking, NULL); + qio_channel_set_blocking(test->src, blocking, NULL); =20 reader =3D g_thread_new("reader", test_io_thread_reader, --=20 2.37.3 From nobody Mon Feb 9 11:43:59 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1665590936; cv=none; d=zohomail.com; s=zohoarc; b=nxl4To9LaTNmJyP1k+d+ZOHKWIvMJ9WQFLcpE+nRfuFUDuKu5ZLDwS/Bt/N0sBwFnOVdBYeAToKgziihyrvB7AGzIm2oizFnSpLff0THaPDC5kIVZ6oWP4KEopPzEB1pSQHrZsNJTeOFuL6ravhxEv46cqHbjQjMFf3uZDX7uEE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665590936; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lC+6k1rr3ChLnulkoyG6ohhttdBLlO/Wxm1mxh5HZYg=; b=UyxmZmLj3i28mL3cpuMY/Qs+fwOz3PprV/lW6LhRuYHeBxgLFzauvVqVDahkfW6JdKjDXY1lTVQqbN5A3UIh45bJSNq52z7KY0dhfA/ogUdeApHB1IkSHlxaSFcBAue+v5n2g58vPhtJho/oX2I/VFvLBwC5nEuAphEU5YIe2qM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1665590936652296.51513490374043; Wed, 12 Oct 2022 09:08:56 -0700 (PDT) Received: from localhost ([::1]:56194 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oieHv-0006Kp-CK for importer@patchew.org; Wed, 12 Oct 2022 12:08:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47066) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oieEU-0003Kw-9x for qemu-devel@nongnu.org; Wed, 12 Oct 2022 12:05:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:37603) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oieEK-0005gm-2v for qemu-devel@nongnu.org; Wed, 12 Oct 2022 12:05:21 -0400 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-232-hcVomkQiNluU0JJ3NuOBIw-1; Wed, 12 Oct 2022 12:05:09 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 357EB85A59D; Wed, 12 Oct 2022 16:05:09 +0000 (UTC) Received: from localhost (unknown [10.39.208.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id EECBF140EBF5; Wed, 12 Oct 2022 16:05:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665590711; 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=lC+6k1rr3ChLnulkoyG6ohhttdBLlO/Wxm1mxh5HZYg=; b=b+SlHLYzufB98sw32iN6BX6nYgw7+UaG0A69+mVAZzGLmb1sWXb+yAKYqyQhkSAyLY4y45 hHlVxHKxE8oDCxcHx/skgc5h/0ERbfaRsyT+NOnlypHX6uSG+08LFpr+JCFNnWhL0l+iO+ ++E1yiDP4Z+SO2lpc3/vhdHhTvztIBc= X-MC-Unique: hcVomkQiNluU0JJ3NuOBIw-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Stefan Weil , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PULL 5/7] io/command: use glib GSpawn, instead of open-coding fork/exec Date: Wed, 12 Oct 2022 20:04:42 +0400 Message-Id: <20221012160444.3762795-6-marcandre.lureau@redhat.com> In-Reply-To: <20221012160444.3762795-1-marcandre.lureau@redhat.com> References: <20221012160444.3762795-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1665590938150100003 From: Marc-Andr=C3=A9 Lureau Simplify qio_channel_command_new_spawn() with GSpawn API. This will allow to build for WIN32 in the following patches. As pointed out by Daniel Berrang=C3=A9: there is a change in semantics here too. The current code only touches stdin/stdout/stderr. Any other FDs which do NOT have O_CLOEXEC set will be inherited. With the new code, all FDs except stdin/out/err will be explicitly closed, because we don't set the flag G_SPAWN_LEAVE_DESCRIPTORS_OPEN. The only place we use QIOChannelCommand today is the migration exec: protocol, and that is only declared to use stdin/stdout. Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Marc-Andr=C3=A9 Lureau Message-Id: <20221006113657.2656108-5-marcandre.lureau@redhat.com> --- include/io/channel-command.h | 2 +- io/channel-command.c | 105 ++++++----------------------------- 2 files changed, 19 insertions(+), 88 deletions(-) diff --git a/include/io/channel-command.h b/include/io/channel-command.h index 305ac1d280..8dc58273c0 100644 --- a/include/io/channel-command.h +++ b/include/io/channel-command.h @@ -41,7 +41,7 @@ struct QIOChannelCommand { QIOChannel parent; int writefd; int readfd; - pid_t pid; + GPid pid; }; =20 =20 diff --git a/io/channel-command.c b/io/channel-command.c index 9f2f4a1793..f84d1f03a0 100644 --- a/io/channel-command.c +++ b/io/channel-command.c @@ -31,7 +31,7 @@ * qio_channel_command_new_pid: * @writefd: the FD connected to the command's stdin * @readfd: the FD connected to the command's stdout - * @pid: the PID of the running child command + * @pid: the PID/HANDLE of the running child command * @errp: pointer to a NULL-initialized error object * * Create a channel for performing I/O with the @@ -50,7 +50,7 @@ static QIOChannelCommand * qio_channel_command_new_pid(int writefd, int readfd, - pid_t pid) + GPid pid) { QIOChannelCommand *ioc; =20 @@ -69,94 +69,24 @@ qio_channel_command_new_spawn(const char *const argv[], int flags, Error **errp) { - pid_t pid =3D -1; - int stdinfd[2] =3D { -1, -1 }; - int stdoutfd[2] =3D { -1, -1 }; - int devnull =3D -1; - bool stdinnull =3D false, stdoutnull =3D false; - QIOChannelCommand *ioc; + g_autoptr(GError) err =3D NULL; + GPid pid =3D 0; + GSpawnFlags gflags =3D G_SPAWN_CLOEXEC_PIPES | G_SPAWN_DO_NOT_REAP_CHI= LD; + int stdinfd =3D -1, stdoutfd =3D -1; =20 flags =3D flags & O_ACCMODE; - - if (flags =3D=3D O_RDONLY) { - stdinnull =3D true; - } - if (flags =3D=3D O_WRONLY) { - stdoutnull =3D true; - } - - if (stdinnull || stdoutnull) { - devnull =3D open("/dev/null", O_RDWR); - if (devnull < 0) { - error_setg_errno(errp, errno, - "Unable to open /dev/null"); - goto error; - } - } - - if ((!stdinnull && !g_unix_open_pipe(stdinfd, FD_CLOEXEC, NULL)) || - (!stdoutnull && !g_unix_open_pipe(stdoutfd, FD_CLOEXEC, NULL))) { - error_setg_errno(errp, errno, - "Unable to open pipe"); - goto error; - } - - pid =3D qemu_fork(errp); - if (pid < 0) { - goto error; - } - - if (pid =3D=3D 0) { /* child */ - dup2(stdinnull ? devnull : stdinfd[0], STDIN_FILENO); - dup2(stdoutnull ? devnull : stdoutfd[1], STDOUT_FILENO); - /* Leave stderr connected to qemu's stderr */ - - if (!stdinnull) { - close(stdinfd[0]); - close(stdinfd[1]); - } - if (!stdoutnull) { - close(stdoutfd[0]); - close(stdoutfd[1]); - } - if (devnull !=3D -1) { - close(devnull); - } - - execv(argv[0], (char * const *)argv); - _exit(1); + gflags |=3D flags =3D=3D O_WRONLY ? G_SPAWN_STDOUT_TO_DEV_NULL : 0; + + if (!g_spawn_async_with_pipes(NULL, (char **)argv, NULL, gflags, NULL,= NULL, + &pid, + flags =3D=3D O_RDONLY ? NULL : &stdinfd, + flags =3D=3D O_WRONLY ? NULL : &stdoutfd, + NULL, &err)) { + error_setg(errp, "%s", err->message); + return NULL; } =20 - if (!stdinnull) { - close(stdinfd[0]); - } - if (!stdoutnull) { - close(stdoutfd[1]); - } - - ioc =3D qio_channel_command_new_pid(stdinnull ? devnull : stdinfd[1], - stdoutnull ? devnull : stdoutfd[0], - pid); - trace_qio_channel_command_new_spawn(ioc, argv[0], flags); - return ioc; - - error: - if (devnull !=3D -1) { - close(devnull); - } - if (stdinfd[0] !=3D -1) { - close(stdinfd[0]); - } - if (stdinfd[1] !=3D -1) { - close(stdinfd[1]); - } - if (stdoutfd[0] !=3D -1) { - close(stdoutfd[0]); - } - if (stdoutfd[1] !=3D -1) { - close(stdoutfd[1]); - } - return NULL; + return qio_channel_command_new_pid(stdinfd, stdoutfd, pid); } =20 #else /* WIN32 */ @@ -221,7 +151,7 @@ static void qio_channel_command_init(Object *obj) QIOChannelCommand *ioc =3D QIO_CHANNEL_COMMAND(obj); ioc->readfd =3D -1; ioc->writefd =3D -1; - ioc->pid =3D -1; + ioc->pid =3D 0; } =20 static void qio_channel_command_finalize(Object *obj) @@ -239,6 +169,7 @@ static void qio_channel_command_finalize(Object *obj) #ifndef WIN32 qio_channel_command_abort(ioc, NULL); #endif + g_spawn_close_pid(ioc->pid); } } =20 --=20 2.37.3 From nobody Mon Feb 9 11:43:59 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1665591957; cv=none; d=zohomail.com; s=zohoarc; b=FrlwI/2CLW9byDJkcEm7d+tLbtYLvNHcpIn4mUfjphz+r2om6tmZXnFAsWowN3C33OO0ZBowixa3uREp5P258BEliKat/DqYyFNPC6GZrz9fnba0l0Xhx4HCxc3Do8iquiB/ot4DRs5zk/KGYhVXMIYhSWAw6keL+aN8dzro91s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665591957; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Q72e1GIur4NsTTQ+PPkYD9TPHv+nXrt3Ii2uSucwaWs=; b=Y64wExT6QhOHkqBujn5shOoszdSVzO+ddnguLGHNSwu6L3ry5YnoIbHDSMdY4nkx1tMWfHM5TJLvK/tZbP0hKhjr94B39ShxKEVKweWjmP7A3vW6WnQQGcK0f3lvRpF99sJ8ylgNv2oHDkr0RbOX8PSge2Oop/weTUGVFi6xSOk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 166559195702365.50068199896873; Wed, 12 Oct 2022 09:25:57 -0700 (PDT) Received: from localhost ([::1]:41894 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oieYO-0000IO-0R for importer@patchew.org; Wed, 12 Oct 2022 12:25:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47068) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oieEV-0003L1-OS for qemu-devel@nongnu.org; Wed, 12 Oct 2022 12:05:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:30702) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oieEN-0005hA-Q1 for qemu-devel@nongnu.org; Wed, 12 Oct 2022 12:05:23 -0400 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-204-P82mCBzEOtCFxIDbqE8qtw-1; Wed, 12 Oct 2022 12:05:13 -0400 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 716C986F130; Wed, 12 Oct 2022 16:05:13 +0000 (UTC) Received: from localhost (unknown [10.39.208.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5BCE3C5692D; Wed, 12 Oct 2022 16:05:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665590715; 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=Q72e1GIur4NsTTQ+PPkYD9TPHv+nXrt3Ii2uSucwaWs=; b=UUBi5/pmOeNE2WGFkkSkzKCmIxrCQJ1WdjLDO3JrMFl8XQuUsX4cEr4LKuFGWFIeO/AOLA pCqCyjd/0951jaoFhh9biLVRKlrmWzr9SWdPWiAuTsMtGR21ixuHqq3JD+wnOw77gNhgEX IGRRfJSfDsIkoz8DUc3ba1CFyC1RYqM= X-MC-Unique: P82mCBzEOtCFxIDbqE8qtw-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Stefan Weil , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PULL 6/7] io/command: implement support for win32 Date: Wed, 12 Oct 2022 20:04:43 +0400 Message-Id: <20221012160444.3762795-7-marcandre.lureau@redhat.com> In-Reply-To: <20221012160444.3762795-1-marcandre.lureau@redhat.com> References: <20221012160444.3762795-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1665591958208100001 From: Marc-Andr=C3=A9 Lureau The initial implementation was changing the pipe state created by GLib to PIPE_NOWAIT, but it turns out it doesn't work (read/write returns an error). Since reading may return less than the requested amount, it seems to be non-blocking already. However, the IO operation may block until the FD is ready, I can't find good sources of information, to be safe we can just poll for readiness before. Alternatively, we could setup the FDs ourself, and use UNIX sockets on Windows, which can be used in blocking/non-blocking mode. I haven't tried it, as I am not sure it is necessary. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Daniel P. Berrang=C3=A9 Message-Id: <20221006113657.2656108-6-marcandre.lureau@redhat.com> --- include/io/channel-command.h | 3 ++ io/channel-command.c | 80 ++++++++++++++++++++++++++---------- 2 files changed, 62 insertions(+), 21 deletions(-) diff --git a/include/io/channel-command.h b/include/io/channel-command.h index 8dc58273c0..98934e6d9e 100644 --- a/include/io/channel-command.h +++ b/include/io/channel-command.h @@ -42,6 +42,9 @@ struct QIOChannelCommand { int writefd; int readfd; GPid pid; +#ifdef WIN32 + bool blocking; +#endif }; =20 =20 diff --git a/io/channel-command.c b/io/channel-command.c index f84d1f03a0..74516252ba 100644 --- a/io/channel-command.c +++ b/io/channel-command.c @@ -26,7 +26,6 @@ #include "qemu/sockets.h" #include "trace.h" =20 -#ifndef WIN32 /** * qio_channel_command_new_pid: * @writefd: the FD connected to the command's stdin @@ -60,7 +59,13 @@ qio_channel_command_new_pid(int writefd, ioc->writefd =3D writefd; ioc->pid =3D pid; =20 - trace_qio_channel_command_new_pid(ioc, writefd, readfd, pid); + trace_qio_channel_command_new_pid(ioc, writefd, readfd, +#ifdef WIN32 + GetProcessId(pid) +#else + pid +#endif + ); return ioc; } =20 @@ -89,18 +94,6 @@ qio_channel_command_new_spawn(const char *const argv[], return qio_channel_command_new_pid(stdinfd, stdoutfd, pid); } =20 -#else /* WIN32 */ -QIOChannelCommand * -qio_channel_command_new_spawn(const char *const argv[], - int flags, - Error **errp) -{ - error_setg_errno(errp, ENOSYS, - "Command spawn not supported on this platform"); - return NULL; -} -#endif /* WIN32 */ - #ifndef WIN32 static int qio_channel_command_abort(QIOChannelCommand *ioc, Error **errp) @@ -143,6 +136,23 @@ static int qio_channel_command_abort(QIOChannelCommand= *ioc, =20 return 0; } +#else +static int qio_channel_command_abort(QIOChannelCommand *ioc, + Error **errp) +{ + DWORD ret; + + TerminateProcess(ioc->pid, 0); + ret =3D WaitForSingleObject(ioc->pid, 1000); + if (ret !=3D WAIT_OBJECT_0) { + error_setg(errp, + "Process %llu refused to die", + (unsigned long long)GetProcessId(ioc->pid)); + return -1; + } + + return 0; +} #endif /* ! WIN32 */ =20 =20 @@ -166,13 +176,27 @@ static void qio_channel_command_finalize(Object *obj) } ioc->writefd =3D ioc->readfd =3D -1; if (ioc->pid > 0) { -#ifndef WIN32 qio_channel_command_abort(ioc, NULL); -#endif g_spawn_close_pid(ioc->pid); } } =20 +#ifdef WIN32 +static bool win32_fd_poll(int fd, gushort events) +{ + GPollFD pfd =3D { .fd =3D _get_osfhandle(fd), .events =3D events }; + int res; + + do { + res =3D g_poll(&pfd, 1, 0); + } while (res < 0 && errno =3D=3D EINTR); + if (res =3D=3D 0) { + return false; + } + + return true; +} +#endif =20 static ssize_t qio_channel_command_readv(QIOChannel *ioc, const struct iovec *iov, @@ -184,6 +208,12 @@ static ssize_t qio_channel_command_readv(QIOChannel *i= oc, QIOChannelCommand *cioc =3D QIO_CHANNEL_COMMAND(ioc); ssize_t ret; =20 +#ifdef WIN32 + if (!cioc->blocking && !win32_fd_poll(cioc->readfd, G_IO_IN)) { + return QIO_CHANNEL_ERR_BLOCK; + } +#endif + retry: ret =3D readv(cioc->readfd, iov, niov); if (ret < 0) { @@ -213,6 +243,12 @@ static ssize_t qio_channel_command_writev(QIOChannel *= ioc, QIOChannelCommand *cioc =3D QIO_CHANNEL_COMMAND(ioc); ssize_t ret; =20 +#ifdef WIN32 + if (!cioc->blocking && !win32_fd_poll(cioc->writefd, G_IO_OUT)) { + return QIO_CHANNEL_ERR_BLOCK; + } +#endif + retry: ret =3D writev(cioc->writefd, iov, niov); if (ret <=3D 0) { @@ -233,14 +269,14 @@ static int qio_channel_command_set_blocking(QIOChanne= l *ioc, bool enabled, Error **errp) { + QIOChannelCommand *cioc =3D QIO_CHANNEL_COMMAND(ioc); + #ifdef WIN32 - /* command spawn is not supported on win32 */ - g_assert_not_reached(); + cioc->blocking =3D enabled; #else - QIOChannelCommand *cioc =3D QIO_CHANNEL_COMMAND(ioc); =20 - if (!g_unix_set_fd_nonblocking(cioc->writefd, !enabled, NULL) || - !g_unix_set_fd_nonblocking(cioc->readfd, !enabled, NULL)) { + if ((cioc->writefd >=3D 0 && !g_unix_set_fd_nonblocking(cioc->writefd,= !enabled, NULL)) || + (cioc->readfd >=3D 0 && !g_unix_set_fd_nonblocking(cioc->readfd, != enabled, NULL))) { error_setg_errno(errp, errno, "Failed to set FD nonblocking"); return -1; } @@ -281,6 +317,8 @@ static int qio_channel_command_close(QIOChannel *ioc, (unsigned long long)cioc->pid); return -1; } +#else + WaitForSingleObject(cioc->pid, INFINITE); #endif =20 if (rv < 0) { --=20 2.37.3 From nobody Mon Feb 9 11:43:59 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1665591201; cv=none; d=zohomail.com; s=zohoarc; b=Xm3Li1RmB14Ye9RdU/xpzSUKgIDkdvjAIUmnlLjHf9IVRU5P/dJr3jkdJeoNgsrlOArSfjyxDrzV5XmU17xv3bnq9UxDUxg3YNfchai6cC+D6r5ar8wdtTz11q7xXrJI3v4qz5xk5oO+hf/eCXobiDV2lbTy64J5sTjx+z1SX6Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665591201; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=f3QgzVG/pGCMEd5mQ9yY3MKqQYhbwaOAz4DWMK6cZ8k=; b=Dhavpk/mtpCP5WLCTASjGxalFTjqnNGyscaY9hcNunzv0nw6qwYWE+52a6bWVsaJygS0twXWfwrBF6+7EpVzVMsQi+1/y0Pf7242LnvJX64+85lMZg7SmMEGiTIk4Qc2/8HR5uaO96I7veUjwljJKjuhNXkN51ZqBPLtkqdyBAU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1665591201494697.5261687311272; Wed, 12 Oct 2022 09:13:21 -0700 (PDT) Received: from localhost ([::1]:50766 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oieMA-0003rH-4A for importer@patchew.org; Wed, 12 Oct 2022 12:13:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47872) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oieEf-0003Mj-PH for qemu-devel@nongnu.org; Wed, 12 Oct 2022 12:05:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:24287) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oieER-0005iS-IQ for qemu-devel@nongnu.org; Wed, 12 Oct 2022 12:05:32 -0400 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-669-ZgdyfamANMaHIsVRGfRXdA-1; Wed, 12 Oct 2022 12:05:17 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4F95C3814580; Wed, 12 Oct 2022 16:05:17 +0000 (UTC) Received: from localhost (unknown [10.39.208.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 630AA1402BDC; Wed, 12 Oct 2022 16:05:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665590718; 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=f3QgzVG/pGCMEd5mQ9yY3MKqQYhbwaOAz4DWMK6cZ8k=; b=NTmACPYGPJ/tIvLSo3k2b/a6Qk73GMgyzZQFBfeuyGT7HMf4noI+QlUhyNYo7BGOuafpjE G1t1ayiRUmWWKGoEsmR4U8RN+fmncyBgyD5KnD1xOVjbYiC6+VKToYthu4oTPDs0rbIdh4 2janN7AqXWZhvGAAgyRVsPFR3cIXmjQ= X-MC-Unique: ZgdyfamANMaHIsVRGfRXdA-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Stefan Weil , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PULL 7/7] tests/unit: make test-io-channel-command work on win32 Date: Wed, 12 Oct 2022 20:04:44 +0400 Message-Id: <20221012160444.3762795-8-marcandre.lureau@redhat.com> In-Reply-To: <20221012160444.3762795-1-marcandre.lureau@redhat.com> References: <20221012160444.3762795-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1665591201787100003 From: Marc-Andr=C3=A9 Lureau This has been tested under msys2 & windows 11. I haven't tried to make it work with other environments yet, but that should be enough to validate the channel-command implementation anyway. Here are the changes: - drop tests/ from fifo/pipe path, to avoid directory issues - use g_find_program() to lookup the socat executable (otherwise we would need to change ChanneCommand to use G_SPAWN_SEARCH_PATH, and deal with missing socat differently) - skip the "echo" test when socat is missing as well Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Daniel P. Berrang=C3=A9 Message-Id: <20221006113657.2656108-7-marcandre.lureau@redhat.com> --- tests/unit/test-io-channel-command.c | 37 ++++++++++++++-------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/tests/unit/test-io-channel-command.c b/tests/unit/test-io-chan= nel-command.c index aa09c559cd..7eee939c07 100644 --- a/tests/unit/test-io-channel-command.c +++ b/tests/unit/test-io-channel-command.c @@ -24,29 +24,30 @@ #include "qapi/error.h" #include "qemu/module.h" =20 -#ifndef WIN32 +#define TEST_FIFO "test-io-channel-command.fifo" + +#define SOCAT_SRC "PIPE:" TEST_FIFO ",wronly" +#define SOCAT_DST "PIPE:" TEST_FIFO ",rdonly" + +static char *socat =3D NULL; + static void test_io_channel_command_fifo(bool async) { -#define TEST_FIFO "tests/test-io-channel-command.fifo" QIOChannel *src, *dst; QIOChannelTest *test; - const char *srcfifo =3D "PIPE:" TEST_FIFO ",wronly"; - const char *dstfifo =3D "PIPE:" TEST_FIFO ",rdonly"; const char *srcargv[] =3D { - "/bin/socat", "-", srcfifo, NULL, + socat, "-", SOCAT_SRC, NULL, }; const char *dstargv[] =3D { - "/bin/socat", dstfifo, "-", NULL, + socat, SOCAT_DST, "-", NULL, }; =20 - unlink(TEST_FIFO); - if (access("/bin/socat", X_OK) < 0) { - g_test_skip("socat is missing"); + if (!socat) { + g_test_skip("socat is not found in PATH"); return; } - if (mkfifo(TEST_FIFO, 0600) < 0) { - abort(); - } + + unlink(TEST_FIFO); src =3D QIO_CHANNEL(qio_channel_command_new_spawn(srcargv, O_WRONLY, &error_abort)); @@ -81,11 +82,12 @@ static void test_io_channel_command_echo(bool async) QIOChannel *ioc; QIOChannelTest *test; const char *socatargv[] =3D { - "/bin/socat", "-", "-", NULL, + socat, "-", "-", NULL, }; =20 - if (access("/bin/socat", X_OK) < 0) { - return; /* Pretend success if socat is not present */ + if (!socat) { + g_test_skip("socat is not found in PATH"); + return; } =20 ioc =3D QIO_CHANNEL(qio_channel_command_new_spawn(socatargv, @@ -108,7 +110,6 @@ static void test_io_channel_command_echo_sync(void) { test_io_channel_command_echo(false); } -#endif =20 int main(int argc, char **argv) { @@ -116,7 +117,8 @@ int main(int argc, char **argv) =20 g_test_init(&argc, &argv, NULL); =20 -#ifndef WIN32 + socat =3D g_find_program_in_path("socat"); + g_test_add_func("/io/channel/command/fifo/sync", test_io_channel_command_fifo_sync); g_test_add_func("/io/channel/command/fifo/async", @@ -125,7 +127,6 @@ int main(int argc, char **argv) test_io_channel_command_echo_sync); g_test_add_func("/io/channel/command/echo/async", test_io_channel_command_echo_async); -#endif =20 return g_test_run(); } --=20 2.37.3