From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by sourceware.org (Postfix) with ESMTPS id DDBBE38582A5 for ; Fri, 16 Feb 2024 13:36:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DDBBE38582A5 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DDBBE38582A5 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1033 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708090563; cv=none; b=KnYP70Zf3oIF86A7AcWjYZwSK+VP8G4vXOmS/+uOZLt+kIKTJZGCZw5aPg43v1rvm0VJxVKeyTw5etobAvGEa3sP3E7nK/73rkr7yPQX1RRUiZ4Cn8oXfLS2PcRdZDkwBzGVOn/uyUC/JJSe28IVWxc7eXfznwmlqB0d9n36jOE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708090563; c=relaxed/simple; bh=o7PQNpT3LCIfeYHktGzsrtp2q9hP4i6/MkrltNwveLE=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=H1uRWLeFYvZfbzaGe4AzAmTcH/YO5zdlHbmDNLDL6ue7xffn01sWYiecBxu0TEKO+TaPUebiKn/0oPj8/K0i/UvZdw9V4ZJhmnsVXh4iQ5uGi4aaaC41wK5p/7AXrUQDChK42+J3sUCAqVjW4IOFJ5YZoQAefiO+JW+AzH0djf0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-296dcd75be7so1654346a91.2 for ; Fri, 16 Feb 2024 05:36:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708090561; x=1708695361; darn=sourceware.org; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=kwBggxLAZqM6HTxFztwPRWezWu/hMOJMGmmfuA2TCiY=; b=OV1biSODZ11gczyhjvgOC9XH/2l4n+Zis2Q8CjaAbdR9CXrns0Q1nRPVXncxb9L99k gSVR0v6V0A4q3v9EqTIoXCDRbU9mmSJ35XuvH6xjgyLAaTkRfzQwuV+tqiWEbuE4bIxg WSsi5nmIFxFo0QnARLaKX6SbUVhM1mnJV656pP+Grtzz8h42gelIct3a9F0+D7QPzVEh PtI+4ZvEpB8pojmCRCwtyGliNcrkyijA/On0Mt0yvoYmKEcNJJU/B1GwlWSsPkKVmwI9 GLB7tBpiVeuHSw9VrtvvYVt0a/p9z0qWE2DVmJumPi1XuFUfDaWRu7wgyJS1iGlxCXBg niuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708090561; x=1708695361; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=kwBggxLAZqM6HTxFztwPRWezWu/hMOJMGmmfuA2TCiY=; b=vkTeWbImNUjc0cV1ls/7G72tEQ+oFbS+icjwnkc76HGuHRhIqtdKbnt3OjtHPc/OTM wpgstMB5kGIDskHfGt+dX9kGsqyInAwLwtHnOEyuLc8UNpzmb60VQWDiHXxzZYERpJDJ fwAft66wUKiexK3lndnHE9Un3sAUoNWOB9CgGLJDI3vPa6RV7WI1nMqzkcKdjA3Ckvzg EwFoTyzRWn1QCuiY+CydDzV+0DpNGpPSa7N/FcaTDsA+SjP8D8x1dxUWqQioK0e3Y+rn a9a+YBhr/5pwVDIZJES/LcVMsGGdx/pluuk5EUeB4Ft5jdXAwJsWWaOuV02lCi68hgqZ 8lMA== X-Gm-Message-State: AOJu0Yz86bQp2POggIXJd0HEbpyiwlbTqQTykhtwlSxbUz36ggrf+SXM EjC3vElSUKfwqXOBw9sa/cCODOwYW4C/b4OICUgn2jmeJmjjhLEOnO91y8QCsxvLB55y1iZJJe6 q X-Google-Smtp-Source: AGHT+IHa69cyP9b0OhH8HNA/CLrzC0hjVK1hK4wMM6/KK7j+vzZEagqr7sDZyFk7LXhTUvjezBsb/Q== X-Received: by 2002:a17:90a:d497:b0:298:aad6:2da4 with SMTP id s23-20020a17090ad49700b00298aad62da4mr4422460pju.1.1708090560830; Fri, 16 Feb 2024 05:36:00 -0800 (PST) Received: from ?IPV6:2804:1b3:a7c0:8177:542a:9f26:15a9:5ce4? ([2804:1b3:a7c0:8177:542a:9f26:15a9:5ce4]) by smtp.gmail.com with ESMTPSA id v18-20020a17090ac91200b00299332505d7sm1471252pjt.26.2024.02.16.05.35.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 16 Feb 2024 05:36:00 -0800 (PST) Message-ID: <42c1cdcb-e96b-47ce-a483-cc07b0ed60b1@linaro.org> Date: Fri, 16 Feb 2024 10:35:58 -0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 11/11] syslog: Use a printf buffer directly to construct the entire packet Content-Language: en-US To: Florian Weimer Cc: libc-alpha@sourceware.org References: <87cysxc23a.fsf@oldenburg.str.redhat.com> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <87cysxc23a.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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: On 15/02/24 10:02, Florian Weimer wrote: > * 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. For unbounded messages I tend to agree that fmemopen/open_memstream might be not the best option. I would like to avoid having a another internal API for such cases, but it seems that printf buffer is a slight better option indeed. > > 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. Right, the resulting code does seems simplified.