From nobody Mon Feb 9 12:25:03 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579779913; cv=none; d=zohomail.com; s=zohoarc; b=K0qC+cx0iCmi376okrE7uRUfgcp3twA2/E50w4RFxUlvTIndkeLrkFyT2rbnXu1m68XQ6OUXq6qiASujrmstvv7vFkfiGzWI1kpV9cAmzgblQjlnrp4QAQDvXAdBYEi+zJiZ4+FMlwBSpX61Q3OdKEy9QN+FIXtMEdWsQZjIKis= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579779913; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eklhtOkGGv6Vs69KB4Jwkbijo5TgR79UpPNy7AUcv6w=; b=gB3zEcmr6UiOnhu/PsRWyXZJmNF2Yu3s9uIVdN6uT3lozQafrsH+E9WZ8tQAUFpJiPocyAwhxDTQ5fMmwbHnRGVI1H9/a89sQDPo4cVIgNQV2FAo3ObiByj119EpBvRW8/YF4tLe5kgX8VUwuXWxuk6m9CurpvQ1P/bVCIFY65A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1579779913650942.2186702279322; Thu, 23 Jan 2020 03:45:13 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-404-HU4DMVBEPWGK0TMmA6IwAw-1; Thu, 23 Jan 2020 06:44:14 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 17AE88010E4; Thu, 23 Jan 2020 11:44:09 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E202F8575F; Thu, 23 Jan 2020 11:44:08 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8B3EB1803C41; Thu, 23 Jan 2020 11:44:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 00NBhv5w025440 for ; Thu, 23 Jan 2020 06:43:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id CCE9285757; Thu, 23 Jan 2020 11:43:57 +0000 (UTC) Received: from domokun.gsslab.fab.redhat.com (unknown [10.33.8.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id 373E39CA3; Thu, 23 Jan 2020 11:43:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579779911; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=eklhtOkGGv6Vs69KB4Jwkbijo5TgR79UpPNy7AUcv6w=; b=IkXLhokxqGTur9owiF3Hux+y8+J7vppP1fCRmys8adWn5CADtlVEVF8JqfrumGhAISF2hV nkIruUlR8jUDPN2SF409uXRlV1/Vr0zfL9GrTjEMrH4C59KlLU0Ctu3cumRjRtzoM8lU8y 8aoEj0t3GiQvVpyLNdZ+XwXFTBJDWWY= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 16/32] util: conditionalize more of virCommand on WIN32 Date: Thu, 23 Jan 2020 11:43:09 +0000 Message-Id: <20200123114325.3860881-17-berrange@redhat.com> In-Reply-To: <20200123114325.3860881-1-berrange@redhat.com> References: <20200123114325.3860881-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: HU4DMVBEPWGK0TMmA6IwAw-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" A large part of the virCommand code is still built on WIN32, despite the fact that the core fork() & execve() functions are not available. So despite succesfully building most of the code, at runtime the APIs are none the less unusuable. With the elimination of GNULIB many of the APIs being used in this code no longer have portability wrappers/shims for Windows. Rather than try to add portability wrappers, or do tests for each individual function, it is clearer to conditionalize nearly all of the code using #ifdef WIN32. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/util/vircommand.c | 165 ++++++++++++++++++++++++++---------------- 1 file changed, 103 insertions(+), 62 deletions(-) diff --git a/src/util/vircommand.c b/src/util/vircommand.c index dd37b0b8dc..26b3488d6b 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -21,11 +21,15 @@ =20 #include =20 -#include +#ifndef WIN32 +# include +#endif #include #include #include -#include +#ifndef WIN32 +# include +#endif #include #include =20 @@ -153,7 +157,9 @@ struct _virCommand { static virBufferPtr dryRunBuffer; static virCommandDryRunCallback dryRunCallback; static void *dryRunOpaque; +#ifndef WIN32 static int dryRunStatus; +#endif /* !WIN32 */ =20 /* * virCommandFDIsSet: @@ -538,6 +544,7 @@ virCommandMassClose(virCommandPtr cmd, return 0; } =20 + /* * virExec: * @cmd virCommandPtr containing all information about the program to @@ -805,6 +812,7 @@ virExec(virCommandPtr cmd) return -1; } =20 + /** * virRun: * @argv NULL terminated argv to run @@ -842,18 +850,6 @@ virRun(const char *const *argv G_GNUC_UNUSED, return -1; } =20 -static int -virExec(virCommandPtr cmd G_GNUC_UNUSED) -{ - /* XXX: Some day we can implement pieces of virCommand/virExec on - * top of _spawn() or CreateProcess(), but we can't implement - * everything, since mingw completely lacks fork(), so we cannot - * run our own code in the child process. */ - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("virExec is not implemented for WIN32")); - return -1; -} - pid_t virFork(void) { @@ -1682,6 +1678,7 @@ virCommandFreeSendBuffers(virCommandPtr cmd) } =20 =20 +#ifndef WIN32 /** * virCommandSetSendBuffer * @cmd: the command to modify @@ -1690,7 +1687,6 @@ virCommandFreeSendBuffers(virCommandPtr cmd) * given file descriptor. The buffer will be freed automatically * and the file descriptor closed. */ -#if defined(F_SETFL) int virCommandSetSendBuffer(virCommandPtr cmd, int fd, @@ -1724,23 +1720,6 @@ virCommandSetSendBuffer(virCommandPtr cmd, return 0; } =20 -#else /* !defined(F_SETFL) */ - -int -virCommandSetSendBuffer(virCommandPtr cmd, - int fd G_GNUC_UNUSED, - unsigned char *buffer G_GNUC_UNUSED, - size_t buflen G_GNUC_UNUSED) -{ - if (!cmd || cmd->has_error) - return -1; - - cmd->has_error =3D ENOTSUP; - - return -1; -} - -#endif =20 static int virCommandSendBuffersFillPollfd(virCommandPtr cmd, @@ -1797,6 +1776,9 @@ virCommandSendBuffersHandlePoll(virCommandPtr cmd, return 0; } =20 +#endif /* !WIN32 */ + + /** * virCommandSetInputBuffer: * @cmd: the command to modify @@ -2105,6 +2087,7 @@ virCommandToString(virCommandPtr cmd, bool linebreaks) } =20 =20 +#ifndef WIN32 /* * Manage input and output to the child process. */ @@ -2276,7 +2259,6 @@ virCommandProcessIO(virCommandPtr cmd) * Returns -1 on any error executing the command. * Will not return on success. */ -#ifndef WIN32 int virCommandExec(virCommandPtr cmd, gid_t *groups, int ngroups) { if (!cmd ||cmd->has_error =3D=3D ENOMEM) { @@ -2299,19 +2281,7 @@ int virCommandExec(virCommandPtr cmd, gid_t *groups,= int ngroups) cmd->args[0]); return -1; } -#else -int virCommandExec(virCommandPtr cmd G_GNUC_UNUSED, gid_t *groups G_GNUC_U= NUSED, - int ngroups G_GNUC_UNUSED) -{ - /* Mingw execve() has a broken signature. Disable this - * function until gnulib fixes the signature, since we - * don't really need this on Win32 anyway. - */ - virReportSystemError(ENOSYS, "%s", - _("Executing new processes is not supported on Wi= n32 platform")); - return -1; -} -#endif + =20 /** * virCommandRun: @@ -2516,7 +2486,7 @@ virCommandRunAsync(virCommandPtr cmd, pid_t *pid) } cmd->infd =3D infd[0]; cmd->inpipe =3D infd[1]; -#if defined (F_SETFL) + if (fcntl(cmd->inpipe, F_SETFL, O_NONBLOCK) < 0) { virReportSystemError(errno, "%s", _("fcntl failed to set O_NONBLOCK")); @@ -2524,11 +2494,6 @@ virCommandRunAsync(virCommandPtr cmd, pid_t *pid) ret =3D -1; goto cleanup; } -#else /* !defined(F_SETFL) */ - cmd->has_error =3D ENOTSUP; - ret =3D -1; - goto cleanup; -#endif } else if ((cmd->inbuf && cmd->infd =3D=3D -1) || (cmd->outbuf && cmd->outfdptr !=3D &cmd->outfd) || (cmd->errbuf && cmd->errfdptr !=3D &cmd->errfd)) { @@ -2719,7 +2684,6 @@ virCommandWait(virCommandPtr cmd, int *exitstatus) } =20 =20 -#ifndef WIN32 /** * virCommandAbort: * @cmd: command to abort @@ -2738,15 +2702,6 @@ virCommandAbort(virCommandPtr cmd) cmd->pid =3D -1; cmd->reap =3D false; } -#else /* WIN32 */ -void -virCommandAbort(virCommandPtr cmd G_GNUC_UNUSED) -{ - /* Mingw lacks WNOHANG and kill(). But since we haven't ported - * virExec to mingw yet, there's no process to be killed, - * making this implementation trivially correct for now :) */ -} -#endif =20 =20 /** @@ -2891,6 +2846,92 @@ int virCommandHandshakeNotify(virCommandPtr cmd) VIR_FORCE_CLOSE(cmd->handshakeNotify[1]); return 0; } +#else /* WIN32 */ +int +virCommandSetSendBuffer(virCommandPtr cmd, + int fd G_GNUC_UNUSED, + unsigned char *buffer G_GNUC_UNUSED, + size_t buflen G_GNUC_UNUSED) +{ + if (!cmd || cmd->has_error) + return -1; + + cmd->has_error =3D ENOTSUP; + + return -1; +} + + +int +virCommandExec(virCommandPtr cmd G_GNUC_UNUSED, gid_t *groups G_GNUC_UNUSE= D, + int ngroups G_GNUC_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Executing new processes is not supported on Wi= n32 platform")); + return -1; +} + + +int +virCommandRun(virCommandPtr cmd G_GNUC_UNUSED, int *exitstatus G_GNUC_UNUS= ED) +{ + virReportSystemError(ENOSYS, "%s", + _("Executing new processes is not supported on Wi= n32 platform")); + return -1; +} + + +int +virCommandRunAsync(virCommandPtr cmd G_GNUC_UNUSED, pid_t *pid G_GNUC_UNUS= ED) +{ + virReportSystemError(ENOSYS, "%s", + _("Executing new processes is not supported on Wi= n32 platform")); + return -1; +} + + +int +virCommandWait(virCommandPtr cmd G_GNUC_UNUSED, int *exitstatus G_GNUC_UNU= SED) +{ + virReportSystemError(ENOSYS, "%s", + _("Executing new processes is not supported on Wi= n32 platform")); + return -1; +} + + +void +virCommandAbort(virCommandPtr cmd G_GNUC_UNUSED) +{ + /* Mingw lacks WNOHANG and kill(). But since we haven't ported + * virExec to mingw yet, there's no process to be killed, + * making this implementation trivially correct for now :) */ +} + + +void virCommandRequireHandshake(virCommandPtr cmd) +{ + if (!cmd || cmd->has_error) + return; + + cmd->has_error =3D ENOSYS; +} + + +int virCommandHandshakeWait(virCommandPtr cmd G_GNUC_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Executing new processes is not supported on Wi= n32 platform")); + return -1; +} + + +int virCommandHandshakeNotify(virCommandPtr cmd G_GNUC_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Executing new processes is not supported on Wi= n32 platform")); + return -1; +} +#endif /* WIN32 */ =20 =20 /** --=20 2.24.1