From nobody Sun May 5 10:18:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1579188539; cv=none; d=zohomail.com; s=zohoarc; b=XFb5ImmYghcpjLNN5CfJmM6BimCci8lx7b8MYhHn5a0S8mjOF0UWgya9n0Un4dZPc7GnADNxd9Kaykbf0SToDgkDdzDMk4hH0Ko7K4hGrwq35az6F1f+WhYUUxx/6NYFOhDKyT2J6FoWWiVnJOAiWGjV+OADjPSaJFskoT9ETWU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579188539; 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=evjCwBlJL9lji0Enk6jV7KHUy82D8U7OaxCale7K4as=; b=blwek1UwjQZCBPi1Jq1z2Yvr61YkViJ+45BfYGshm8/Snd5gNx4RE+zU+hUz4p6W/s1VhO456sTCF7iPhiGJHcYhgR/h2b3XyEIFavz0SHV2OecjYKY8639CLs/ChdhskgwAiTpVj6g7DFUCzlXbjtzuIRJGFme3wt26E0gN5zo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1579188539421785.3204499240126; Thu, 16 Jan 2020 07:28:59 -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-164-DiCSsMIdPUyseS8i-tOjTQ-1; Thu, 16 Jan 2020 10:28:53 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5BDB0DBAB; Thu, 16 Jan 2020 15:28:48 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 327BC5C296; Thu, 16 Jan 2020 15:28:48 +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 E5A80845F8; Thu, 16 Jan 2020 15:28:47 +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 00GFRNZK025931 for ; Thu, 16 Jan 2020 10:27:23 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3BE4081207; Thu, 16 Jan 2020 15:27:23 +0000 (UTC) Received: from catbus.gsslab.fab.redhat.com (mustard.gsslab.fab.redhat.com [10.33.8.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F4738120C; Thu, 16 Jan 2020 15:27:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579188538; 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=evjCwBlJL9lji0Enk6jV7KHUy82D8U7OaxCale7K4as=; b=W/JBT/w4NBUuaTcVtglVtWhg+10LCZO/WJH+grLQ+G8eFegnyA1QE87r/xUGQT8plsRxSD 2NHA31uhapayLkfV6ZEE0p4PjXX4SYfYq0Gwgk4QsIPBWk1sxNpTyXfm8nI6Ow7RlKzSlH K+BWH+ZtHUyW3wFGRqFxZM4pZY/h2NQ= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH v2 01/13] src: replace use of INT_BUFSIZE_BOUND macros Date: Thu, 16 Jan 2020 15:24:36 +0000 Message-Id: <20200116152448.592267-2-berrange@redhat.com> In-Reply-To: <20200116152448.592267-1-berrange@redhat.com> References: <20200116152448.592267-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.16 X-MC-Unique: DiCSsMIdPUyseS8i-tOjTQ-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" Introduce a vastly simpler VIR_INT64_STR_BUFLEN constant which is large enough for all cases where we currently use INT_BUFSIZE_BOUND. This eliminates most use of the gnulib intprops.h header. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Pavel Hrdina --- src/hyperv/hyperv_driver.c | 3 +- src/nwfilter/nwfilter_ebiptables_driver.c | 35 +++++++++-------------- src/nwfilter/nwfilter_learnipaddr.c | 14 ++++----- src/util/virfile.c | 9 +++--- src/util/virhostcpu.c | 3 +- src/util/virlog.c | 3 +- src/util/virnetdevbridge.c | 10 +++---- src/util/virpidfile.c | 7 ++--- src/util/virstring.h | 2 ++ tests/virsystemdtest.c | 5 ++-- tools/virsh-domain-monitor.c | 3 +- tools/virt-login-shell.c | 7 +++-- 12 files changed, 42 insertions(+), 59 deletions(-) diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index c9d22ec7c4..4677a25ff8 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -36,7 +36,6 @@ #include "openwsman.h" #include "virstring.h" #include "virkeycode.h" -#include "intprops.h" =20 #define VIR_FROM_THIS VIR_FROM_HYPERV =20 @@ -1339,7 +1338,7 @@ hypervDomainSendKey(virDomainPtr domain, unsigned int= codeset, Msvm_Keyboard *keyboard =3D NULL; virBuffer query =3D VIR_BUFFER_INITIALIZER; hypervInvokeParamsListPtr params =3D NULL; - char keycodeStr[INT_BUFSIZE_BOUND(int)]; + char keycodeStr[VIR_INT64_STR_BUFLEN]; =20 virCheckFlags(0, -1); =20 diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfil= ter_ebiptables_driver.c index eec1414023..f4c192aebb 100644 --- a/src/nwfilter/nwfilter_ebiptables_driver.c +++ b/src/nwfilter/nwfilter_ebiptables_driver.c @@ -40,7 +40,6 @@ #include "virfile.h" #include "vircommand.h" #include "configmake.h" -#include "intprops.h" #include "virstring.h" #include "virfirewall.h" =20 @@ -820,10 +819,9 @@ iptablesHandleIPHdr(virFirewallPtr fw, bool directionIn, bool *skipRule, bool *skipMatch) { - char ipaddr[INET6_ADDRSTRLEN], - ipaddralt[INET6_ADDRSTRLEN], - number[MAX(INT_BUFSIZE_BOUND(uint32_t), - INT_BUFSIZE_BOUND(int))]; + char ipaddr[INET6_ADDRSTRLEN]; + char ipaddralt[INET6_ADDRSTRLEN]; + char number[VIR_INT64_STR_BUFLEN]; const char *src =3D "--source"; const char *dst =3D "--destination"; const char *srcrange =3D "--src-range"; @@ -968,8 +966,7 @@ iptablesHandleIPHdrAfterStateMatch(virFirewallPtr fw, ipHdrDataDefPtr ipHdr, bool directionIn) { - char number[MAX(INT_BUFSIZE_BOUND(uint32_t), - INT_BUFSIZE_BOUND(int))]; + char number[VIR_INT64_STR_BUFLEN]; char str[MAX_IPSET_NAME_LENGTH]; =20 if (HAS_ENTRY_ITEM(&ipHdr->dataIPSet) && @@ -1152,10 +1149,8 @@ _iptablesCreateRuleInstance(virFirewallPtr fw, bool maySkipICMP) { char chain[MAX_CHAINNAME_LENGTH]; - char number[MAX(INT_BUFSIZE_BOUND(uint32_t), - INT_BUFSIZE_BOUND(int))]; - char numberalt[MAX(INT_BUFSIZE_BOUND(uint32_t), - INT_BUFSIZE_BOUND(int))]; + char number[VIR_INT64_STR_BUFLEN]; + char numberalt[VIR_INT64_STR_BUFLEN]; const char *target; bool srcMacSkipped =3D false; bool skipRule =3D false; @@ -1789,16 +1784,14 @@ ebtablesCreateRuleInstance(virFirewallPtr fw, virNWFilterVarCombIterPtr vars, bool reverse) { - char macaddr[VIR_MAC_STRING_BUFLEN], - ipaddr[INET_ADDRSTRLEN], - ipmask[INET_ADDRSTRLEN], - ipv6addr[INET6_ADDRSTRLEN], - number[MAX(INT_BUFSIZE_BOUND(uint32_t), - INT_BUFSIZE_BOUND(int))], - numberalt[MAX(INT_BUFSIZE_BOUND(uint32_t), - INT_BUFSIZE_BOUND(int))], - field[MAX(VIR_MAC_STRING_BUFLEN, INET6_ADDRSTRLEN)], - fieldalt[MAX(VIR_MAC_STRING_BUFLEN, INET6_ADDRSTRLEN)]; + char macaddr[VIR_MAC_STRING_BUFLEN]; + char ipaddr[INET_ADDRSTRLEN]; + char ipmask[INET_ADDRSTRLEN]; + char ipv6addr[INET6_ADDRSTRLEN]; + char number[VIR_INT64_STR_BUFLEN]; + char numberalt[VIR_INT64_STR_BUFLEN]; + char field[VIR_INT64_STR_BUFLEN]; + char fieldalt[VIR_INT64_STR_BUFLEN]; char chain[MAX_CHAINNAME_LENGTH]; const char *target; bool hasMask =3D false; diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_le= arnipaddr.c index 46ef65401c..5791724cf4 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -39,7 +39,6 @@ =20 #include "internal.h" =20 -#include "intprops.h" #include "virbuffer.h" #include "viralloc.h" #include "virlog.h" @@ -59,10 +58,6 @@ =20 VIR_LOG_INIT("nwfilter.nwfilter_learnipaddr"); =20 -#define IFINDEX2STR(VARNAME, ifindex) \ - char VARNAME[INT_BUFSIZE_BOUND(ifindex)]; \ - g_snprintf(VARNAME, sizeof(VARNAME), "%d", ifindex); - #define PKT_TIMEOUT_MS 500 /* ms */ =20 /* structure of an ARP request/reply message */ @@ -239,7 +234,7 @@ static int virNWFilterRegisterLearnReq(virNWFilterIPAddrLearnReqPtr req) { int res =3D -1; - IFINDEX2STR(ifindex_str, req->ifindex); + g_autofree char *ifindex_str =3D g_strdup_printf("%d", req->ifindex); =20 virMutexLock(&pendingLearnReqLock); =20 @@ -260,6 +255,7 @@ virNWFilterTerminateLearnReq(const char *ifname) int rc =3D -1; int ifindex; virNWFilterIPAddrLearnReqPtr req; + g_autofree char *ifindex_str =3D NULL; =20 /* It's possible that it's already been removed as a result of * virNWFilterDeregisterLearnReq during learnIPAddressThread() exit @@ -274,7 +270,7 @@ virNWFilterTerminateLearnReq(const char *ifname) return rc; } =20 - IFINDEX2STR(ifindex_str, ifindex); + ifindex_str =3D g_strdup_printf("%d", ifindex); =20 virMutexLock(&pendingLearnReqLock); =20 @@ -294,7 +290,7 @@ bool virNWFilterHasLearnReq(int ifindex) { void *res; - IFINDEX2STR(ifindex_str, ifindex); + g_autofree char *ifindex_str =3D g_strdup_printf("%d", ifindex); =20 virMutexLock(&pendingLearnReqLock); =20 @@ -319,7 +315,7 @@ static virNWFilterIPAddrLearnReqPtr virNWFilterDeregisterLearnReq(int ifindex) { virNWFilterIPAddrLearnReqPtr res; - IFINDEX2STR(ifindex_str, ifindex); + g_autofree char *ifindex_str =3D g_strdup_printf("%d", ifindex); =20 virMutexLock(&pendingLearnReqLock); =20 diff --git a/src/util/virfile.c b/src/util/virfile.c index 5acac85bb9..6eaabf5371 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -68,7 +68,6 @@ #endif =20 #include "configmake.h" -#include "intprops.h" #include "viralloc.h" #include "vircommand.h" #include "virerror.h" @@ -4067,7 +4066,7 @@ virFileReadValueInt(int *value, const char *format, .= ..) if (!virFileExists(path)) return -2; =20 - if (virFileReadAll(path, INT_BUFSIZE_BOUND(*value), &str) < 0) + if (virFileReadAll(path, VIR_INT64_STR_BUFLEN, &str) < 0) return -1; =20 virStringTrimOptionalNewline(str); @@ -4107,7 +4106,7 @@ virFileReadValueUint(unsigned int *value, const char = *format, ...) if (!virFileExists(path)) return -2; =20 - if (virFileReadAll(path, INT_BUFSIZE_BOUND(*value), &str) < 0) + if (virFileReadAll(path, VIR_INT64_STR_BUFLEN, &str) < 0) return -1; =20 virStringTrimOptionalNewline(str); @@ -4147,7 +4146,7 @@ virFileReadValueUllong(unsigned long long *value, con= st char *format, ...) if (!virFileExists(path)) return -2; =20 - if (virFileReadAll(path, INT_BUFSIZE_BOUND(*value), &str) < 0) + if (virFileReadAll(path, VIR_INT64_STR_BUFLEN, &str) < 0) return -1; =20 virStringTrimOptionalNewline(str); @@ -4188,7 +4187,7 @@ virFileReadValueScaledInt(unsigned long long *value, = const char *format, ...) if (!virFileExists(path)) return -2; =20 - if (virFileReadAll(path, INT_BUFSIZE_BOUND(*value), &str) < 0) + if (virFileReadAll(path, VIR_INT64_STR_BUFLEN, &str) < 0) return -1; =20 virStringTrimOptionalNewline(str); diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c index 7f14340f49..f3adc1b4ae 100644 --- a/src/util/virhostcpu.c +++ b/src/util/virhostcpu.c @@ -43,7 +43,6 @@ #include "virhostcpupriv.h" #include "physmem.h" #include "virerror.h" -#include "intprops.h" #include "virarch.h" #include "virfile.h" #include "virtypedparam.h" @@ -775,7 +774,7 @@ virHostCPUGetStatsLinux(FILE *procstat, char line[1024]; unsigned long long usr, ni, sys, idle, iowait; unsigned long long irq, softirq, steal, guest, guest_nice; - char cpu_header[4 + INT_BUFSIZE_BOUND(cpuNum)]; + char cpu_header[4 + VIR_INT64_STR_BUFLEN]; =20 if ((*nparams) =3D=3D 0) { /* Current number of cpu stats supported by linux */ diff --git a/src/util/virlog.c b/src/util/virlog.c index 8a9fb34161..ddc3ac1edb 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -45,7 +45,6 @@ #include "virthread.h" #include "virfile.h" #include "virtime.h" -#include "intprops.h" #include "virstring.h" #include "configmake.h" =20 @@ -832,7 +831,7 @@ virLogNewOutputToSyslog(virLogPriority priority, # define IOVEC_SET_STRING(iov, str) IOVEC_SET(iov, str, strlen(str)) =20 /* Used for conversion of numbers to strings, and for length of binary dat= a */ -# define JOURNAL_BUF_SIZE (MAX(INT_BUFSIZE_BOUND(int), sizeof(uint64_t))) +# define JOURNAL_BUF_SIZE (MAX(VIR_INT64_STR_BUFLEN, sizeof(uint64_t))) =20 struct journalState { diff --git a/src/util/virnetdevbridge.c b/src/util/virnetdevbridge.c index 3a7a6dc730..a37bcb4004 100644 --- a/src/util/virnetdevbridge.c +++ b/src/util/virnetdevbridge.c @@ -25,7 +25,6 @@ #include "virfile.h" #include "viralloc.h" #include "virlog.h" -#include "intprops.h" #include "virstring.h" =20 #include @@ -125,8 +124,7 @@ static int virNetDevBridgeSet(const char *brname, path =3D g_strdup_printf(SYSFS_NET_DIR "%s/bridge/%s", brname, paramna= me); =20 if (virFileExists(path)) { - char valuestr[INT_BUFSIZE_BOUND(value)]; - g_snprintf(valuestr, sizeof(valuestr), "%lu", value); + g_autofree char *valuestr =3D g_strdup_printf("%lu", value); if (virFileWriteStr(path, valuestr, 0) >=3D 0) return 0; VIR_DEBUG("Unable to set bridge %s %s via sysfs", brname, paramnam= e); @@ -169,7 +167,7 @@ static int virNetDevBridgeGet(const char *brname, if (virFileExists(path)) { g_autofree char *valuestr =3D NULL; =20 - if (virFileReadAll(path, INT_BUFSIZE_BOUND(unsigned long), + if (virFileReadAll(path, VIR_INT64_STR_BUFLEN, &valuestr) < 0) return -1; =20 @@ -215,7 +213,7 @@ virNetDevBridgePortSet(const char *brname, const char *paramname, unsigned long value) { - char valuestr[INT_BUFSIZE_BOUND(value)]; + char valuestr[VIR_INT64_STR_BUFLEN]; int ret =3D -1; g_autofree char *path =3D NULL; =20 @@ -251,7 +249,7 @@ virNetDevBridgePortGet(const char *brname, path =3D g_strdup_printf(SYSFS_NET_DIR "%s/brif/%s/%s", brname, ifname, paramname); =20 - if (virFileReadAll(path, INT_BUFSIZE_BOUND(unsigned long), &valuestr) = < 0) + if (virFileReadAll(path, VIR_INT64_STR_BUFLEN, &valuestr) < 0) return -1; =20 if (virStrToLong_ul(valuestr, NULL, 10, value) < 0) { diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c index b08e0d8d52..a8a743504d 100644 --- a/src/util/virpidfile.c +++ b/src/util/virpidfile.c @@ -31,7 +31,6 @@ #include "virfile.h" #include "viralloc.h" #include "virutil.h" -#include "intprops.h" #include "virlog.h" #include "virerror.h" #include "virstring.h" @@ -57,7 +56,7 @@ int virPidFileWritePath(const char *pidfile, { int rc; int fd; - char pidstr[INT_BUFSIZE_BOUND(pid)]; + char pidstr[VIR_INT64_STR_BUFLEN]; =20 if ((fd =3D open(pidfile, O_WRONLY | O_CREAT | O_TRUNC, @@ -110,7 +109,7 @@ int virPidFileReadPath(const char *path, int rc; ssize_t bytes; long long pid_value =3D 0; - char pidstr[INT_BUFSIZE_BOUND(pid_value)]; + char pidstr[VIR_INT64_STR_BUFLEN]; char *endptr =3D NULL; =20 *pid =3D 0; @@ -333,7 +332,7 @@ int virPidFileAcquirePath(const char *path, pid_t pid) { int fd =3D -1; - char pidstr[INT_BUFSIZE_BOUND(pid)]; + char pidstr[VIR_INT64_STR_BUFLEN]; =20 if (path[0] =3D=3D '\0') return 0; diff --git a/src/util/virstring.h b/src/util/virstring.h index a2cd92cf83..360c68395c 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -22,6 +22,8 @@ =20 #include "internal.h" =20 +#define VIR_INT64_STR_BUFLEN 21 + char **virStringSplitCount(const char *string, const char *delim, size_t max_tokens, diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c index 26876850b8..a9b02af7db 100644 --- a/tests/virsystemdtest.c +++ b/tests/virsystemdtest.c @@ -33,7 +33,6 @@ # include "virlog.h" # include "virmock.h" # include "rpc/virnetsocket.h" -# include "intprops.h" # define VIR_FROM_THIS VIR_FROM_NONE =20 VIR_LOG_INIT("tests.systemdtest"); @@ -548,8 +547,8 @@ testActivation(bool useNames) size_t nsockIP; int ret =3D -1; size_t i; - char nfdstr[INT_BUFSIZE_BOUND(size_t)]; - char pidstr[INT_BUFSIZE_BOUND(pid_t)]; + char nfdstr[VIR_INT64_STR_BUFLEN]; + char pidstr[VIR_INT64_STR_BUFLEN]; virSystemdActivationMap map[2]; int *fds =3D NULL; size_t nfds =3D 0; diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index e357635757..efcdc613c6 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -29,7 +29,6 @@ =20 #include "internal.h" #include "conf/virdomainobjlist.h" -#include "intprops.h" #include "viralloc.h" #include "virmacaddr.h" #include "virxml.h" @@ -1964,7 +1963,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd) bool ret =3D false; virshDomainListPtr list =3D NULL; virDomainPtr dom; - char id_buf[INT_BUFSIZE_BOUND(unsigned int)]; + char id_buf[VIR_INT64_STR_BUFLEN]; unsigned int id; unsigned int flags =3D VIR_CONNECT_LIST_DOMAINS_ACTIVE; vshTablePtr table =3D NULL; diff --git a/tools/virt-login-shell.c b/tools/virt-login-shell.c index 7d1e0ccc8a..cf4a249f0a 100644 --- a/tools/virt-login-shell.c +++ b/tools/virt-login-shell.c @@ -33,11 +33,12 @@ * so don't introduce a link time dep, which we must avoid */ #include "gnulib/lib/configmake.h" -#include "gnulib/lib/intprops.h" + +#define VIR_INT64_STR_BUFLEN 21 =20 int main(int argc, char **argv) { - char uidstr[INT_BUFSIZE_BOUND(uid_t)]; - char gidstr[INT_BUFSIZE_BOUND(gid_t)]; + char uidstr[VIR_INT64_STR_BUFLEN]; + char gidstr[VIR_INT64_STR_BUFLEN]; const char * newargv[6]; size_t nargs =3D 0; char *newenv[] =3D { --=20 2.24.1 From nobody Sun May 5 10:18:36 2024 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=1579188515; cv=none; d=zohomail.com; s=zohoarc; b=CacP2b3BgbeZPDUEZE3BA91VEisYsVFd3ZgVEcSlsDDRAdyfswKIIZ3fct/guZSjM+/DLH9P61NpeMI7a4PVQDDmQCvqPGEgkys1uV0lydnypZICA8shqSz0n+gwGEvSvFzProaduwxlo05g2hFBeA5yzh5sJN/8lw3YsSBoONw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579188515; 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=wyfb+R2ZLk3r83o1DgfdMJdWvaeHhthfb/PDyQxMbC8=; b=By0YWbOhd+d3fryHm0w/8GpQw03AIqn1CqsxnArILzA/s4ImfQfQAmJrDsd5R/K2wcdhPzSinhO3yY68wjeI5kUwfwj2m5rVrZ7iCRB9OeBDCqaX0jMfhShsCbhh1PhU5jlcUPzEAiXBq3U9b+AyrtvaycPSxRetb2vApANXrFY= 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-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1579188515468997.1830860843666; Thu, 16 Jan 2020 07:28:35 -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-403-yHiCFQASMFG7vroF7tKpEA-1; Thu, 16 Jan 2020 10:28:32 -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 23967100551A; Thu, 16 Jan 2020 15:28:27 +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 F204C81200; Thu, 16 Jan 2020 15:28:26 +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 ABDA918034ED; Thu, 16 Jan 2020 15:28:26 +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 00GFROG0025940 for ; Thu, 16 Jan 2020 10:27:24 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1C0C581209; Thu, 16 Jan 2020 15:27:24 +0000 (UTC) Received: from catbus.gsslab.fab.redhat.com (mustard.gsslab.fab.redhat.com [10.33.8.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8122181206; Thu, 16 Jan 2020 15:27:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579188514; 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=wyfb+R2ZLk3r83o1DgfdMJdWvaeHhthfb/PDyQxMbC8=; b=FiHFJtRfXLuPBO47+Ev2r/KLq2JJb+vCO7fenRC+VNlMem+X8WNhKrzZ1F5ukaUGPh7E4+ t8p4NXzzwCzWyk/q+PsnJIsVGMb82lrZcz+AmZAAfuTdAgGAxDXlEi/vTurZP4YdhDoopw brHutwqDBpy652qD+qrvLM4jnfzFFIU= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH v2 02/13] src: remove use of the INT_MULTIPLY_OVERFLOW macro Date: Thu, 16 Jan 2020 15:24:37 +0000 Message-Id: <20200116152448.592267-3-berrange@redhat.com> In-Reply-To: <20200116152448.592267-1-berrange@redhat.com> References: <20200116152448.592267-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: yHiCFQASMFG7vroF7tKpEA-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" The GLib g_size_checked_mul() function is not quite the same signature, and gives compiler warnings due to not correctly casting from gsize to guint64/32. Implementing a replacement for INT_MULTIPLY_OVERFLOW is easy enough to do ourselves. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Pavel Hrdina --- build-aux/syntax-check.mk | 15 --------------- src/internal.h | 2 ++ src/libvirt-domain.c | 6 ++---- src/remote/remote_daemon_dispatch.c | 5 ++--- src/remote/remote_driver.c | 5 ++--- 5 files changed, 8 insertions(+), 25 deletions(-) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 7e7c59c3df..6e9328ee63 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -1606,20 +1606,6 @@ sc_prohibit_strings_without_use: re=3D'\<(strn?casecmp|ffs(ll)?)\>' \ $(_sc_header_without_use) =20 -# Extract the raw list of symbol names with this: -gl_extract_define_simple =3D \ - /^\# *define ([A-Z]\w+)\(/ and print $$1 -# Filter out duplicates and convert to a space-separated list: -_intprops_names =3D \ - $(shell f=3D$(gnulib_dir)/lib/intprops.h; \ - perl -lne '$(gl_extract_define_simple)' $$f | sort -u | tr '\n' ' ') -# Remove trailing space and convert to a regular expression: -_intprops_syms_re =3D $(subst $(_sp),|,$(strip $(_intprops_names))) -# Prohibit the inclusion of intprops.h without an actual use. -sc_prohibit_intprops_without_use: - @h=3D'intprops.h' \ - re=3D'\<($(_intprops_syms_re)) *\(' \ - $(_sc_header_without_use) =20 _stddef_syms_re =3D NULL|offsetof|ptrdiff_t|size_t|wchar_t # Prohibit the inclusion of stddef.h without an actual use. @@ -1714,7 +1700,6 @@ sc_prohibit_defined_have_decl_tests: =20 # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D gl_other_headers_ ?=3D \ - intprops.h \ openat.h \ stat-macros.h =20 diff --git a/src/internal.h b/src/internal.h index 686b7cfcc2..e356db6c78 100644 --- a/src/internal.h +++ b/src/internal.h @@ -38,6 +38,8 @@ # define sa_assert(expr) /* empty */ #endif =20 +#define VIR_INT_MULTIPLY_OVERFLOW(a,b) (G_UNLIKELY ((b) > 0 && (a) > G_MAX= INT / (b))) + /* The library itself is allowed to use deprecated functions / * variables, so effectively undefine the deprecated attribute * which would otherwise be defined in libvirt.h. diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index d0304e174f..e7585d1872 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -21,8 +21,6 @@ #include #include =20 -#include "intprops.h" - #include "datatypes.h" #include "viralloc.h" #include "virfile.h" @@ -7302,7 +7300,7 @@ virDomainGetVcpuPinInfo(virDomainPtr domain, int ncpu= maps, virCheckPositiveArgGoto(ncpumaps, error); virCheckPositiveArgGoto(maplen, error); =20 - if (INT_MULTIPLY_OVERFLOW(ncpumaps, maplen)) { + if (VIR_INT_MULTIPLY_OVERFLOW(ncpumaps, maplen)) { virReportError(VIR_ERR_OVERFLOW, _("input too large: %d * %d"), ncpumaps, maplen); goto error; @@ -7503,7 +7501,7 @@ virDomainGetVcpus(virDomainPtr domain, virVcpuInfoPtr= info, int maxinfo, else virCheckZeroArgGoto(maplen, error); =20 - if (cpumaps && INT_MULTIPLY_OVERFLOW(maxinfo, maplen)) { + if (cpumaps && VIR_INT_MULTIPLY_OVERFLOW(maxinfo, maplen)) { virReportError(VIR_ERR_OVERFLOW, _("input too large: %d * %d"), maxinfo, maplen); goto error; diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon= _dispatch.c index 9c294ddc39..6c00690f68 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -31,7 +31,6 @@ #include "remote_daemon_stream.h" #include "viruuid.h" #include "vircommand.h" -#include "intprops.h" #include "virnetserverservice.h" #include "virnetserver.h" #include "virfile.h" @@ -2755,7 +2754,7 @@ remoteDispatchDomainGetVcpuPinInfo(virNetServerPtr se= rver G_GNUC_UNUSED, goto cleanup; } =20 - if (INT_MULTIPLY_OVERFLOW(args->ncpumaps, args->maplen) || + if (VIR_INT_MULTIPLY_OVERFLOW(args->ncpumaps, args->maplen) || args->ncpumaps * args->maplen > REMOTE_CPUMAPS_MAX) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("maxinfo * maplen >= REMOTE_CPUMAPS_MAX")); goto cleanup; @@ -2898,7 +2897,7 @@ remoteDispatchDomainGetVcpus(virNetServerPtr server G= _GNUC_UNUSED, goto cleanup; } =20 - if (INT_MULTIPLY_OVERFLOW(args->maxinfo, args->maplen) || + if (VIR_INT_MULTIPLY_OVERFLOW(args->maxinfo, args->maplen) || args->maxinfo * args->maplen > REMOTE_CPUMAPS_MAX) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("maxinfo * maplen >= REMOTE_CPUMAPS_MAX")); goto cleanup; diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index c11f73ab4d..66472a6cc1 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -43,7 +43,6 @@ #include "viralloc.h" #include "virfile.h" #include "vircommand.h" -#include "intprops.h" #include "virtypedparam.h" #include "viruri.h" #include "virauth.h" @@ -2236,7 +2235,7 @@ remoteDomainGetVcpuPinInfo(virDomainPtr domain, goto done; } =20 - if (INT_MULTIPLY_OVERFLOW(ncpumaps, maplen) || + if (VIR_INT_MULTIPLY_OVERFLOW(ncpumaps, maplen) || ncpumaps * maplen > REMOTE_CPUMAPS_MAX) { virReportError(VIR_ERR_RPC, _("vCPU map buffer length exceeds maximum: %d > %d"= ), @@ -2405,7 +2404,7 @@ remoteDomainGetVcpus(virDomainPtr domain, maxinfo, REMOTE_VCPUINFO_MAX); goto done; } - if (INT_MULTIPLY_OVERFLOW(maxinfo, maplen) || + if (VIR_INT_MULTIPLY_OVERFLOW(maxinfo, maplen) || maxinfo * maplen > REMOTE_CPUMAPS_MAX) { virReportError(VIR_ERR_RPC, _("vCPU map buffer length exceeds maximum: %d > %d"= ), --=20 2.24.1 From nobody Sun May 5 10:18:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1579188528; cv=none; d=zohomail.com; s=zohoarc; b=JZLxAf8VSASm2jnhbjKLbNzVBgn8X4m+70wi+2pdh1tOfEtQ11MwyOUwgy8GX3WcHxzBpq6ZgHFLhA+16sh/jH4W6u7BIlfe7EmKrj/FBZ76a2UUaM2t2v9dNZIIUQ0ew4TQzABhHVondHMjUaNp7BUaPjgBKSAWRoAO5CiAhg4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579188528; 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=qimoo3WQJhFhgvtlc2biAk5o/RaCPEPHM9Ht2X3kAnQ=; b=LNlLkqVeEqGQXlcNjnANz2tcg1lgpa17z3XY/AV7XU5ECg44f+7WRCadJ2uTwxtt8VCwmrdKcbUVw99d2VW9ekj0ao9vd+pZE1pyuuhL0UWpiDbhMuzhYfVSlKNofABysIk7OUk0iRgQH0zVtdn880A1eusRkPZt7qJdguVx+p8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1579188528181692.4213888125743; Thu, 16 Jan 2020 07:28:48 -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-135-P0L6BZoLPRqGW8jD7Inn0Q-1; Thu, 16 Jan 2020 10:28:44 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 40B6818FE870; Thu, 16 Jan 2020 15:28:38 +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 18EE210016DA; Thu, 16 Jan 2020 15:28:38 +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 CAC2618034EB; Thu, 16 Jan 2020 15:28:37 +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 00GFRP2H025949 for ; Thu, 16 Jan 2020 10:27:25 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1EDFA81207; Thu, 16 Jan 2020 15:27:25 +0000 (UTC) Received: from catbus.gsslab.fab.redhat.com (mustard.gsslab.fab.redhat.com [10.33.8.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 609AC8120C; Thu, 16 Jan 2020 15:27:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579188526; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=qimoo3WQJhFhgvtlc2biAk5o/RaCPEPHM9Ht2X3kAnQ=; b=L0qg+QgdkN+N+XxsVJmO5D/ihyKeZ7SIYbkQZHwYQqBMiFID0cUcbZkFUGql9aO9K5+8c7 hMUaQXczi+tXdqX+AxPniTRh/u6/M93ZUQWw0bV8fVCFsr69ZycJal3ka5O4uKlniHSVpv kpcnYkH5oShPZSI1q5d4v5G8T9vYCt4= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH v2 03/13] tests: always declare environ Date: Thu, 16 Jan 2020 15:24:38 +0000 Message-Id: <20200116152448.592267-4-berrange@redhat.com> In-Reply-To: <20200116152448.592267-1-berrange@redhat.com> References: <20200116152448.592267-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 Cc: Pavel Hrdina 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.84 on 10.5.11.22 X-MC-Unique: P0L6BZoLPRqGW8jD7Inn0Q-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" Some UNIX platforms don't declare 'environ' in their header files. We can unconditionally declare it ourselves to avoid this problem. There is no need to do this in the aa-helper code since that is Linux only code. Reviewed-by: Pavel Hrdina Signed-off-by: Daniel P. Berrang=C3=A9 --- tests/commandhelper.c | 3 +++ tests/commandtest.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index 77cbcd4680..a7a3c44e33 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -31,6 +31,9 @@ =20 #ifndef WIN32 =20 +/* Some UNIX lack it in headers & it doesn't hurt to redeclare */ +extern char **environ; + # define VIR_FROM_THIS VIR_FROM_NONE =20 static int envsort(const void *a, const void *b) diff --git a/tests/commandtest.c b/tests/commandtest.c index 5df1aa4221..cc8676811e 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -58,6 +58,9 @@ main(void) =20 #else =20 +/* Some UNIX lack it in headers & it doesn't hurt to redeclare */ +extern char **environ; + static int checkoutput(const char *testname, char *prefix) { --=20 2.24.1 From nobody Sun May 5 10:18:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1579188528; cv=none; d=zohomail.com; s=zohoarc; b=Mw6Y/w716ZUV0NfjuHWnpqOv5UJ0i1W1dfaFP2kdIyNQ+vdl1i+EgcJsee54Ou+Q3LXN/WqA2PkvVynmnz89JE4Qn+AKICuJemd+Qsq1Rj4wIfxC5iODhrLPpEeaPaPZEOnv+mnSFH8a73jGK+X8eJfJop5HiF53P9XproImWvo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579188528; 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=VIEcAj4f9+54nWahPbQASTGvSCtIyD+T1igDK1jAv1g=; b=bIkD3clOiNluQr6JUAYjxkuh9X2h7NjfssXWaRcNFvaWXpUUdoTYA6uMs75UuSCR1CBnn9x8LceGu4+mWmfgyod8fccdpUSWZoPmGE1SZqTx7EPRvzGuKCo6GpJRNSaOUoIVaaGhQZwU8Se2PSpZi4Fx5G1aMV/6f2/zbauHGgY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 157918852868789.20033167733095; Thu, 16 Jan 2020 07:28:48 -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-126-do1wPasBOjSNwcBOe7p66g-1; Thu, 16 Jan 2020 10:28:30 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3A12E800D41; Thu, 16 Jan 2020 15:28:24 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 239B286CB7; Thu, 16 Jan 2020 15:28:23 +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 BA525845F5; Thu, 16 Jan 2020 15:28:22 +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 00GFRQvP025956 for ; Thu, 16 Jan 2020 10:27:26 -0500 Received: by smtp.corp.redhat.com (Postfix) id 22A8981209; Thu, 16 Jan 2020 15:27:26 +0000 (UTC) Received: from catbus.gsslab.fab.redhat.com (mustard.gsslab.fab.redhat.com [10.33.8.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6396A81206; Thu, 16 Jan 2020 15:27:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579188526; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=VIEcAj4f9+54nWahPbQASTGvSCtIyD+T1igDK1jAv1g=; b=ZqAYiNkCN0CuD/tzUXJ0Hgsx8vYdvsk86o97TjVCUgKXVZYwUOIpK11tdCSqvahMJBvX6I ZbBPFhFK432E03fPi7o0iGFG/1nr/dUCUvHZ8cSGFKFFokq14ZEzrlhAdDJ8ektyXUKkjN NYQIBIvl2bWp7fW3/cei9jYzxLN6wL8= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH v2 04/13] build: validate headers against local gnulib not git repo Date: Thu, 16 Jan 2020 15:24:39 +0000 Message-Id: <20200116152448.592267-5-berrange@redhat.com> In-Reply-To: <20200116152448.592267-1-berrange@redhat.com> References: <20200116152448.592267-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 Cc: Pavel Hrdina 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.13 X-MC-Unique: do1wPasBOjSNwcBOe7p66g-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" Some syntax check rules validate usage of headers provided by gnulib. We want to validate these only against the gnulib modules we've chosen to use, not all modules, since we're trying to eliminate them. Reviewed-by: Pavel Hrdina Signed-off-by: Daniel P. Berrang=C3=A9 --- build-aux/syntax-check.mk | 3 --- 1 file changed, 3 deletions(-) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 6e9328ee63..1fd11093d8 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -132,9 +132,6 @@ local-check :=3D \ =20 syntax-check: $(local-check) =20 -# We use .gnulib, not gnulib. -gnulib_dir =3D $(srcdir)/.gnulib - # We haven't converted all scripts to using gnulib's init.sh yet. _test_script_regex =3D \<\(init\|test-lib\)\.sh\> =20 --=20 2.24.1 From nobody Sun May 5 10:18:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; 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 205.139.110.61 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=1579188528; cv=none; d=zohomail.com; s=zohoarc; b=Jk8LFGt4HOj5OdkXen12ak8g6hve8CKW8k4vKwlf/HnuG/Tb7CJ40u7WVJ+ougB/rD1UeAh4XJ2Jwfx11UFOfpf9QTM+MCrgBSuGnDEQBka3u81zJdfM3ZBRcGkygJE1VTM0m4vYXMYKoF4ciPpE2MIig+F+A1lvC7VGHiqlBXY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579188528; 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=clSLuSCq0fXMFLFG8bNi8M0L9EQoYOE5lDJygmR70yE=; b=eBUvm4y5id+NQtOZuRTc/PW5i4gkWlTY2msiViqDB4bgjUMxarkRM+cuglJxTz7ZE7A4ifra9Mw3zT5LrcbP7Dlu1YL8reCdqF1+Vby1FtPzs85ca7s/a5JK622nTzECbDGlylJmiUZZa3u51XO61Fypd+Cr0n+7KuBgYJizAEc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1579188528380110.42093582792722; Thu, 16 Jan 2020 07:28:48 -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-194-ZOVKUw29MyiMI6HfeVx1SA-1; Thu, 16 Jan 2020 10:28:43 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CBDD8801E77; Thu, 16 Jan 2020 15:28:37 +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 A4AED60F82; Thu, 16 Jan 2020 15:28:37 +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 677C718034EB; Thu, 16 Jan 2020 15:28:37 +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 00GFRRD2025962 for ; Thu, 16 Jan 2020 10:27:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2693381207; Thu, 16 Jan 2020 15:27:27 +0000 (UTC) Received: from catbus.gsslab.fab.redhat.com (mustard.gsslab.fab.redhat.com [10.33.8.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 67B4E81206; Thu, 16 Jan 2020 15:27:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579188527; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=clSLuSCq0fXMFLFG8bNi8M0L9EQoYOE5lDJygmR70yE=; b=QDQP6yjojlvyAhpmqXH6aDfEeXE5P1ZlXVrml3JdVf6EpimNaAcWg47xVc+WvfFZR+8c9U abptn9I3zr4/2QAgf8axrlBQUc4hh9wf4OgBxotZUvgFN4qW1o+x+p9fxepeQsKisVcilG K4mFIxiYW8uSyS3FXA2/x7BLs2FWzM8= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH v2 05/13] util: add detection of openpty function Date: Thu, 16 Jan 2020 15:24:40 +0000 Message-Id: <20200116152448.592267-6-berrange@redhat.com> In-Reply-To: <20200116152448.592267-1-berrange@redhat.com> References: <20200116152448.592267-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 Cc: Pavel Hrdina 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.12 X-MC-Unique: ZOVKUw29MyiMI6HfeVx1SA-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" All UNIX platforms we care about have openpty() in the libutil library. Use of pty.h must also be made conditional, excluding Win32. Reviewed-by: Pavel Hrdina Signed-off-by: Daniel P. Berrang=C3=A9 --- build-aux/syntax-check.mk | 3 +++ configure.ac | 4 ++++ src/util/Makefile.inc.am | 1 + src/util/virfile.c | 14 +++++++++++++- 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 1fd11093d8..687a4ef368 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -2342,3 +2342,6 @@ exclude_file_name_regexp--sc_prohibit_strcmp =3D \ =20 exclude_file_name_regexp--sc_prohibit_backslash_alignment =3D \ ^build-aux/syntax-check\.mk$$ + +exclude_file_name_regexp--sc_prohibit_always_true_header_tests =3D \ + ^src/util/virfile\.c$$ diff --git a/configure.ac b/configure.ac index 8837928358..b28ed4a6dc 100644 --- a/configure.ac +++ b/configure.ac @@ -383,10 +383,13 @@ dnl Availability of various common headers (non-fatal= if missing). AC_CHECK_HEADERS([\ ifaddrs.h \ libtasn1.h \ + util.h \ + libutil.h \ linux/magic.h \ mntent.h \ net/ethernet.h \ netinet/tcp.h \ + pty.h \ pwd.h \ stdarg.h \ syslog.h \ @@ -430,6 +433,7 @@ dnl header could be found. AM_CONDITIONAL([HAVE_LIBTASN1], [test "x$ac_cv_header_libtasn1_h" =3D "xye= s"]) =20 AC_CHECK_LIB([intl],[gettext],[]) +AC_CHECK_LIB([util],[openpty],[]) =20 =20 dnl diff --git a/src/util/Makefile.inc.am b/src/util/Makefile.inc.am index dfa8347853..23de4a6375 100644 --- a/src/util/Makefile.inc.am +++ b/src/util/Makefile.inc.am @@ -282,6 +282,7 @@ libvirt_util_la_CFLAGS =3D \ $(NULL) libvirt_util_la_LIBADD =3D \ -lm \ + $(OPENPTY_LIBS) \ $(CAPNG_LIBS) \ $(YAJL_LIBS) \ $(LIBNL_LIBS) \ diff --git a/src/util/virfile.c b/src/util/virfile.c index 6eaabf5371..8bd03f8176 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -27,7 +27,19 @@ =20 #include #include -#include +#include +#ifdef HAVE_PTY_H +/* Linux openpty */ +# include +#endif /* !HAVE_PTY_H */ +#ifdef HAVE_UTIL_H +/* macOS openpty */ +# include +#endif /* !HAVE_LIBUTIL_H */ +#ifdef HAVE_LIBUTIL_H +/* FreeBSD openpty */ +# include +#endif /* !HAVE_LIBUTIL_H */ #include #include #include --=20 2.24.1 From nobody Sun May 5 10:18:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1579188531; cv=none; d=zohomail.com; s=zohoarc; b=lWv/Q0XYyYZuTHYRCRcXO30oTLSUpVdbiJG8Z7Eig/A70maR/uQiYpOUKXwRk/o/B7IvVw6RmVEW0BLEA1Ebju/OHnB+VmIzQWUVffJSkOvDWgnkWzFA133kjH5dQSzGBV+cjeA+gHgHUDT9AOWMgiepTA+LxVKPqrgzV6vBa9E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579188531; 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=+UugutgM53u/nTg5S8GGfomJLZZXQ6dIXyYAHe270ls=; b=RsT3EPEobmkJn7raUCfvkXpP4HTt0Mfn09L/NM5WoMBjcuUnkf+8B9TY3N0cEvg2u/t3PmC9iVr4dVGKgoWiBl7U99p6spJRmoFEo8GNaSQgp0e8++YXZhkIAMIng6UmKcE96DXdUZeSGoA8V8pd22nQFLDxdCOdoD35hv78+CY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 157918853163155.25231503276575; Thu, 16 Jan 2020 07:28:51 -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-50-QMywI_3ROM2TvNhfWIfnzw-1; Thu, 16 Jan 2020 10:28:47 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1D5CE18FE873; Thu, 16 Jan 2020 15:28:42 +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 EBC005C299; Thu, 16 Jan 2020 15:28:41 +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 A994418034F0; Thu, 16 Jan 2020 15:28:41 +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 00GFRS9R025976 for ; Thu, 16 Jan 2020 10:27:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2B27A81209; Thu, 16 Jan 2020 15:27:28 +0000 (UTC) Received: from catbus.gsslab.fab.redhat.com (mustard.gsslab.fab.redhat.com [10.33.8.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C72681201; Thu, 16 Jan 2020 15:27:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579188530; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=+UugutgM53u/nTg5S8GGfomJLZZXQ6dIXyYAHe270ls=; b=QMGIQ1DpEH2OiJ5JL/TEljOdFCLpYVAY0WFnn3m3tztTHY4ZFvs9hwowbZj5izuQRB3B9e YN7gDHgi1kVwHDGHUBXin4I9XdRgXf0qPhIeuA9Ui2asp8t6dmRtM1j7c6ZX6uDZNnjG7h +HBZp7TGRNwbdKEZb9fc9MPnt63JEl0= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH v2 06/13] util: introduce compat wrappers for Winsock2 Date: Thu, 16 Jan 2020 15:24:41 +0000 Message-Id: <20200116152448.592267-7-berrange@redhat.com> In-Reply-To: <20200116152448.592267-1-berrange@redhat.com> References: <20200116152448.592267-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 Cc: Pavel Hrdina 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.16 X-MC-Unique: QMywI_3ROM2TvNhfWIfnzw-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" Windows sockets take a SOCKET HANDLE object instead of a file descriptor. Wrap them in the same way that gnulib does so that they use C runtime file descriptors. While we could in theory use GSocket, it is hard to get the exact same semantics libvirt has for its current socket usage. Wrapping the Winsock2 APIs is thus the easiest approach in the short term. Reviewed-by: Pavel Hrdina Signed-off-by: Daniel P. Berrang=C3=A9 --- src/util/Makefile.inc.am | 2 + src/util/virsocket.c | 369 +++++++++++++++++++++++++++++++++++++++ src/util/virsocket.h | 92 ++++++++++ src/util/virutil.c | 29 ++- 4 files changed, 488 insertions(+), 4 deletions(-) create mode 100644 src/util/virsocket.c create mode 100644 src/util/virsocket.h diff --git a/src/util/Makefile.inc.am b/src/util/Makefile.inc.am index 23de4a6375..528c9f6cfe 100644 --- a/src/util/Makefile.inc.am +++ b/src/util/Makefile.inc.am @@ -188,6 +188,8 @@ UTIL_SOURCES =3D \ util/virseclabel.h \ util/virsecret.c \ util/virsecret.h \ + util/virsocket.c \ + util/virsocket.h \ util/virsocketaddr.c \ util/virsocketaddr.h \ util/virstorageencryption.c \ diff --git a/src/util/virsocket.c b/src/util/virsocket.c new file mode 100644 index 0000000000..2d770b931b --- /dev/null +++ b/src/util/virsocket.c @@ -0,0 +1,369 @@ +/* + * Copyright (C) 2020 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include "virsocket.h" + +#ifdef WIN32 + +# include + +# define FD2SK(fd) _get_osfhandle(fd) +# define SK2FD(sk) (_open_osfhandle((intptr_t) (sk), O_RDWR | O_BINARY)) + +# define GET_HANDLE(fd) \ + +# define RETURN_ERROR(call) \ + if ((call) < 0) { \ + set_errno(); \ + return -1; \ + } + +# undef accept +# undef bind +# undef closesocket +# undef connect +# undef dup +# undef dup2 +# undef getpeername +# undef getsockname +# undef getsockopt +# undef ioctlsocket +# undef listen +# undef setsockopt +# undef socket + +static void +set_errno(void) +{ + int err =3D WSAGetLastError(); + + /* Map some WSAE* errors to the runtime library's error codes. */ + switch (err) { + case WSA_INVALID_HANDLE: + errno =3D EBADF; + break; + case WSA_NOT_ENOUGH_MEMORY: + errno =3D ENOMEM; + break; + case WSA_INVALID_PARAMETER: + errno =3D EINVAL; + break; + case WSAENAMETOOLONG: + errno =3D ENAMETOOLONG; + break; + case WSAENOTEMPTY: + errno =3D ENOTEMPTY; + break; + case WSAEWOULDBLOCK: + errno =3D EWOULDBLOCK; + break; + case WSAEINPROGRESS: + errno =3D EINPROGRESS; + break; + case WSAEALREADY: + errno =3D EALREADY; + break; + case WSAENOTSOCK: + errno =3D ENOTSOCK; + break; + case WSAEDESTADDRREQ: + errno =3D EDESTADDRREQ; + break; + case WSAEMSGSIZE: + errno =3D EMSGSIZE; + break; + case WSAEPROTOTYPE: + errno =3D EPROTOTYPE; + break; + case WSAENOPROTOOPT: + errno =3D ENOPROTOOPT; + break; + case WSAEPROTONOSUPPORT: + errno =3D EPROTONOSUPPORT; + break; + case WSAEOPNOTSUPP: + errno =3D EOPNOTSUPP; + break; + case WSAEAFNOSUPPORT: + errno =3D EAFNOSUPPORT; + break; + case WSAEADDRINUSE: + errno =3D EADDRINUSE; + break; + case WSAEADDRNOTAVAIL: + errno =3D EADDRNOTAVAIL; + break; + case WSAENETDOWN: + errno =3D ENETDOWN; + break; + case WSAENETUNREACH: + errno =3D ENETUNREACH; + break; + case WSAENETRESET: + errno =3D ENETRESET; + break; + case WSAECONNABORTED: + errno =3D ECONNABORTED; + break; + case WSAECONNRESET: + errno =3D ECONNRESET; + break; + case WSAENOBUFS: + errno =3D ENOBUFS; + break; + case WSAEISCONN: + errno =3D EISCONN; + break; + case WSAENOTCONN: + errno =3D ENOTCONN; + break; + case WSAETIMEDOUT: + errno =3D ETIMEDOUT; + break; + case WSAECONNREFUSED: + errno =3D ECONNREFUSED; + break; + case WSAELOOP: + errno =3D ELOOP; + break; + case WSAEHOSTUNREACH: + errno =3D EHOSTUNREACH; + break; + default: + errno =3D (err > 10000 && err < 10025) ? err - 10000 : err; + break; + } +} + + +int +vir_accept(int fd, struct sockaddr *addr, socklen_t *addrlen) +{ + SOCKET sk =3D FD2SK(fd); + SOCKET csk; + + if (sk =3D=3D INVALID_SOCKET) { + errno =3D EBADF; + return -1; + } + + csk =3D accept(sk, addr, addrlen); + + if (csk =3D=3D INVALID_SOCKET) { + set_errno(); + return -1; + } + + return SK2FD(csk); +} + + +int +vir_bind(int fd, const struct sockaddr *addr, socklen_t addrlen) +{ + SOCKET sk =3D FD2SK(fd); + + if (sk =3D=3D INVALID_SOCKET) { + errno =3D EBADF; + return -1; + } + + if (bind(sk, addr, addrlen) < 0) { + set_errno(); + return -1; + } + + return 0; +} + + +int +vir_closesocket(int fd) +{ + SOCKET sk =3D FD2SK(fd); + + if (sk =3D=3D INVALID_SOCKET) { + errno =3D EBADF; + return -1; + } + + if (closesocket(sk) < 0) { + set_errno(); + return -1; + } + + return 0; +} + + +int +vir_connect(int fd, const struct sockaddr *addr, socklen_t addrlen) +{ + SOCKET sk =3D FD2SK(fd); + + if (sk =3D=3D INVALID_SOCKET) { + errno =3D EBADF; + return -1; + } + + if (connect(sk, addr, addrlen) < 0) { + set_errno(); + return -1; + } + + return 0; +} + + +int +vir_getpeername(int fd, struct sockaddr *addr, socklen_t *addrlen) +{ + SOCKET sk =3D FD2SK(fd); + + if (sk =3D=3D INVALID_SOCKET) { + errno =3D EBADF; + return -1; + } + + if (getpeername(sk, addr, addrlen) < 0) { + set_errno(); + return -1; + } + + return 0; +} + + +int +vir_getsockname(int fd, struct sockaddr *addr, socklen_t *addrlen) +{ + SOCKET sk =3D FD2SK(fd); + + if (sk =3D=3D INVALID_SOCKET) { + errno =3D EBADF; + return -1; + } + + if (getsockname(sk, addr, addrlen) < 0) { + set_errno(); + return -1; + } + + return 0; +} + + +int +vir_listen(int fd, int backlog) +{ + SOCKET sk =3D FD2SK(fd); + + if (sk =3D=3D INVALID_SOCKET) { + errno =3D EBADF; + return -1; + } + + if (listen(sk, backlog) < 0) { + set_errno(); + return -1; + } + + return 0; +} + + +int +vir_ioctlsocket(int fd, int cmd, void *arg) +{ + SOCKET sk =3D FD2SK(fd); + + if (sk =3D=3D INVALID_SOCKET) { + errno =3D EBADF; + return -1; + } + + if (ioctlsocket(sk, cmd, arg) < 0) { + set_errno(); + return -1; + } + + return 0; +} + + +int +vir_getsockopt(int fd, int level, int optname, + void *optval, socklen_t *optlen) +{ + SOCKET sk =3D FD2SK(fd); + + if (sk =3D=3D INVALID_SOCKET) { + errno =3D EBADF; + return -1; + } + + if (getsockopt(sk, level, optname, optval, optlen) < 0) { + set_errno(); + return -1; + } + + return 0; +} + + +int +vir_setsockopt(int fd, int level, int optname, + const void *optval, socklen_t optlen) +{ + SOCKET sk =3D FD2SK(fd); + + if (sk =3D=3D INVALID_SOCKET) { + errno =3D EBADF; + return -1; + } + + if (setsockopt(sk, level, optname, optval, optlen) < 0) { + set_errno(); + return -1; + } + + return 0; +} + + +int +vir_socket(int domain, int type, int protocol) +{ + SOCKET sk; + + /* We have to use WSASocket() instead of socket(), to create + * non-overlapped IO sockets. Overlapped IO sockets cannot + * be used with read/write. + */ + sk =3D WSASocket(domain, type, protocol, NULL, 0, 0); + if (sk =3D=3D INVALID_SOCKET) { + set_errno(); + return -1; + } + + return SK2FD(sk); +} + +#endif /* WIN32 */ diff --git a/src/util/virsocket.h b/src/util/virsocket.h new file mode 100644 index 0000000000..e9ef5380a3 --- /dev/null +++ b/src/util/virsocket.h @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2020 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#pragma once + +#include "internal.h" + +#ifdef WIN32 + +# define WIN32_LEAN_AND_MEAN +# include +# include +# include +# include + +int vir_accept(int fd, struct sockaddr *addr, socklen_t *addrlen); +int vir_bind(int fd, const struct sockaddr *addr, socklen_t addrlen); +int vir_closesocket(int fd); +int vir_connect(int fd, const struct sockaddr *addr, socklen_t addrlen); +int vir_dup(int oldfd); +int vir_dup2(int oldfd, int newfd); +int vir_getpeername(int fd, struct sockaddr *addr, socklen_t *addrlen); +int vir_getsockname(int fd, struct sockaddr *addr, socklen_t *addrlen); +int vir_listen(int fd, int backlog); +int vir_ioctlsocket(int fd, int cmd, void *arg); +int vir_getsockopt(int fd, int level, int optname, + void *optval, socklen_t *optlen); +int vir_setsockopt(int fd, int level, int optname, + const void *optval, socklen_t optlen); +int vir_socket(int domain, int type, int protocol); + + +/* Get rid of GNULIB's replacements */ +# undef accept +# undef bind +# undef closesocket +# undef connect +# undef dup +# undef dup2 +# undef getpeername +# undef getsockname +# undef getsockopt +# undef ioctlsocket +# undef listen +# undef setsockopt +# undef socket + +/* Provide our own replacements */ +# define accept vir_accept +# define bind vir_bind +# define closesocket vir_closesocket +# define connect vir_connect +# define dup _dup +# define dup2 _dup2 +# define ioctlsocket vir_ioctlsocket +# define getpeername vir_getpeername +# define getsockname vir_getsockname +# define getsockopt vir_getsockopt +# define listen vir_listen +# define setsockopt vir_setsockopt +# define socket vir_socket + +#else + +# include +# include +# include +# include +# include +# include +# include +# include + +# define closesocket close +# define ioctlsocket ioctl + +#endif diff --git a/src/util/virutil.c b/src/util/virutil.c index a0fd7618ee..9ea9e2946d 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -71,10 +71,10 @@ #include "verify.h" #include "virfile.h" #include "vircommand.h" -#include "nonblocking.h" #include "virprocess.h" #include "virstring.h" #include "virutil.h" +#include "virsocket.h" =20 verify(sizeof(gid_t) <=3D sizeof(unsigned int) && sizeof(uid_t) <=3D sizeof(unsigned int)); @@ -99,6 +99,21 @@ int virSetInherit(int fd, bool inherit) return 0; } =20 + +int virSetBlocking(int fd, bool block) +{ + int fflags; + if ((fflags =3D fcntl(fd, F_GETFL)) < 0) + return -1; + if (block) + fflags &=3D ~O_NONBLOCK; + else + fflags |=3D O_NONBLOCK; + if ((fcntl(fd, F_SETFL, fflags)) < 0) + return -1; + return 0; +} + #else /* WIN32 */ =20 int virSetInherit(int fd G_GNUC_UNUSED, bool inherit G_GNUC_UNUSED) @@ -110,13 +125,19 @@ int virSetInherit(int fd G_GNUC_UNUSED, bool inherit = G_GNUC_UNUSED) return 0; } =20 -#endif /* WIN32 */ - int virSetBlocking(int fd, bool blocking) { - return set_nonblocking_flag(fd, !blocking); + unsigned long arg =3D blocking ? 0 : 1; + + if (ioctlsocket(fd, FIONBIO, &arg) < 0) + return -1; + + return 0; } =20 +#endif /* WIN32 */ + + int virSetNonBlock(int fd) { return virSetBlocking(fd, false); --=20 2.24.1 From nobody Sun May 5 10:18:36 2024 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=1579188545; cv=none; d=zohomail.com; s=zohoarc; b=Bvht3b2/8ak9Dpr188OnT3A28hPk8qhDO78DTAduhtH5ehAyS/h43HUuxaeoXQ/kl+lJ7DCdzCaQm3wVeWGMSUSZlyVWZm6GkYn6wIahjuODkDvO0Wfu8ZghCGYg1gDQQYKxSxoNMrXREHN4Kim7B9zEVM5mBrrTOnd+z4YWtL0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579188545; 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=HDaraoy3SfNrj17HwXy78y/K22i+plnV1yVQUyEY4+k=; b=HRxNDfsTbSOsWh/ybC2S119jalawNKfLELepKsksOL19jhGL/sCci+KkK/ACkJkTrmYYpwBS9Tzu/vyc9y8nxKuBHPLdvd570flAlzm698IfFM2du1XmNLNV0VdyeczM5byE2VHBlut1cVGCpOAeny3gpj4YRq+AeX0VfiYR/MU= 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 1579188545389330.8567201322776; Thu, 16 Jan 2020 07:29:05 -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-233-jhmriKIgNCKT5AECQ8flmw-1; Thu, 16 Jan 2020 10:28:59 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D2AEFDBAA; Thu, 16 Jan 2020 15:28:52 +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 9DCA460C85; Thu, 16 Jan 2020 15:28:52 +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 45DC518034F0; Thu, 16 Jan 2020 15:28:52 +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 00GFRTIu025989 for ; Thu, 16 Jan 2020 10:27:29 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2EB7481206; Thu, 16 Jan 2020 15:27:29 +0000 (UTC) Received: from catbus.gsslab.fab.redhat.com (mustard.gsslab.fab.redhat.com [10.33.8.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F99281201; Thu, 16 Jan 2020 15:27:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579188543; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=HDaraoy3SfNrj17HwXy78y/K22i+plnV1yVQUyEY4+k=; b=NY/WdYeqajmzzzNlKuLXL1aosbCrqT1cmCq+IVbSk1/0SjWEn5Shv7Ugz1Qhn/FxmD/gtg q4/p3ce7WLGWmS6C4DC1VvukcxvKr2HCrp3nX9W8vjNKXSndIfOWow0cuHwb9PdiqqECiS m7JkWl5xCAl0dcc9DmsZ94mNoYS4aNU= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH v2 07/13] src: convert code to use new socket portability wrappers Date: Thu, 16 Jan 2020 15:24:42 +0000 Message-Id: <20200116152448.592267-8-berrange@redhat.com> In-Reply-To: <20200116152448.592267-1-berrange@redhat.com> References: <20200116152448.592267-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 Cc: Pavel Hrdina 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.12 X-MC-Unique: jhmriKIgNCKT5AECQ8flmw-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" Convert to use socket wrappers. Aside from the header file include change, this requires changing close -> closesocket since our portability isn't trying to replace the close function. Reviewed-by: Pavel Hrdina Signed-off-by: Daniel P. Berrang=C3=A9 --- src/rpc/virnetsocket.c | 34 +++++++++++++++++++++++----------- src/util/virportallocator.c | 8 +++----- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index 9ad7c2cc28..973827ebde 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -44,6 +44,7 @@ # include #endif =20 +#include "virsocket.h" #include "virnetsocket.h" #include "virutil.h" #include "viralloc.h" @@ -403,7 +404,8 @@ int virNetSocketNewListenTCP(const char *nodename, goto error; } bindErrno =3D errno; - VIR_FORCE_CLOSE(fd); + closesocket(fd); + fd =3D -1; runp =3D runp->ai_next; continue; } @@ -454,7 +456,8 @@ int virNetSocketNewListenTCP(const char *nodename, virObjectUnref(socks[i]); VIR_FREE(socks); freeaddrinfo(ai); - VIR_FORCE_CLOSE(fd); + if (fd !=3D -1) + closesocket(fd); return -1; } =20 @@ -521,7 +524,8 @@ int virNetSocketNewListenUNIX(const char *path, error: if (path[0] !=3D '@') unlink(path); - VIR_FORCE_CLOSE(fd); + if (fd !=3D -1) + closesocket(fd); return -1; } #else @@ -605,7 +609,8 @@ int virNetSocketNewConnectTCP(const char *nodename, break; =20 savedErrno =3D errno; - VIR_FORCE_CLOSE(fd); + closesocket(fd); + fd =3D -1; runp =3D runp->ai_next; } =20 @@ -637,7 +642,8 @@ int virNetSocketNewConnectTCP(const char *nodename, =20 error: freeaddrinfo(ai); - VIR_FORCE_CLOSE(fd); + if (fd !=3D -1) + closesocket(fd); return -1; } =20 @@ -758,8 +764,8 @@ int virNetSocketNewConnectUNIX(const char *path, VIR_FREE(lockpath); VIR_FREE(rundir); =20 - if (ret < 0) - VIR_FORCE_CLOSE(fd); + if (ret < 0 && fd !=3D -1) + closesocket(fd); =20 return ret; } @@ -1370,8 +1376,10 @@ void virNetSocketDispose(void *obj) virObjectUnref(sock->libsshSession); #endif =20 - if (sock->ownsFd) - VIR_FORCE_CLOSE(sock->fd); + if (sock->ownsFd && sock->fd !=3D -1) { + closesocket(sock->fd); + sock->fd =3D -1; + } VIR_FORCE_CLOSE(sock->errfd); =20 virProcessAbort(sock->pid); @@ -2144,7 +2152,8 @@ int virNetSocketAccept(virNetSocketPtr sock, virNetSo= cketPtr *clientsock) ret =3D 0; =20 cleanup: - VIR_FORCE_CLOSE(fd); + if (fd !=3D -1) + closesocket(fd); virObjectUnlock(sock); return ret; } @@ -2264,7 +2273,10 @@ void virNetSocketClose(virNetSocketPtr sock) =20 virObjectLock(sock); =20 - VIR_FORCE_CLOSE(sock->fd); + if (sock->fd !=3D -1) { + closesocket(sock->fd); + sock->fd =3D -1; + } =20 #ifdef HAVE_SYS_UN_H /* If a server socket, then unlink UNIX path */ diff --git a/src/util/virportallocator.c b/src/util/virportallocator.c index 494bf9107a..285b8ddc45 100644 --- a/src/util/virportallocator.c +++ b/src/util/virportallocator.c @@ -21,10 +21,7 @@ =20 #include =20 -#include -#include -#include - +#include "virsocket.h" #include "viralloc.h" #include "virbitmap.h" #include "virportallocator.h" @@ -192,7 +189,8 @@ virPortAllocatorBindToPort(bool *used, =20 ret =3D 0; cleanup: - VIR_FORCE_CLOSE(fd); + if (fd !=3D -1) + closesocket(fd); return ret; } =20 --=20 2.24.1 From nobody Sun May 5 10:18:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1579188607; cv=none; d=zohomail.com; s=zohoarc; b=HKlDK4nyVv6qS6z3DG6OYEDUNwTHezYLqlGSNpTL8nRZYP/ys6gdrswSPa4FYMtCS3e360smJu4E37Jwd09Kp5h00F6mD/W7vdTEfolGMzMYVBA5OkuOi6setB1Hbz6GVgiPa5ZLJucwvTeoZXwyyKsd2hplZs1fqpxq/bKhZSw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579188607; 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=IKrmid2GRPt2I3w1rxDulraqDfDGj3CJdi9TkJ1CDZM=; b=WxBk0H/GNTAN6q+Khj8k3oTwchKwmdzAs4XDHNOZLGDwTk0xlJ+zEGEyS0NIgxwK2Kt+WMGESw7QSWRA9/XsSiQt5Gv1hj4JBMfTPPwZg9ma+4b4EHdrYu+npB/4+WrnT2Ucbbyf+tNiKWnK0yYfTkmbM1cu0HV78GyVjs6xjis= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1579188607417853.9457127702085; Thu, 16 Jan 2020 07:30:07 -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-46-q1DGIf2SNqamOLfN9htkdA-1; Thu, 16 Jan 2020 10:29:03 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B8F7C1005516; Thu, 16 Jan 2020 15:28:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 927FD5DA7D; Thu, 16 Jan 2020 15:28:56 +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 3A9BC845F5; Thu, 16 Jan 2020 15:28:56 +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 00GFRUrY025994 for ; Thu, 16 Jan 2020 10:27:30 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0FB1481206; Thu, 16 Jan 2020 15:27:30 +0000 (UTC) Received: from catbus.gsslab.fab.redhat.com (mustard.gsslab.fab.redhat.com [10.33.8.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7367E81201; Thu, 16 Jan 2020 15:27:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579188606; 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=IKrmid2GRPt2I3w1rxDulraqDfDGj3CJdi9TkJ1CDZM=; b=W+9RTlQc6PmGRQasBvauY9D+3h3nvaio4NnsdpfT9z8kueez+vqmjY6tH4+n+gJQGg+zUY 8DZhzHrgjJuS/9BHMg7SvpbNgUZYy24uFzKtnss5e04hHQGEosdqde9LtpCbeShpk39qBR +qNtV412fTI9NPX8wAY3JjaoHHAdQMY= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH v2 08/13] util: pull gnulib physmem impl into local code Date: Thu, 16 Jan 2020 15:24:43 +0000 Message-Id: <20200116152448.592267-9-berrange@redhat.com> In-Reply-To: <20200116152448.592267-1-berrange@redhat.com> References: <20200116152448.592267-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.14 X-MC-Unique: q1DGIf2SNqamOLfN9htkdA-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" We don't need all the platforms gnulib deals with, so this is a cut down version of GNULIB's physmem.c code. This also allows us to integrate libvirt's error reporting functions closer to the error cause. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Pavel Hrdina --- build-aux/syntax-check.mk | 2 +- src/conf/capabilities.c | 1 - src/util/virhostcpu.c | 1 - src/util/virhostmem.c | 182 +++++++++++++++++++++++++++++++------- 4 files changed, 153 insertions(+), 33 deletions(-) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 687a4ef368..359688ea54 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -2320,7 +2320,7 @@ exclude_file_name_regexp--sc_prohibit_virXXXFree =3D \ ^(docs/|tests/|examples/|tools/|build-aux/syntax-check\.mk|src/test/test= _driver.c|src/libvirt_public.syms|include/libvirt/libvirt-(domain|network|n= odedev|storage|stream|secret|nwfilter|interface|domain-snapshot).h|src/libv= irt-(domain|qemu|network|nodedev|storage|stream|secret|nwfilter|interface|d= omain-snapshot).c$$) =20 exclude_file_name_regexp--sc_prohibit_sysconf_pagesize =3D \ - ^(build-aux/syntax-check\.mk|src/util/virutil\.c)$$ + ^(build-aux/syntax-check\.mk|src/util/vir(hostmem|util)\.c)$$ =20 exclude_file_name_regexp--sc_prohibit_pthread_create =3D \ ^(build-aux/syntax-check\.mk|src/util/virthread\.c|tests/.*)$$ diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 9a39858280..ade04b7cd6 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -26,7 +26,6 @@ #include "capabilities.h" #include "cpu_conf.h" #include "domain_conf.h" -#include "physmem.h" #include "storage_conf.h" #include "viralloc.h" #include "virarch.h" diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c index f3adc1b4ae..a26e339a0a 100644 --- a/src/util/virhostcpu.c +++ b/src/util/virhostcpu.c @@ -41,7 +41,6 @@ #include "viralloc.h" #define LIBVIRT_VIRHOSTCPUPRIV_H_ALLOW #include "virhostcpupriv.h" -#include "physmem.h" #include "virerror.h" #include "virarch.h" #include "virfile.h" diff --git a/src/util/virhostmem.c b/src/util/virhostmem.c index 34e6f7adcf..9c08b9bd78 100644 --- a/src/util/virhostmem.c +++ b/src/util/virhostmem.c @@ -33,9 +33,13 @@ # include #endif =20 +#ifdef WIN32 +# define WIN32_LEAN_AND_MEAN +# include +#endif + #include "viralloc.h" #include "virhostmem.h" -#include "physmem.h" #include "virerror.h" #include "virarch.h" #include "virfile.h" @@ -577,13 +581,151 @@ virHostMemGetParameters(virTypedParameterPtr params = G_GNUC_UNUSED, } =20 =20 +#ifdef WIN32 +/* MEMORYSTATUSEX is missing from older windows headers, so define + a local replacement. */ +typedef struct +{ + DWORD dwLength; + DWORD dwMemoryLoad; + DWORDLONG ullTotalPhys; + DWORDLONG ullAvailPhys; + DWORDLONG ullTotalPageFile; + DWORDLONG ullAvailPageFile; + DWORDLONG ullTotalVirtual; + DWORDLONG ullAvailVirtual; + DWORDLONG ullAvailExtendedVirtual; +} lMEMORYSTATUSEX; +typedef WINBOOL(WINAPI *PFN_MS_EX) (lMEMORYSTATUSEX*); +#endif /* !WIN32 */ + +static unsigned long long +virHostMemGetTotal(void) +{ +#if defined HAVE_SYSCTLBYNAME + /* This works on freebsd & macOS. */ + unsigned long long physmem =3D 0; + size_t len =3D sizeof(physmem); + + if (sysctlbyname("hw.physmem", &physmem, &len, NULL, 0) < 0) { + virReportSystemError(errno, "%s", + _("Unable to query memory total")); + return 0; + } + + return physmem; +#elif defined _SC_PHYS_PAGES && defined _SC_PAGESIZE + /* this works on linux */ + long long pages; + long long pagesize; + if ((pages =3D sysconf(_SC_PHYS_PAGES)) < 0) { + virReportSystemError(errno, "%s", + _("Unable to query memory total")); + return 0; + } + if ((pagesize =3D sysconf(_SC_PAGESIZE)) < 0) { + virReportSystemError(errno, "%s", + _("Unable to query memory page size")); + return 0; + } + return (unsigned long long)pages * (unsigned long long)pagesize; +#elif defined WIN32 + PFN_MS_EX pfnex; + HMODULE h =3D GetModuleHandle("kernel32.dll"); + + if (!h) { + virReportSystemError(errno, "%s", + _("Unable to access kernel32.dll")); + return 0; + } + + /* Use GlobalMemoryStatusEx if available. */ + if ((pfnex =3D (PFN_MS_EX) GetProcAddress(h, "GlobalMemoryStatusEx")))= { + lMEMORYSTATUSEX lms_ex; + lms_ex.dwLength =3D sizeof(lms_ex); + if (!pfnex(&lms_ex)) { + virReportSystemError(EIO, "%s", + _("Unable to query memory total")); + return 0; + } + return lms_ex.ullTotalPhys; + } else { + /* Fall back to GlobalMemoryStatus which is always available. + but returns wrong results for physical memory > 4GB. */ + MEMORYSTATUS ms; + GlobalMemoryStatus(&ms); + return ms.dwTotalPhys; + } +#endif +} + + +static unsigned long long +virHostMemGetAvailable(void) +{ +#if defined HAVE_SYSCTLBYNAME + /* This works on freebsd and macOS */ + unsigned long long usermem =3D 0; + size_t len =3D sizeof(usermem); + + if (sysctlbyname("hw.usermem", &usermem, &len, NULL, 0) < 0) { + virReportSystemError(errno, "%s", + _("Unable to query memory available")); + return 0; + } + + return usermem; +#elif defined _SC_AVPHYS_PAGES && defined _SC_PAGESIZE + /* this works on linux */ + long long pages; + long long pagesize; + if ((pages =3D sysconf(_SC_AVPHYS_PAGES)) < 0) { + virReportSystemError(errno, "%s", + _("Unable to query memory available")); + return 0; + } + if ((pagesize =3D sysconf(_SC_PAGESIZE)) < 0) { + virReportSystemError(errno, "%s", + _("Unable to query memory page size")); + return 0; + } + return (unsigned long long)pages * (unsigned long long)pagesize; +#elif defined WIN32 + PFN_MS_EX pfnex; + HMODULE h =3D GetModuleHandle("kernel32.dll"); + + if (!h) { + virReportSystemError(errno, "%s", + _("Unable to access kernel32.dll")); + return 0; + } + + /* Use GlobalMemoryStatusEx if available. */ + if ((pfnex =3D (PFN_MS_EX) GetProcAddress(h, "GlobalMemoryStatusEx")))= { + lMEMORYSTATUSEX lms_ex; + lms_ex.dwLength =3D sizeof(lms_ex); + if (!pfnex(&lms_ex)) { + virReportSystemError(EIO, "%s", + _("Unable to query memory available")); + return 0; + } + return lms_ex.ullAvailPhys; + } else { + /* Fall back to GlobalMemoryStatus which is always available. + but returns wrong results for physical memory > 4GB */ + MEMORYSTATUS ms; + GlobalMemoryStatus(&ms); + return ms.dwAvailPhys; + } +#endif +} + + static int virHostMemGetCellsFreeFake(unsigned long long *freeMems, int startCell, int maxCells G_GNUC_UNUSED) { - double avail =3D physmem_available(); - if (startCell !=3D 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("start cell %d out of range (0-%d)"), @@ -591,13 +733,8 @@ virHostMemGetCellsFreeFake(unsigned long long *freeMem= s, return -1; } =20 - freeMems[0] =3D (unsigned long long)avail; - - if (!freeMems[0]) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot determine free memory")); + if ((freeMems[0] =3D virHostMemGetAvailable()) =3D=3D 0) return -1; - } =20 return 1; } @@ -606,28 +743,13 @@ static int virHostMemGetInfoFake(unsigned long long *mem, unsigned long long *freeMem) { - if (mem) { - double total =3D physmem_total(); - if (!total) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot determine free memory")); - return -1; - } - - *mem =3D (unsigned long long) total; - } - - if (freeMem) { - double avail =3D physmem_available(); - - if (!avail) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot determine free memory")); - return -1; - } + if (mem && + (*mem =3D virHostMemGetTotal()) =3D=3D 0) + return -1; =20 - *freeMem =3D (unsigned long long) avail; - } + if (freeMem && + (*freeMem =3D virHostMemGetAvailable()) =3D=3D 0) + return -1; =20 return 0; } --=20 2.24.1 From nobody Sun May 5 10:18:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1579188607; cv=none; d=zohomail.com; s=zohoarc; b=FmOcAm5LRMko+4aa7SfeQaTe5o9y5RKoA1fXSjkzA7E1535UBrbMNnZBAEDX/eEot4+EIi2ab2xMiOb/AGHlH7GB8Tx5NaJRcNNF2MA7UBNt5541EgRf+SELUvwMaDUf+25YiYk0O67G7wEAxVy/0hMiofxYkEAvg6CTfwtnP1c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579188607; 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=wFxzl7rdPNOT/D6wSG9An80/JMx78VfX7Guf8RCBQ5Q=; b=Xk0n1CPIFOkiOxbYGQzMdn2gMS1pieBssAZKaj7Q8wbx5L2X+lI30WKZRq+b4mnB4ab2Vhv0Wna4yqeidESt5QqoIuoJp5g21NIW/mHsTOPN4IbSJEsi/bvScjS+2O9S3DW2Pok79Pkz9ir2EpTxl1FHoCWqYxAzRpCfA66OaPA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1579188607286398.69249968167037; Thu, 16 Jan 2020 07:30:07 -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-320-c1_U5Ew2MDSSWa3nDqlENQ-1; Thu, 16 Jan 2020 10:29:06 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E740C801E72; Thu, 16 Jan 2020 15:29:00 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BB37B10016DA; Thu, 16 Jan 2020 15:29:00 +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 64D5F845FA; Thu, 16 Jan 2020 15:29:00 +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 00GFRVve026008 for ; Thu, 16 Jan 2020 10:27:31 -0500 Received: by smtp.corp.redhat.com (Postfix) id 392B381207; Thu, 16 Jan 2020 15:27:31 +0000 (UTC) Received: from catbus.gsslab.fab.redhat.com (mustard.gsslab.fab.redhat.com [10.33.8.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5764981209; Thu, 16 Jan 2020 15:27:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579188606; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=wFxzl7rdPNOT/D6wSG9An80/JMx78VfX7Guf8RCBQ5Q=; b=Sn4HUQ2FA7B5e3wZvGysOY4SDG6tiUSHIiuZTdTcA53GE1S1sY34cJximWn+WSNxOI0SN3 TqzjYbYWtbm/WW4ZIw3wIYliGtXidDmoQHlg6jXErUsdeWG+nYFr1ZBXRcHRc1igdjFbnw SgqArT/7UksUXhv2jVXT3i5NWZIMPv4= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH v2 09/13] util: replace atomic ops impls with g_atomic_int* Date: Thu, 16 Jan 2020 15:24:44 +0000 Message-Id: <20200116152448.592267-10-berrange@redhat.com> In-Reply-To: <20200116152448.592267-1-berrange@redhat.com> References: <20200116152448.592267-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 Cc: Pavel Hrdina 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.84 on 10.5.11.22 X-MC-Unique: c1_U5Ew2MDSSWa3nDqlENQ-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" Libvirt's original atomic ops impls were largely copied from GLib's code at the time. The only API difference was that libvirt's virAtomicIntInc() would return a value, but g_atomic_int_inc was void. We thus use g_atomic_int_add(v, 1) instead, though this means virAtomicIntInc() now returns the original value, instead of the new value. This rewrites libvirt's impl in terms of g_atomic_int* as a short term conversion. The key motivation was to quickly eliminate use of GNULIB's verify_expr() macro which is not a direct match for G_STATIC_ASSERT_EXPR. Long term all the callers should be updated to use g_atomic_int* directly. Reviewed-by: Pavel Hrdina Signed-off-by: Daniel P. Berrang=C3=A9 --- src/libxl/libxl_domain.c | 2 +- src/libxl/libxl_driver.c | 2 +- src/lxc/lxc_process.c | 4 +- src/nwfilter/nwfilter_dhcpsnoop.c | 6 +- src/qemu/qemu_process.c | 4 +- src/util/viratomic.h | 351 ++---------------------------- src/util/virprocess.c | 2 +- tests/viratomictest.c | 2 +- 8 files changed, 26 insertions(+), 347 deletions(-) diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 915aaeb8b0..f9be4ad583 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -1473,7 +1473,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver, if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) goto destroy_dom; =20 - if (virAtomicIntInc(&driver->nactive) =3D=3D 1 && driver->inhibitCallb= ack) + if (virAtomicIntInc(&driver->nactive) =3D=3D 0 && driver->inhibitCallb= ack) driver->inhibitCallback(true, driver->inhibitOpaque); =20 /* finally we can call the 'started' hook script if any */ diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index f021ec9c5d..ef02a066d9 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -446,7 +446,7 @@ libxlReconnectDomain(virDomainObjPtr vm, virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_UNKNOWN); =20 - if (virAtomicIntInc(&driver->nactive) =3D=3D 1 && driver->inhibitCallb= ack) + if (virAtomicIntInc(&driver->nactive) =3D=3D 0 && driver->inhibitCallb= ack) driver->inhibitCallback(true, driver->inhibitOpaque); =20 /* Enable domain death events */ diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 0a9ccdf9ec..af8593d6a5 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -1468,7 +1468,7 @@ int virLXCProcessStart(virConnectPtr conn, if (virCommandHandshakeNotify(cmd) < 0) goto cleanup; =20 - if (virAtomicIntInc(&driver->nactive) =3D=3D 1 && driver->inhibitCallb= ack) + if (virAtomicIntInc(&driver->nactive) =3D=3D 0 && driver->inhibitCallb= ack) driver->inhibitCallback(true, driver->inhibitOpaque); =20 if (lxcContainerWaitForContinue(handshakefds[0]) < 0) { @@ -1670,7 +1670,7 @@ virLXCProcessReconnectDomain(virDomainObjPtr vm, virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_UNKNOWN); =20 - if (virAtomicIntInc(&driver->nactive) =3D=3D 1 && driver->inhibitC= allback) + if (virAtomicIntInc(&driver->nactive) =3D=3D 0 && driver->inhibitC= allback) driver->inhibitCallback(true, driver->inhibitOpaque); =20 if (!(priv->monitor =3D virLXCProcessConnectMonitor(driver, vm))) diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcp= snoop.c index 9a71d13d57..f3acaf00dd 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -888,7 +888,7 @@ virNWFilterSnoopReqLeaseDel(virNWFilterSnoopReqPtr req, skip_instantiate: VIR_FREE(ipl); =20 - virAtomicIntDecAndTest(&virNWFilterSnoopState.nLeases); + ignore_value(virAtomicIntDecAndTest(&virNWFilterSnoopState.nLeases)); =20 lease_not_found: VIR_FREE(ipstr); @@ -1167,7 +1167,7 @@ static void virNWFilterDHCPDecodeWorker(void *jobdata= , void *opaque) _("Instantiation of rules failed on " "interface '%s'"), req->binding->portdevname); } - virAtomicIntDecAndTest(job->qCtr); + ignore_value(virAtomicIntDecAndTest(job->qCtr)); VIR_FREE(job); } =20 @@ -1568,7 +1568,7 @@ virNWFilterDHCPSnoopThread(void *req0) pcap_close(pcapConf[i].handle); } =20 - virAtomicIntDecAndTest(&virNWFilterSnoopState.nThreads); + ignore_value(virAtomicIntDecAndTest(&virNWFilterSnoopState.nThreads)); =20 return; } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index a7bbab9e56..420d1c9c93 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5571,7 +5571,7 @@ qemuProcessInit(virQEMUDriverPtr driver, qemuDomainSetFakeReboot(driver, vm, false); virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, VIR_DOMAIN_PAUSED_STAR= TING_UP); =20 - if (virAtomicIntInc(&driver->nactive) =3D=3D 1 && driver->inhibitC= allback) + if (virAtomicIntInc(&driver->nactive) =3D=3D 0 && driver->inhibitC= allback) driver->inhibitCallback(true, driver->inhibitOpaque); =20 /* Run an early hook to set-up missing devices */ @@ -8139,7 +8139,7 @@ qemuProcessReconnect(void *opaque) goto error; } =20 - if (virAtomicIntInc(&driver->nactive) =3D=3D 1 && driver->inhibitCallb= ack) + if (virAtomicIntInc(&driver->nactive) =3D=3D 0 && driver->inhibitCallb= ack) driver->inhibitCallback(true, driver->inhibitOpaque); =20 cleanup: diff --git a/src/util/viratomic.h b/src/util/viratomic.h index 9dfb77b992..12b116a6cd 100644 --- a/src/util/viratomic.h +++ b/src/util/viratomic.h @@ -1,11 +1,7 @@ /* * viratomic.h: atomic integer operations * - * Copyright (C) 2012 Red Hat, Inc. - * - * Based on code taken from GLib 2.32, under the LGPLv2+ - * - * Copyright (C) 2011 Ryan Lortie + * Copyright (C) 2012-2020 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -21,18 +17,15 @@ * License along with this library. If not, see * . * + * APIs in this header should no longer be used. Direct + * use of the g_atomic APIs is preferred & existing code + * should be converted as needed. */ =20 #pragma once =20 #include "internal.h" =20 -#ifdef VIR_ATOMIC_OPS_GCC -# define VIR_STATIC /* Nothing; we just never define the functions */ -#else -# define VIR_STATIC static -#endif - /** * virAtomicIntGet: * Gets the current value of atomic. @@ -40,8 +33,7 @@ * This call acts as a full compiler and hardware memory barrier * (before the get) */ -VIR_STATIC int virAtomicIntGet(volatile int *atomic) - ATTRIBUTE_NONNULL(1); +#define virAtomicIntGet(v) g_atomic_int_get(v) =20 /** * virAtomicIntSet: @@ -50,21 +42,18 @@ VIR_STATIC int virAtomicIntGet(volatile int *atomic) * This call acts as a full compiler and hardware memory barrier * (after the set) */ -VIR_STATIC void virAtomicIntSet(volatile int *atomic, - int newval) - ATTRIBUTE_NONNULL(1); +#define virAtomicIntSet(i, newv) g_atomic_int_set(i, newv) =20 /** * virAtomicIntInc: * Increments the value of atomic by 1. * * Think of this operation as an atomic version of - * { *atomic +=3D 1; return *atomic; } + * { tmp =3D *atomic; *atomic +=3D 1; return tmp; } * * This call acts as a full compiler and hardware memory barrier. */ -VIR_STATIC int virAtomicIntInc(volatile int *atomic) - ATTRIBUTE_NONNULL(1); +#define virAtomicIntInc(i) g_atomic_int_add(i, 1) =20 /** * virAtomicIntDecAndTest: @@ -75,8 +64,7 @@ VIR_STATIC int virAtomicIntInc(volatile int *atomic) * * This call acts as a full compiler and hardware memory barrier. */ -VIR_STATIC bool virAtomicIntDecAndTest(volatile int *atomic) - ATTRIBUTE_NONNULL(1); +#define virAtomicIntDecAndTest(i) (!!g_atomic_int_dec_and_test(i)) =20 /** * virAtomicIntCompareExchange: @@ -91,10 +79,8 @@ VIR_STATIC bool virAtomicIntDecAndTest(volatile int *ato= mic) * * This call acts as a full compiler and hardware memory barrier. */ -VIR_STATIC bool virAtomicIntCompareExchange(volatile int *atomic, - int oldval, - int newval) - ATTRIBUTE_NONNULL(1); +#define virAtomicIntCompareExchange(i, oldi, newi) \ + (!!g_atomic_int_compare_and_exchange(i, oldi, newi)) =20 /** * virAtomicIntAdd: @@ -105,9 +91,7 @@ VIR_STATIC bool virAtomicIntCompareExchange(volatile int= *atomic, * * This call acts as a full compiler and hardware memory barrier. */ -VIR_STATIC int virAtomicIntAdd(volatile int *atomic, - int val) - ATTRIBUTE_NONNULL(1); +#define virAtomicIntAdd(i, v) g_atomic_int_add(i, v) =20 /** * virAtomicIntAnd: @@ -119,9 +103,7 @@ VIR_STATIC int virAtomicIntAdd(volatile int *atomic, * Think of this operation as an atomic version of * { tmp =3D *atomic; *atomic &=3D val; return tmp; } */ -VIR_STATIC unsigned int virAtomicIntAnd(volatile unsigned int *atomic, - unsigned int val) - ATTRIBUTE_NONNULL(1); +#define virAtomicIntAnd(i, v) g_atomic_int_and(i, v) =20 /** * virAtomicIntOr: @@ -133,9 +115,7 @@ VIR_STATIC unsigned int virAtomicIntAnd(volatile unsign= ed int *atomic, * * This call acts as a full compiler and hardware memory barrier. */ -VIR_STATIC unsigned int virAtomicIntOr(volatile unsigned int *atomic, - unsigned int val) - ATTRIBUTE_NONNULL(1); +#define virAtomicIntOr(i, v) g_atomic_int_or(i, v) =20 /** * virAtomicIntXor: @@ -147,305 +127,4 @@ VIR_STATIC unsigned int virAtomicIntOr(volatile unsig= ned int *atomic, * * This call acts as a full compiler and hardware memory barrier. */ -VIR_STATIC unsigned int virAtomicIntXor(volatile unsigned int *atomic, - unsigned int val) - ATTRIBUTE_NONNULL(1); - -#undef VIR_STATIC - -#ifdef VIR_ATOMIC_OPS_GCC - -# define virAtomicIntGet(atomic) \ - (__extension__ ({ \ - (void)verify_expr(sizeof(*(atomic)) =3D=3D sizeof(int), 0); \ - (void)(0 ? *(atomic) ^ *(atomic) : 0); \ - __sync_synchronize(); \ - (int)*(atomic); \ - })) -# define virAtomicIntSet(atomic, newval) \ - (__extension__ ({ \ - (void)verify_expr(sizeof(*(atomic)) =3D=3D sizeof(int), 0); \ - (void)(0 ? *(atomic) ^ (newval) : 0); \ - *(atomic) =3D (newval); \ - __sync_synchronize(); \ - })) -# define virAtomicIntInc(atomic) \ - (__extension__ ({ \ - (void)verify_expr(sizeof(*(atomic)) =3D=3D sizeof(int), 0); \ - (void)(0 ? *(atomic) ^ *(atomic) : 0); \ - __sync_add_and_fetch((atomic), 1); \ - })) -# define virAtomicIntDecAndTest(atomic) \ - (__extension__ ({ \ - (void)verify_expr(sizeof(*(atomic)) =3D=3D sizeof(int), 0); \ - (void)(0 ? *(atomic) ^ *(atomic) : 0); \ - __sync_fetch_and_sub((atomic), 1) =3D=3D 1; \ - })) -# define virAtomicIntCompareExchange(atomic, oldval, newval) \ - (__extension__ ({ \ - (void)verify_expr(sizeof(*(atomic)) =3D=3D sizeof(int), 0); \ - (void)(0 ? *(atomic) ^ (newval) ^ (oldval) : 0); \ - (bool)__sync_bool_compare_and_swap((atomic), \ - (oldval), (newval)); \ - })) -# define virAtomicIntAdd(atomic, val) \ - (__extension__ ({ \ - (void)verify_expr(sizeof(*(atomic)) =3D=3D sizeof(int), 0); \ - (void)(0 ? *(atomic) ^ (val) : 0); \ - (int) __sync_fetch_and_add((atomic), (val)); \ - })) -# define virAtomicIntAnd(atomic, val) \ - (__extension__ ({ \ - (void)verify_expr(sizeof(*(atomic)) =3D=3D sizeof(int), 0); \ - (void) (0 ? *(atomic) ^ (val) : 0); \ - (unsigned int) __sync_fetch_and_and((atomic), (val)); \ - })) -# define virAtomicIntOr(atomic, val) \ - (__extension__ ({ \ - (void)verify_expr(sizeof(*(atomic)) =3D=3D sizeof(int), 0); \ - (void) (0 ? *(atomic) ^ (val) : 0); \ - (unsigned int) __sync_fetch_and_or((atomic), (val)); \ - })) -# define virAtomicIntXor(atomic, val) \ - (__extension__ ({ \ - (void)verify_expr(sizeof(*(atomic)) =3D=3D sizeof(int), 0); \ - (void) (0 ? *(atomic) ^ (val) : 0); \ - (unsigned int) __sync_fetch_and_xor((atomic), (val)); \ - })) - - -#else - -# ifdef VIR_ATOMIC_OPS_WIN32 - -# include -# include -# include -# if !defined(_M_AMD64) && !defined (_M_IA64) && !defined(_M_X64) -# define InterlockedAnd _InterlockedAnd -# define InterlockedOr _InterlockedOr -# define InterlockedXor _InterlockedXor -# endif - -/* - * http://msdn.microsoft.com/en-us/library/ms684122(v=3Dvs.85).aspx - */ -static inline int -virAtomicIntGet(volatile int *atomic) -{ - MemoryBarrier(); - return *atomic; -} - -static inline void -virAtomicIntSet(volatile int *atomic, - int newval) -{ - *atomic =3D newval; - MemoryBarrier(); -} - -static inline int -virAtomicIntInc(volatile int *atomic) -{ - return InterlockedIncrement((volatile LONG *)atomic); -} - -static inline bool -virAtomicIntDecAndTest(volatile int *atomic) -{ - return InterlockedDecrement((volatile LONG *)atomic) =3D=3D 0; -} - -static inline bool -virAtomicIntCompareExchange(volatile int *atomic, - int oldval, - int newval) -{ - return InterlockedCompareExchange((volatile LONG *)atomic, newval, old= val) =3D=3D oldval; -} - -static inline int -virAtomicIntAdd(volatile int *atomic, - int val) -{ - return InterlockedExchangeAdd((volatile LONG *)atomic, val); -} - -static inline unsigned int -virAtomicIntAnd(volatile unsigned int *atomic, - unsigned int val) -{ - return InterlockedAnd((volatile LONG *)atomic, val); -} - -static inline unsigned int -virAtomicIntOr(volatile unsigned int *atomic, - unsigned int val) -{ - return InterlockedOr((volatile LONG *)atomic, val); -} - -static inline unsigned int -virAtomicIntXor(volatile unsigned int *atomic, - unsigned int val) -{ - return InterlockedXor((volatile LONG *)atomic, val); -} - - -# else -# ifdef VIR_ATOMIC_OPS_PTHREAD -# include - -extern pthread_mutex_t virAtomicLock; - -static inline int -virAtomicIntGet(volatile int *atomic) -{ - int value; - - pthread_mutex_lock(&virAtomicLock); - value =3D *atomic; - pthread_mutex_unlock(&virAtomicLock); - - return value; -} - -static inline void -virAtomicIntSet(volatile int *atomic, - int value) -{ - pthread_mutex_lock(&virAtomicLock); - *atomic =3D value; - pthread_mutex_unlock(&virAtomicLock); -} - -static inline int -virAtomicIntInc(volatile int *atomic) -{ - int value; - - pthread_mutex_lock(&virAtomicLock); - value =3D ++(*atomic); - pthread_mutex_unlock(&virAtomicLock); - - return value; -} - -static inline bool -virAtomicIntDecAndTest(volatile int *atomic) -{ - bool is_zero; - - pthread_mutex_lock(&virAtomicLock); - is_zero =3D --(*atomic) =3D=3D 0; - pthread_mutex_unlock(&virAtomicLock); - - return is_zero; -} - -static inline bool -virAtomicIntCompareExchange(volatile int *atomic, - int oldval, - int newval) -{ - bool success; - - pthread_mutex_lock(&virAtomicLock); - - if ((success =3D (*atomic =3D=3D oldval))) - *atomic =3D newval; - - pthread_mutex_unlock(&virAtomicLock); - - return success; -} - -static inline int -virAtomicIntAdd(volatile int *atomic, - int val) -{ - int oldval; - - pthread_mutex_lock(&virAtomicLock); - oldval =3D *atomic; - *atomic =3D oldval + val; - pthread_mutex_unlock(&virAtomicLock); - - return oldval; -} - -static inline unsigned int -virAtomicIntAnd(volatile unsigned int *atomic, - unsigned int val) -{ - unsigned int oldval; - - pthread_mutex_lock(&virAtomicLock); - oldval =3D *atomic; - *atomic =3D oldval & val; - pthread_mutex_unlock(&virAtomicLock); - - return oldval; -} - -static inline unsigned int -virAtomicIntOr(volatile unsigned int *atomic, - unsigned int val) -{ - unsigned int oldval; - - pthread_mutex_lock(&virAtomicLock); - oldval =3D *atomic; - *atomic =3D oldval | val; - pthread_mutex_unlock(&virAtomicLock); - - return oldval; -} - -static inline unsigned int -virAtomicIntXor(volatile unsigned int *atomic, - unsigned int val) -{ - unsigned int oldval; - - pthread_mutex_lock(&virAtomicLock); - oldval =3D *atomic; - *atomic =3D oldval ^ val; - pthread_mutex_unlock(&virAtomicLock); - - return oldval; -} - - -# else -# error "No atomic integer impl for this platform" -# endif -# endif - -/* The int/unsigned int casts here ensure that you can - * pass either an int or unsigned int to all atomic op - * functions, in the same way that we can with GCC - * atomic op helpers. - */ -# define virAtomicIntGet(atomic) \ - virAtomicIntGet((int *)atomic) -# define virAtomicIntSet(atomic, val) \ - virAtomicIntSet((int *)atomic, val) -# define virAtomicIntInc(atomic) \ - virAtomicIntInc((int *)atomic) -# define virAtomicIntDecAndTest(atomic) \ - virAtomicIntDecAndTest((int *)atomic) -# define virAtomicIntCompareExchange(atomic, oldval, newval) \ - virAtomicIntCompareExchange((int *)atomic, oldval, newval) -# define virAtomicIntAdd(atomic, val) \ - virAtomicIntAdd((int *)atomic, val) -# define virAtomicIntAnd(atomic, val) \ - virAtomicIntAnd((unsigned int *)atomic, val) -# define virAtomicIntOr(atomic, val) \ - virAtomicIntOr((unsigned int *)atomic, val) -# define virAtomicIntXor(atomic, val) \ - virAtomicIntXor((unsigned int *)atomic, val) - -#endif +#define virAtomicIntXor(i, v) g_atomic_int_xor(i, v) diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 32f19e6b63..d5589daf6a 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -1021,7 +1021,7 @@ int virProcessGetStartTime(pid_t pid, unsigned long long *timestamp) { static int warned; - if (virAtomicIntInc(&warned) =3D=3D 1) { + if (virAtomicIntInc(&warned) =3D=3D 0) { VIR_WARN("Process start time of pid %lld not available on this pla= tform", (long long) pid); } diff --git a/tests/viratomictest.c b/tests/viratomictest.c index 8c885a5b96..e30df66cd7 100644 --- a/tests/viratomictest.c +++ b/tests/viratomictest.c @@ -50,7 +50,7 @@ testTypes(const void *data G_GNUC_UNUSED) testAssertEq(virAtomicIntAdd(&u, 1), 5); testAssertEq(u, 6); =20 - testAssertEq(virAtomicIntInc(&u), 7); + testAssertEq(virAtomicIntInc(&u), 6); testAssertEq(u, 7); =20 res =3D virAtomicIntDecAndTest(&u); --=20 2.24.1 From nobody Sun May 5 10:18:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1579188532; cv=none; d=zohomail.com; s=zohoarc; b=IMwQdhJZzNkZpLoJZv9Xfzrgtau95jEoUssGRxiafWN48oV4/4Yu8SFzlHpWvXPOD7KqZ+cashdYqUQ1Ey6RfVFU2+4an4SB3PQkF0wxxFBed+QbQk6mUGZHIXp/Io9e0mQX2s/M8CLfxN5YxHcVFWHwgT3sB5OatyWojW1tGHQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579188532; 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=PV4Y2nYpC77GUAYs01J4XIX+I3sJVtIYJfF1VVFw43o=; b=AxFq7Y1q+82/hOpFIKq8dzDRDZpr1/U95ZJU4Tg2jxMy8XUO3Yw3g5FdMoZozuGZgLS4DC461LrBj9eLhus9ygtgc3t/b/JxgaCqSdwShJkVFWzGIlAXptd2mfeX5TCIEEBGbXksjH6sOl5UapL13Ay6wq+so8cNVRvHh2KAwec= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1579188532700346.0756285295737; Thu, 16 Jan 2020 07:28:52 -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-251-DzwoVjpRPSa0E6TmrcABZw-1; Thu, 16 Jan 2020 10:28:49 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 26D528010DE; Thu, 16 Jan 2020 15:28:43 +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 F0C9460C85; Thu, 16 Jan 2020 15:28:42 +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 A698218034FA; Thu, 16 Jan 2020 15:28:42 +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 00GFRWtW026020 for ; Thu, 16 Jan 2020 10:27:32 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3F22781209; Thu, 16 Jan 2020 15:27:32 +0000 (UTC) Received: from catbus.gsslab.fab.redhat.com (mustard.gsslab.fab.redhat.com [10.33.8.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7EF6A81201; Thu, 16 Jan 2020 15:27:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579188531; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=PV4Y2nYpC77GUAYs01J4XIX+I3sJVtIYJfF1VVFw43o=; b=jJqPVsfttkxzK3F9uIvZY6+8511WE6JJ4odgpk6EakdUbZr+pfmARJcg+krfbUmkz6Poz/ v2x8VpU58vAuRTaDtL4fWjXRPjp1bHeEJn4L8mzpYwX8vPH0HwBz0t5rlHy9Lf+8h3U9jZ BZTglz+/x3UNUzCMarrK75DSAA9phpo= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH v2 10/13] src: replace verify(expr) with G_STATIC_ASSERT(expr) Date: Thu, 16 Jan 2020 15:24:45 +0000 Message-Id: <20200116152448.592267-11-berrange@redhat.com> In-Reply-To: <20200116152448.592267-1-berrange@redhat.com> References: <20200116152448.592267-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 Cc: Pavel Hrdina 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.12 X-MC-Unique: DzwoVjpRPSa0E6TmrcABZw-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" G_STATIC_ASSERT() is a drop-in functional equivalent of the GNULIB verify() macro. Reviewed-by: Pavel Hrdina Signed-off-by: Daniel P. Berrang=C3=A9 --- build-aux/syntax-check.mk | 6 ------ examples/c/misc/event-test.c | 12 ++++++------ src/conf/snapshot_conf.h | 2 +- src/conf/virdomaincheckpointobjlist.c | 8 ++++---- src/esx/esx_network_driver.c | 2 +- src/esx/esx_storage_backend_iscsi.c | 2 +- src/esx/esx_storage_backend_vmfs.c | 2 +- src/internal.h | 1 - src/libxl/xen_xm.c | 3 +-- src/nwfilter/nwfilter_dhcpsnoop.c | 4 ++-- src/qemu/qemu_blockjob.h | 4 ++-- src/qemu/qemu_capabilities.c | 2 +- src/qemu/qemu_driver.c | 2 +- src/qemu/qemu_firmware.h | 2 +- src/qemu/qemu_migration_params.c | 2 +- src/remote/remote_daemon_dispatch.c | 10 +++++----- src/util/virarch.c | 3 +-- src/util/vircgroup.h | 2 +- src/util/vircrypto.c | 2 +- src/util/virenum.h | 8 ++++---- src/util/virinitctl.c | 4 ++-- src/util/virkeycode.c | 22 +++++++++++----------- src/util/virmacaddr.h | 2 +- src/util/virobject.h | 8 ++++---- src/util/virperf.c | 2 +- src/util/virstoragefile.c | 4 ++-- src/util/virtypedparam.h | 2 +- src/util/virutil.c | 3 +-- src/vz/vz_driver.c | 2 +- tests/virstringtest.c | 7 +++---- tools/virsh-domain.c | 2 +- tools/virsh-network.c | 2 +- tools/virsh-nodedev.c | 2 +- tools/virsh-pool.c | 2 +- tools/virsh-secret.c | 2 +- tools/virt-host-validate-common.c | 4 ++-- 36 files changed, 69 insertions(+), 80 deletions(-) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 359688ea54..b0a977201e 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -1621,12 +1621,6 @@ sc_prohibit_dirent_without_use: re=3D'\<($(_dirent_syms_re))\>' \ $(_sc_header_without_use) =20 -# Prohibit the inclusion of verify.h without an actual use. -sc_prohibit_verify_without_use: - @h=3D'verify.h' \ - re=3D'\<(verify(true|expr)?|assume|static_assert) *\(' \ - $(_sc_header_without_use) - # Don't include xfreopen.h unless you use one of its functions. sc_prohibit_xfreopen_without_use: @h=3D'xfreopen.h' re=3D'\base, from, names, diff --git a/src/esx/esx_network_driver.c b/src/esx/esx_network_driver.c index 4f359c61e2..0d52818e18 100644 --- a/src/esx/esx_network_driver.c +++ b/src/esx/esx_network_driver.c @@ -41,7 +41,7 @@ * The UUID of a network is the MD5 sum of its key. Therefore, verify that * UUID and MD5 sum match in size, because we rely on that. */ -verify(VIR_CRYPTO_HASH_SIZE_MD5 =3D=3D VIR_UUID_BUFLEN); +G_STATIC_ASSERT(VIR_CRYPTO_HASH_SIZE_MD5 =3D=3D VIR_UUID_BUFLEN); =20 =20 static int diff --git a/src/esx/esx_storage_backend_iscsi.c b/src/esx/esx_storage_back= end_iscsi.c index 72ab0d3cb0..395a347cf3 100644 --- a/src/esx/esx_storage_backend_iscsi.c +++ b/src/esx/esx_storage_backend_iscsi.c @@ -43,7 +43,7 @@ * The UUID of a storage pool is the MD5 sum of its mount path. Therefore, * verify that UUID and MD5 sum match in size, because we rely on that. */ -verify(VIR_CRYPTO_HASH_SIZE_MD5 =3D=3D VIR_UUID_BUFLEN); +G_STATIC_ASSERT(VIR_CRYPTO_HASH_SIZE_MD5 =3D=3D VIR_UUID_BUFLEN); =20 =20 =20 diff --git a/src/esx/esx_storage_backend_vmfs.c b/src/esx/esx_storage_backe= nd_vmfs.c index 61b30c3c1d..4f613bf93b 100644 --- a/src/esx/esx_storage_backend_vmfs.c +++ b/src/esx/esx_storage_backend_vmfs.c @@ -49,7 +49,7 @@ VIR_LOG_INIT("esx.esx_storage_backend_vmfs"); * The UUID of a storage pool is the MD5 sum of its mount path. Therefore, * verify that UUID and MD5 sum match in size, because we rely on that. */ -verify(VIR_CRYPTO_HASH_SIZE_MD5 =3D=3D VIR_UUID_BUFLEN); +G_STATIC_ASSERT(VIR_CRYPTO_HASH_SIZE_MD5 =3D=3D VIR_UUID_BUFLEN); =20 =20 =20 diff --git a/src/internal.h b/src/internal.h index e356db6c78..4b0286e237 100644 --- a/src/internal.h +++ b/src/internal.h @@ -22,7 +22,6 @@ =20 #include #include -#include #include #include #include diff --git a/src/libxl/xen_xm.c b/src/libxl/xen_xm.c index 5d5d521c18..54eb6fc97d 100644 --- a/src/libxl/xen_xm.c +++ b/src/libxl/xen_xm.c @@ -26,7 +26,6 @@ #include "virerror.h" #include "virconf.h" #include "viralloc.h" -#include "verify.h" #include "xenxs_private.h" #include "xen_xm.h" #include "domain_conf.h" @@ -581,7 +580,7 @@ xenFormatXMInputDevs(virConfPtr conf, virDomainDefPtr d= ef) =20 /* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is either 32, or 64 on a platform where long is big enough. */ -verify(MAX_VIRT_CPUS <=3D sizeof(1UL) * CHAR_BIT); +G_STATIC_ASSERT(MAX_VIRT_CPUS <=3D sizeof(1UL) * CHAR_BIT); =20 /* * Convert a virDomainDef object into an XM config record. diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcp= snoop.c index f3acaf00dd..629f974177 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -186,7 +186,7 @@ struct _virNWFilterSnoopEthHdr { uint16_t eh_type; uint8_t eh_data[]; } ATTRIBUTE_PACKED; -verify(sizeof(struct _virNWFilterSnoopEthHdr) =3D=3D 14); +G_STATIC_ASSERT(sizeof(struct _virNWFilterSnoopEthHdr) =3D=3D 14); =20 typedef struct _virNWFilterSnoopDHCPHdr virNWFilterSnoopDHCPHdr; typedef virNWFilterSnoopDHCPHdr *virNWFilterSnoopDHCPHdrPtr; @@ -208,7 +208,7 @@ struct _virNWFilterSnoopDHCPHdr { char d_file[128]; uint8_t d_opts[]; } ATTRIBUTE_PACKED; -verify(sizeof(struct _virNWFilterSnoopDHCPHdr) =3D=3D 236); +G_STATIC_ASSERT(sizeof(struct _virNWFilterSnoopDHCPHdr) =3D=3D 236); =20 /* DHCP options */ =20 diff --git a/src/qemu/qemu_blockjob.h b/src/qemu/qemu_blockjob.h index 7d584a2980..2f29e8209c 100644 --- a/src/qemu/qemu_blockjob.h +++ b/src/qemu/qemu_blockjob.h @@ -44,7 +44,7 @@ typedef enum { QEMU_BLOCKJOB_STATE_PIVOTING, QEMU_BLOCKJOB_STATE_LAST } qemuBlockjobState; -verify((int)QEMU_BLOCKJOB_STATE_NEW =3D=3D VIR_DOMAIN_BLOCK_JOB_LAST); +G_STATIC_ASSERT((int)QEMU_BLOCKJOB_STATE_NEW =3D=3D VIR_DOMAIN_BLOCK_JOB_L= AST); =20 VIR_ENUM_DECL(qemuBlockjobState); =20 @@ -67,7 +67,7 @@ typedef enum { QEMU_BLOCKJOB_TYPE_BROKEN, QEMU_BLOCKJOB_TYPE_LAST } qemuBlockJobType; -verify((int)QEMU_BLOCKJOB_TYPE_INTERNAL =3D=3D VIR_DOMAIN_BLOCK_JOB_TYPE_L= AST); +G_STATIC_ASSERT((int)QEMU_BLOCKJOB_TYPE_INTERNAL =3D=3D VIR_DOMAIN_BLOCK_J= OB_TYPE_LAST); =20 VIR_ENUM_DECL(qemuBlockjob); =20 diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 84c62a4e28..697f07ece3 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2490,7 +2490,7 @@ static const char *preferredMachines[] =3D "sim", /* VIR_ARCH_XTENSA */ "sim", /* VIR_ARCH_XTENSAEB */ }; -verify(G_N_ELEMENTS(preferredMachines) =3D=3D VIR_ARCH_LAST); +G_STATIC_ASSERT(G_N_ELEMENTS(preferredMachines) =3D=3D VIR_ARCH_LAST); =20 =20 void diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 62d7b581f4..4862d75923 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -2765,7 +2765,7 @@ qemuDomainGetControlInfo(virDomainPtr dom, #define QEMU_SAVE_PARTIAL "LibvirtQemudPart" #define QEMU_SAVE_VERSION 2 =20 -verify(sizeof(QEMU_SAVE_MAGIC) =3D=3D sizeof(QEMU_SAVE_PARTIAL)); +G_STATIC_ASSERT(sizeof(QEMU_SAVE_MAGIC) =3D=3D sizeof(QEMU_SAVE_PARTIAL)); =20 typedef enum { QEMU_SAVE_FORMAT_RAW =3D 0, diff --git a/src/qemu/qemu_firmware.h b/src/qemu/qemu_firmware.h index 37cbfae39d..2fdd71ba52 100644 --- a/src/qemu/qemu_firmware.h +++ b/src/qemu/qemu_firmware.h @@ -57,4 +57,4 @@ qemuFirmwareGetSupported(const char *machine, virFirmwarePtr **fws, size_t *nfws); =20 -verify(VIR_DOMAIN_OS_DEF_FIRMWARE_LAST <=3D 64); +G_STATIC_ASSERT(VIR_DOMAIN_OS_DEF_FIRMWARE_LAST <=3D 64); diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_par= ams.c index 9430ce1d00..1b28e5e031 100644 --- a/src/qemu/qemu_migration_params.c +++ b/src/qemu/qemu_migration_params.c @@ -218,7 +218,7 @@ static const qemuMigrationParamType qemuMigrationParamT= ypes[] =3D { [QEMU_MIGRATION_PARAM_MAX_POSTCOPY_BANDWIDTH] =3D QEMU_MIGRATION_PARAM= _TYPE_ULL, [QEMU_MIGRATION_PARAM_MULTIFD_CHANNELS] =3D QEMU_MIGRATION_PARAM_TYPE_= INT, }; -verify(G_N_ELEMENTS(qemuMigrationParamTypes) =3D=3D QEMU_MIGRATION_PARAM_L= AST); +G_STATIC_ASSERT(G_N_ELEMENTS(qemuMigrationParamTypes) =3D=3D QEMU_MIGRATIO= N_PARAM_LAST); =20 =20 virBitmapPtr diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon= _dispatch.c index 6c00690f68..df4733b3ba 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -1331,7 +1331,7 @@ static virConnectDomainEventGenericCallback domainEve= ntCallbacks[] =3D { VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventBlockThreshold), }; =20 -verify(G_N_ELEMENTS(domainEventCallbacks) =3D=3D VIR_DOMAIN_EVENT_ID_LAST); +G_STATIC_ASSERT(G_N_ELEMENTS(domainEventCallbacks) =3D=3D VIR_DOMAIN_EVENT= _ID_LAST); =20 static int remoteRelayNetworkEventLifecycle(virConnectPtr conn, @@ -1368,7 +1368,7 @@ static virConnectNetworkEventGenericCallback networkE= ventCallbacks[] =3D { VIR_NETWORK_EVENT_CALLBACK(remoteRelayNetworkEventLifecycle), }; =20 -verify(G_N_ELEMENTS(networkEventCallbacks) =3D=3D VIR_NETWORK_EVENT_ID_LAS= T); +G_STATIC_ASSERT(G_N_ELEMENTS(networkEventCallbacks) =3D=3D VIR_NETWORK_EVE= NT_ID_LAST); =20 static int remoteRelayStoragePoolEventLifecycle(virConnectPtr conn, @@ -1435,7 +1435,7 @@ static virConnectStoragePoolEventGenericCallback stor= ageEventCallbacks[] =3D { VIR_STORAGE_POOL_EVENT_CALLBACK(remoteRelayStoragePoolEventRefresh), }; =20 -verify(G_N_ELEMENTS(storageEventCallbacks) =3D=3D VIR_STORAGE_POOL_EVENT_I= D_LAST); +G_STATIC_ASSERT(G_N_ELEMENTS(storageEventCallbacks) =3D=3D VIR_STORAGE_POO= L_EVENT_ID_LAST); =20 static int remoteRelayNodeDeviceEventLifecycle(virConnectPtr conn, @@ -1502,7 +1502,7 @@ static virConnectNodeDeviceEventGenericCallback nodeD= eviceEventCallbacks[] =3D { VIR_NODE_DEVICE_EVENT_CALLBACK(remoteRelayNodeDeviceEventUpdate), }; =20 -verify(G_N_ELEMENTS(nodeDeviceEventCallbacks) =3D=3D VIR_NODE_DEVICE_EVENT= _ID_LAST); +G_STATIC_ASSERT(G_N_ELEMENTS(nodeDeviceEventCallbacks) =3D=3D VIR_NODE_DEV= ICE_EVENT_ID_LAST); =20 static int remoteRelaySecretEventLifecycle(virConnectPtr conn, @@ -1569,7 +1569,7 @@ static virConnectSecretEventGenericCallback secretEve= ntCallbacks[] =3D { VIR_SECRET_EVENT_CALLBACK(remoteRelaySecretEventValueChanged), }; =20 -verify(G_N_ELEMENTS(secretEventCallbacks) =3D=3D VIR_SECRET_EVENT_ID_LAST); +G_STATIC_ASSERT(G_N_ELEMENTS(secretEventCallbacks) =3D=3D VIR_SECRET_EVENT= _ID_LAST); =20 static void remoteRelayDomainQemuMonitorEvent(virConnectPtr conn, diff --git a/src/util/virarch.c b/src/util/virarch.c index f41e3e86bb..b132e178c3 100644 --- a/src/util/virarch.c +++ b/src/util/virarch.c @@ -25,7 +25,6 @@ =20 #include "virlog.h" #include "virarch.h" -#include "verify.h" =20 VIR_LOG_INIT("util.arch"); =20 @@ -81,7 +80,7 @@ static const struct virArchData { { "xtensaeb", 32, VIR_ARCH_BIG_ENDIAN }, }; =20 -verify(G_N_ELEMENTS(virArchData) =3D=3D VIR_ARCH_LAST); +G_STATIC_ASSERT(G_N_ELEMENTS(virArchData) =3D=3D VIR_ARCH_LAST); =20 =20 /** diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 3eefe78787..15263f534a 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -49,7 +49,7 @@ VIR_ENUM_DECL(virCgroupController); * bit array stored in int. Like this: * 1 << VIR_CGROUP_CONTROLLER_CPU * Make sure we will not overflow */ -verify(VIR_CGROUP_CONTROLLER_LAST < 8 * sizeof(int)); +G_STATIC_ASSERT(VIR_CGROUP_CONTROLLER_LAST < 8 * sizeof(int)); =20 typedef enum { VIR_CGROUP_THREAD_VCPU =3D 0, diff --git a/src/util/vircrypto.c b/src/util/vircrypto.c index 87fabfbba1..90aed32c53 100644 --- a/src/util/vircrypto.c +++ b/src/util/vircrypto.c @@ -47,7 +47,7 @@ struct virHashInfo { }; =20 =20 -verify(G_N_ELEMENTS(hashinfo) =3D=3D VIR_CRYPTO_HASH_LAST); +G_STATIC_ASSERT(G_N_ELEMENTS(hashinfo) =3D=3D VIR_CRYPTO_HASH_LAST); =20 ssize_t virCryptoHashBuf(virCryptoHash hash, diff --git a/src/util/virenum.h b/src/util/virenum.h index d68421b203..d74af35530 100644 --- a/src/util/virenum.h +++ b/src/util/virenum.h @@ -42,7 +42,7 @@ virEnumToString(const char * const *types, G_N_ELEMENTS(name ## TypeList), \ type); \ } \ - verify(G_N_ELEMENTS(name ## TypeList) =3D=3D lastVal) + G_STATIC_ASSERT(G_N_ELEMENTS(name ## TypeList) =3D=3D lastVal) =20 #define VIR_ENUM_DECL(name) \ const char *name ## TypeToString(int type); \ @@ -72,6 +72,6 @@ virTristateSwitch virTristateSwitchFromBool(bool val); =20 /* the two enums must be in sync to be able to use helpers interchangeably= in * some special cases */ -verify((int)VIR_TRISTATE_BOOL_YES =3D=3D (int)VIR_TRISTATE_SWITCH_ON); -verify((int)VIR_TRISTATE_BOOL_NO =3D=3D (int)VIR_TRISTATE_SWITCH_OFF); -verify((int)VIR_TRISTATE_BOOL_ABSENT =3D=3D (int)VIR_TRISTATE_SWITCH_ABSEN= T); +G_STATIC_ASSERT((int)VIR_TRISTATE_BOOL_YES =3D=3D (int)VIR_TRISTATE_SWITCH= _ON); +G_STATIC_ASSERT((int)VIR_TRISTATE_BOOL_NO =3D=3D (int)VIR_TRISTATE_SWITCH_= OFF); +G_STATIC_ASSERT((int)VIR_TRISTATE_BOOL_ABSENT =3D=3D (int)VIR_TRISTATE_SWI= TCH_ABSENT); diff --git a/src/util/virinitctl.c b/src/util/virinitctl.c index 955e8f398e..d7e29f24c3 100644 --- a/src/util/virinitctl.c +++ b/src/util/virinitctl.c @@ -96,9 +96,9 @@ struct virInitctlRequest { }; =20 # ifdef MAXHOSTNAMELEN - verify(sizeof(struct virInitctlRequest) =3D=3D 320 + MAXHOSTNAMELEN); + G_STATIC_ASSERT(sizeof(struct virInitctlRequest) =3D=3D 320 + MAXHOSTNAM= ELEN); # else - verify(sizeof(struct virInitctlRequest) =3D=3D 384); + G_STATIC_ASSERT(sizeof(struct virInitctlRequest) =3D=3D 384); # endif =20 =20 diff --git a/src/util/virkeycode.c b/src/util/virkeycode.c index 1a0a94e3ab..1475f69b84 100644 --- a/src/util/virkeycode.c +++ b/src/util/virkeycode.c @@ -56,17 +56,17 @@ static const unsigned short *virKeymapValues[VIR_KEYCOD= E_SET_LAST] =3D { =20 #define VIR_KEYMAP_ENTRY_MAX G_N_ELEMENTS(virKeyCodeTable_linux) =20 -verify(VIR_KEYMAP_ENTRY_MAX =3D=3D G_N_ELEMENTS(virKeyCodeTable_atset1)); -verify(VIR_KEYMAP_ENTRY_MAX =3D=3D G_N_ELEMENTS(virKeyCodeTable_atset2)); -verify(VIR_KEYMAP_ENTRY_MAX =3D=3D G_N_ELEMENTS(virKeyCodeTable_atset3)); -verify(VIR_KEYMAP_ENTRY_MAX =3D=3D G_N_ELEMENTS(virKeyCodeTable_osx)); -verify(VIR_KEYMAP_ENTRY_MAX =3D=3D G_N_ELEMENTS(virKeyCodeTable_xtkbd)); -verify(VIR_KEYMAP_ENTRY_MAX =3D=3D G_N_ELEMENTS(virKeyCodeTable_usb)); -verify(VIR_KEYMAP_ENTRY_MAX =3D=3D G_N_ELEMENTS(virKeyCodeTable_win32)); -verify(VIR_KEYMAP_ENTRY_MAX =3D=3D G_N_ELEMENTS(virKeyCodeTable_qnum)); -verify(VIR_KEYMAP_ENTRY_MAX =3D=3D G_N_ELEMENTS(virKeyNameTable_linux)); -verify(VIR_KEYMAP_ENTRY_MAX =3D=3D G_N_ELEMENTS(virKeyNameTable_osx)); -verify(VIR_KEYMAP_ENTRY_MAX =3D=3D G_N_ELEMENTS(virKeyNameTable_win32)); +G_STATIC_ASSERT(VIR_KEYMAP_ENTRY_MAX =3D=3D G_N_ELEMENTS(virKeyCodeTable_a= tset1)); +G_STATIC_ASSERT(VIR_KEYMAP_ENTRY_MAX =3D=3D G_N_ELEMENTS(virKeyCodeTable_a= tset2)); +G_STATIC_ASSERT(VIR_KEYMAP_ENTRY_MAX =3D=3D G_N_ELEMENTS(virKeyCodeTable_a= tset3)); +G_STATIC_ASSERT(VIR_KEYMAP_ENTRY_MAX =3D=3D G_N_ELEMENTS(virKeyCodeTable_o= sx)); +G_STATIC_ASSERT(VIR_KEYMAP_ENTRY_MAX =3D=3D G_N_ELEMENTS(virKeyCodeTable_x= tkbd)); +G_STATIC_ASSERT(VIR_KEYMAP_ENTRY_MAX =3D=3D G_N_ELEMENTS(virKeyCodeTable_u= sb)); +G_STATIC_ASSERT(VIR_KEYMAP_ENTRY_MAX =3D=3D G_N_ELEMENTS(virKeyCodeTable_w= in32)); +G_STATIC_ASSERT(VIR_KEYMAP_ENTRY_MAX =3D=3D G_N_ELEMENTS(virKeyCodeTable_q= num)); +G_STATIC_ASSERT(VIR_KEYMAP_ENTRY_MAX =3D=3D G_N_ELEMENTS(virKeyNameTable_l= inux)); +G_STATIC_ASSERT(VIR_KEYMAP_ENTRY_MAX =3D=3D G_N_ELEMENTS(virKeyNameTable_o= sx)); +G_STATIC_ASSERT(VIR_KEYMAP_ENTRY_MAX =3D=3D G_N_ELEMENTS(virKeyNameTable_w= in32)); =20 VIR_ENUM_IMPL(virKeycodeSet, VIR_KEYCODE_SET_LAST, diff --git a/src/util/virmacaddr.h b/src/util/virmacaddr.h index 0296cfa965..e43ac3f32a 100644 --- a/src/util/virmacaddr.h +++ b/src/util/virmacaddr.h @@ -38,7 +38,7 @@ struct _virMacAddr { * must not have any extra members added - it must remain exactly * 6 bytes in length. */ -verify(sizeof(struct _virMacAddr) =3D=3D 6); +G_STATIC_ASSERT(sizeof(struct _virMacAddr) =3D=3D 6); =20 =20 int virMacAddrCompare(const char *mac1, const char *mac2); diff --git a/src/util/virobject.h b/src/util/virobject.h index 5c4bcf4dde..62a8a3d132 100644 --- a/src/util/virobject.h +++ b/src/util/virobject.h @@ -80,10 +80,10 @@ virClassPtr virClassForObjectRWLockable(void); * function or as a macro defined to NULL. */ #define VIR_CLASS_NEW(name, prnt) \ - verify_expr(offsetof(name, parent) =3D=3D 0, \ - (name##Class =3D virClassNew(prnt, #name, sizeof(name), \ - sizeof(((name *)NULL)->parent), \ - name##Dispose))) + (G_STATIC_ASSERT_EXPR(offsetof(name, parent) =3D=3D 0), \ + (name##Class =3D virClassNew(prnt, #name, sizeof(name),\ + sizeof(((name *)NULL)->parent), \ + name##Dispose))) =20 virClassPtr virClassNew(virClassPtr parent, diff --git a/src/util/virperf.c b/src/util/virperf.c index fe2c3f8864..29c388a1f2 100644 --- a/src/util/virperf.c +++ b/src/util/virperf.c @@ -168,7 +168,7 @@ static struct virPerfEventAttr attrs[] =3D { .attrConfig =3D PERF_COUNT_SW_EMULATION_FAULTS }, }; -verify(G_N_ELEMENTS(attrs) =3D=3D VIR_PERF_EVENT_LAST); +G_STATIC_ASSERT(G_N_ELEMENTS(attrs) =3D=3D VIR_PERF_EVENT_LAST); typedef struct virPerfEventAttr *virPerfEventAttrPtr; =20 =20 diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 1397f532fd..90e9b6796e 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -386,7 +386,7 @@ static struct FileTypeInfo const fileTypeInfo[] =3D { 4+4+4, 8, 512, NULL, vmdk4GetBackingStore, NULL }, }; -verify(G_N_ELEMENTS(fileTypeInfo) =3D=3D VIR_STORAGE_FILE_LAST); +G_STATIC_ASSERT(G_N_ELEMENTS(fileTypeInfo) =3D=3D VIR_STORAGE_FILE_LAST); =20 =20 /* qcow2 compatible features in the order they appear on-disk */ @@ -400,7 +400,7 @@ enum qcow2CompatibleFeature { static const int qcow2CompatibleFeatureArray[] =3D { VIR_STORAGE_FILE_FEATURE_LAZY_REFCOUNTS, }; -verify(G_N_ELEMENTS(qcow2CompatibleFeatureArray) =3D=3D +G_STATIC_ASSERT(G_N_ELEMENTS(qcow2CompatibleFeatureArray) =3D=3D QCOW2_COMPATIBLE_FEATURE_LAST); =20 static int diff --git a/src/util/virtypedparam.h b/src/util/virtypedparam.h index ea48ee5009..3ac2e68144 100644 --- a/src/util/virtypedparam.h +++ b/src/util/virtypedparam.h @@ -33,7 +33,7 @@ */ #define VIR_TYPED_PARAM_MULTIPLE (1U << 31) =20 -verify(!(VIR_TYPED_PARAM_LAST & VIR_TYPED_PARAM_MULTIPLE)); +G_STATIC_ASSERT(!(VIR_TYPED_PARAM_LAST & VIR_TYPED_PARAM_MULTIPLE)); =20 typedef struct _virTypedParameterRemoteValue virTypedParameterRemoteValue; typedef struct virTypedParameterRemoteValue *virTypedParameterRemoteValueP= tr; diff --git a/src/util/virutil.c b/src/util/virutil.c index 9ea9e2946d..c14c02a8c4 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -68,7 +68,6 @@ #include "virlog.h" #include "virbuffer.h" #include "viralloc.h" -#include "verify.h" #include "virfile.h" #include "vircommand.h" #include "virprocess.h" @@ -76,7 +75,7 @@ #include "virutil.h" #include "virsocket.h" =20 -verify(sizeof(gid_t) <=3D sizeof(unsigned int) && +G_STATIC_ASSERT(sizeof(gid_t) <=3D sizeof(unsigned int) && sizeof(uid_t) <=3D sizeof(unsigned int)); =20 #define VIR_FROM_THIS VIR_FROM_NONE diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index bcdbb50404..bd427fb07e 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -122,7 +122,7 @@ vzBuildCapabilities(void) if (virCapabilitiesInitCaches(caps) < 0) goto error; =20 - verify(G_N_ELEMENTS(archs) =3D=3D G_N_ELEMENTS(emulators)); + G_STATIC_ASSERT(G_N_ELEMENTS(archs) =3D=3D G_N_ELEMENTS(emulators)); =20 for (i =3D 0; i < G_N_ELEMENTS(ostypes); i++) for (j =3D 0; j < G_N_ELEMENTS(archs); j++) diff --git a/tests/virstringtest.c b/tests/virstringtest.c index 1f195ab4b9..88f50185e5 100644 --- a/tests/virstringtest.c +++ b/tests/virstringtest.c @@ -20,7 +20,6 @@ =20 =20 #include "testutils.h" -#include "verify.h" #include "virerror.h" #include "viralloc.h" #include "virfile.h" @@ -420,9 +419,9 @@ struct stringToLongData { * not guaranteed by POSIX. Good luck to you if you are crazy enough * to try and port libvirt to a platform with 16-bit int. Gnulib * already assumes that signed integers are two's complement. */ -verify(sizeof(int) =3D=3D 4); -verify(sizeof(long) =3D=3D sizeof(int) || sizeof(long) =3D=3D sizeof(long = long)); -verify(sizeof(long long) =3D=3D 8); +G_STATIC_ASSERT(sizeof(int) =3D=3D 4); +G_STATIC_ASSERT(sizeof(long) =3D=3D sizeof(int) || sizeof(long) =3D=3D siz= eof(long long)); +G_STATIC_ASSERT(sizeof(long long) =3D=3D 8); =20 static int testStringToLong(const void *opaque) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index ac8ac33582..c48575279c 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -13513,7 +13513,7 @@ virshDomainEventCallback virshDomainEventCallbacks[= ] =3D { { "block-threshold", VIR_DOMAIN_EVENT_CALLBACK(virshEventBlockThresholdPrint), }, }; -verify(VIR_DOMAIN_EVENT_ID_LAST =3D=3D G_N_ELEMENTS(virshDomainEventCallba= cks)); +G_STATIC_ASSERT(VIR_DOMAIN_EVENT_ID_LAST =3D=3D G_N_ELEMENTS(virshDomainEv= entCallbacks)); =20 static const vshCmdInfo info_event[] =3D { {.name =3D "help", diff --git a/tools/virsh-network.c b/tools/virsh-network.c index 700cb0d3e1..a02c85fcb1 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -1242,7 +1242,7 @@ virshNetworkEventCallback virshNetworkEventCallbacks[= ] =3D { { "lifecycle", VIR_NETWORK_EVENT_CALLBACK(vshEventLifecyclePrint), }, }; -verify(VIR_NETWORK_EVENT_ID_LAST =3D=3D G_N_ELEMENTS(virshNetworkEventCall= backs)); +G_STATIC_ASSERT(VIR_NETWORK_EVENT_ID_LAST =3D=3D G_N_ELEMENTS(virshNetwork= EventCallbacks)); =20 static const vshCmdInfo info_network_event[] =3D { {.name =3D "help", diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index cb2fc26d1a..68790ea802 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -845,7 +845,7 @@ virshNodeDeviceEventCallback virshNodeDeviceEventCallba= cks[] =3D { VIR_NODE_DEVICE_EVENT_CALLBACK(vshEventLifecyclePrint), }, { "update", vshEventGenericPrint, } }; -verify(VIR_NODE_DEVICE_EVENT_ID_LAST =3D=3D G_N_ELEMENTS(virshNodeDeviceEv= entCallbacks)); +G_STATIC_ASSERT(VIR_NODE_DEVICE_EVENT_ID_LAST =3D=3D G_N_ELEMENTS(virshNod= eDeviceEventCallbacks)); =20 =20 static const vshCmdInfo info_node_device_event[] =3D { diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index feae0787cb..9c32449fbb 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -1972,7 +1972,7 @@ virshPoolEventCallback virshPoolEventCallbacks[] =3D { VIR_STORAGE_POOL_EVENT_CALLBACK(vshEventLifecyclePrint), }, { "refresh", vshEventGenericPrint, } }; -verify(VIR_STORAGE_POOL_EVENT_ID_LAST =3D=3D G_N_ELEMENTS(virshPoolEventCa= llbacks)); +G_STATIC_ASSERT(VIR_STORAGE_POOL_EVENT_ID_LAST =3D=3D G_N_ELEMENTS(virshPo= olEventCallbacks)); =20 =20 static const vshCmdInfo info_pool_event[] =3D { diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index 66369a25dc..01c62b9ce8 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -649,7 +649,7 @@ virshSecretEventCallback virshSecretEventCallbacks[] = =3D { VIR_SECRET_EVENT_CALLBACK(vshEventLifecyclePrint), }, { "value-changed", vshEventGenericPrint, }, }; -verify(VIR_SECRET_EVENT_ID_LAST =3D=3D G_N_ELEMENTS(virshSecretEventCallba= cks)); +G_STATIC_ASSERT(VIR_SECRET_EVENT_ID_LAST =3D=3D G_N_ELEMENTS(virshSecretEv= entCallbacks)); =20 static const vshCmdInfo info_secret_event[] =3D { {.name =3D "help", diff --git a/tools/virt-host-validate-common.c b/tools/virt-host-validate-c= ommon.c index bce0f14917..6a715ede76 100644 --- a/tools/virt-host-validate-common.c +++ b/tools/virt-host-validate-common.c @@ -96,7 +96,7 @@ static const char * failMessages[] =3D { N_("NOTE"), }; =20 -verify(G_N_ELEMENTS(failMessages) =3D=3D VIR_HOST_VALIDATE_LAST); +G_STATIC_ASSERT(G_N_ELEMENTS(failMessages) =3D=3D VIR_HOST_VALIDATE_LAST); =20 static const char *failEscapeCodes[] =3D { "\033[31m", @@ -104,7 +104,7 @@ static const char *failEscapeCodes[] =3D { "\033[34m", }; =20 -verify(G_N_ELEMENTS(failEscapeCodes) =3D=3D VIR_HOST_VALIDATE_LAST); +G_STATIC_ASSERT(G_N_ELEMENTS(failEscapeCodes) =3D=3D VIR_HOST_VALIDATE_LAS= T); =20 void virHostMsgFail(virHostValidateLevel level, const char *format, --=20 2.24.1 From nobody Sun May 5 10:18:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1579188605; cv=none; d=zohomail.com; s=zohoarc; b=kGFwtaDJfsu0JZ3RDlRtL2vuapafH/bZvvQqgaNJH1jff36HPM3Bog9L5RlQ55DnWIzuYMKS7DBeQbvIuv3biNu7RMyjnTaOAk11PYHdy7fOwEQgc1o0+wrr8aQXpM3g8Z7A+u0JsBneuIj0wvv57KCEkvDsBFlENDQRf5E6tas= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579188605; 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=2u6nVjKYuJBn7bQkiTjBZXxnFatxEvNZ+qtiyBpSZd0=; b=AhRfitv2aHL8x0nhbSX2ndZ/Xvd6qHgC4qm84Hpcre4V5FIuPJHHJlV0FsyWbBlhVw/SqGJZ04m9G0OfPtBrdz1SgoQBsAlZCWzEAsObZmZ6WuTEcFc8Xz98sJssu0zj5qetwhxNtQhzY9WW2qFmB42YXveBTUsHh2SdHaD+EbU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1579188604998911.917707278611; Thu, 16 Jan 2020 07:30:04 -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-72-e5ZeSHt0P0i2uRr5PrYUXQ-1; Thu, 16 Jan 2020 10:28:52 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0AFF98010CC; Thu, 16 Jan 2020 15:28:46 +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 D0C685C28D; Thu, 16 Jan 2020 15:28:45 +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 8362118034FE; Thu, 16 Jan 2020 15:28:45 +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 00GFRXcA026034 for ; Thu, 16 Jan 2020 10:27:33 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1FD6D81206; Thu, 16 Jan 2020 15:27:33 +0000 (UTC) Received: from catbus.gsslab.fab.redhat.com (mustard.gsslab.fab.redhat.com [10.33.8.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 849FE81201; Thu, 16 Jan 2020 15:27:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579188603; 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=2u6nVjKYuJBn7bQkiTjBZXxnFatxEvNZ+qtiyBpSZd0=; b=LIWc8T8eVRVyFqtDnFOun2nNC6WftBZpZD+XFVP3h+fG9s64A4DqEX63zBRNSNberJf9FC 51wWx2w+RhK6jTgGqcGKv4PqWE01M/UjM5WmbLsJgsbQZhGhBitfLp/YtJJP5cOUINmjtf 0jINLfJEh4kQDCksAw+Pvf6Ptxj8gF0= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH v2 11/13] src: conditionally exclude cfmakeraw/termios.h on WIN32 Date: Thu, 16 Jan 2020 15:24:46 +0000 Message-Id: <20200116152448.592267-12-berrange@redhat.com> In-Reply-To: <20200116152448.592267-1-berrange@redhat.com> References: <20200116152448.592267-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.16 X-MC-Unique: e5ZeSHt0P0i2uRr5PrYUXQ-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" The GNULIB termios module ensures termios.h exists (but is none the less empty) when building for Windows. We already exclude usage of the functions that would exist in a real termios.h, so having an empty termios.h is not especially useful. It is simpler to just put all use of termios.h related functions behind a "#ifndef WIN32" conditional. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Pavel Hrdina --- configure.ac | 1 - src/util/virfdstream.c | 10 ++++++---- src/util/virfile.c | 4 +++- src/util/virutil.c | 1 - tools/virsh.h | 1 - tools/vsh.c | 15 --------------- tools/vsh.h | 4 +++- 7 files changed, 12 insertions(+), 24 deletions(-) diff --git a/configure.ac b/configure.ac index b28ed4a6dc..7d69b8bcb4 100644 --- a/configure.ac +++ b/configure.ac @@ -353,7 +353,6 @@ AC_CHECK_SIZEOF([long]) dnl Availability of various common functions (non-fatal if missing), dnl and various less common threadsafe functions AC_CHECK_FUNCS_ONCE([\ - cfmakeraw \ fallocate \ geteuid \ getgid \ diff --git a/src/util/virfdstream.c b/src/util/virfdstream.c index 719185d992..a903107afb 100644 --- a/src/util/virfdstream.c +++ b/src/util/virfdstream.c @@ -31,7 +31,9 @@ # include #endif #include -#include +#ifndef WIN32 +# include +#endif =20 #include "virfdstream.h" #include "virerror.h" @@ -1361,7 +1363,7 @@ int virFDStreamCreateFile(virStreamPtr st, false, false); } =20 -#ifdef HAVE_CFMAKERAW +#ifndef WIN32 int virFDStreamOpenPTY(virStreamPtr st, const char *path, unsigned long long offset, @@ -1401,7 +1403,7 @@ int virFDStreamOpenPTY(virStreamPtr st, virFDStreamClose(st); return -1; } -#else /* !HAVE_CFMAKERAW */ +#else /* WIN32 */ int virFDStreamOpenPTY(virStreamPtr st, const char *path, unsigned long long offset, @@ -1413,7 +1415,7 @@ int virFDStreamOpenPTY(virStreamPtr st, oflags | O_CREAT, 0, false, false); } -#endif /* !HAVE_CFMAKERAW */ +#endif /* WIN32 */ =20 int virFDStreamOpenBlockDevice(virStreamPtr st, const char *path, diff --git a/src/util/virfile.c b/src/util/virfile.c index 8bd03f8176..b3a63fa2ea 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -27,7 +27,9 @@ =20 #include #include -#include +#ifndef WIN32 +# include +#endif /* !WIN32 */ #ifdef HAVE_PTY_H /* Linux openpty */ # include diff --git a/src/util/virutil.c b/src/util/virutil.c index c14c02a8c4..7c2c5a78f6 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -35,7 +35,6 @@ #endif =20 #include -#include =20 #if WITH_DEVMAPPER # include diff --git a/tools/virsh.h b/tools/virsh.h index 903a2e53b6..fa9e54b1d1 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -23,7 +23,6 @@ #include #include #include -#include =20 #include "internal.h" #include "virerror.h" diff --git a/tools/vsh.c b/tools/vsh.c index a36b6bfe23..5c8908f240 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -1928,21 +1928,6 @@ vshTTYRestore(vshControl *ctl G_GNUC_UNUSED) } =20 =20 -#if !defined(WIN32) && !defined(HAVE_CFMAKERAW) -/* provide fallback in case cfmakeraw isn't available */ -static void -cfmakeraw(struct termios *attr) -{ - attr->c_iflag &=3D ~(IGNBRK | BRKINT | PARMRK | ISTRIP - | INLCR | IGNCR | ICRNL | IXON); - attr->c_oflag &=3D ~OPOST; - attr->c_lflag &=3D ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); - attr->c_cflag &=3D ~(CSIZE | PARENB); - attr->c_cflag |=3D CS8; -} -#endif /* !WIN32 && !HAVE_CFMAKERAW */ - - int vshTTYMakeRaw(vshControl *ctl G_GNUC_UNUSED, bool report_errors G_GNUC_UNUSED) diff --git a/tools/vsh.h b/tools/vsh.h index 960cae8df0..174116b369 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -23,7 +23,9 @@ #include #include #include -#include +#ifndef WIN32 +# include +#endif =20 #include "internal.h" #include "virerror.h" --=20 2.24.1 From nobody Sun May 5 10:18:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; 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 205.139.110.61 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=1579188539; cv=none; d=zohomail.com; s=zohoarc; b=kq9tj2N+QD18PEUuE2EuyEQbXbye74Ay8BL8qy+7vhXANkK8lZ2B0Vn3/vdQBFD1IrtGE4MF34B2xZEajwVEe2OikpILSp/taNGPUet94OgxKGS4M6FKUdTEyAcRpMI50cpeF1dPjzqPzkd5xnqIE1hdrMI3udMR0Tc7zq+gwGE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579188539; 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=iDa7nKA6KFgetDiB3ECkKm+QpV7Dybutih2xrxr+1qU=; b=BrYExB4stVHR7WC3DIb/1LOks0c+km8RqKrWN8J26pi3F+V5dXzEyRcwRksIMrCr90sZT/kUWX7gvK7Ln47x5A2TaTZ17fbIzkVF4ti7w4CcyXDqoHkjKZdq3PfZ7UN2nCFC3N+W4nqUZsYqdRKnXl5EoeEBBm0o5+zBtl/xvYs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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 [205.139.110.61]) by mx.zohomail.com with SMTPS id 1579188539028796.9358611763757; Thu, 16 Jan 2020 07:28:59 -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-254-XPH6FH2cMvqgoJEfjqJKAg-1; Thu, 16 Jan 2020 10:28:55 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C80488010C2; Thu, 16 Jan 2020 15:28:49 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 948F380890; Thu, 16 Jan 2020 15:28:49 +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 3E18A845FB; Thu, 16 Jan 2020 15:28:49 +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 00GFRYRW026044 for ; Thu, 16 Jan 2020 10:27:34 -0500 Received: by smtp.corp.redhat.com (Postfix) id 23B0D81207; Thu, 16 Jan 2020 15:27:34 +0000 (UTC) Received: from catbus.gsslab.fab.redhat.com (mustard.gsslab.fab.redhat.com [10.33.8.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6560681201; Thu, 16 Jan 2020 15:27:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579188537; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=iDa7nKA6KFgetDiB3ECkKm+QpV7Dybutih2xrxr+1qU=; b=NOXAG6gaeh9PHGdhNcynCY7Kfw12s9taOTfdSd46I0DhYXK4VIsscjavkULGrnlgdE2h3E lksOpwMH+Yr8pMfp/z4Wd80nR0IOV0MOsda3F+hQB5W2YSTGa6NXJM81/x2v30Gy49yPo3 xaB0UwdhTZaq7xUF/uxsg2HM5IkA6aI= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH v2 12/13] src: replace gmtime_r/localtime_r/strftime with GDateTime Date: Thu, 16 Jan 2020 15:24:47 +0000 Message-Id: <20200116152448.592267-13-berrange@redhat.com> In-Reply-To: <20200116152448.592267-1-berrange@redhat.com> References: <20200116152448.592267-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 Cc: Pavel Hrdina 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.15 X-MC-Unique: XPH6FH2cMvqgoJEfjqJKAg-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" gmtime_r/localtime_r are mostly used in combination with strftime to format timestamps in libvirt. This can all be replaced with GDateTime resulting in simpler code that is also more portable. There is some boundary condition problem in parsing POSIX timezone offsets in GLib which tickles our test suite. The test suite is hacked to avoid the problem. The upsteam GLib bug report is https://gitlab.gnome.org/GNOME/glib/issues/1999 Reviewed-by: Pavel Hrdina Signed-off-by: Daniel P. Berrang=C3=A9 --- src/conf/domain_conf.c | 11 ++++---- src/libxl/libxl_domain.c | 10 +++---- src/qemu/qemu_command.c | 17 ++++------- src/qemu/qemu_driver.c | 10 +++---- src/util/virtime.c | 35 ++++------------------- tests/qemuxml2argvmock.c | 12 ++++---- tests/virtimetest.c | 39 +++++++++++++------------ tools/virsh-checkpoint.c | 20 +++++-------- tools/virsh-domain-monitor.c | 14 ++++----- tools/virsh-domain.c | 13 ++++----- tools/virsh-network.c | 11 ++++---- tools/virsh-snapshot.c | 19 ++++--------- tools/virt-admin.c | 55 ++++++++---------------------------- tools/vsh.c | 16 ++++------- 14 files changed, 96 insertions(+), 186 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 2a8a04cacb..91ddad4d86 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -26789,11 +26789,12 @@ virDomainGraphicsAuthDefFormatAttr(virBufferPtr b= uf, def->passwd); =20 if (def->expires) { - char strbuf[100]; - struct tm tmbuf, *tm; - tm =3D gmtime_r(&def->validTo, &tmbuf); - strftime(strbuf, sizeof(strbuf), "%Y-%m-%dT%H:%M:%S", tm); - virBufferAsprintf(buf, " passwdValidTo=3D'%s'", strbuf); + g_autoptr(GDateTime) then =3D NULL; + g_autofree char *thenstr =3D NULL; + + then =3D g_date_time_new_from_unix_utc(def->validTo); + thenstr =3D g_date_time_format(then, "%Y-%m-%dT%H:%M:%S"); + virBufferAsprintf(buf, " passwdValidTo=3D'%s'", thenstr); } =20 if (def->connected) diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index f9be4ad583..d63eca0bd6 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -943,16 +943,14 @@ libxlDomainAutoCoreDump(libxlDriverPrivatePtr driver, virDomainObjPtr vm) { g_autoptr(libxlDriverConfig) cfg =3D libxlDriverConfigGet(driver); - time_t curtime =3D time(NULL); - char timestr[100]; - struct tm time_info; + g_autoptr(GDateTime) now =3D g_date_time_new_now_local(); + g_autofree char *nowstr =3D NULL; char *dumpfile =3D NULL; =20 - localtime_r(&curtime, &time_info); - strftime(timestr, sizeof(timestr), "%Y-%m-%d-%H:%M:%S", &time_info); + nowstr =3D g_date_time_format(now, "%Y-%m-%d-%H:%M:%S"); =20 dumpfile =3D g_strdup_printf("%s/%s-%s", cfg->autoDumpDir, vm->def->na= me, - timestr); + nowstr); =20 /* Unlock virDomainObj while dumping core */ virObjectUnlock(vm); diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 904d2beab5..62cd3be7c4 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6070,8 +6070,9 @@ qemuBuildClockArgStr(virDomainClockDefPtr def) break; =20 case VIR_DOMAIN_CLOCK_OFFSET_VARIABLE: { - time_t now =3D time(NULL); - struct tm nowbits; + g_autoptr(GDateTime) now =3D g_date_time_new_now_utc(); + g_autoptr(GDateTime) then =3D NULL; + g_autofree char *thenstr =3D NULL; =20 if (def->data.variable.basis =3D=3D VIR_DOMAIN_CLOCK_BASIS_LOCALTI= ME) { long localOffset; @@ -6094,8 +6095,8 @@ qemuBuildClockArgStr(virDomainClockDefPtr def) def->data.variable.basis =3D VIR_DOMAIN_CLOCK_BASIS_UTC; } =20 - now +=3D def->data.variable.adjustment; - gmtime_r(&now, &nowbits); + then =3D g_date_time_add_seconds(now, def->data.variable.adjustmen= t); + thenstr =3D g_date_time_format(then, "%Y-%m-%dT%H:%M:%S"); =20 /* when an RTC_CHANGE event is received from qemu, we need to * have the adjustment used at domain start time available to @@ -6105,13 +6106,7 @@ qemuBuildClockArgStr(virDomainClockDefPtr def) */ def->data.variable.adjustment0 =3D def->data.variable.adjustment; =20 - virBufferAsprintf(&buf, "base=3D%d-%02d-%02dT%02d:%02d:%02d", - nowbits.tm_year + 1900, - nowbits.tm_mon + 1, - nowbits.tm_mday, - nowbits.tm_hour, - nowbits.tm_min, - nowbits.tm_sec); + virBufferAsprintf(&buf, "base=3D%s", thenstr); } break; =20 default: diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 4862d75923..b73079001a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4090,9 +4090,8 @@ getAutoDumpPath(virQEMUDriverPtr driver, virDomainObjPtr vm) { g_autofree char *domname =3D virDomainDefGetShortName(vm->def); - char timestr[100]; - struct tm time_info; - time_t curtime =3D time(NULL); + g_autoptr(GDateTime) now =3D g_date_time_new_now_local(); + g_autofree char *nowstr =3D NULL; g_autoptr(virQEMUDriverConfig) cfg =3D NULL; =20 if (!domname) @@ -4100,10 +4099,9 @@ getAutoDumpPath(virQEMUDriverPtr driver, =20 cfg =3D virQEMUDriverGetConfig(driver); =20 - localtime_r(&curtime, &time_info); - strftime(timestr, sizeof(timestr), "%Y-%m-%d-%H:%M:%S", &time_info); + nowstr =3D g_date_time_format(now, "%Y-%m-%d-%H:%M:%S"); =20 - return g_strdup_printf("%s/%s-%s", cfg->autoDumpPath, domname, timestr= ); + return g_strdup_printf("%s/%s-%s", cfg->autoDumpPath, domname, nowstr); } =20 static void diff --git a/src/util/virtime.c b/src/util/virtime.c index 13f899cb91..bc8f06cd48 100644 --- a/src/util/virtime.c +++ b/src/util/virtime.c @@ -302,8 +302,8 @@ char *virTimeStringThen(unsigned long long when) /** * virTimeLocalOffsetFromUTC: * - * This function is threadsafe, but is *not* async signal safe (due to - * gmtime_r() and mktime()). + * This function is threadsafe, but is *not* async signal safe + * due to use of GLib APIs. * * @offset: pointer to time_t that will be set to the difference * between localtime and UTC in seconds (east of UTC is a @@ -314,34 +314,11 @@ char *virTimeStringThen(unsigned long long when) int virTimeLocalOffsetFromUTC(long *offset) { - struct tm gmtimeinfo; - time_t current, utc; + g_autoptr(GDateTime) now =3D g_date_time_new_now_local(); + GTimeSpan diff =3D g_date_time_get_utc_offset(now); =20 - /* time() gives seconds since Epoch in current timezone */ - if ((current =3D time(NULL)) =3D=3D (time_t)-1) { - virReportSystemError(errno, "%s", - _("failed to get current system time")); - return -1; - } - - /* treat current as if it were in UTC */ - if (!gmtime_r(¤t, &gmtimeinfo)) { - virReportSystemError(errno, "%s", - _("gmtime_r failed")); - return -1; - } - - /* tell mktime to figure out itself whether or not DST is in effect */ - gmtimeinfo.tm_isdst =3D -1; - - /* mktime() also obeys current timezone rules */ - if ((utc =3D mktime(&gmtimeinfo)) =3D=3D (time_t)-1) { - virReportSystemError(errno, "%s", - _("mktime failed")); - return -1; - } - - *offset =3D current - utc; + /* GTimeSpan measures microseconds, we want seconds */ + *offset =3D diff / 1000000; return 0; } =20 diff --git a/tests/qemuxml2argvmock.c b/tests/qemuxml2argvmock.c index 8143de1618..e5841bc8e3 100644 --- a/tests/qemuxml2argvmock.c +++ b/tests/qemuxml2argvmock.c @@ -47,12 +47,14 @@ long virGetSystemPageSize(void) return 4096; } =20 -time_t time(time_t *t) +GDateTime *g_date_time_new_now_utc(void) { - const time_t ret =3D 1234567890; - if (t) - *t =3D ret; - return ret; + return g_date_time_new_from_unix_utc(1234567890); +} + +GDateTime *g_date_time_new_now_local(void) +{ + return g_date_time_new_from_unix_local(1234567890); } =20 bool diff --git a/tests/virtimetest.c b/tests/virtimetest.c index f8a81ff090..f9ac55192d 100644 --- a/tests/virtimetest.c +++ b/tests/virtimetest.c @@ -101,20 +101,12 @@ testTimeLocalOffset(const void *args) static bool isNearYearEnd(void) { - time_t current =3D time(NULL); - struct tm timeinfo; + g_autoptr(GDateTime) now =3D g_date_time_new_now_local(); =20 - if (current =3D=3D (time_t)-1) { - VIR_DEBUG("time() failed"); - return false; - } - if (!localtime_r(¤t, &timeinfo)) { - VIR_DEBUG("localtime_r() failed"); - return false; - } - - return (timeinfo.tm_mon =3D=3D 0 && timeinfo.tm_mday =3D=3D 1) || - (timeinfo.tm_mon =3D=3D 11 && timeinfo.tm_mday =3D=3D 31); + return ((g_date_time_get_month(now) =3D=3D 1 && + g_date_time_get_day_of_month(now) =3D=3D 1) || + (g_date_time_get_month(now) =3D=3D 12 && + g_date_time_get_day_of_month(now) =3D=3D 31)); } =20 =20 @@ -186,14 +178,21 @@ mymain(void) /* test DST processing with timezones that always * have DST in effect; what's more, cover a zone with * with an unusual DST different than a usual one hour + * + * These tests originally used '0' as the first day, + * but changed to '1' due to GLib GTimeZone parsing bug: + * https://gitlab.gnome.org/GNOME/glib/issues/1999 + * + * Once we depend on a new enough GLib, we can put then + * back to 0 again. */ - TEST_LOCALOFFSET("VIR-00:30VID,0/00:00:00,365/23:59:59", + TEST_LOCALOFFSET("VIR-00:30VID,1/00:00:00,364/23:59:59", ((1 * 60) + 30) * 60); - TEST_LOCALOFFSET("VIR-02:30VID,0/00:00:00,365/23:59:59", + TEST_LOCALOFFSET("VIR-02:30VID,1/00:00:00,364/23:59:59", ((3 * 60) + 30) * 60); - TEST_LOCALOFFSET("VIR-02:30VID-04:30,0/00:00:00,365/23:59:59", + TEST_LOCALOFFSET("VIR-02:30VID-04:30,1/00:00:00,364/23:59:59", ((4 * 60) + 30) * 60); - TEST_LOCALOFFSET("VIR-12:00VID-13:00,0/00:00:00,365/23:59:59", + TEST_LOCALOFFSET("VIR-12:00VID-13:00,1/00:00:00,364/23:59:59", ((13 * 60) + 0) * 60); =20 if (!isNearYearEnd()) { @@ -209,11 +208,11 @@ mymain(void) * tests, except on Dec 31 and Jan 1. */ =20 - TEST_LOCALOFFSET("VIR02:45VID00:45,0/00:00:00,365/23:59:59", + TEST_LOCALOFFSET("VIR02:45VID00:45,1/00:00:00,364/23:59:59", -45 * 60); - TEST_LOCALOFFSET("VIR05:00VID04:00,0/00:00:00,365/23:59:59", + TEST_LOCALOFFSET("VIR05:00VID04:00,1/00:00:00,364/23:59:59", ((-4 * 60) + 0) * 60); - TEST_LOCALOFFSET("VIR11:00VID10:00,0/00:00:00,365/23:59:59", + TEST_LOCALOFFSET("VIR11:00VID10:00,1/00:00:00,364/23:59:59", ((-10 * 60) + 0) * 60); } =20 diff --git a/tools/virsh-checkpoint.c b/tools/virsh-checkpoint.c index f9749b5f6d..e82a67f075 100644 --- a/tools/virsh-checkpoint.c +++ b/tools/virsh-checkpoint.c @@ -719,9 +719,8 @@ cmdCheckpointList(vshControl *ctl, char *doc =3D NULL; virDomainCheckpointPtr checkpoint =3D NULL; long long creation_longlong; - time_t creation_time_t; - char timestr[100]; - struct tm time_info; + g_autoptr(GDateTime) then =3D NULL; + g_autofree gchar *thenstr =3D NULL; bool tree =3D vshCommandOptBool(cmd, "tree"); bool name =3D vshCommandOptBool(cmd, "name"); bool from =3D vshCommandOptBool(cmd, "from"); @@ -835,21 +834,16 @@ cmdCheckpointList(vshControl *ctl, if (virXPathLongLong("string(/domaincheckpoint/creationTime)", ctx= t, &creation_longlong) < 0) continue; - creation_time_t =3D creation_longlong; - if (creation_time_t !=3D creation_longlong) { - vshError(ctl, "%s", _("time_t overflow")); - continue; - } - localtime_r(&creation_time_t, &time_info); - strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S %z", - &time_info); + + then =3D g_date_time_new_from_unix_local(creation_longlong); + thenstr =3D g_date_time_format(then, "%Y-%m-%d %H:%M:%S %z"); =20 if (parent) { - if (vshTableRowAppend(table, chk_name, timestr, + if (vshTableRowAppend(table, chk_name, thenstr, NULLSTR_EMPTY(parent_chk), NULL) < 0) goto cleanup; } else { - if (vshTableRowAppend(table, chk_name, timestr, NULL) < 0) + if (vshTableRowAppend(table, chk_name, thenstr, NULL) < 0) goto cleanup; } } diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index efcdc613c6..933e2aa75f 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -1534,17 +1534,13 @@ cmdDomTime(vshControl *ctl, const vshCmd *cmd) goto cleanup; =20 if (pretty) { - char timestr[100]; - time_t cur_time =3D seconds; - struct tm time_info; + g_autoptr(GDateTime) then =3D NULL; + g_autofree char *thenstr =3D NULL; =20 - if (!gmtime_r(&cur_time, &time_info)) { - vshError(ctl, _("Unable to format time")); - goto cleanup; - } - strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S", &time_= info); + then =3D g_date_time_new_from_unix_utc(seconds); + thenstr =3D g_date_time_format(then, "%Y-%m-%d %H:%M:%S"); =20 - vshPrint(ctl, _("Time: %s"), timestr); + vshPrint(ctl, _("Time: %s"), thenstr); } else { vshPrint(ctl, _("Time: %lld"), seconds); } diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index c48575279c..e64e08e5da 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -5492,9 +5492,8 @@ static const vshCmdOptDef opts_screenshot[] =3D { static char * virshGenFileName(vshControl *ctl, virDomainPtr dom, const char *mime) { - char timestr[100]; - time_t cur_time; - struct tm time_info; + g_autoptr(GDateTime) now =3D g_date_time_new_now_local(); + g_autofree char *nowstr =3D NULL; const char *ext =3D NULL; char *ret =3D NULL; =20 @@ -5509,12 +5508,10 @@ virshGenFileName(vshControl *ctl, virDomainPtr dom,= const char *mime) ext =3D ".png"; /* add mime type here */ =20 - time(&cur_time); - localtime_r(&cur_time, &time_info); - strftime(timestr, sizeof(timestr), "%Y-%m-%d-%H:%M:%S", &time_info); + nowstr =3D g_date_time_format(now, "%Y-%m-%d-%H:%M:%S"); =20 - ret =3D g_strdup_printf("%s-%s%s", virDomainGetName(dom), timestr, - NULLSTR_EMPTY(ext)); + ret =3D g_strdup_printf("%s-%s%s", virDomainGetName(dom), + nowstr, NULLSTR_EMPTY(ext)); =20 return ret; } diff --git a/tools/virsh-network.c b/tools/virsh-network.c index a02c85fcb1..ed90736345 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -1433,11 +1433,10 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd = *cmd) const char *typestr =3D NULL; g_autofree char *cidr_format =3D NULL; virNetworkDHCPLeasePtr lease =3D leases[i]; - time_t expirytime_tmp =3D lease->expirytime; - struct tm ts; - char expirytime[32]; - localtime_r(&expirytime_tmp, &ts); - strftime(expirytime, sizeof(expirytime), "%Y-%m-%d %H:%M:%S", &ts); + g_autoptr(GDateTime) then =3D g_date_time_new_from_unix_local(leas= e->expirytime); + g_autofree char *thenstr =3D NULL; + + thenstr =3D g_date_time_format(then, "%Y-%m-%d %H:%M:%S"); =20 if (lease->type =3D=3D VIR_IP_ADDR_TYPE_IPV4) typestr =3D "ipv4"; @@ -1447,7 +1446,7 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd *c= md) cidr_format =3D g_strdup_printf("%s/%d", lease->ipaddr, lease->pre= fix); =20 if (vshTableRowAppend(table, - expirytime, + thenstr, NULLSTR_MINUS(lease->mac), NULLSTR_MINUS(typestr), NULLSTR_MINUS(cidr_format), diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index a42397b42e..d5e68e4b18 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -1492,9 +1492,8 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd) virDomainSnapshotPtr snapshot =3D NULL; char *state =3D NULL; long long creation_longlong; - time_t creation_time_t; - char timestr[100]; - struct tm time_info; + g_autoptr(GDateTime) then =3D NULL; + g_autofree gchar *thenstr =3D NULL; bool tree =3D vshCommandOptBool(cmd, "tree"); bool name =3D vshCommandOptBool(cmd, "name"); bool from =3D vshCommandOptBool(cmd, "from"); @@ -1624,22 +1623,16 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd) if (virXPathLongLong("string(/domainsnapshot/creationTime)", ctxt, &creation_longlong) < 0) continue; - creation_time_t =3D creation_longlong; - if (creation_time_t !=3D creation_longlong) { - vshError(ctl, "%s", _("time_t overflow")); - continue; - } - localtime_r(&creation_time_t, &time_info); - strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S %z", - &time_info); + then =3D g_date_time_new_from_unix_local(creation_longlong); + thenstr =3D g_date_time_format(then, "%Y-%m-%d %H:%M:%S %z"); =20 if (parent) { - if (vshTableRowAppend(table, snap_name, timestr, state, + if (vshTableRowAppend(table, snap_name, thenstr, state, NULLSTR_EMPTY(parent_snap), NULL) < 0) goto cleanup; } else { - if (vshTableRowAppend(table, snap_name, timestr, state, + if (vshTableRowAppend(table, snap_name, thenstr, state, NULL) < 0) goto cleanup; } diff --git a/tools/virt-admin.c b/tools/virt-admin.c index 30106d1971..c71ebb1012 100644 --- a/tools/virt-admin.c +++ b/tools/virt-admin.c @@ -69,40 +69,6 @@ vshAdmClientTransportToString(int transport) return str ? _(str) : _("unknown"); } =20 -/* - * vshAdmGetTimeStr: - * - * Produces string representation (local time) of @then - * (seconds since epoch UTC) using format 'YYYY-MM-DD HH:MM:SS+ZZZZ'. - * - * Returns 0 if conversion finished successfully, -1 in case of an error. - * Caller is responsible for freeing the string returned. - */ -static int -vshAdmGetTimeStr(vshControl *ctl, time_t then, char **result) -{ - char *tmp =3D NULL; - struct tm timeinfo; - - if (!localtime_r(&then, &timeinfo)) - goto error; - - if (VIR_ALLOC_N(tmp, VIRT_ADMIN_TIME_BUFLEN) < 0) - goto error; - - if (strftime(tmp, VIRT_ADMIN_TIME_BUFLEN, "%Y-%m-%d %H:%M:%S%z", - &timeinfo) =3D=3D 0) { - VIR_FREE(tmp); - goto error; - } - - *result =3D tmp; - return 0; - - error: - vshError(ctl, "%s", _("Timestamp string conversion failed")); - return -1; -} =20 /* * vshAdmCatchDisconnect: @@ -646,19 +612,19 @@ cmdSrvClientsList(vshControl *ctl, const vshCmd *cmd) goto cleanup; =20 for (i =3D 0; i < nclts; i++) { - g_autofree char *timestr =3D NULL; + g_autoptr(GDateTime) then =3D NULL; + g_autofree gchar *thenstr =3D NULL; g_autofree char *idStr =3D NULL; virAdmClientPtr client =3D clts[i]; id =3D virAdmClientGetID(client); + then =3D g_date_time_new_from_unix_local(virAdmClientGetTimestamp(= client)); transport =3D virAdmClientGetTransport(client); - if (vshAdmGetTimeStr(ctl, virAdmClientGetTimestamp(client), - ×tr) < 0) - goto cleanup; =20 + thenstr =3D g_date_time_format(then, "%Y-%m-%d %H:%M:%S%z"); idStr =3D g_strdup_printf("%llu", id); if (vshTableRowAppend(table, idStr, vshAdmClientTransportToString(transport), - timestr, NULL) < 0) + thenstr, NULL) < 0) goto cleanup; } =20 @@ -714,7 +680,8 @@ cmdClientInfo(vshControl *ctl, const vshCmd *cmd) size_t i; unsigned long long id; const char *srvname =3D NULL; - char *timestr =3D NULL; + g_autoptr(GDateTime) then =3D NULL; + g_autofree gchar *thenstr =3D NULL; virAdmServerPtr srv =3D NULL; virAdmClientPtr clnt =3D NULL; virTypedParameterPtr params =3D NULL; @@ -739,12 +706,13 @@ cmdClientInfo(vshControl *ctl, const vshCmd *cmd) goto cleanup; } =20 - if (vshAdmGetTimeStr(ctl, virAdmClientGetTimestamp(clnt), ×tr) < = 0) - goto cleanup; + + then =3D g_date_time_new_from_unix_local(virAdmClientGetTimestamp(clnt= )); + thenstr =3D g_date_time_format(then, "%Y-%m-%d %H:%M:%S%z"); =20 /* this info is provided by the client object itself */ vshPrint(ctl, "%-15s: %llu\n", "id", virAdmClientGetID(clnt)); - vshPrint(ctl, "%-15s: %s\n", "connection_time", timestr); + vshPrint(ctl, "%-15s: %s\n", "connection_time", thenstr); vshPrint(ctl, "%-15s: %s\n", "transport", vshAdmClientTransportToString(virAdmClientGetTransport(clnt))= ); =20 @@ -760,7 +728,6 @@ cmdClientInfo(vshControl *ctl, const vshCmd *cmd) virTypedParamsFree(params, nparams); virAdmServerFree(srv); virAdmClientFree(clnt); - VIR_FREE(timestr); return ret; } =20 diff --git a/tools/vsh.c b/tools/vsh.c index 5c8908f240..949c8dad7b 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2182,8 +2182,8 @@ vshOutputLogFile(vshControl *ctl, int log_level, cons= t char *msg_format, char *str =3D NULL; size_t len; const char *lvl =3D ""; - time_t stTime; - struct tm stTm; + g_autoptr(GDateTime) now =3D g_date_time_new_now_local(); + g_autofree gchar *nowstr =3D NULL; =20 if (ctl->log_fd =3D=3D -1) return; @@ -2193,15 +2193,9 @@ vshOutputLogFile(vshControl *ctl, int log_level, con= st char *msg_format, * * [YYYY.MM.DD HH:MM:SS SIGNATURE PID] LOG_LEVEL message */ - time(&stTime); - localtime_r(&stTime, &stTm); - virBufferAsprintf(&buf, "[%d.%02d.%02d %02d:%02d:%02d %s %d] ", - (1900 + stTm.tm_year), - (1 + stTm.tm_mon), - stTm.tm_mday, - stTm.tm_hour, - stTm.tm_min, - stTm.tm_sec, + nowstr =3D g_date_time_format(now, "%Y.%m.%d %H:%M:%S"); + virBufferAsprintf(&buf, "[%s %s %d] ", + nowstr, ctl->progname, (int) getpid()); switch (log_level) { --=20 2.24.1 From nobody Sun May 5 10:18:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; 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 205.139.110.61 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=1579188558; cv=none; d=zohomail.com; s=zohoarc; b=S3vOAL2tgYraY7kJLUe6J7E2/mpO398Ic+UfDaxZjof3nD01n3c/HOHOeHxsjp1zHUWa8VOUUXGO4e2+UMtXVMx1q1lW3wDDLF5m/eOkd57uPXgDSFbfx6fa0Dju41EBU9/wXDMHzM/tZRocb8KsIK066KqkR3zY0+PfgEwysOg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579188558; 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=BY3v87UuvEL+QXDoFOO70mv2qGp/t9b3qzeLh17Urlo=; b=bQLQbO9/fETWJdmwrWhALPA7rRVPLjrd/es6cNg2kyO9nX5dR1svlXDrRMSbqdqzeIYfOlrQDxPKD1BxFH8KMfQUS0jQ2amZC2dbziUJL5F5VgydONLbbgmgCuG84CMhtvyIIl9S1tp0KndwgwMmGTeKRXEjfvEICmvvsaKT2WQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1579188558047468.1576196456907; Thu, 16 Jan 2020 07:29:18 -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-356-tXNx5ktWOsKl5yUCqPCW7w-1; Thu, 16 Jan 2020 10:29:13 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D299A18FE86C; Thu, 16 Jan 2020 15:29:05 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A66DB5D9C9; Thu, 16 Jan 2020 15:29:05 +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 58133845FD; Thu, 16 Jan 2020 15:29:05 +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 00GFRZDn026058 for ; Thu, 16 Jan 2020 10:27:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2851581206; Thu, 16 Jan 2020 15:27:35 +0000 (UTC) Received: from catbus.gsslab.fab.redhat.com (mustard.gsslab.fab.redhat.com [10.33.8.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 68F7C81201; Thu, 16 Jan 2020 15:27:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579188556; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=BY3v87UuvEL+QXDoFOO70mv2qGp/t9b3qzeLh17Urlo=; b=ASTn52w+d/r+VdnVwT9VKs0OIkLc/2zK8weYWORyADNqlH8WKz6Zouv+zf6ZxK50glpM1m +bxSOXxpumfToWCO15ZFYlHxajbDw63Hip4Qy9N201xI0IEyZ+hiEpGvQccpqfl00FNdri C2xU5hcG3+UXmBuPu6+P5z7O+1EB+dQ= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH v2 13/13] bootstrap: remove 25 more gnulib modules Date: Thu, 16 Jan 2020 15:24:48 +0000 Message-Id: <20200116152448.592267-14-berrange@redhat.com> In-Reply-To: <20200116152448.592267-1-berrange@redhat.com> References: <20200116152448.592267-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 Cc: Pavel Hrdina 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.14 X-MC-Unique: tXNx5ktWOsKl5yUCqPCW7w-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" * send, recv: we use write & read for sockets so don't need these portability wrappers * ioctl, fcntl, fcntl-h: any usage of these is conditionally compiled and excludes Windows * ttyname_r: this exists in all supported platforms that we require now * environ: the tests explicitly declare this global variable * intprops: the code has been converted / simplified * openpty: custom checks in configure.ac cope with portability * accept, bind, connect, getpeername, getsockname, listen, setsockopt, socket: code needing Windows portability uses our wrapper functions * close: avoids abort when passed invalid FD on Windows. Our VIR_FORCE_CLOSE wrapper avoids calling close(-1) and it is reasonable to abort in other scenarios in the RPC client * physmem: the gnulib code has been partially imported * warnings, manywarnings: copy the files directly into our local m4 dir * verify: replaced by G_STATIC_ASSERT * pthread_sigmask: none of the fixed portability problems affect libvirt's usage on current supported platforms * termios: the header is now conditionally included only when needed * time_r: replaced with GDateTime APIs Reviewed-by: Pavel Hrdina Signed-off-by: Daniel P. Berrang=C3=A9 --- bootstrap.conf | 50 ------ m4/virt-manywarnings.m4 | 339 ++++++++++++++++++++++++++++++++++++++++ m4/virt-warnings.m4 | 115 ++++++++++++++ 3 files changed, 454 insertions(+), 50 deletions(-) create mode 100644 m4/virt-manywarnings.m4 create mode 100644 m4/virt-warnings.m4 diff --git a/bootstrap.conf b/bootstrap.conf index ae9ecb4039..7e550a379c 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -24,44 +24,18 @@ # turning it into a FD, since closing an FD also closes # the original HANDLE. =20 -# -> GSocket -gnulib_modules=3D"$gnulib_modules accept" -# -> GSocket -gnulib_modules=3D"$gnulib_modules bind" # -> conditional build to avoid Win32 gnulib_modules=3D"$gnulib_modules chown" -# -> GSocket -gnulib_modules=3D"$gnulib_modules close" -# -> GSocket -gnulib_modules=3D"$gnulib_modules connect" # -> Meson gnulib_modules=3D"$gnulib_modules configmake" -# -> eliminate usage in some manner -gnulib_modules=3D"$gnulib_modules environ" -# -> GSocket -gnulib_modules=3D"$gnulib_modules fcntl" -# -> conditional build avoid win32 -gnulib_modules=3D"$gnulib_modules fcntl-h" # -> GSocket gnulib_modules=3D"$gnulib_modules getaddrinfo" # -> copy gnuliub win32 impl gnulib_modules=3D"$gnulib_modules getpass" -# -> GSocket -gnulib_modules=3D"$gnulib_modules getpeername" -# -> GSocket -gnulib_modules=3D"$gnulib_modules getsockname" -# -> copy gnulib STRBUFLEN macro -gnulib_modules=3D"$gnulib_modules intprops" -# -> GSocket -gnulib_modules=3D"$gnulib_modules ioctl" # -> Meson gnulib_modules=3D"$gnulib_modules largefile" -# -> GSocket -gnulib_modules=3D"$gnulib_modules listen" # -> custom configure check gnulib_modules=3D"$gnulib_modules localeconv" -# -> Meson -gnulib_modules=3D"$gnulib_modules manywarnings" # -> painful copy gnulib gnulib_modules=3D"$gnulib_modules mgetgroups" # -> GSocket @@ -70,12 +44,8 @@ gnulib_modules=3D"$gnulib_modules net_if" gnulib_modules=3D"$gnulib_modules netdb" # -> GSocket gnulib_modules=3D"$gnulib_modules nonblocking" -# -> Just add -lutil to cli -gnulib_modules=3D"$gnulib_modules openpty" # -> GSocket gnulib_modules=3D"$gnulib_modules passfd" -# -> open code / copy gnulib code -gnulib_modules=3D"$gnulib_modules physmem" # -> open code / conditional comp gnulib_modules=3D"$gnulib_modules pipe-posix" # -> open code / conditional comp @@ -85,19 +55,9 @@ gnulib_modules=3D"$gnulib_modules poll" # -> Meson gnulib_modules=3D"$gnulib_modules posix-shell" # -> open code conditional logic -gnulib_modules=3D"$gnulib_modules pthread_sigmask" -# -> GSocket -gnulib_modules=3D"$gnulib_modules recv" -# -> GSocket -gnulib_modules=3D"$gnulib_modules send" -# -> GSocket -gnulib_modules=3D"$gnulib_modules setsockopt" -# -> open code conditional logic gnulib_modules=3D"$gnulib_modules sigaction" # -> open code conditional logic gnulib_modules=3D"$gnulib_modules sigpipe" -# -> GSocket -gnulib_modules=3D"$gnulib_modules socket" # -> open code conditional or use GIO GFileInfo gnulib_modules=3D"$gnulib_modules stat-time" # -> remove use or open-code it. possibly add to glib @@ -108,20 +68,10 @@ gnulib_modules=3D"$gnulib_modules strtok_r" gnulib_modules=3D"$gnulib_modules sys_stat" # -> remove sys/wait.h include from any win32 code paths gnulib_modules=3D"$gnulib_modules sys_wait" -# -> remove from any win32 code paths -gnulib_modules=3D"$gnulib_modules termios" -# -> GDateTime ? -gnulib_modules=3D"$gnulib_modules time_r" -# -> obsolete - exists on Linux, MacOS >=3D ?? & FreeBSD >=3D 6 -gnulib_modules=3D"$gnulib_modules ttyname_r" # -> g_get_os_info in GLib 2.64 but can't use that yet gnulib_modules=3D"$gnulib_modules uname" -# -> G_STATIC_ASSERT -gnulib_modules=3D"$gnulib_modules verify" # -> remove from Win32 code paths gnulib_modules=3D"$gnulib_modules waitpid" -# -> Meson -gnulib_modules=3D"$gnulib_modules warnings" # -> open code impl gnulib_modules=3D"$gnulib_modules wcwidth" =20 diff --git a/m4/virt-manywarnings.m4 b/m4/virt-manywarnings.m4 new file mode 100644 index 0000000000..783620da3a --- /dev/null +++ b/m4/virt-manywarnings.m4 @@ -0,0 +1,339 @@ +# manywarnings.m4 serial 18 +dnl Copyright (C) 2008-2020 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Simon Josefsson + +# gl_MANYWARN_COMPLEMENT(OUTVAR, LISTVAR, REMOVEVAR) +# -------------------------------------------------- +# Copy LISTVAR to OUTVAR except for the entries in REMOVEVAR. +# Elements separated by whitespace. In set logic terms, the function +# does OUTVAR =3D LISTVAR \ REMOVEVAR. +AC_DEFUN([gl_MANYWARN_COMPLEMENT], +[ + gl_warn_set=3D + set x $2; shift + for gl_warn_item + do + case " $3 " in + *" $gl_warn_item "*) + ;; + *) + gl_warn_set=3D"$gl_warn_set $gl_warn_item" + ;; + esac + done + $1=3D$gl_warn_set +]) + +# gl_MANYWARN_ALL_GCC(VARIABLE) +# ----------------------------- +# Add all documented GCC warning parameters to variable VARIABLE. +# Note that you need to test them using gl_WARN_ADD if you want to +# make sure your gcc understands it. +# +# The effects of this macro depend on the current language (_AC_LANG). +AC_DEFUN([gl_MANYWARN_ALL_GCC], +[_AC_LANG_DISPATCH([$0], _AC_LANG, $@)]) + +# Specialization for _AC_LANG =3D C. +# Use of m4_defun rather than AC_DEFUN works around a bug in autoconf < 2.= 63b. +m4_defun([gl_MANYWARN_ALL_GCC(C)], +[ + AC_LANG_PUSH([C]) + + dnl First, check for some issues that only occur when combining multiple + dnl gcc warning categories. + AC_REQUIRE([AC_PROG_CC]) + if test -n "$GCC"; then + + dnl Check if -W -Werror -Wno-missing-field-initializers is supported + dnl with the current $CC $CFLAGS $CPPFLAGS. + AC_CACHE_CHECK([whether -Wno-missing-field-initializers is supported], + [gl_cv_cc_nomfi_supported], + [gl_save_CFLAGS=3D"$CFLAGS" + CFLAGS=3D"$CFLAGS -W -Werror -Wno-missing-field-initializers" + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[]], [[]])], + [gl_cv_cc_nomfi_supported=3Dyes], + [gl_cv_cc_nomfi_supported=3Dno]) + CFLAGS=3D"$gl_save_CFLAGS" + ]) + + if test "$gl_cv_cc_nomfi_supported" =3D yes; then + dnl Now check whether -Wno-missing-field-initializers is needed + dnl for the { 0, } construct. + AC_CACHE_CHECK([whether -Wno-missing-field-initializers is needed], + [gl_cv_cc_nomfi_needed], + [gl_save_CFLAGS=3D"$CFLAGS" + CFLAGS=3D"$CFLAGS -W -Werror" + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[int f (void) + { + typedef struct { int a; int b; } s_t; + s_t s1 =3D { 0, }; + return s1.b; + } + ]], + [[]])], + [gl_cv_cc_nomfi_needed=3Dno], + [gl_cv_cc_nomfi_needed=3Dyes]) + CFLAGS=3D"$gl_save_CFLAGS" + ]) + fi + + dnl Next, check if -Werror -Wuninitialized is useful with the + dnl user's choice of $CFLAGS; some versions of gcc warn that it + dnl has no effect if -O is not also used + AC_CACHE_CHECK([whether -Wuninitialized is supported], + [gl_cv_cc_uninitialized_supported], + [gl_save_CFLAGS=3D"$CFLAGS" + CFLAGS=3D"$CFLAGS -Werror -Wuninitialized" + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[]], [[]])], + [gl_cv_cc_uninitialized_supported=3Dyes], + [gl_cv_cc_uninitialized_supported=3Dno]) + CFLAGS=3D"$gl_save_CFLAGS" + ]) + + fi + + # List all gcc warning categories. + # To compare this list to your installed GCC's, run this Bash command: + # + # comm -3 \ + # <((sed -n 's/^ *\(-[^ 0-9][^ ]*\) .*/\1/p' manywarnings.m4; \ + # awk '/^[^#]/ {print $1}' ../build-aux/gcc-warning.spec) | sort) \ + # <(LC_ALL=3DC gcc --help=3Dwarnings | sed -n 's/^ \(-[^ ]*\) .*/\1/p'= | sort) + + gl_manywarn_set=3D + for gl_manywarn_item in -fno-common \ + -W \ + -Wabsolute-value \ + -Waddress \ + -Waddress-of-packed-member \ + -Waggressive-loop-optimizations \ + -Wall \ + -Wattribute-warning \ + -Wattributes \ + -Wbad-function-cast \ + -Wbool-compare \ + -Wbool-operation \ + -Wbuiltin-declaration-mismatch \ + -Wbuiltin-macro-redefined \ + -Wcannot-profile \ + -Wcast-align \ + -Wcast-align=3Dstrict \ + -Wcast-function-type \ + -Wchar-subscripts \ + -Wclobbered \ + -Wcomment \ + -Wcomments \ + -Wcoverage-mismatch \ + -Wcpp \ + -Wdangling-else \ + -Wdate-time \ + -Wdeprecated \ + -Wdeprecated-declarations \ + -Wdesignated-init \ + -Wdisabled-optimization \ + -Wdiscarded-array-qualifiers \ + -Wdiscarded-qualifiers \ + -Wdiv-by-zero \ + -Wdouble-promotion \ + -Wduplicated-branches \ + -Wduplicated-cond \ + -Wduplicate-decl-specifier \ + -Wempty-body \ + -Wendif-labels \ + -Wenum-compare \ + -Wexpansion-to-defined \ + -Wextra \ + -Wformat-contains-nul \ + -Wformat-extra-args \ + -Wformat-nonliteral \ + -Wformat-security \ + -Wformat-signedness \ + -Wformat-y2k \ + -Wformat-zero-length \ + -Wframe-address \ + -Wfree-nonheap-object \ + -Whsa \ + -Wif-not-aligned \ + -Wignored-attributes \ + -Wignored-qualifiers \ + -Wimplicit \ + -Wimplicit-function-declaration \ + -Wimplicit-int \ + -Wincompatible-pointer-types \ + -Winit-self \ + -Winline \ + -Wint-conversion \ + -Wint-in-bool-context \ + -Wint-to-pointer-cast \ + -Winvalid-memory-model \ + -Winvalid-pch \ + -Wlogical-not-parentheses \ + -Wlogical-op \ + -Wmain \ + -Wmaybe-uninitialized \ + -Wmemset-elt-size \ + -Wmemset-transposed-args \ + -Wmisleading-indentation \ + -Wmissing-attributes \ + -Wmissing-braces \ + -Wmissing-declarations \ + -Wmissing-field-initializers \ + -Wmissing-include-dirs \ + -Wmissing-parameter-type \ + -Wmissing-profile \ + -Wmissing-prototypes \ + -Wmultichar \ + -Wmultistatement-macros \ + -Wnarrowing \ + -Wnested-externs \ + -Wnonnull \ + -Wnonnull-compare \ + -Wnull-dereference \ + -Wodr \ + -Wold-style-declaration \ + -Wold-style-definition \ + -Wopenmp-simd \ + -Woverflow \ + -Woverlength-strings \ + -Woverride-init \ + -Wpacked \ + -Wpacked-bitfield-compat \ + -Wpacked-not-aligned \ + -Wparentheses \ + -Wpointer-arith \ + -Wpointer-compare \ + -Wpointer-sign \ + -Wpointer-to-int-cast \ + -Wpragmas \ + -Wpsabi \ + -Wrestrict \ + -Wreturn-local-addr \ + -Wreturn-type \ + -Wscalar-storage-order \ + -Wsequence-point \ + -Wshadow \ + -Wshift-count-negative \ + -Wshift-count-overflow \ + -Wshift-negative-value \ + -Wsizeof-array-argument \ + -Wsizeof-pointer-div \ + -Wsizeof-pointer-memaccess \ + -Wstack-protector \ + -Wstrict-aliasing \ + -Wstrict-overflow \ + -Wstrict-prototypes \ + -Wstringop-truncation \ + -Wsuggest-attribute=3Dcold \ + -Wsuggest-attribute=3Dconst \ + -Wsuggest-attribute=3Dformat \ + -Wsuggest-attribute=3Dmalloc \ + -Wsuggest-attribute=3Dnoreturn \ + -Wsuggest-attribute=3Dpure \ + -Wsuggest-final-methods \ + -Wsuggest-final-types \ + -Wswitch \ + -Wswitch-bool \ + -Wswitch-unreachable \ + -Wsync-nand \ + -Wsystem-headers \ + -Wtautological-compare \ + -Wtrampolines \ + -Wtrigraphs \ + -Wtype-limits \ + -Wuninitialized \ + -Wunknown-pragmas \ + -Wunsafe-loop-optimizations \ + -Wunused \ + -Wunused-but-set-parameter \ + -Wunused-but-set-variable \ + -Wunused-function \ + -Wunused-label \ + -Wunused-local-typedefs \ + -Wunused-macros \ + -Wunused-parameter \ + -Wunused-result \ + -Wunused-value \ + -Wunused-variable \ + -Wvarargs \ + -Wvariadic-macros \ + -Wvector-operation-performance \ + -Wvla \ + -Wvolatile-register-var \ + -Wwrite-strings \ + \ + ; do + gl_manywarn_set=3D"$gl_manywarn_set $gl_manywarn_item" + done + + # gcc --help=3Dwarnings outputs an unusual form for these options; list + # them here so that the above 'comm' command doesn't report a false matc= h. + # Would prefer "min (PTRDIFF_MAX, SIZE_MAX)", but it must be a literal. + # Also, AC_COMPUTE_INT requires it to fit in a long; it is 2**63 on + # the only platforms where it does not fit in a long, so make that + # a special case. + AC_MSG_CHECKING([max safe object size]) + AC_COMPUTE_INT([gl_alloc_max], + [LONG_MAX < (PTRDIFF_MAX < (size_t) -1 ? PTRDIFF_MAX : (size_t) -1) + ? -1 + : PTRDIFF_MAX < (size_t) -1 ? (long) PTRDIFF_MAX : (long) (size_t) -1= ], + [[#include + #include + #include + ]], + [gl_alloc_max=3D2147483647]) + case $gl_alloc_max in + -1) gl_alloc_max=3D9223372036854775807;; + esac + AC_MSG_RESULT([$gl_alloc_max]) + gl_manywarn_set=3D"$gl_manywarn_set -Walloc-size-larger-than=3D$gl_alloc= _max" + gl_manywarn_set=3D"$gl_manywarn_set -Warray-bounds=3D2" + gl_manywarn_set=3D"$gl_manywarn_set -Wattribute-alias=3D2" + gl_manywarn_set=3D"$gl_manywarn_set -Wformat-overflow=3D2" + gl_manywarn_set=3D"$gl_manywarn_set -Wformat-truncation=3D2" + gl_manywarn_set=3D"$gl_manywarn_set -Wimplicit-fallthrough=3D5" + gl_manywarn_set=3D"$gl_manywarn_set -Wnormalized=3Dnfc" + gl_manywarn_set=3D"$gl_manywarn_set -Wshift-overflow=3D2" + gl_manywarn_set=3D"$gl_manywarn_set -Wstringop-overflow=3D2" + gl_manywarn_set=3D"$gl_manywarn_set -Wunused-const-variable=3D2" + gl_manywarn_set=3D"$gl_manywarn_set -Wvla-larger-than=3D4031" + + # These are needed for older GCC versions. + if test -n "$GCC"; then + case `($CC --version) 2>/dev/null` in + 'gcc (GCC) '[[0-3]].* | \ + 'gcc (GCC) '4.[[0-7]].*) + gl_manywarn_set=3D"$gl_manywarn_set -fdiagnostics-show-option" + gl_manywarn_set=3D"$gl_manywarn_set -funit-at-a-time" + ;; + esac + fi + + # Disable specific options as needed. + if test "$gl_cv_cc_nomfi_needed" =3D yes; then + gl_manywarn_set=3D"$gl_manywarn_set -Wno-missing-field-initializers" + fi + + if test "$gl_cv_cc_uninitialized_supported" =3D no; then + gl_manywarn_set=3D"$gl_manywarn_set -Wno-uninitialized" + fi + + $1=3D$gl_manywarn_set + + AC_LANG_POP([C]) +]) + +# Specialization for _AC_LANG =3D C++. +# Use of m4_defun rather than AC_DEFUN works around a bug in autoconf < 2.= 63b. +m4_defun([gl_MANYWARN_ALL_GCC(C++)], +[ + gl_MANYWARN_ALL_GCC_CXX_IMPL([$1]) +]) diff --git a/m4/virt-warnings.m4 b/m4/virt-warnings.m4 new file mode 100644 index 0000000000..d272365f0a --- /dev/null +++ b/m4/virt-warnings.m4 @@ -0,0 +1,115 @@ +# warnings.m4 serial 14 +dnl Copyright (C) 2008-2020 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Simon Josefsson + +# gl_AS_VAR_APPEND(VAR, VALUE) +# ---------------------------- +# Provide the functionality of AS_VAR_APPEND if Autoconf does not have it. +m4_ifdef([AS_VAR_APPEND], +[m4_copy([AS_VAR_APPEND], [gl_AS_VAR_APPEND])], +[m4_define([gl_AS_VAR_APPEND], +[AS_VAR_SET([$1], [AS_VAR_GET([$1])$2])])]) + + +# gl_COMPILER_OPTION_IF(OPTION, [IF-SUPPORTED], [IF-NOT-SUPPORTED], +# [PROGRAM =3D AC_LANG_PROGRAM()]) +# ----------------------------------------------------------------- +# Check if the compiler supports OPTION when compiling PROGRAM. +# +# The effects of this macro depend on the current language (_AC_LANG). +AC_DEFUN([gl_COMPILER_OPTION_IF], +[ +dnl FIXME: gl_Warn must be used unquoted until we can assume Autoconf +dnl 2.64 or newer. +AS_VAR_PUSHDEF([gl_Warn], [gl_cv_warn_[]_AC_LANG_ABBREV[]_$1])dnl +AS_VAR_PUSHDEF([gl_Flags], [_AC_LANG_PREFIX[]FLAGS])dnl +AS_LITERAL_IF([$1], + [m4_pushdef([gl_Positive], m4_bpatsubst([$1], [^-Wno-], [-W]))], + [gl_positive=3D"$1" +case $gl_positive in + -Wno-*) gl_positive=3D-W`expr "X$gl_positive" : 'X-Wno-\(.*\)'` ;; +esac +m4_pushdef([gl_Positive], [$gl_positive])])dnl +AC_CACHE_CHECK([whether _AC_LANG compiler handles $1], m4_defn([gl_Warn]),= [ + gl_save_compiler_FLAGS=3D"$gl_Flags" + gl_AS_VAR_APPEND(m4_defn([gl_Flags]), + [" $gl_unknown_warnings_are_errors ]m4_defn([gl_Positive])["]) + AC_LINK_IFELSE([m4_default([$4], [AC_LANG_PROGRAM([])])], + [AS_VAR_SET(gl_Warn, [yes])], + [AS_VAR_SET(gl_Warn, [no])]) + gl_Flags=3D"$gl_save_compiler_FLAGS" +]) +AS_VAR_IF(gl_Warn, [yes], [$2], [$3]) +m4_popdef([gl_Positive])dnl +AS_VAR_POPDEF([gl_Flags])dnl +AS_VAR_POPDEF([gl_Warn])dnl +]) + +# gl_UNKNOWN_WARNINGS_ARE_ERRORS +# ------------------------------ +# Clang doesn't complain about unknown warning options unless one also +# specifies -Wunknown-warning-option -Werror. Detect this. +# +# The effects of this macro depend on the current language (_AC_LANG). +AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS], +[_AC_LANG_DISPATCH([$0], _AC_LANG, $@)]) + +# Specialization for _AC_LANG =3D C. This macro can be AC_REQUIREd. +# Use of m4_defun rather than AC_DEFUN works around a bug in autoconf < 2.= 63b. +m4_defun([gl_UNKNOWN_WARNINGS_ARE_ERRORS(C)], +[ + AC_LANG_PUSH([C]) + gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL + AC_LANG_POP([C]) +]) + +# Specialization for _AC_LANG =3D C++. This macro can be AC_REQUIREd. +# Use of m4_defun rather than AC_DEFUN works around a bug in autoconf < 2.= 63b. +m4_defun([gl_UNKNOWN_WARNINGS_ARE_ERRORS(C++)], +[ + AC_LANG_PUSH([C++]) + gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL + AC_LANG_POP([C++]) +]) + +# Specialization for _AC_LANG =3D Objective C. This macro can be AC_REQUIR= Ed. +# Use of m4_defun rather than AC_DEFUN works around a bug in autoconf < 2.= 63b. +m4_defun([gl_UNKNOWN_WARNINGS_ARE_ERRORS(Objective C)], +[ + AC_LANG_PUSH([Objective C]) + gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL + AC_LANG_POP([Objective C]) +]) + +AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL], +[gl_COMPILER_OPTION_IF([-Werror -Wunknown-warning-option], + [gl_unknown_warnings_are_errors=3D'-Wunknown-warning-option -Werror'], + [gl_unknown_warnings_are_errors=3D])]) + +# gl_WARN_ADD(OPTION, [VARIABLE =3D WARN_CFLAGS/WARN_CXXFLAGS], +# [PROGRAM =3D AC_LANG_PROGRAM()]) +# ----------------------------------------------------------- +# Adds parameter to WARN_CFLAGS/WARN_CXXFLAGS if the compiler supports it +# when compiling PROGRAM. For example, gl_WARN_ADD([-Wparentheses]). +# +# If VARIABLE is a variable name, AC_SUBST it. +# +# The effects of this macro depend on the current language (_AC_LANG). +AC_DEFUN([gl_WARN_ADD], +[AC_REQUIRE([gl_UNKNOWN_WARNINGS_ARE_ERRORS(]_AC_LANG[)]) +gl_COMPILER_OPTION_IF([$1], + [gl_AS_VAR_APPEND(m4_if([$2], [], [[WARN_]_AC_LANG_PREFIX[FLAGS]], [[$2]= ]), [" $1"])], + [], + [$3]) +m4_ifval([$2], + [AS_LITERAL_IF([$2], [AC_SUBST([$2])])], + [AC_SUBST([WARN_]_AC_LANG_PREFIX[FLAGS])])dnl +]) + +# Local Variables: +# mode: autoconf +# End: --=20 2.24.1