From nobody Tue Apr 30 04:22:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1571402456; cv=none; d=zoho.com; s=zohoarc; b=X61YED8mKzdMPJm0gM/25CoxRtuKE/F69tgbcrkHBGkjweueOxQn5y75s15bj/sIqPqsK8Ad/zFYgXUpt5KNUCdMPpdu9k5uDBPQJSohNLYWY8cQjOtQFC35+Ti6bi04OHx8HSV4rw2XU9A1akG+Ek+PVcwilJ8z4XSq1zEkibo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571402456; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=kt6hCb71HMjRO4RRESpuhhWGR50hBnIDScjkaIh4CSM=; b=A8kBj3XAh+hB6jJc8zePFORyEj8uxp4/uV/uTc+dBFGR85JpFosQuW+4MeyQ0tQwUvke4ms3XA/v4odaOFWqQC/tFHrYl4DWGXvsdji54/XQwikwF5E9CV6r+lY88B8G80wauCdColLYLiZF6HeMv4dEpCRwlf+GAGlxNROUoeI= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1571402456725233.5980718645269; Fri, 18 Oct 2019 05:40:56 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CAC9410DCC99; Fri, 18 Oct 2019 12:40:53 +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 822AE60BF1; Fri, 18 Oct 2019 12:40:52 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 92063180085A; Fri, 18 Oct 2019 12:40:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9ICek0A024210 for ; Fri, 18 Oct 2019 08:40:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6422F5C21E; Fri, 18 Oct 2019 12:40:46 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id E182A5C1B5 for ; Fri, 18 Oct 2019 12:40:43 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 18 Oct 2019 14:40:41 +0200 Message-Id: <12b0926fe7054d8d851d26b3d976ebd54ae7d668.1571402409.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3] glibcompat: Reimplement g_strdup_printf() and g_strdup_vprintf() 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.64]); Fri, 18 Oct 2019 12:40:54 +0000 (UTC) Content-Type: text/plain; charset="utf-8" These functions don't really abort() on OOM. The fix was merged upstream, but not in the minimal version we require. Provide our own implementation which can be removed once we bump the minimal version. Signed-off-by: Michal Privoznik Reviewed-by: Daniel P. Berrang=C3=A9 --- Diff to v3: - fixed infinite recursion src/internal.h | 1 + src/libvirt_private.syms | 5 ++++ src/util/Makefile.inc.am | 2 ++ src/util/glibcompat.c | 51 ++++++++++++++++++++++++++++++++++++++++ src/util/glibcompat.h | 31 ++++++++++++++++++++++++ 5 files changed, 90 insertions(+) create mode 100644 src/util/glibcompat.c create mode 100644 src/util/glibcompat.h diff --git a/src/internal.h b/src/internal.h index fb17b87baa..5b0a2335f5 100644 --- a/src/internal.h +++ b/src/internal.h @@ -64,6 +64,7 @@ #include "libvirt/virterror.h" =20 #include "c-strcase.h" +#include "glibcompat.h" =20 /* Merely casting to (void) is not sufficient since the * introduction of the "warn_unused_result" attribute diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 0da02bb8bd..206295bef0 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1485,6 +1485,11 @@ virSecurityManagerTransactionStart; virSecurityManagerVerify; =20 =20 +# util/glibcompat.h +vir_g_strdup_printf; +vir_g_strdup_vprintf; + + # util/viralloc.h virAlloc; virAllocN; diff --git a/src/util/Makefile.inc.am b/src/util/Makefile.inc.am index 705b93c93c..d8c8e61c4b 100644 --- a/src/util/Makefile.inc.am +++ b/src/util/Makefile.inc.am @@ -3,6 +3,8 @@ # These files are not related to driver APIs. Simply generic # helper APIs for various purposes UTIL_SOURCES =3D \ + util/glibcompat.c \ + util/glibcompat.h \ util/viralloc.c \ util/viralloc.h \ util/virarch.c \ diff --git a/src/util/glibcompat.c b/src/util/glibcompat.c new file mode 100644 index 0000000000..5c50153efe --- /dev/null +++ b/src/util/glibcompat.c @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2019 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 "glibcompat.h" + +#undef g_strdup_printf +#undef g_strdup_vprintf + +/* Due to a bug in glib, g_strdup_printf() nor g_strdup_vprintf() + * abort on OOM. It's fixed in glib's upstream. Provide our own + * implementation until the fix get's distributed. */ +char * +vir_g_strdup_printf(const char *msg, ...) +{ + va_list args; + char *ret; + va_start(args, msg); + ret =3D g_strdup_vprintf(msg, args); + if (!ret) + abort(); + va_end(args); + return ret; +} + + +char * +vir_g_strdup_vprintf(const char *msg, va_list args) +{ + char *ret; + ret =3D g_strdup_vprintf(msg, args); + if (!ret) + abort(); + return ret; +} diff --git a/src/util/glibcompat.h b/src/util/glibcompat.h new file mode 100644 index 0000000000..9c5fef09bf --- /dev/null +++ b/src/util/glibcompat.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2019 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 + +char *vir_g_strdup_printf(const char *msg, ...) + G_GNUC_PRINTF(1, 2); +char *vir_g_strdup_vprintf(const char *msg, va_list args) + G_GNUC_PRINTF(1, 0); + +#if !GLIB_CHECK_VERSION(2, 64, 0) +# define g_strdup_printf vir_g_strdup_printf +# define g_strdup_vprintf vir_g_strdup_vprintf +#endif --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list