From nobody Thu Apr 25 12:19:07 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=1578670904; cv=none; d=zohomail.com; s=zohoarc; b=CgTB0ScJya2SHHhNVkM6dv/wsV9Pay/T3WthGo4wMZwuO7e7p65mkEPaVxv9J4bD3yWpbVWX0RqMzE+8039+U/wuyHlkJR00R479K77StCQqkewQ8Wx2ebMlHxA36MAQpQY6jcGiBSC7u76zYymgZe6vSLoEmRUHp1d5y7Jrn80= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578670904; 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=iweXdY3MPy5u//j5G4oCkmeLLFf/meMk2W60lvdAy3A=; b=EbL4P3pen4ehhvbfrBe0eiyaoShTjY/1wgaTHX+uGBqR5ZvW1/aiglBClHhQJTv9xM5e7H+0mE18++5b1azp0t4hVbGw4ncjw6yoEMwp4bLsiLkrNrA/urJAQxUEvpcuMbsLmQbEfa4L+Mmj0l0DD2GqQeAouKE24Efn6T6Kf7E= 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 1578670904004875.7054457697458; Fri, 10 Jan 2020 07:41:44 -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-340-uF0DManfNgWpdLtROE2LzA-1; Fri, 10 Jan 2020 10:41:38 -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 5064AB20FB; Fri, 10 Jan 2020 15:41:31 +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 2786B86CCD; Fri, 10 Jan 2020 15:41:31 +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 D93ED18034EE; Fri, 10 Jan 2020 15:41:30 +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 00AFfMGj022212 for ; Fri, 10 Jan 2020 10:41:22 -0500 Received: by smtp.corp.redhat.com (Postfix) id AC01878E77; Fri, 10 Jan 2020 15:41:22 +0000 (UTC) Received: from domokun.gsslab.fab.redhat.com (dhcp-46.gsslab.fab.redhat.com [10.33.9.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id EC2198061D; Fri, 10 Jan 2020 15:41:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578670902; 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=iweXdY3MPy5u//j5G4oCkmeLLFf/meMk2W60lvdAy3A=; b=IOnIsJmUwQip10D4fY8mjXhsZB9lEREaZ/biJL8q4DGUGk56kuF/w+B8PmN7uofHPKuFvW +Ph+p+xlrjYLUJ2IrMRonQfsFSBU5qzPJF3luHbImw7oRoFYRGe6yR0/fLltB1LngIhryO CHfsDY3nXbPpoqVm/KrPH2LLTXfoZhk= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 10 Jan 2020 15:41:05 +0000 Message-Id: <20200110154116.3055969-2-berrange@redhat.com> In-Reply-To: <20200110154116.3055969-1-berrange@redhat.com> References: <20200110154116.3055969-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 Subject: [libvirt] [PATCH 01/12] src: import gnulib's intprops.h header 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: uF0DManfNgWpdLtROE2LzA-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) This copies intprops.h to virintprops.h. A couple of conditionals were cut out since we don't need to support OpenVMS or ancient GCC 2.x Signed-off-by: Daniel P. Berrang=C3=A9 --- build-aux/syntax-check.mk | 7 +- src/hyperv/hyperv_driver.c | 2 +- src/libvirt-domain.c | 2 +- src/nwfilter/nwfilter_ebiptables_driver.c | 2 +- src/nwfilter/nwfilter_learnipaddr.c | 2 +- src/remote/remote_daemon_dispatch.c | 2 +- src/remote/remote_driver.c | 2 +- src/util/Makefile.inc.am | 1 + src/util/virfile.c | 2 +- src/util/virhostcpu.c | 2 +- src/util/virintprops.h | 526 ++++++++++++++++++++++ src/util/virlog.c | 2 +- src/util/virnetdevbridge.c | 2 +- src/util/virpidfile.c | 2 +- tests/virsystemdtest.c | 2 +- tools/virsh-domain-monitor.c | 2 +- tools/virt-login-shell.c | 7 +- 17 files changed, 548 insertions(+), 19 deletions(-) create mode 100644 src/util/virintprops.h diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 7e7c59c3df..5b85b4d1de 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -1611,13 +1611,13 @@ 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; \ + $(shell f=3D$(srcdir)/src/util/virintprops.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' \ + @h=3D'virintprops.h' \ re=3D'\<($(_intprops_syms_re)) *\(' \ $(_sc_header_without_use) =20 @@ -2360,3 +2360,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_wrong_filename_in_comment =3D \ + ^src/util/virintprops\.h$$ diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index c9d22ec7c4..f9751b7591 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -36,7 +36,7 @@ #include "openwsman.h" #include "virstring.h" #include "virkeycode.h" -#include "intprops.h" +#include "virintprops.h" =20 #define VIR_FROM_THIS VIR_FROM_HYPERV =20 diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index eb66999f07..9144f0a98a 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -21,7 +21,7 @@ #include #include =20 -#include "intprops.h" +#include "virintprops.h" =20 #include "datatypes.h" #include "viralloc.h" diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfil= ter_ebiptables_driver.c index eec1414023..8e85c9723b 100644 --- a/src/nwfilter/nwfilter_ebiptables_driver.c +++ b/src/nwfilter/nwfilter_ebiptables_driver.c @@ -40,7 +40,7 @@ #include "virfile.h" #include "vircommand.h" #include "configmake.h" -#include "intprops.h" +#include "virintprops.h" #include "virstring.h" #include "virfirewall.h" =20 diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_le= arnipaddr.c index 46ef65401c..91e7e1d100 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -39,7 +39,7 @@ =20 #include "internal.h" =20 -#include "intprops.h" +#include "virintprops.h" #include "virbuffer.h" #include "viralloc.h" #include "virlog.h" diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon= _dispatch.c index 9c294ddc39..995d463266 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -31,7 +31,7 @@ #include "remote_daemon_stream.h" #include "viruuid.h" #include "vircommand.h" -#include "intprops.h" +#include "virintprops.h" #include "virnetserverservice.h" #include "virnetserver.h" #include "virfile.h" diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index c11f73ab4d..7eb9e1bc7c 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -43,7 +43,7 @@ #include "viralloc.h" #include "virfile.h" #include "vircommand.h" -#include "intprops.h" +#include "virintprops.h" #include "virtypedparam.h" #include "viruri.h" #include "virauth.h" diff --git a/src/util/Makefile.inc.am b/src/util/Makefile.inc.am index dfa8347853..03054e8862 100644 --- a/src/util/Makefile.inc.am +++ b/src/util/Makefile.inc.am @@ -102,6 +102,7 @@ UTIL_SOURCES =3D \ util/viridentity.h \ util/virinitctl.c \ util/virinitctl.h \ + util/virintprops.h \ util/viriptables.c \ util/viriptables.h \ util/viriscsi.c \ diff --git a/src/util/virfile.c b/src/util/virfile.c index 5acac85bb9..a6d2d4a8e3 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -68,7 +68,7 @@ #endif =20 #include "configmake.h" -#include "intprops.h" +#include "virintprops.h" #include "viralloc.h" #include "vircommand.h" #include "virerror.h" diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c index 7f14340f49..c948278c9a 100644 --- a/src/util/virhostcpu.c +++ b/src/util/virhostcpu.c @@ -43,7 +43,7 @@ #include "virhostcpupriv.h" #include "physmem.h" #include "virerror.h" -#include "intprops.h" +#include "virintprops.h" #include "virarch.h" #include "virfile.h" #include "virtypedparam.h" diff --git a/src/util/virintprops.h b/src/util/virintprops.h new file mode 100644 index 0000000000..7cde3c0445 --- /dev/null +++ b/src/util/virintprops.h @@ -0,0 +1,526 @@ +/* + * Based on GNULIB intprops.h -- properties of integer types + * + * Copyright (C) 2001-2019 Free Software Foundation, Inc. + * This program 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 program 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 program. If not, see . + * + * Written by Paul Eggert. + */ + +#pragma once + +#include "internal.h" + +#include + +/* Return a value with the common real type of E and V and the value of V. + Do not evaluate E. */ +#define VIR_INT_CONVERT(e, v) ((1 ? 0 : (e)) + (v)) + +/* Act like VIR_INT_CONVERT (E, -V) but work around a bug in IRIX 6.5 cc; = see + . */ +#define VIR_INT_NEGATE_CONVERT(e, v) ((1 ? 0 : (e)) - (v)) + +/* The extra casts in the following macros work around compiler bugs, + e.g., in Cray C 5.0.3.0. */ + +/* True if the arithmetic type T is an integer type. bool counts as + an integer. */ +#define TYPE_IS_INTEGER(t) ((t) 1.5 =3D=3D 1) + +/* True if the real type T is signed. */ +#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) + +/* Return 1 if the real expression E, after promotion, has a + signed or floating type. Do not evaluate E. */ +#define EXPR_SIGNED(e) (VIR_INT_NEGATE_CONVERT (e, 1) < 0) + + +/* Minimum and maximum values for integer types and expressions. */ + +/* The width in bits of the integer type or expression T. + Do not evaluate T. + Padding bits are not supported; this is checked at compile-time below. = */ +#define TYPE_WIDTH(t) (sizeof(t) * CHAR_BIT) + +/* The maximum and minimum values for the integer type T. */ +#define TYPE_MINIMUM(t) ((t) ~ TYPE_MAXIMUM (t)) +#define TYPE_MAXIMUM(t) \ + ((t) (! TYPE_SIGNED (t) \ + ? (t) -1 \ + : ((((t) 1 << (TYPE_WIDTH (t) - 2)) - 1) * 2 + 1))) + +/* The maximum and minimum values for the type of the expression E, + after integer promotion. E is not evaluated. */ +#define VIR_INT_MINIMUM(e) \ + (EXPR_SIGNED (e) \ + ? ~ VIR_SIGNED_INT_MAXIMUM (e) \ + : VIR_INT_CONVERT (e, 0)) +#define VIR_INT_MAXIMUM(e) \ + (EXPR_SIGNED (e) \ + ? VIR_SIGNED_INT_MAXIMUM (e) \ + : VIR_INT_NEGATE_CONVERT (e, 1)) +#define VIR_SIGNED_INT_MAXIMUM(e) \ + (((VIR_INT_CONVERT (e, 1) << (TYPE_WIDTH ((e) + 0) - 2)) - 1) * 2 + 1) + +/* This include file assumes that signed types are two's complement without + padding bits; the above macros have undefined behavior otherwise. + If this is a problem for you, please let us know how to fix it for your= host. + This assumption is tested by the intprops-tests module. */ + +/* Return 1 if the integer type or expression T might be signed. Return 0 + if it is definitely unsigned. This macro does not evaluate its argumen= t, + and expands to an integer constant expression. */ +#define VIR_SIGNED_TYPE_OR_EXPR(t) TYPE_SIGNED (__typeof__ (t)) + +/* Bound on length of the string representing an unsigned integer + value representable in B bits. log10 (2.0) < 146/485. The + smallest value of B where this bound is not tight is 2621. */ +#define INT_BITS_STRLEN_BOUND(b) (((b) * 146 + 484) / 485) + +/* Bound on length of the string representing an integer type or expressio= n T. + Subtract 1 for the sign bit if T is signed, and then add 1 more for + a minus sign if needed. + + Because VIR_SIGNED_TYPE_OR_EXPR sometimes returns 1 when its argument is + unsigned, this macro may overestimate the true bound by one byte when + applied to unsigned types of size 2, 4, 16, ... bytes. */ +#define INT_STRLEN_BOUND(t) \ + (INT_BITS_STRLEN_BOUND (TYPE_WIDTH (t) - VIR_SIGNED_TYPE_OR_EXPR (t)) \ + + VIR_SIGNED_TYPE_OR_EXPR (t)) + +/* Bound on buffer size needed to represent an integer type or expression = T, + including the terminating null. */ +#define INT_BUFSIZE_BOUND(t) (INT_STRLEN_BOUND (t) + 1) + + +/* Range overflow checks. + + The INT__RANGE_OVERFLOW macros return 1 if the corresponding C + operators might not yield numerically correct answers due to + arithmetic overflow. They do not rely on undefined or + implementation-defined behavior. Their implementations are simple + and straightforward, but they are a bit harder to use than the + INT__OVERFLOW macros described below. + + Example usage: + + long int x =3D ...; + long int y =3D ...; + if (INT_MULTIPLY_RANGE_OVERFLOW (x, y, LONG_MIN, LONG_MAX)) + printf ("multiply would overflow"); + else + printf ("product is %ld", x * y); + + Restrictions on *_RANGE_OVERFLOW macros: + + These macros do not check for all possible numerical problems or + undefined or unspecified behavior: they do not check for division + by zero, for bad shift counts, or for shifting negative numbers. + + These macros may evaluate their arguments zero or multiple times, + so the arguments should not have side effects. The arithmetic + arguments (including the MIN and MAX arguments) must be of the same + integer type after the usual arithmetic conversions, and the type + must have minimum value MIN and maximum MAX. Unsigned types should + use a zero MIN of the proper type. + + These macros are tuned for constant MIN and MAX. For commutative + operations such as A + B, they are also tuned for constant B. */ + +/* Return 1 if A + B would overflow in [MIN,MAX] arithmetic. + See above for restrictions. */ +#define INT_ADD_RANGE_OVERFLOW(a, b, min, max) \ + ((b) < 0 \ + ? (a) < (min) - (b) \ + : (max) - (b) < (a)) + +/* Return 1 if A - B would overflow in [MIN,MAX] arithmetic. + See above for restrictions. */ +#define INT_SUBTRACT_RANGE_OVERFLOW(a, b, min, max) \ + ((b) < 0 \ + ? (max) + (b) < (a) \ + : (a) < (min) + (b)) + +/* Return 1 if - A would overflow in [MIN,MAX] arithmetic. + See above for restrictions. */ +#define INT_NEGATE_RANGE_OVERFLOW(a, min, max) \ + ((min) < 0 \ + ? (a) < - (max) \ + : 0 < (a)) + +/* Return 1 if A * B would overflow in [MIN,MAX] arithmetic. + See above for restrictions. Avoid && and || as they tickle + bugs in Sun C 5.11 2010/08/13 and other compilers; see + . */ +#define INT_MULTIPLY_RANGE_OVERFLOW(a, b, min, max) \ + ((b) < 0 \ + ? ((a) < 0 \ + ? (a) < (max) / (b) \ + : (b) =3D=3D -1 \ + ? 0 \ + : (min) / (b) < (a)) \ + : (b) =3D=3D 0 \ + ? 0 \ + : ((a) < 0 \ + ? (a) < (min) / (b) \ + : (max) / (b) < (a))) + +/* Return 1 if A / B would overflow in [MIN,MAX] arithmetic. + See above for restrictions. Do not check for division by zero. */ +#define INT_DIVIDE_RANGE_OVERFLOW(a, b, min, max) \ + ((min) < 0 && (b) =3D=3D -1 && (a) < - (max)) + +/* Return 1 if A % B would overflow in [MIN,MAX] arithmetic. + See above for restrictions. Do not check for division by zero. + Mathematically, % should never overflow, but on x86-like hosts + INT_MIN % -1 traps, and the C standard permits this, so treat this + as an overflow too. */ +#define INT_REMAINDER_RANGE_OVERFLOW(a, b, min, max) \ + INT_DIVIDE_RANGE_OVERFLOW (a, b, min, max) + +/* Return 1 if A << B would overflow in [MIN,MAX] arithmetic. + See above for restrictions. Here, MIN and MAX are for A only, and B ne= ed + not be of the same type as the other arguments. The C standard says th= at + behavior is undefined for shifts unless 0 <=3D B < wordwidth, and that = when + A is negative then A << B has undefined behavior and A >> B has + implementation-defined behavior, but do not check these other + restrictions. */ +#define INT_LEFT_SHIFT_RANGE_OVERFLOW(a, b, min, max) \ + ((a) < 0 \ + ? (a) < (min) >> (b) \ + : (max) >> (b) < (a)) + +/* True if __builtin_add_overflow (A, B, P) works when P is non-null. */ +#if 5 <=3D __GNUC__ && !defined __ICC +# define VIR_HAS_BUILTIN_OVERFLOW 1 +#else +# define VIR_HAS_BUILTIN_OVERFLOW 0 +#endif + +/* True if __builtin_add_overflow_p (A, B, C) works. */ +#define VIR_HAS_BUILTIN_OVERFLOW_P (7 <=3D __GNUC__) + +/* The VIR*_OVERFLOW macros have the same restrictions as the + *_RANGE_OVERFLOW macros, except that they do not assume that operands + (e.g., A and B) have the same type as MIN and MAX. Instead, they assume + that the result (e.g., A + B) has that type. */ +#if VIR_HAS_BUILTIN_OVERFLOW_P +# define VIR_ADD_OVERFLOW(a, b, min, max) \ + __builtin_add_overflow_p (a, b, (__typeof__ ((a) + (b))) 0) +# define VIR_SUBTRACT_OVERFLOW(a, b, min, max) \ + __builtin_sub_overflow_p (a, b, (__typeof__ ((a) - (b))) 0) +# define VIR_MULTIPLY_OVERFLOW(a, b, min, max) \ + __builtin_mul_overflow_p (a, b, (__typeof__ ((a) * (b))) 0) +#else +# define VIR_ADD_OVERFLOW(a, b, min, max) \ + ((min) < 0 ? INT_ADD_RANGE_OVERFLOW (a, b, min, max) \ + : (a) < 0 ? (b) <=3D (a) + (b) \ + : (b) < 0 ? (a) <=3D (a) + (b) \ + : (a) + (b) < (b)) +# define VIR_SUBTRACT_OVERFLOW(a, b, min, max) \ + ((min) < 0 ? INT_SUBTRACT_RANGE_OVERFLOW (a, b, min, max) \ + : (a) < 0 ? 1 \ + : (b) < 0 ? (a) - (b) <=3D (a) \ + : (a) < (b)) +# define VIR_MULTIPLY_OVERFLOW(a, b, min, max) \ + (((min) =3D=3D 0 && (((a) < 0 && 0 < (b)) || ((b) < 0 && 0 < (a)))) \ + || INT_MULTIPLY_RANGE_OVERFLOW (a, b, min, max)) +#endif +#define VIR_DIVIDE_OVERFLOW(a, b, min, max) \ + ((min) < 0 ? (b) =3D=3D VIR_INT_NEGATE_CONVERT (min, 1) && (a) < - (max)= \ + : (a) < 0 ? (b) <=3D (a) + (b) - 1 \ + : (b) < 0 && (a) + (b) <=3D (a)) +#define VIR_REMAINDER_OVERFLOW(a, b, min, max) \ + ((min) < 0 ? (b) =3D=3D VIR_INT_NEGATE_CONVERT (min, 1) && (a) < - (max)= \ + : (a) < 0 ? (a) % (b) !=3D ((max) - (b) + 1) % (b) \ + : (b) < 0 && ! VIR_UNSIGNED_NEG_MULTIPLE (a, b, max)) + +/* Return a nonzero value if A is a mathematical multiple of B, where + A is unsigned, B is negative, and MAX is the maximum value of A's + type. A's type must be the same as (A % B)'s type. Normally (A % + -B =3D=3D 0) suffices, but things get tricky if -B would overflow. */ +#define VIR_UNSIGNED_NEG_MULTIPLE(a, b, max) \ + (((b) < -VIR_SIGNED_INT_MAXIMUM (b) \ + ? (VIR_SIGNED_INT_MAXIMUM (b) =3D=3D (max) \ + ? (a) \ + : (a) % (VIR_INT_CONVERT (a, VIR_SIGNED_INT_MAXIMUM (b)) + 1)) \ + : (a) % - (b)) \ + =3D=3D 0) + +/* Check for integer overflow, and report low order bits of answer. + + The INT__OVERFLOW macros return 1 if the corresponding C operators + might not yield numerically correct answers due to arithmetic overflow. + The INT__WRAPV macros compute the low-order bits of the sum, + difference, and product of two C integers, and return 1 if these + low-order bits are not numerically correct. + These macros work correctly on all known practical hosts, and do not re= ly + on undefined behavior due to signed arithmetic overflow. + + Example usage, assuming A and B are long int: + + if (INT_MULTIPLY_OVERFLOW (a, b)) + printf ("result would overflow\n"); + else + printf ("result is %ld (no overflow)\n", a * b); + + Example usage with WRAPV flavor: + + long int result; + bool overflow =3D INT_MULTIPLY_WRAPV (a, b, &result); + printf ("result is %ld (%s)\n", result, + overflow ? "after overflow" : "no overflow"); + + Restrictions on these macros: + + These macros do not check for all possible numerical problems or + undefined or unspecified behavior: they do not check for division + by zero, for bad shift counts, or for shifting negative numbers. + + These macros may evaluate their arguments zero or multiple times, so the + arguments should not have side effects. + + The WRAPV macros are not constant expressions. They support only + +, binary -, and *. Because the WRAPV macros convert the result, + they report overflow in different circumstances than the OVERFLOW + macros do. + + These macros are tuned for their last input argument being a constant. + + Return 1 if the integer expressions A * B, A - B, -A, A * B, A / B, + A % B, and A << B would overflow, respectively. */ + +#define INT_ADD_OVERFLOW(a, b) \ + VIR_BINARY_OP_OVERFLOW (a, b, VIR_ADD_OVERFLOW) +#define INT_SUBTRACT_OVERFLOW(a, b) \ + VIR_BINARY_OP_OVERFLOW (a, b, VIR_SUBTRACT_OVERFLOW) +#if VIR_HAS_BUILTIN_OVERFLOW_P +# define INT_NEGATE_OVERFLOW(a) INT_SUBTRACT_OVERFLOW (0, a) +#else +# define INT_NEGATE_OVERFLOW(a) \ + INT_NEGATE_RANGE_OVERFLOW (a, VIR_INT_MINIMUM (a), VIR_INT_MAXIMUM (a)) +#endif +#define INT_MULTIPLY_OVERFLOW(a, b) \ + VIR_BINARY_OP_OVERFLOW (a, b, VIR_MULTIPLY_OVERFLOW) +#define INT_DIVIDE_OVERFLOW(a, b) \ + VIR_BINARY_OP_OVERFLOW (a, b, VIR_DIVIDE_OVERFLOW) +#define INT_REMAINDER_OVERFLOW(a, b) \ + VIR_BINARY_OP_OVERFLOW (a, b, VIR_REMAINDER_OVERFLOW) +#define INT_LEFT_SHIFT_OVERFLOW(a, b) \ + INT_LEFT_SHIFT_RANGE_OVERFLOW (a, b, \ + VIR_INT_MINIMUM (a), VIR_INT_MAXIMUM (a)) + +/* Return 1 if the expression A B would overflow, + where OP_RESULT_OVERFLOW (A, B, MIN, MAX) does the actual test, + assuming MIN and MAX are the minimum and maximum for the result type. + Arguments should be free of side effects. */ +#define VIR_BINARY_OP_OVERFLOW(a, b, op_result_overflow) \ + op_result_overflow (a, b, \ + VIR_INT_MINIMUM (VIR_INT_CONVERT (a, b)), \ + VIR_INT_MAXIMUM (VIR_INT_CONVERT (a, b))) + +/* Store the low-order bits of A + B, A - B, A * B, respectively, into *R. + Return 1 if the result overflows. See above for restrictions. */ +#define INT_ADD_WRAPV(a, b, r) \ + VIR_INT_OP_WRAPV (a, b, r, +, __builtin_add_overflow, \ + VIR_INT_ADD_RANGE_OVERFLOW) +#define INT_SUBTRACT_WRAPV(a, b, r) \ + VIR_INT_OP_WRAPV (a, b, r, -, __builtin_sub_overflow, \ + VIR_INT_SUBTRACT_RANGE_OVERFLOW) +#define INT_MULTIPLY_WRAPV(a, b, r) \ + VIR_INT_OP_WRAPV (a, b, r, *, VIR_BUILTIN_MUL_OVERFLOW, \ + VIR_INT_MULTIPLY_RANGE_OVERFLOW) + +/* Like __builtin_mul_overflow, but work around GCC bug 91450. */ +#define VIR_BUILTIN_MUL_OVERFLOW(a, b, r) \ + ((!VIR_SIGNED_TYPE_OR_EXPR (*(r)) && EXPR_SIGNED (a) && EXPR_SIGNED (b) \ + && VIR_INT_MULTIPLY_RANGE_OVERFLOW (a, b, 0, (__typeof__ (*(r))) -1)) \ + ? ((void) __builtin_mul_overflow (a, b, r), 1) \ + : __builtin_mul_overflow (a, b, r)) + +/* Nonzero if this compiler has GCC bug 68193 or Clang bug 25390. See: + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D68193 + https://llvm.org/bugs/show_bug.cgi?id=3D25390 + For now, assume all versions of GCC-like compilers generate bogus + warnings for _Generic. This matters only for older compilers that + lack __builtin_add_overflow. */ +#if __GNUC__ +# define VIR__GENERIC_BOGUS 1 +#else +# define VIR__GENERIC_BOGUS 0 +#endif + +/* Store the low-order bits of A B into *R, where OP specifies + the operation. BUILTIN is the builtin operation, and OVERFLOW the + overflow predicate. Return 1 if the result overflows. See above + for restrictions. */ +#if VIR_HAS_BUILTIN_OVERFLOW +# define VIR_INT_OP_WRAPV(a, b, r, op, builtin, overflow) builtin (a, b, r) +#elif 201112 <=3D __STDC_VERSION__ && !VIR__GENERIC_BOGUS +# define VIR_INT_OP_WRAPV(a, b, r, op, builtin, overflow) \ + (_Generic \ + (*(r), \ + signed char: \ + VIR_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ + signed char, SCHAR_MIN, SCHAR_MAX), \ + unsigned char: \ + VIR_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ + unsigned char, 0, UCHAR_MAX), \ + short int: \ + VIR_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ + short int, SHRT_MIN, SHRT_MAX), \ + unsigned short int: \ + VIR_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ + unsigned short int, 0, USHRT_MAX), \ + int: \ + VIR_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ + int, INT_MIN, INT_MAX), \ + unsigned int: \ + VIR_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ + unsigned int, 0, UINT_MAX), \ + long int: \ + VIR_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \ + long int, LONG_MIN, LONG_MAX), \ + unsigned long int: \ + VIR_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \ + unsigned long int, 0, ULONG_MAX), \ + long long int: \ + VIR_INT_OP_CALC (a, b, r, op, overflow, unsigned long long int, \ + long long int, LLONG_MIN, LLONG_MAX), \ + unsigned long long int: \ + VIR_INT_OP_CALC (a, b, r, op, overflow, unsigned long long int, \ + unsigned long long int, 0, ULLONG_MAX))) +#else +/* Store the low-order bits of A B into *R, where OP specifies + the operation and OVERFLOW the overflow predicate. If *R is + signed, its type is ST with bounds SMIN..SMAX; otherwise its type + is UT with bounds U..UMAX. ST and UT are narrower than int. + Return 1 if the result overflows. See above for restrictions. */ +# define VIR_INT_OP_WRAPV_SMALLISH(a,b,r,op,overflow,st,smin,smax,ut,umax)= \ + (TYPE_SIGNED (__typeof__ (*(r))) \ + ? VIR_INT_OP_CALC (a, b, r, op, overflow, unsigned int, st, smin, sma= x) \ + : VIR_INT_OP_CALC (a, b, r, op, overflow, unsigned int, ut, 0, umax)) + +# define VIR_INT_OP_WRAPV(a, b, r, op, builtin, overflow) \ + (sizeof(*(r)) =3D=3D sizeof(signed char) \ + ? VIR_INT_OP_WRAPV_SMALLISH(a, b, r, op, overflow, \ + signed char, SCHAR_MIN, SCHAR_MAX, \ + unsigned char, UCHAR_MAX) \ + : sizeof(*(r)) =3D=3D sizeof(short int) \ + ? VIR_INT_OP_WRAPV_SMALLISH(a, b, r, op, overflow, \ + short int, SHRT_MIN, SHRT_MAX, \ + unsigned short int, USHRT_MAX) \ + : sizeof(*(r)) =3D=3D sizeof(int) \ + ? (EXPR_SIGNED(*(r)) \ + ? VIR_INT_OP_CALC(a, b, r, op, overflow, unsigned int, \ + int, INT_MIN, INT_MAX) \ + : VIR_INT_OP_CALC(a, b, r, op, overflow, unsigned int, \ + unsigned int, 0, UINT_MAX)) \ + : VIR_INT_OP_WRAPV_LONGISH(a, b, r, op, overflow)) +# define VIR_INT_OP_WRAPV_LONGISH(a, b, r, op, overflow) \ + (sizeof(*(r)) =3D=3D sizeof(long int) \ + ? (EXPR_SIGNED (*(r)) \ + ? VIR_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \ + long int, LONG_MIN, LONG_MAX) \ + : VIR_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \ + unsigned long int, 0, ULONG_MAX)) \ + : (EXPR_SIGNED (*(r)) \ + ? VIR_INT_OP_CALC (a, b, r, op, overflow, unsigned long long int, \ + long long int, LLONG_MIN, LLONG_MAX) \ + : VIR_INT_OP_CALC (a, b, r, op, overflow, unsigned long long int, \ + unsigned long long int, 0, ULLONG_MAX))) +#endif + +/* Store the low-order bits of A B into *R, where the operation + is given by OP. Use the unsigned type UT for calculation to avoid + overflow problems. *R's type is T, with extrema TMIN and TMAX. + T must be a signed integer type. Return 1 if the result overflows. */ +#define VIR_INT_OP_CALC(a, b, r, op, overflow, ut, t, tmin, tmax) \ + (overflow (a, b, tmin, tmax) \ + ? (*(r) =3D VIR_INT_OP_WRAPV_VIA_UNSIGNED (a, b, op, ut, t), 1) \ + : (*(r) =3D VIR_INT_OP_WRAPV_VIA_UNSIGNED (a, b, op, ut, t), 0)) + +/* Return the low-order bits of A B, where the operation is given + by OP. Use the unsigned type UT for calculation to avoid undefined + behavior on signed integer overflow, and convert the result to type T. + UT is at least as wide as T and is no narrower than unsigned int, + T is two's complement, and there is no padding or trap representations. + Assume that converting UT to T yields the low-order bits, as is + done in all known two's-complement C compilers. E.g., see: + https://gcc.gnu.org/onlinedocs/gcc/Integers-implementation.html + + According to the C standard, converting UT to T yields an + implementation-defined result or signal for values outside T's + range. However, code that works around this theoretical problem + runs afoul of a compiler bug in Oracle Studio 12.3 x86. See: + https://lists.gnu.org/r/bug-gnulib/2017-04/msg00049.html + As the compiler bug is real, don't try to work around the + theoretical problem. */ + +#define VIR_INT_OP_WRAPV_VIA_UNSIGNED(a, b, op, ut, t) \ + ((t) ((ut) (a) op (ut) (b))) + +/* Return true if the numeric values A + B, A - B, A * B fall outside + the range TMIN..TMAX. Arguments should be integer expressions + without side effects. TMIN should be signed and nonpositive. + TMAX should be positive, and should be signed unless TMIN is zero. */ +#define VIR_INT_ADD_RANGE_OVERFLOW(a, b, tmin, tmax) \ + ((b) < 0 \ + ? (((tmin) \ + ? ((EXPR_SIGNED (VIR_INT_CONVERT (a, (tmin) - (b))) || (b) < (tmin)= ) \ + && (a) < (tmin) - (b)) \ + : (a) <=3D -1 - (b)) \ + || ((EXPR_SIGNED (a) ? 0 <=3D (a) : (tmax) < (a)) && (tmax) < (a) + = (b))) \ + : (a) < 0 \ + ? (((tmin) \ + ? ((EXPR_SIGNED (VIR_INT_CONVERT (b, (tmin) - (a))) || (a) < (tmin)= ) \ + && (b) < (tmin) - (a)) \ + : (b) <=3D -1 - (a)) \ + || ((EXPR_SIGNED (VIR_INT_CONVERT (a, b)) || (tmax) < (b)) \ + && (tmax) < (a) + (b))) \ + : (tmax) < (b) || (tmax) - (b) < (a)) +#define VIR_INT_SUBTRACT_RANGE_OVERFLOW(a, b, tmin, tmax) \ + (((a) < 0) =3D=3D ((b) < 0) \ + ? ((a) < (b) \ + ? !(tmin) || -1 - (tmin) < (b) - (a) - 1 \ + : (tmax) < (a) - (b)) \ + : (a) < 0 \ + ? ((!EXPR_SIGNED (VIR_INT_CONVERT ((a) - (tmin), b)) && (a) - (tmin) < = 0) \ + || (a) - (tmin) < (b)) \ + : ((! (EXPR_SIGNED (VIR_INT_CONVERT (tmax, b)) \ + && EXPR_SIGNED (VIR_INT_CONVERT ((tmax) + (b), a))) \ + && (tmax) <=3D -1 - (b)) \ + || (tmax) + (b) < (a))) +#define VIR_INT_MULTIPLY_RANGE_OVERFLOW(a, b, tmin, tmax) \ + ((b) < 0 \ + ? ((a) < 0 \ + ? (EXPR_SIGNED (VIR_INT_CONVERT (tmax, b)) \ + ? (a) < (tmax) / (b) \ + : ((INT_NEGATE_OVERFLOW (b) \ + ? VIR_INT_CONVERT (b, tmax) >> (TYPE_WIDTH (b) - 1) \ + : (tmax) / -(b)) \ + <=3D -1 - (a))) \ + : INT_NEGATE_OVERFLOW (VIR_INT_CONVERT (b, tmin)) && (b) =3D=3D -1 \ + ? (EXPR_SIGNED (a) \ + ? 0 < (a) + (tmin) \ + : 0 < (a) && -1 - (tmin) < (a) - 1) \ + : (tmin) / (b) < (a)) \ + : (b) =3D=3D 0 \ + ? 0 \ + : ((a) < 0 \ + ? (INT_NEGATE_OVERFLOW (VIR_INT_CONVERT (a, tmin)) && (a) =3D=3D -1 \ + ? (EXPR_SIGNED (b) ? 0 < (b) + (tmin) : -1 - (tmin) < (b) - 1) \ + : (tmin) / (a) < (b)) \ + : (tmax) / (b) < (a))) diff --git a/src/util/virlog.c b/src/util/virlog.c index 8a9fb34161..dc04f57640 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -45,7 +45,7 @@ #include "virthread.h" #include "virfile.h" #include "virtime.h" -#include "intprops.h" +#include "virintprops.h" #include "virstring.h" #include "configmake.h" =20 diff --git a/src/util/virnetdevbridge.c b/src/util/virnetdevbridge.c index 3a7a6dc730..e89b81101a 100644 --- a/src/util/virnetdevbridge.c +++ b/src/util/virnetdevbridge.c @@ -25,7 +25,7 @@ #include "virfile.h" #include "viralloc.h" #include "virlog.h" -#include "intprops.h" +#include "virintprops.h" #include "virstring.h" =20 #include diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c index b08e0d8d52..83e8da4516 100644 --- a/src/util/virpidfile.c +++ b/src/util/virpidfile.c @@ -31,7 +31,7 @@ #include "virfile.h" #include "viralloc.h" #include "virutil.h" -#include "intprops.h" +#include "virintprops.h" #include "virlog.h" #include "virerror.h" #include "virstring.h" diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c index 9b95ca6789..7fa02f2e8c 100644 --- a/tests/virsystemdtest.c +++ b/tests/virsystemdtest.c @@ -33,7 +33,7 @@ # include "virlog.h" # include "virmock.h" # include "rpc/virnetsocket.h" -# include "intprops.h" +# include "virintprops.h" # define VIR_FROM_THIS VIR_FROM_NONE =20 VIR_LOG_INIT("tests.systemdtest"); diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index e357635757..e224b70293 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -29,7 +29,7 @@ =20 #include "internal.h" #include "conf/virdomainobjlist.h" -#include "intprops.h" +#include "virintprops.h" #include "viralloc.h" #include "virmacaddr.h" #include "virxml.h" diff --git a/tools/virt-login-shell.c b/tools/virt-login-shell.c index 7d1e0ccc8a..5ad77aaae2 100644 --- a/tools/virt-login-shell.c +++ b/tools/virt-login-shell.c @@ -29,15 +29,14 @@ #include =20 /* - * These gnulib files are used for their macros only, + * This GNULIB file is used for its macros only, * so don't introduce a link time dep, which we must avoid */ #include "gnulib/lib/configmake.h" -#include "gnulib/lib/intprops.h" =20 int main(int argc, char **argv) { - char uidstr[INT_BUFSIZE_BOUND(uid_t)]; - char gidstr[INT_BUFSIZE_BOUND(gid_t)]; + char uidstr[100]; + char gidstr[100]; const char * newargv[6]; size_t nargs =3D 0; char *newenv[] =3D { --=20 2.24.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 12:19:07 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=1578670929; cv=none; d=zohomail.com; s=zohoarc; b=VsK8TtDOULn2YxRwdtdfi9nCEtU/yQYo/fOCmODT3NKvTU7hfn+P8c1TqHCQeSY+omxY2x9Z/fwS3sJGIFaAM4ZUbnG9AFBCZS6YELOAn8tef142QSUL0kJNfm8W0s2yTeiOnvGX9tjmTZewUO5HkrTRY5PlmKT55VmyXgdGlAU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578670929; 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=GnZk5PXx3BYq2y9zSRQt7UYt3AGlezWTPj66GD516Ok=; b=j4gG44dsjM0/XgS4g2MDC/G2uDIxsmo62/Yf5WFqY40+3NnF+JjIRtJB00wh5lVMlXpB1o3t7xYjCWBk7eU/LZtcfo2zagbu5fL1oYmvb3B2CfTZNJqRmlj0xnWMnR0FaO6iqQlXJmVFV8hqClVfvAoMon+Ijc1HNgNSZvd5DMg= 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 15786709294121014.8452484935399; Fri, 10 Jan 2020 07:42:09 -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-351-vUqNOwRQPZOXnQRRQ4QDQg-1; Fri, 10 Jan 2020 10:41:43 -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 09D3C8024DC; Fri, 10 Jan 2020 15:41:36 +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 DC0465DA76; Fri, 10 Jan 2020 15:41:35 +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 8D2E281C7C; Fri, 10 Jan 2020 15:41:35 +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 00AFfNoI022220 for ; Fri, 10 Jan 2020 10:41:23 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8FFF578E89; Fri, 10 Jan 2020 15:41:23 +0000 (UTC) Received: from domokun.gsslab.fab.redhat.com (dhcp-46.gsslab.fab.redhat.com [10.33.9.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id F1D6878E77; Fri, 10 Jan 2020 15:41:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578670928; 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=GnZk5PXx3BYq2y9zSRQt7UYt3AGlezWTPj66GD516Ok=; b=akNMM4uywvZzjSqkpr2Qotpy4LUxL0LO2A2dsusfF9MviP8eveWYYO688BBRlcY6Gb6IBI kqUbbrI4X6/hFWarnPWiGUAr68xM7/Y/q8MY2W2d9R2VLVtdRuQYdVMHx/A7vzp9QvtCrQ HPsHPOJj3A+NhtTBMBgpomHzLMa8jQ0= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 10 Jan 2020 15:41:06 +0000 Message-Id: <20200110154116.3055969-3-berrange@redhat.com> In-Reply-To: <20200110154116.3055969-1-berrange@redhat.com> References: <20200110154116.3055969-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 Subject: [libvirt] [PATCH 02/12] tests: always declare environ 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: vUqNOwRQPZOXnQRRQ4QDQg-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Pavel Hrdina --- 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 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 12:19:07 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=1578670895; cv=none; d=zohomail.com; s=zohoarc; b=BM4uVbUx7OaVk6CxrJmNnt9aiSnwqroRt8mv4rf/j2I/ipif+noESLRtDJ5qiY+2LlhWbleUcrXqykrCrykuSSNPrQIXpBv/1qXi0DNVhtXN0RH1nYj1AITDzf1NkwvL96OjglhXeSuhoU0bc1PiyxCyBl9N6FK0FEOVZygE1iU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578670895; 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=88B4ZdNBT00pF1AJOL7JG+OBs3UHYdqlQJLX36ygsh8=; b=nLQ0X/EDooSw0hh5Nn/b0Ppj7IXedvseTNKEnwFAxz5gTZAWYFNTNXUQGc4JMkZJP4TCo569p/LNcxJQKuznmcVbdIl83UDcisWJA9F55Ad6f8gXVygrDCNcQLTgk3BR8F6AEgccIjZFbhp7tCZQ+cP9M4x03PMTxCLA2LkAQZA= 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 1578670895755356.17291014984323; Fri, 10 Jan 2020 07:41: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-371-yeuL7q7pN1u5SgqIUzfSlA-1; Fri, 10 Jan 2020 10:41:32 -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 3A7DF1800D78; Fri, 10 Jan 2020 15:41: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 16A9D5DA32; Fri, 10 Jan 2020 15:41:27 +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 CBD9818034F9; Fri, 10 Jan 2020 15:41: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 00AFfOgX022227 for ; Fri, 10 Jan 2020 10:41:24 -0500 Received: by smtp.corp.redhat.com (Postfix) id 733FE78E89; Fri, 10 Jan 2020 15:41:24 +0000 (UTC) Received: from domokun.gsslab.fab.redhat.com (dhcp-46.gsslab.fab.redhat.com [10.33.9.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id D6B8880610; Fri, 10 Jan 2020 15:41:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578670894; 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=88B4ZdNBT00pF1AJOL7JG+OBs3UHYdqlQJLX36ygsh8=; b=P0oawov+UTvN8iJR4bLsUJVUpAwk+w1F2OvMlwufQ2BVXGofVe0WhE2XC8590DghImnB2s l0uWK+/vo3nGMngGXsFZCVkJO75FqpFXH+NCCWK9IdCJYbbIEp02cG6TwqVUQOVyIOWlit OSB0D3TlC4JssNEd8iJ9/PwyR9C+0Zo= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 10 Jan 2020 15:41:07 +0000 Message-Id: <20200110154116.3055969-4-berrange@redhat.com> In-Reply-To: <20200110154116.3055969-1-berrange@redhat.com> References: <20200110154116.3055969-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 Subject: [libvirt] [PATCH 03/12] build: validate headers against local gnulib not git repo 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: yeuL7q7pN1u5SgqIUzfSlA-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Pavel Hrdina --- 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 5b85b4d1de..9138ba1fe2 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 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 12:19:07 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=1578670899; cv=none; d=zohomail.com; s=zohoarc; b=c5ES+hmN9zN/OFn9UZMa9IS+UpWNb9Gj2pYSLUGo5rDH+y2kLYo1SnWkBKU/1KfuDzcFnRabbHVQ3/xb/P9PO2j7XVLvUGldZf1cksFWxlaQkamx2IikDbrQYzwcWYgMGGxYIPjZMeiuRj2WNdWnAdTNikrtbLNU0IdUbTivM/s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578670899; 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=5TuPSAJjifRPw5itY+qf67m98FqqJ46l4M1hoWWDx1I=; b=NXtmZed4ryt2t5b0qz3jGfNAtLvdaIloBSoTe/zyAb3TNdU40DlFJcddhPWBeDSdrQYJJ2e06dOzQ1pS4VDIaicOnOuEbT+liHDp3hyOjX4wRpv5Pi4WD0aQD62MPFBha9hI06bk8sEit9eK4bRoh5IHBUcIn3zdsxQEUajWPJU= 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 1578670899421897.3830435293036; Fri, 10 Jan 2020 07:41:39 -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-35-jvMsM7ScPUWCqdPw5cCG4Q-1; Fri, 10 Jan 2020 10:41:36 -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 2E6F610120A0; Fri, 10 Jan 2020 15:41:31 +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 07F7678E89; Fri, 10 Jan 2020 15:41:31 +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 AF93B503DB; Fri, 10 Jan 2020 15:41:30 +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 00AFfPFB022240 for ; Fri, 10 Jan 2020 10:41:25 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5B1A080628; Fri, 10 Jan 2020 15:41:25 +0000 (UTC) Received: from domokun.gsslab.fab.redhat.com (dhcp-46.gsslab.fab.redhat.com [10.33.9.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id B9C3678E77; Fri, 10 Jan 2020 15:41:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578670898; 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=5TuPSAJjifRPw5itY+qf67m98FqqJ46l4M1hoWWDx1I=; b=aSOdhJ03BSDM4T//6oPIs0GcTwvfvA4yLVmIRDpuNjGezqzjoP5f2lL6zzFEykcqPTQQBB nsfVr213y6zKZdmF3pxTEZfj2Neo7Md2lJ6V7Dv3llhW03Gic+PlNyOxJaCM4iHwqm/coP zz/SEBk900xu2lL90m6auozjxELj2fM= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 10 Jan 2020 15:41:08 +0000 Message-Id: <20200110154116.3055969-5-berrange@redhat.com> In-Reply-To: <20200110154116.3055969-1-berrange@redhat.com> References: <20200110154116.3055969-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 Subject: [libvirt] [PATCH 04/12] util: add detection of openpty function 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: jvMsM7ScPUWCqdPw5cCG4Q-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) All UNIX platforms we care about have openpty() in the libutil library. Use of pty.h must also be made conditional, excluding Win32. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Pavel Hrdina --- configure.ac | 4 ++++ src/util/Makefile.inc.am | 1 + src/util/virfile.c | 14 +++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 002a3dcdb0..3e5032a8c4 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 03054e8862..c65fcb5f9b 100644 --- a/src/util/Makefile.inc.am +++ b/src/util/Makefile.inc.am @@ -283,6 +283,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 a6d2d4a8e3..14bfd3beb6 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 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 12:19:07 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=1578670906; cv=none; d=zohomail.com; s=zohoarc; b=hTkbL5WG+132qSdUqp6HIgptiMYxiyvkGXIMpBNYwIEg9gsEw5Ec6l1Wh3W4v0jR7nHKUZMo1byP7HyGwSicrkyD8QgX9/OvShqDE/K5XbVoii+Do1Cg/ODjvIkhTxQOYG7kEJXKvsPYv6zWEPY/Oj5tx5nAw6x8PlGNt7xudYg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578670906; 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=cRe00s603tlLd2LKZkrOKysvM9CtzRGUaZQ5P1qo2M8=; b=lnyR/QR7QBLOOsi45pnzWYfnOGsGso6m1p7bJ24vI/4bcH00hAJ95TyeGvXWNvxB35diu6KpY/pRB5q+Koe5wjkIwIt9awDoWU1cxxOCEp1MC2MaTNOO2rfEo6iLodObewwsjWq5fAepyK2LjhP0fWNyjWPrreeSVhQYDwd+oCs= 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 1578670906696993.5293450067196; Fri, 10 Jan 2020 07:41:46 -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-94-2amR-6IuNeaG6KwTEyeuhg-1; Fri, 10 Jan 2020 10:41:41 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0DA6D189CD05; Fri, 10 Jan 2020 15:41:35 +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 DCA2819C6A; Fri, 10 Jan 2020 15:41:34 +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 97AF518034F0; Fri, 10 Jan 2020 15:41:34 +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 00AFfQn2022248 for ; Fri, 10 Jan 2020 10:41:26 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3FD2280630; Fri, 10 Jan 2020 15:41:26 +0000 (UTC) Received: from domokun.gsslab.fab.redhat.com (dhcp-46.gsslab.fab.redhat.com [10.33.9.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id A27C178E77; Fri, 10 Jan 2020 15:41:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578670905; 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=cRe00s603tlLd2LKZkrOKysvM9CtzRGUaZQ5P1qo2M8=; b=EDqfEMPON83Bv0jOXPSWt4TYvZuGLOMqJeVVIbv6fsVR+cW/Ur42m7zwZDqJ2wzfQeH7nP R4hFFNKr2RjNQlpkY7kTDifUpfhjUVcd+OFU6ZBOhArfb/RUtIL53r+orpWwy809m85aO7 I0AIr8EP/BsAIe7yGpMsAL3t81n026U= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 10 Jan 2020 15:41:09 +0000 Message-Id: <20200110154116.3055969-6-berrange@redhat.com> In-Reply-To: <20200110154116.3055969-1-berrange@redhat.com> References: <20200110154116.3055969-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 Subject: [libvirt] [PATCH 05/12] util: introduce compat wrappers for Winsock2 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.23 X-MC-Unique: 2amR-6IuNeaG6KwTEyeuhg-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Pavel Hrdina --- src/util/Makefile.inc.am | 2 + src/util/virsocket.c | 346 +++++++++++++++++++++++++++++++++++++++ src/util/virsocket.h | 89 ++++++++++ 3 files changed, 437 insertions(+) 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 c65fcb5f9b..ef9b55a047 100644 --- a/src/util/Makefile.inc.am +++ b/src/util/Makefile.inc.am @@ -189,6 +189,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..367b707c59 --- /dev/null +++ b/src/util/virsocket.c @@ -0,0 +1,346 @@ +/* + * 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_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; + + sk =3D socket(domain, type, protocol); + 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..4ed38dbd5f --- /dev/null +++ b/src/util/virsocket.h @@ -0,0 +1,89 @@ +/* + * 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_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 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 + +#endif --=20 2.24.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 12:19:07 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=1578670990; cv=none; d=zohomail.com; s=zohoarc; b=A+cLTS2BH3gKzL1PeR8xVr0Hbv5+SIh8ML44IuNloHbTf+/KyxDOkxisQkIBwvCuwWVtxjkHjWaJNyDSWnQR9suAPqqrpU7d8oSKRramq+joFYNDAkMGhhdzuV3Khp0LJ3mG0pYatT0VFn1KaKZiahrBwKwuLg/qKCUQhivNlVk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578670990; 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=bqVqVSsSuPCDA/fN5mD9vB5GWmsStJKbpUtUYKwQ/Rk=; b=I7LNUKI3kirkcTQFml4dDr5VvgxzKdcAah3WbK8UMD7QSa/wxKc3kl3B3DAmxzFq2fEDGmdHzrPY4Jl6GuEurFvRSmy4t9avhux6USv7eehGyY+vqBLzqeNcPaQqnNeZFSZeElr8em6oebcynwSfsj8MgEgx5gWN3AeLZk7TFAk= 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 1578670990169489.0569223336505; Fri, 10 Jan 2020 07:43:10 -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-156-LG6YtF47NK6-nQUTggnsgA-1; Fri, 10 Jan 2020 10:41: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 7D114B20E1; Fri, 10 Jan 2020 15:41:38 +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 54C5E5C1B5; Fri, 10 Jan 2020 15:41: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 15FE681C7C; Fri, 10 Jan 2020 15:41:38 +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 00AFfRY3022257 for ; Fri, 10 Jan 2020 10:41:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2117780623; Fri, 10 Jan 2020 15:41:27 +0000 (UTC) Received: from domokun.gsslab.fab.redhat.com (dhcp-46.gsslab.fab.redhat.com [10.33.9.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 84FD078E77; Fri, 10 Jan 2020 15:41:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578670989; 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=bqVqVSsSuPCDA/fN5mD9vB5GWmsStJKbpUtUYKwQ/Rk=; b=Kpq3fDGu9v4MjXDKgAHacuJaj+jIyI3dHPEoaaw8k0M2Tr3BsfEO8K98u7hg/6oe1vp8Vk NnZkpgOnamdLSMT3GnbY6h1IRYpHwXtYsJvQnXQ/XiL8E4rWi1peqQNZbbkC082Vw1ikZV jcDFh3rlNvRbp1p9Rt2zrPgJZy7SDiw= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 10 Jan 2020 15:41:10 +0000 Message-Id: <20200110154116.3055969-7-berrange@redhat.com> In-Reply-To: <20200110154116.3055969-1-berrange@redhat.com> References: <20200110154116.3055969-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 Subject: [libvirt] [PATCH 06/12] src: convert code to use new socket portability wrappers 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: LG6YtF47NK6-nQUTggnsgA-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Pavel Hrdina --- 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 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 12:19:07 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-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=1578670911; cv=none; d=zohomail.com; s=zohoarc; b=irtnDzQfQqFu1up1pnGfOQaNOLZmApDwyrBrDqjAb03GVRz22FftcguG7zybfiB8QxejRV/QAmVkGEwJnCzpdazeqrpNbREO6XOB4SWQ/3cBbqgLi2n0hg0ZfBbUqJ99g0wirj2mBt/JbOa+N0ziOSZG+Z2pwNKqlsKu5iWVJ1I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578670911; 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=J76kOZZxdu/Pnh2hyCzkzSXX8FtSqCaa+AoiSGtbvWk=; b=mjyHSRlOx53/6cmcRqQaXFodV9NjJh4FkELJKVS2axDNh54elNFrTTYEgOv3QsZ1AHTbZnLpzYjbu8lr3xon8NnVoETqFd7mHSjqjljuf31A9qv5yXJ6W97ASAGnNJBzy8sa2tuh0BTSB6ddHUi4iC2g9wyT9n+2tM7JNvsj+Xk= 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-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1578670911122254.645787768658; Fri, 10 Jan 2020 07:41: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-20-KsW953yxNkiVmZCim_M9IA-1; Fri, 10 Jan 2020 10:41:48 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B58DF189CD07; Fri, 10 Jan 2020 15:41:39 +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 88E31272A7; Fri, 10 Jan 2020 15:41:39 +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 40F6881C99; Fri, 10 Jan 2020 15:41:39 +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 00AFfSTn022272 for ; Fri, 10 Jan 2020 10:41:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0400478E89; Fri, 10 Jan 2020 15:41:28 +0000 (UTC) Received: from domokun.gsslab.fab.redhat.com (dhcp-46.gsslab.fab.redhat.com [10.33.9.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 67BFD80630; Fri, 10 Jan 2020 15:41:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578670909; 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=J76kOZZxdu/Pnh2hyCzkzSXX8FtSqCaa+AoiSGtbvWk=; b=T4N9svABggBcSSbeO9zGS/Lmlqr85xtoCoE9tgxT8b6XhdgCXcIgEu+jViCpgwPZpAPy6w FRZ2u3at9hd0YcZ5+XImYqze54f4bXp6+VeVPUPd0q+zxuKh1dR/fNat1iwIxQcksjpnAJ Ohc7Eo8TDxL2zHpKVh969Isix/7f1fc= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 10 Jan 2020 15:41:11 +0000 Message-Id: <20200110154116.3055969-8-berrange@redhat.com> In-Reply-To: <20200110154116.3055969-1-berrange@redhat.com> References: <20200110154116.3055969-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 Subject: [libvirt] [PATCH 07/12] util: pull gnulib physmem impl into local code 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.23 X-MC-Unique: KsW953yxNkiVmZCim_M9IA-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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 9138ba1fe2..2bbadd426c 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -2335,7 +2335,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 c948278c9a..277b8efa62 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 "virintprops.h" #include "virarch.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 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 12:19:07 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=1578670912; cv=none; d=zohomail.com; s=zohoarc; b=gQfqrXt3n3x+feajtmFCSwoWIU4XvCVMTcrd8qT2T9LY3uYUnqjMOyuYJAos8wpcrCicEvwN7Yv490PJwAR50WABs5m6q9cdGooaC40kxwm9F+HQQJLvKyX1iLTaWiAbw82/gZOfHfoyFM7v45CxSrhUAmLSTrVfgUlP8mdzK1k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578670912; 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=0gcvEflxPxpuc6uOtg8+1dTUXL4e84oNkMGaf8poCDk=; b=IUWNMCc19QH0gJzfuKIyMlthFDRHt+kEOfYb6QRn51kWJzCrOYnKZ6H6f7aoZW5G7ZmMUMWuWFyRvGcX93bD4vCbapZkVmt509/DQ4dsapnfa0FLhtgprFqGcqSPceZQXxk/riwyaSKy0EPffJFiEiLpKwiGHF41bHnGURV2Xm8= 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 1578670912601404.23254353014806; Fri, 10 Jan 2020 07:41: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-189-2yncQzhmMfid_qfVUd7MHw-1; Fri, 10 Jan 2020 10:41:49 -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 24E52107ACE4; Fri, 10 Jan 2020 15:41: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 F16C35C541; Fri, 10 Jan 2020 15:41: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 A8D6E18034EA; Fri, 10 Jan 2020 15:41: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 00AFfSpZ022279 for ; Fri, 10 Jan 2020 10:41:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id DC23B78E8E; Fri, 10 Jan 2020 15:41:28 +0000 (UTC) Received: from domokun.gsslab.fab.redhat.com (dhcp-46.gsslab.fab.redhat.com [10.33.9.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4AF2B78E77; Fri, 10 Jan 2020 15:41:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578670911; 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=0gcvEflxPxpuc6uOtg8+1dTUXL4e84oNkMGaf8poCDk=; b=g5rFCDTs0lD5QyzlKEJK4PWivW0fZQ7CE5l2+P/cPXiWbbyBFIoChjOl8a+u5i8/VpDJPf bgqfd4E0Tf4asYWNHH7maXYM1H50FuHfanQ/CgdPecq5z1AucWWbvCU2rzeiceiI01J8Ya r0TExF0jT2lS9Es72wORjhcmLyLz1DM= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 10 Jan 2020 15:41:12 +0000 Message-Id: <20200110154116.3055969-9-berrange@redhat.com> In-Reply-To: <20200110154116.3055969-1-berrange@redhat.com> References: <20200110154116.3055969-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 Subject: [libvirt] [PATCH 08/12] util: replace atomic ops impls with g_atomic_int* 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: 2yncQzhmMfid_qfVUd7MHw-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Pavel Hrdina --- 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 4195042194..1a98f56946 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5570,7 +5570,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 */ @@ -8138,7 +8138,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 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 12:19:07 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=1578670904; cv=none; d=zohomail.com; s=zohoarc; b=jk0MN8Qa5bi1SWflpDzQkv/O09tLbghQ33/mAQjImzOFe2pGsftX7xsRedB7sKmlUWiPTdm9dqeRHBI7bWgtQ9VbU8vrWQ2cbnfzvzh0j6W6zCCD2f/9lp5OjniusOXpiEd1I4V83MbrOweSVhhc7by6pPCoiIeWCEpp3+IMu7o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578670904; 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=/6EzatCFsA/gv415s33ERbKjuYHBO2BIRklSTxNCesw=; b=hveb4rwaoppUTxnFcEEskj96SDwQNdnH3PsdEY0cu1zAYb/VsBDQPtHQ1NpOBCmkCWB0xu0qAPZqkMDHtcxbCve/fa8CDBCHv5xxLibSVIFI0d8c23v+kG7h7juVmhe62OHRo7a41BF+BYIpwNuRToMF27Rrbr1LK3nsJQ7IxJs= 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 1578670904047106.68416775666844; Fri, 10 Jan 2020 07:41:44 -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-60-NWPF5DUqPn6sc8_wYvE_RA-1; Fri, 10 Jan 2020 10:41:38 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8AF71B2102; Fri, 10 Jan 2020 15:41:32 +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 64188271BE; Fri, 10 Jan 2020 15:41:32 +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 2309D503DF; Fri, 10 Jan 2020 15:41:32 +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 00AFfTWR022292 for ; Fri, 10 Jan 2020 10:41:29 -0500 Received: by smtp.corp.redhat.com (Postfix) id E367178E8E; Fri, 10 Jan 2020 15:41:29 +0000 (UTC) Received: from domokun.gsslab.fab.redhat.com (dhcp-46.gsslab.fab.redhat.com [10.33.9.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F08480610; Fri, 10 Jan 2020 15:41:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578670902; 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=/6EzatCFsA/gv415s33ERbKjuYHBO2BIRklSTxNCesw=; b=I/jd5zIVUdyAT6sN4j9gNrTt6umRXIS0gUHUKokAUc4rJpinSB8hTWO9vteNp4twlMRYWu cJXp02bhfBMNGvjwcJeAlTdYOI6NJupca6lkJwMiv9CEbvD2iwZcspjNXQJaTn4BP3vrfi AzYrWykPrzKSxNrvZOUuq8eY1vsRnl8= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 10 Jan 2020 15:41:13 +0000 Message-Id: <20200110154116.3055969-10-berrange@redhat.com> In-Reply-To: <20200110154116.3055969-1-berrange@redhat.com> References: <20200110154116.3055969-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 Subject: [libvirt] [PATCH 09/12] src: replace verify(expr) with G_STATIC_ASSERT(expr) 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.23 X-MC-Unique: NWPF5DUqPn6sc8_wYvE_RA-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) G_STATIC_ASSERT() is a drop-in functional equivalent of the GNULIB verify() macro. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Pavel Hrdina --- build-aux/syntax-check.mk | 6 ------ 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 ++-- 35 files changed, 63 insertions(+), 74 deletions(-) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 2bbadd426c..7d5597e028 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -1635,12 +1635,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 686b7cfcc2..dad3cf757c 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 da0c7a257f..0867116096 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 d6b1e9f00c..d01b4eb76f 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 995d463266..9fd49161ce 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -1332,7 +1332,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, @@ -1369,7 +1369,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, @@ -1436,7 +1436,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, @@ -1503,7 +1503,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, @@ -1570,7 +1570,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 a0fd7618ee..beb890a7f4 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 "nonblocking.h" @@ -76,7 +75,7 @@ #include "virstring.h" #include "virutil.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 358067dce4..a74817cd91 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -13478,7 +13478,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 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 12:19:07 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=1578670913; cv=none; d=zohomail.com; s=zohoarc; b=XK5fEaUSynVwzamGqjOgZq/aTUJ25Lxmff4YuzQQk3juet0wBlOwiqSq+k9Re+Ycsc2Dt09dmgW6AqM6iwqBePGLTFHtiWWV7KUZlCnSTTThUmpQOhsk8kanzC4ZXF+vBjmG+Px3reV5NyFfUKOiRPOJTA0fUMJ4RNCx5GCh/jA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578670913; 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=Q2TItZYrR/mroLFtWw3vR6zWOh+0TUBZuJ1TPHv5D2Y=; b=HKJPpEh++h7wVRdAnfIvmNmOqCmqMV4g/b/ZrWWcgGzK4iiQHmQdJkGSK2bi1Xjg1kzMb0/kxv6g/LDOQFIY8J3d70q3cFiAqP5QpGXN4D7WR32W7Tdq0WkC4JetoDyt9zWSn2MjdEEa374jmIe9CxWFgYR1MDeyhredqWUIbFU= 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 1578670913874794.3171256682732; Fri, 10 Jan 2020 07:41:53 -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-292-wOHt7uWWN2Ojpz1VoZiDzA-1; Fri, 10 Jan 2020 10:41:50 -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 5C444189CD15; Fri, 10 Jan 2020 15:41:44 +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 38D035DA76; Fri, 10 Jan 2020 15:41:44 +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 D34FF18034EF; Fri, 10 Jan 2020 15:41:43 +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 00AFfUOX022300 for ; Fri, 10 Jan 2020 10:41:30 -0500 Received: by smtp.corp.redhat.com (Postfix) id C649B78E8E; Fri, 10 Jan 2020 15:41:30 +0000 (UTC) Received: from domokun.gsslab.fab.redhat.com (dhcp-46.gsslab.fab.redhat.com [10.33.9.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3521480630; Fri, 10 Jan 2020 15:41:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578670912; 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=Q2TItZYrR/mroLFtWw3vR6zWOh+0TUBZuJ1TPHv5D2Y=; b=C7IHHgRP8PAIaPownpPpkFPHI0BvfEWJH3pDFwl3nkl/YPkatKNHIwDdUM3SfRQdQie54I R3QndXx1AQHOToNnBPU9kI2LqnUUc8jgvR04k6CjL+H+PZo/OzoP5UFAxmVzTWwXBpPraI hDHS4sEE03dV+L4PSOf9jMmqlqPM+OA= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 10 Jan 2020 15:41:14 +0000 Message-Id: <20200110154116.3055969-11-berrange@redhat.com> In-Reply-To: <20200110154116.3055969-1-berrange@redhat.com> References: <20200110154116.3055969-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 Subject: [libvirt] [PATCH 10/12] src: add check for termios.h and conditionally include it 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: wOHt7uWWN2Ojpz1VoZiDzA-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) The GNULIB termios module ensures termios.h exists, but this is not neccessary and libvirt doesn't use any of its functionality on platforms where it is missing. It is thus sufficient to conditonallyinclude termios.h Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Pavel Hrdina --- configure.ac | 1 + src/util/virfdstream.c | 4 +++- src/util/virfile.c | 4 +++- src/util/virutil.c | 1 - tools/virsh.h | 1 - tools/vsh.h | 4 +++- 6 files changed, 10 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index 3e5032a8c4..5e75688658 100644 --- a/configure.ac +++ b/configure.ac @@ -398,6 +398,7 @@ AC_CHECK_HEADERS([\ sys/sysctl.h \ sys/ucred.h \ sys/un.h \ + termios.h \ ]) dnl Check whether endian provides handy macros. AC_CHECK_DECLS([htole64], [], [], [[#include ]]) diff --git a/src/util/virfdstream.c b/src/util/virfdstream.c index 719185d992..4d17dd0353 100644 --- a/src/util/virfdstream.c +++ b/src/util/virfdstream.c @@ -31,7 +31,9 @@ # include #endif #include -#include +#ifdef HAVE_TERMIOS_H +# include +#endif =20 #include "virfdstream.h" #include "virerror.h" diff --git a/src/util/virfile.c b/src/util/virfile.c index 14bfd3beb6..0a743c8c3b 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -27,7 +27,9 @@ =20 #include #include -#include +#ifdef HAVE_TERMIOS_H +# include +#endif /* !HAVE_TERMIOS_H */ #ifdef HAVE_PTY_H /* Linux openpty */ # include diff --git a/src/util/virutil.c b/src/util/virutil.c index beb890a7f4..6d1a914ae3 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.h b/tools/vsh.h index 960cae8df0..75272c2c97 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -23,7 +23,9 @@ #include #include #include -#include +#ifdef HAVE_TERMIOS_H +# include +#endif =20 #include "internal.h" #include "virerror.h" --=20 2.24.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 12:19:07 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=1578670989; cv=none; d=zohomail.com; s=zohoarc; b=YHnyTy3WznwDsQffk0/1/qY6ljRNjp+1XaIIJvUVbWvqsWGaNzQ5ccEE9zK/VQU1w99l8oy9hqR7j+Cjvtk63JuqWVqjJRiSnIrWOnSQIDMfE++3HyFGrbDbfdcHTY0RwwvddgvNBfCtC6Qpjg5SUXmRIBkuxU3Xs/CHmO913kk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578670989; 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=UDozvUUYiyv8CHW8x83ft3Y4/havPR1H9dyNA26/lR4=; b=YuhEzdubD3Wf/85T64XlntH5mqn4KyQikjHlWqQmWPgFxj/srNDPOKB2OmUJNBfh9gKEdQM7lXQyf1D9gs3JdqbAtfqzQAm9aA2d2v0X+y1pbUOV3BiLLGGOMPtyrAdWWXLF+XM3bs5m27yue4fwtRZtCfjcgJVSU5OLx+O0BfQ= 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 1578670989644442.21755013546465; Fri, 10 Jan 2020 07:43:09 -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-371-GWJ8YlfANuStzDcvC1P28A-1; Fri, 10 Jan 2020 10:41:53 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B767D800D4E; Fri, 10 Jan 2020 15:41:47 +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 8F3D6272A7; Fri, 10 Jan 2020 15:41:47 +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 49EF381C99; Fri, 10 Jan 2020 15:41: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 00AFfVQf022305 for ; Fri, 10 Jan 2020 10:41:31 -0500 Received: by smtp.corp.redhat.com (Postfix) id A8BC978E89; Fri, 10 Jan 2020 15:41:31 +0000 (UTC) Received: from domokun.gsslab.fab.redhat.com (dhcp-46.gsslab.fab.redhat.com [10.33.9.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 180AE78E77; Fri, 10 Jan 2020 15:41:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578670988; 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=UDozvUUYiyv8CHW8x83ft3Y4/havPR1H9dyNA26/lR4=; b=SrVDlL5RbU6XTpyxmOIf84+FQztNBJhh2qJ7U9TmBtoV3z6RqpLMaI9Os7e1ifDUE6Fhdt QRIxp5zgrccSkYYf8vatJiHKghuVc26KqtnYgaSRLlg893BxkYBJMb+IUqQLZy+wDaE3SS 3GwMHbGlWzifu2F59r62/8s9cYp2ZvE= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 10 Jan 2020 15:41:15 +0000 Message-Id: <20200110154116.3055969-12-berrange@redhat.com> In-Reply-To: <20200110154116.3055969-1-berrange@redhat.com> References: <20200110154116.3055969-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 Subject: [libvirt] [PATCH 11/12] src: replace gmtime_r/localtime_r/strftime with GDateTime 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.23 X-MC-Unique: GWJ8YlfANuStzDcvC1P28A-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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 Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Pavel Hrdina --- 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 1290241923..a582f5f79e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -26784,11 +26784,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 d01b4eb76f..0801959465 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4091,9 +4091,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) @@ -4101,10 +4100,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 e224b70293..27428e18fd 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -1535,17 +1535,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 a74817cd91..397fa847d6 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 a36b6bfe23..eeb9659ef9 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2197,8 +2197,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; @@ -2208,15 +2208,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 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 12:19:07 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=1578670914; cv=none; d=zohomail.com; s=zohoarc; b=hr7tFpMM1h/WM3bloOxqCrD6Wc8uAeIcULVFCBBancx+ctbh4LEPsP8K3Yl2AZ/1Yk1X3Ne6Dxnc8aLOXABM5E7kg7KA4aO8Adm3rC30beLQXnsRTE52UVwVlfiGacyYSdPvjrmaC23ynyFjGrY5zVjop3iBvll5O5N/T3oM+7I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578670914; 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=AamLr3qruxNC9ireI0jgSm+97JGzYGNby+Hmn2I5tFI=; b=d/6u6PKFPY6H9TBk3TMGQAsAZZkg/dKUyflQ6Iof6mdlN8IgW9E+4XxofnTNCfS5iT8ew/PybEfIU3q6zQHel1aA3l2k0FqoAu4Nq4t7bJDJKCWj00xyFrg9x6HOZZUCAfjaNYszjfd+HyHv6URSYYQXtGPw4CCfaTUq0opddDw= 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 15786709141981004.9756057102405; Fri, 10 Jan 2020 07:41:54 -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-159-Nrdva5qdODWvvVoygR5tYw-1; Fri, 10 Jan 2020 10:41:51 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C7C041005514; Fri, 10 Jan 2020 15:41:45 +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 9B619272D1; Fri, 10 Jan 2020 15:41: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 5BB5181C7B; Fri, 10 Jan 2020 15:41: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 00AFfWuE022314 for ; Fri, 10 Jan 2020 10:41:32 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8C1A478E8E; Fri, 10 Jan 2020 15:41:32 +0000 (UTC) Received: from domokun.gsslab.fab.redhat.com (dhcp-46.gsslab.fab.redhat.com [10.33.9.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF67378E77; Fri, 10 Jan 2020 15:41:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578670913; 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=AamLr3qruxNC9ireI0jgSm+97JGzYGNby+Hmn2I5tFI=; b=N0rws+Gztkyz1o6pTlLCUTMphzR74PTL9NPm36yDIhZOGalIeXIIdJsaAnuakYZ4iecKX6 KFVy1Uguz9IOrCBy9med1t2nrEb3wCLAEiREvLpXFcftVtiPAN8pedPKtRhlruAZYV1qD+ Yc+VY4IQjBMvG2CSGuH7Vuiyhu19Tak= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 10 Jan 2020 15:41:16 +0000 Message-Id: <20200110154116.3055969-13-berrange@redhat.com> In-Reply-To: <20200110154116.3055969-1-berrange@redhat.com> References: <20200110154116.3055969-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 Subject: [libvirt] [PATCH 12/12] bootstrap: remove 25 more gnulib modules 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.23 X-MC-Unique: Nrdva5qdODWvvVoygR5tYw-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) * 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 gnulib code has been imported * 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 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 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list