From nobody Mon May 6 20:17:59 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=1571392371; cv=none; d=zoho.com; s=zohoarc; b=K1lNWjvnZdWnrsyr1T7/V6sB68q/y9lH10VGZeLAlpt3y9aHv5IKRAgcX0KRHjuR0RddL9+JnKOPwlkkwBZydFgn392pE5F9S1snlAi1rw7ltP6x2hmZkAtGdHjF613OZducdCMgZt7DsFW9Uy2E/H09wgkpgeAHklhZ4+jOJAM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571392371; 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=pVPalwj3oC1biN1Oj+rmBty39NnF4VgAtR5zHd62nk0=; b=ibDdQbYZ1tIb/XzL4qKKL0ODusCyjclFVkjKXNIRbbp3MOfVK9v++Qi83SKQC1op2rzjjSkpYj6KtUHTKLGJtChbro/oVZwtbZ6KZZL2A5FJtU0YOYQShL3Bn5xQTupHSgo8nBbdyyDACz4c24op80FK6KHpGAo3wbUdV4DOFis= 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 1571392371039505.37033122153264; Fri, 18 Oct 2019 02:52:51 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2702B2B89; Fri, 18 Oct 2019 09:52:48 +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 2A2C25D71C; Fri, 18 Oct 2019 09:52:46 +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 9E8DE180B536; Fri, 18 Oct 2019 09:52:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9I9obCk015494 for ; Fri, 18 Oct 2019 05:50:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id A7C8B5D713; Fri, 18 Oct 2019 09:50:37 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 31DC95D712 for ; Fri, 18 Oct 2019 09:50:32 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 18 Oct 2019 11:49:05 +0200 Message-Id: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2] 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.71]); Fri, 18 Oct 2019 09:52:49 +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 --- v2 of: https://www.redhat.com/archives/libvir-list/2019-October/msg01153.html diff to v1: - moved the code to src/utils/glibcompat.c src/internal.h | 1 + src/libvirt_private.syms | 5 +++++ src/util/Makefile.inc.am | 2 ++ src/util/glibcompat.c | 48 ++++++++++++++++++++++++++++++++++++++++ src/util/glibcompat.h | 31 ++++++++++++++++++++++++++ 5 files changed, 87 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..af638f4d8c --- /dev/null +++ b/src/util/glibcompat.c @@ -0,0 +1,48 @@ +/* + * 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" + +/* 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