From nobody Mon Feb 9 14:16:00 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=1662118170; cv=none; d=zohomail.com; s=zohoarc; b=EbLKz8NV+IBXzOrGvqFg9h2aZ3Ud027GDjBwIOSOSt38c49FyAKCDpDv94lxyMGobTwOOoRUWtPKwfk94qKGebDDAcSk9ZAls4SpybG52QJM17v+dXuxeBv7eAzmDcViwqh2gr4+23qy3U6reU7M0SzKoTWLLJl1GE4TqxwJ+Hs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662118170; 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=FwYVskadkS1uB66JbjHhxN2B882K8draWD2BgFqqNc8=; b=fCWyPa/pxsZypqHnocerX2KAECR7U6SAljPmkbSPW1BTX/2f1/gpsqlVuIgngibOIWMKONqeTRJBydHzYMLVzG4tayOx7SwEgRWesZ3cXPCJMuG5m4gXqhRvKWJL4K8/WNrlY69Anq2zgg5OMhpM1wtvUuyyvSQUswhCRIOYrYw= 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 1662118170027848.5002660727442; Fri, 2 Sep 2022 04:29:30 -0700 (PDT) Received: from localhost ([::1]:33686 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU4rY-0000xy-23 for importer@patchew.org; Fri, 02 Sep 2022 07:29:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56892) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU4he-0001H7-IE for qemu-devel@nongnu.org; Fri, 02 Sep 2022 07:19:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:51583) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU4hb-0006ZX-Ai for qemu-devel@nongnu.org; Fri, 02 Sep 2022 07:19:13 -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-653-EWEl94GZOXOvJzPYl1b_2A-1; Fri, 02 Sep 2022 07:19: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 42E0638173C3 for ; Fri, 2 Sep 2022 11:19:09 +0000 (UTC) Received: from localhost (unknown [10.39.208.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id F3D771415125; Fri, 2 Sep 2022 11:19:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662117550; 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=FwYVskadkS1uB66JbjHhxN2B882K8draWD2BgFqqNc8=; b=iiABwg+SZ6u5Z0KoN9w/z+fIigNbjJ3oUZfJun4GWQvGAsh1R+hYf2xmSXSe3FwCD2nD7n SCyxShxdzMUqW5RIkSRGzD5tCaKqlvTB+/oAKkkifwhk+0FUYRbw4SQF/lX2iEx1PBityB 26mEgYtE6kbPQVTcWYIShhkPax3O1ZA= X-MC-Unique: EWEl94GZOXOvJzPYl1b_2A-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PATCH v2 1/3] io/command: use glib GSpawn, instead of open-coding fork/exec Date: Fri, 2 Sep 2022 15:18:58 +0400 Message-Id: <20220902111900.3029260-2-marcandre.lureau@redhat.com> In-Reply-To: <20220902111900.3029260-1-marcandre.lureau@redhat.com> References: <20220902111900.3029260-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 2.85 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662118172150100001 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. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Daniel P. Berrang=C3=A9 --- 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..35ba14c6a2 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; + 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.2 From nobody Mon Feb 9 14:16:00 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=1662118463; cv=none; d=zohomail.com; s=zohoarc; b=gb/5Q1sEA4i3jn+oZuvd3mjb0Y0D6+fAo/3sg+3oWkWXi6ZBbm9WMvYuoeqDTC8uEjK7+pG6b2gNMkvs4E4TkqD0tH9GjUlEb5B6I+N9S0AGVrpf8IKfuraIig7n2JBVLAg35D01nTg3FEeebfiXz1dp42BYD+0B2vtSTIVR82o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662118463; 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=52NAMJZDToe0/qwaXgHbNBBIJFLzcLd3cbJxkM16roo=; b=UleL+zSYQLyACRo52zng1MIQ3qPkSrqe5bpWRuPX/EeQnwb48MmOA7kTD35otQTujeyPQfyLe/7tAIHofiQJivi31PB3NXKbh5cAH80bbZp0KUAd6+95T6xKL9oefwPOLUvGJcoKXZZ8YQwQE5qlaqEQQdSAH/Lk/ghGnwLIDgM= 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 1662118463787721.6733283142013; Fri, 2 Sep 2022 04:34:23 -0700 (PDT) Received: from localhost ([::1]:39426 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU4wI-0005LU-It for importer@patchew.org; Fri, 02 Sep 2022 07:34:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46046) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU4hh-0001HY-RM for qemu-devel@nongnu.org; Fri, 02 Sep 2022 07:19:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:42005) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU4hg-0006aM-3v for qemu-devel@nongnu.org; Fri, 02 Sep 2022 07:19:17 -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-635-_StsSeSOOUWtiwXuSJxBgw-1; Fri, 02 Sep 2022 07:19:14 -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 842EC1818212 for ; Fri, 2 Sep 2022 11:19:13 +0000 (UTC) Received: from localhost (unknown [10.39.208.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id 619361415125; Fri, 2 Sep 2022 11:19:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662117555; 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=52NAMJZDToe0/qwaXgHbNBBIJFLzcLd3cbJxkM16roo=; b=Ty29CST7qSDu4WKA2IYthaXPxaNShXrgjfQO4laE6fwGoR2I64EeB57M6E5xPZF75jvBHg ng9jXCnGS8OMkdIJ16a+xCsOXjNKa+kC/X0ZPytb+HdKz8IfqLH1HZp0aJEVs0v+Jrf8Jp OYaUqLHKfkbFKg+ws22IJM5ViO7r2Ng= X-MC-Unique: _StsSeSOOUWtiwXuSJxBgw-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PATCH v2 2/3] io/command: implement support for win32 Date: Fri, 2 Sep 2022 15:18:59 +0400 Message-Id: <20220902111900.3029260-3-marcandre.lureau@redhat.com> In-Reply-To: <20220902111900.3029260-1-marcandre.lureau@redhat.com> References: <20220902111900.3029260-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 2.85 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662118465503100001 From: Marc-Andr=C3=A9 Lureau This is a fairly straightforward implementation of the equivalent UNIX version. GLib uses _mkpipe() to setup the FDs. We take that for granted, and set the underlying named-pipes to nonblocking. This is done by other projects as well (found on github), but I am not confident this works reliably (msdn SetNamedPipeHandleState documentation discourage this usage). 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 --- io/channel-command.c | 58 ++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/io/channel-command.c b/io/channel-command.c index 35ba14c6a2..9bc292f3fd 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,9 +176,7 @@ 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); } } @@ -233,14 +241,20 @@ 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(); + DWORD dwMode =3D PIPE_READMODE_BYTE | enabled ? PIPE_WAIT : PIPE_NOWAI= T; + + if ((cioc->writefd >=3D 0 && !SetNamedPipeHandleState((HANDLE)_get_osf= handle(cioc->writefd), &dwMode, NULL, NULL)) || + (cioc->readfd >=3D 0 &&!SetNamedPipeHandleState((HANDLE)_get_osfha= ndle(cioc->readfd), &dwMode, NULL, NULL))) { + error_setg_win32(errp, GetLastError(), "Failed to set nonblocking"= ); + return -1; + } #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 +295,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.2 From nobody Mon Feb 9 14:16:00 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=1662118296; cv=none; d=zohomail.com; s=zohoarc; b=VNfSteEvC3ADCmDmINrvYKWd4fjxMjqb0zsteZ3K74IdPZhZvhQPvjQUUwKb6QYsQ2tmCI5JIvNW3SifDcsIPHF9HotZzARe3AFVy9yAwtYyQRtrbPwC8F9zZVtkxtWXWXAUDDa3bWRFJDI0W0iDnwbUlvayMb8I1QdMKuOS4yE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662118296; 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=/PFdD2R5sOXGWoM5/LIPX/Ihv6N1EQmtuPD8yP7u8cs=; b=SxNEoi3rPyNYmFb+xg2BVVcOGk+MENHJspfsJJOc/AhtJlSMqxlg1REewMzG83UBzyzHUaE5VqGYVH4Rz8Rd/j7E8im1vgaADVIUnnLxZFTOFFoS/4N2txYO8KN9ZJPPkZNV+UQC/YZJ6kiEU+/MydXlFkx0K2SE6ONp5LHJpuw= 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 1662118296710797.6100786632982; Fri, 2 Sep 2022 04:31:36 -0700 (PDT) Received: from localhost ([::1]:51854 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU4tW-00035d-U3 for importer@patchew.org; Fri, 02 Sep 2022 07:31:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46048) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU4hm-0001IG-60 for qemu-devel@nongnu.org; Fri, 02 Sep 2022 07:19:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:28379) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU4hk-0006lr-LJ for qemu-devel@nongnu.org; Fri, 02 Sep 2022 07:19: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-370-VU-D4hs1N8q32H3fzUYmSQ-1; Fri, 02 Sep 2022 07:19:18 -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 54C3E801755 for ; Fri, 2 Sep 2022 11:19:18 +0000 (UTC) Received: from localhost (unknown [10.39.208.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id 64BED2026D4C; Fri, 2 Sep 2022 11:19:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662117559; 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=/PFdD2R5sOXGWoM5/LIPX/Ihv6N1EQmtuPD8yP7u8cs=; b=ar7YiCVZf1uFEbC/Cl8ypQOiuyhCYHPypeex5DiaHs4Ckq6jHYumrn6Vx8lsjKDeUg0Q1T wDKdUmpVBpXxbAetFa9QOmhDOSWeFE4r3R3Ni+/th3QaOiYrX+Cm8RSMr6OVKIeTT5CFO4 b8DeaANmKfF1y7wTGdY/wOrkZLYC4iA= X-MC-Unique: VU-D4hs1N8q32H3fzUYmSQ-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PATCH v2 3/3] tests/unit: make test-io-channel-command work on win32 Date: Fri, 2 Sep 2022 15:19:00 +0400 Message-Id: <20220902111900.3029260-4-marcandre.lureau@redhat.com> In-Reply-To: <20220902111900.3029260-1-marcandre.lureau@redhat.com> References: <20220902111900.3029260-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 2.78 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.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, 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662118299048100001 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. Signed-off-by: Marc-Andr=C3=A9 Lureau --- tests/unit/test-io-channel-command.c | 31 +++++++++++++++++----------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/tests/unit/test-io-channel-command.c b/tests/unit/test-io-chan= nel-command.c index 99056e07c0..56dcc0be19 100644 --- a/tests/unit/test-io-channel-command.c +++ b/tests/unit/test-io-channel-command.c @@ -24,28 +24,38 @@ #include "qapi/error.h" #include "qemu/module.h" =20 -#ifndef WIN32 +#define TEST_FIFO "tests/test-io-channel-command.fifo" + +#ifdef WIN32 +#define SOCAT "/bin/socat.exe" +#define SOCAT_SRC "PIPE:" TEST_FIFO ",wronly" +#define SOCAT_DST "PIPE:" TEST_FIFO ",rdonly" +#else +#define SOCAT "/bin/socat" +#define SOCAT_SRC "UNIX-LISTEN:" TEST_FIFO +#define SOCAT_DST "UNIX-CONNECT:" TEST_FIFO +#endif + 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) { + if (access(SOCAT, X_OK) < 0) { return; /* Pretend success if socat is not present */ } +#ifndef WIN32 if (mkfifo(TEST_FIFO, 0600) < 0) { abort(); } +#endif src =3D QIO_CHANNEL(qio_channel_command_new_spawn(srcargv, O_WRONLY, &error_abort)); @@ -80,10 +90,10 @@ 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) { + if (access(SOCAT, X_OK) < 0) { return; /* Pretend success if socat is not present */ } =20 @@ -107,7 +117,6 @@ static void test_io_channel_command_echo_sync(void) { test_io_channel_command_echo(false); } -#endif =20 int main(int argc, char **argv) { @@ -115,7 +124,6 @@ int main(int argc, char **argv) =20 g_test_init(&argc, &argv, NULL); =20 -#ifndef WIN32 g_test_add_func("/io/channel/command/fifo/sync", test_io_channel_command_fifo_sync); g_test_add_func("/io/channel/command/fifo/async", @@ -124,7 +132,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.2