From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on atuin.qyliss.net X-Spam-Level: X-Spam-Status: No, score=-4.5 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.4 Received: by atuin.qyliss.net (Postfix, from userid 496) id D8C1415453; Wed, 10 Mar 2021 22:43:31 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by atuin.qyliss.net (Postfix) with ESMTP id 073AB1543E; Wed, 10 Mar 2021 22:43:23 +0000 (UTC) Received: by atuin.qyliss.net (Postfix, from userid 496) id 3B6141542F; Wed, 10 Mar 2021 22:43:21 +0000 (UTC) Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by atuin.qyliss.net (Postfix) with ESMTPS id 2A3B41542D for ; Wed, 10 Mar 2021 22:43:19 +0000 (UTC) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 855A45C01A2; Wed, 10 Mar 2021 17:43:18 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Wed, 10 Mar 2021 17:43:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alyssa.is; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=tdcSt1+pAlG1Hml84bPgqVed/6y hpM2esEAyCHnnyTA=; b=fktkTkHyf3c73L2KI3en+Au0j6YXqnaMI4o4bSYqiox SYjgJQ/LOsWaQy/rXfplUEQS2uCVfOrAMVuEW2wnntuyZR2i86GnzUY+SyvSZ+yJ bCEbfMMxz3ix/iHXm9K4XlSBVRDWw/YWKd/KPgUKIZQjNVgLj5HVQ9GwR5wkDlg/ 0+Hk8eXCQccneMatNyyJKHiH4SJcbRenohIRH402fugmv8YATmJK75wM0etsP9AR cZyXW3ZT5+pIwLQHeyQMtPGLqSltMokva6tIzDQHHCKlRbJzfOelzxyw95ZZ+UGI PkJbs3v/Grf3Qy4znz/xC9s7T213/2vDdnMsaJFA+Qw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=tdcSt1 +pAlG1Hml84bPgqVed/6yhpM2esEAyCHnnyTA=; b=G9yGe2qu8+4kh0I8eDMcWG mxLYNJnOEjroCaFwyh9AUZF3/CnYJKnBwvu1JD2179PNRlPb7Ai9cbDgt7Q0z+oI 3rqWKLCJu2qXT8K4/+2YqFBd16ShWIIXWyaqOiA3DvxpYb83CX6+6YTHSRrO3dvg suAHC2RKVSYpaxrRCglv+Tk2Lt4gUu5XCayjeLdDXw4Icl0KYsNpje0dzdYSUoKz rs8zgeuyRaVelwK1qyPjxFr41AtOY1ke174c8UXvllQWt0tAadtyLvxcIHOUgwqr AjLDO7l7yueqgrw2wITEOA19dzlbegIzOHOsS+scQcFRbd9Lnc2NwY5eT/efX0dA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudduledgtdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehgtddtredttddvnecuhfhrohhmpeetlhihshhs rgcutfhoshhsuceohhhisegrlhihshhsrgdrihhsqeenucggtffrrghtthgvrhhnpeeuff egffdtvdffiedttefggfehtdfgudfhfffgteefgfdugeegveffieffudduvdenucfkphep keegrddukedurddvheehrdekheenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpehqhihlihhsshesvghvvgdrqhihlhhishhsrdhnvght X-ME-Proxy: Received: from eve.qyliss.net (p54b5ff55.dip0.t-ipconnect.de [84.181.255.85]) by mail.messagingengine.com (Postfix) with ESMTPA id 0FD2424006A; Wed, 10 Mar 2021 17:43:18 -0500 (EST) Received: by eve.qyliss.net (Postfix, from userid 1000) id 1C8F7EAB; Wed, 10 Mar 2021 22:43:16 +0000 (UTC) Date: Wed, 10 Mar 2021 22:43:16 +0000 From: Alyssa Ross To: Cole Helbling Subject: Re: [PATCH ucspi-vsock] vsockserver: use fclose instead of close Message-ID: <20210310224316.hbtujxmcyvd2ophq@eve.qyliss.net> References: <20210309154048.14474-1-hi@alyssa.is> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="5i6tjbtxge4hsx6a" Content-Disposition: inline In-Reply-To: Message-ID-Hash: M7JBFFFQ5I7SAV2UYQ3FGDXZGTMIVWVY X-Message-ID-Hash: M7JBFFFQ5I7SAV2UYQ3FGDXZGTMIVWVY X-MailFrom: qyliss@eve.qyliss.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: devel@spectrum-os.org X-Mailman-Version: 3.3.1 Precedence: list List-Id: Patches and low-level development discussion Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: --5i6tjbtxge4hsx6a Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Mar 10, 2021 at 09:41:01AM -0800, Cole Helbling wrote: > On Tue Mar 9, 2021 at 7:40 AM PST, Alyssa Ross wrote: > > stdio can buffer output, so if we close stdout without going through > > stdio, there might be buffered output that is never written. > > --- > > vsockserver.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/vsockserver.c b/vsockserver.c > > index dd9a74a..196056a 100644 > > --- a/vsockserver.c > > +++ b/vsockserver.c > > @@ -90,7 +90,7 @@ int main(int argc, char *argv[]) > > > > if (notify) { > > printf("%" PRIu32 "\n", lport); > > - close(STDOUT_FILENO); > > + fclose(stdout); > > } > > > > setenvf("VSOCKLOCALCID", 1, "%" PRIu32, lcid); > > -- > > 2.30.0 > > I don't write much (if any) C, so I never knew there was both > STDOUT_FILENO (as an int) _and_ stdout (as a FILE*). I suppose the most > important part is that fclose() uses fflush(3) under the hood to make > sure we actually write everything. Yeah, C on UNIX essentially gives you two different IO interfaces (open/write/close/etc. from POSIX, and fopen/fprintf/fclose/etc. from stdio in the C standard library). The POSIX stuff doesn't know anything about the buffering that stdio does on top of it. Mixing them is probably never a good idea if you're not doing it very deliberately. --5i6tjbtxge4hsx6a Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEdZTIUP7JZVWM3Ir2XDnhXb2v5OUFAmBJS4MACgkQXDnhXb2v 5OVskxAAkqvkw8GpySsZKwtmALz/YfkI7gKeyNbfSbWasPdBIlArkusHhHEZ9Dt/ plbrCpTk9hWDKP4wBexSBpRIXyFqem2ZHBYv25nJkaAN8sP3CE8Kb9YqdTz0c4Sh u5/iV3ARwanfENE8tfUalW7HQ2WaZRDc9VQ7HC8xdMntpEeXn91uod1Af0eCSphZ sc0B/MQYHL/KgMzVMyTAivXvx44Dl6HMMA1oZT6TPJ9p0S8s2Ef304ZMEHcaGdVt pFRBbV/ckw0coVudpSPYm3ZlfjZrN4bZws0MLDjlxiFf5oM7aec38X4AMJhbXbeY jAfKjfRkXNFJ7vTHSNZXT1/U/iyxbWAOdUiuYlzy5keuxk0+Xn3+vqamfsUXxML7 KxiYl7Hfz7kcW8rhrz2bZ7SHSignlpuXvhADqVpHVubSa2eTCQ+gev2lKzc4balP 1BNBV7+gCGVc9nroc+7MA+3ZhQHS1QB669Wzm1PgK1O/qYdc6nKoFQPyBnfroSdp eTKF8rJRNDEATQ9i8+2Y2uQTHfxOiAOlr4xQ0LVVemaSNx/l9Adq/jF1TOkqZf0c NIp2mbBHOHJUuxGw9Z5qc7wnvE6yYQAO9Jsx1CW8QasaQT+epjU2p+fWitJg+ceU 0e7XGFaRfkXrD+2sMiWrrg0grHB6UepwO1bkQttYW1oHEc/khoc= =D+RR -----END PGP SIGNATURE----- --5i6tjbtxge4hsx6a--