From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 5DEF53864802 for ; Thu, 15 Feb 2024 13:02:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5DEF53864802 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5DEF53864802 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708002168; cv=none; b=JgfC95xHIlqugZUqYgg8j74m65N+0GG++TZ6RLW+xtVfVEPm9x02OV8MKoxi9LkYeJl8ff3FXYZfFVUeOpB/IsinQ2gq6ygTT4mFOd/+/ASX2jyWgFwsJXypaTSL/xv2I/sY63beE3w/0GClzk2gBKMY/Pi46GSL9mpyTD7EBDY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708002168; c=relaxed/simple; bh=CAeFa65uemo/EncOnFqMZNQjuvBPRIZb2/rshH9aU1E=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=xeA2hUQTOiWVe9P+EDxxv7Q1t0Ku5ACsCdPFldBPAqi9fE9qB19BdUheWuZiCE3pDAbIM091yyIC7Jdy64KFPYIZPAXGW8yFJ5PGEHkFE+Tr3nN1e0gnaVOOwIaxutOTM4mlwZfUgJE5U6+tFGLqXE549FGKOIksOJBNWd3SUvI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708002158; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=glLAQELR7KZEWuWHDAspc3OAL7UXv+vD3G1BYu0qsLA=; b=ecy268bsVJhBe4O7hdaxfpH5rxzCRQ4CQSCfpXTu1G6lFcf8vfc7CgHPKJ5TKHcSgR60yz qsY6+UppbQH54yscC2mi2Dkycw3KHYvGl/YEYexBnm4lCi+LDONApQMQFPhhWqtCsgr+t3 Xh59ixUSXJ39BvucHs5PHVK8q8GgGXE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-479-8lth6wMBNqSsFzCezSEhpg-1; Thu, 15 Feb 2024 08:02:36 -0500 X-MC-Unique: 8lth6wMBNqSsFzCezSEhpg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 558DF108C0E3; Thu, 15 Feb 2024 13:02:36 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.50]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7C74AC185C0; Thu, 15 Feb 2024 13:02:35 +0000 (UTC) From: Florian Weimer To: Adhemerval Zanella Netto Cc: libc-alpha@sourceware.org Subject: Re: [PATCH 11/11] syslog: Use a printf buffer directly to construct the entire packet References: Date: Thu, 15 Feb 2024 14:02:33 +0100 In-Reply-To: (Adhemerval Zanella Netto's message of "Wed, 14 Feb 2024 12:16:49 -0300") Message-ID: <87cysxc23a.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.3 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: * Adhemerval Zanella Netto: > On 09/02/24 12:26, Florian Weimer wrote: >> This defers buffer management largely to the asprintf implementation. >> It is quite close to the original implementation around >> open_memstream, except that an on-stack buffer is used for shorter >> messages, and that strftime no longer writes directly into the >> buffer. >> >> The new version no longer uses the (slow) %n format specifier. >> It also fixes an issue in the localtime_r failure path, where >> the message is prefixed with ": " due to an incorrect placement >> of the %n specifier. > > What I am not sure if this is really the direction we want for > internal FILE usage. I had the impression that the printf buffer > internal API was mainly meant to improve the old FILE implementation > and its historical drawnbacks and limitations. For internal usage we > would continue to use standard FILE API, should we move to always use > printf buffers instead? There are currently no internal uses (that I can see) of _IO_strfile for writing purposes. The psiginfo function uses __fmemopen, but that seems excessive. The syslog implementation was the only user of open_memstream. The reason for the open_memstream removal was allocation removal, which makes sense for a logging function. We must have manual constructs that use some printf function variant to write to temporary buffers elsewhere. One example is stdio-common/psignal.c. I can't find others outside sunrpc/ right now, but they likely exist. Switching those to fmemopen/open_memstream would introduce the allocation issue as well, and dynamically sized printf buffers could be a replacement. I know that musl uses its _IO_strfile equivalent in such cases, but our libio implementation is much more heavyweight, and it's hard to review if new direct low-level uses of the libio internals are actually correct. > I am asking because it is a lot of code and refactoring for a specific > code that I would like to avoid change due the recent issues. Most of > complication is the static buffer optimization, so maybe we should just > remove it? Pretty much all buffer management code is deleted. We now have even fewer code of that than in the previous open_memstream-based function. > Also, since the motivation for this change is just to remove the %n > requirement, maybe we can just not enable it on syslog instead (since > we now that the internal calls should not act as a gadget)? That doesn't remove the complicated buffer management. Thanks, Florian