From patchwork Wed Jan 29 12:30:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 105611 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A61D33857BB6 for ; Wed, 29 Jan 2025 12:31:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A61D33857BB6 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=b/udMXDZ X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id C44943858D34 for ; Wed, 29 Jan 2025 12:30:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C44943858D34 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 C44943858D34 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=1738153845; cv=none; b=jAmn6GRpE/WvSQZRGhV+RPT5phxWGQTyB3ewuWPMBPVtO3yXRRK97PVJRhJyqiqilpaTFSXLJl8nI0TA3SGlwXZiyrQomvyBQNIrSJV+AvDjQz2Gtb1mL2am48ieTQaMgllQrY5W4njuNyPY+z6c1kJLXQ1xvPgVbiHk+O9fHwk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1738153845; c=relaxed/simple; bh=TIPTU8RfzOf/RPzgg6flLvLPi9XJq+89EjgSAzzeIqc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=v3xP/fXQ22jfkovxhpuWWZdI+Wn4MnHm3u8vy3O9t4N0FUWfR8De2pwnmFu1kSs8coJVIaW3zllfjvcRU+YJwnkZmwsXJLib2fUGFDjryKx7NaHeUg87WT+b+00b/i3f+K+AC41fQOH+ZF+bLxpC/MeRr4psIl4QLfSt4nFj+uI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C44943858D34 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738153845; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=vUuEvadOGq6DZ5/svboGWUaRZFgT4Jz9j3bMGi76MMs=; b=b/udMXDZDLxK91ZzGQlMrb+oCvuCJmZ0GG+j+AcGcd1CXTCJXH6r8MuYVAbpXuMYoF7fXZ WLqboDVfuOPa/M1BTitDYaBZevQzVjMfN/fUXyZcdykEPTR/PpqVXwmZIyd5SUXkK3NGEC ClH8HfGNDzdfiia7d0ATW+eKjdKGQQw= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-355-dXa3yjlUMy6dbDbq9eEPwA-1; Wed, 29 Jan 2025 07:30:44 -0500 X-MC-Unique: dXa3yjlUMy6dbDbq9eEPwA-1 X-Mimecast-MFC-AGG-ID: dXa3yjlUMy6dbDbq9eEPwA Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 43242180036E for ; Wed, 29 Jan 2025 12:30:43 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.12]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7797F18008D8 for ; Wed, 29 Jan 2025 12:30:42 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH v3] manual: Describe glibc's limited linked stream handling Date: Wed, 29 Jan 2025 13:30:39 +0100 Message-ID: <87ed0lhkeo.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: jJ9XNr9WP4oh1MFwq3TdGyalBd8YnQMvZt4Gn0Yk9gY_1738153843 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org The implementation was changed in commit 3d759cb8d32614667f58688899f, but the manual was not updated. Warn that linked stream handling for stdout may introduce deadlocks. --- v3: Fix typo identified by Andreas. manual/stdio.texi | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) base-commit: 5429bae110e2f094482b3f7974b3ce9b4bfdab57 diff --git a/manual/stdio.texi b/manual/stdio.texi index 01b9f478dd..16b759e57c 100644 --- a/manual/stdio.texi +++ b/manual/stdio.texi @@ -513,6 +513,13 @@ themselves would ensure only atomicity of their own operation, but not atomicity over all the function calls. For this it is necessary to perform the stream locking in the application code. +@strong{Portability note:} @Theglibc{} may attempt to flush the +@code{stdout} stream when input occurs on another stream. +@xref{Flushing Buffers}. If @code{stdout} has been locked using +@code{flockfile} or @code{ftrylockfile} while reading from another +stream, a deadlock may occur. @Theglibc{} does not implement the +deadlock detection that POSIX recommends for flushing linked streams. + @deftypefun void flockfile (FILE *@var{stream}) @standards{POSIX, stdio.h} @safety{@prelim{}@mtsafe{}@assafe{}@acunsafe{@aculock{}}} @@ -4805,8 +4812,24 @@ When the program terminates by calling @code{exit}. When a newline is written, if the stream is line buffered. @item -Whenever an input operation on @emph{any} stream actually reads data -from its file. +@c See the stdout reference in _IO_new_file_underflow. +When reading from a line-buffered or unbuffered stream and the stream's +buffer is empty or becomes empty, and the stream being read is the +original @code{stdin} stream at program start, or has been created using +@code{fopen} or @code{fdopen}, a line-buffered @code{stdout} stream is +flushed if it is the original @code{stdout} stream or has been created +using @code{fopen} or @code{fdopen}. (The @code{fopen64} function +counts as @code{fopen} in this regard.) That is, reading from a stream +may implicitly flush the @code{stdout} stream under specific +circumstances. + +This exact behavior is specific to @theglibc{}. According to some +interpretations of POSIX, such flushing is required for all buffered +output streams, not just @code{stdout}. Other C libraries may not +implement such linked stream handling at all. A future version of +@theglibc{} may remove the limited linked stream handling described +above. Portable programs cannot rely on this implicit flushing +behavior. @end itemize If you want to flush the buffered output at another time, call