From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from second.openwall.net (second.openwall.net [193.110.157.125]) by inbox.vuxu.org (Postfix) with SMTP id 7966C21131 for ; Sun, 10 Mar 2024 14:18:07 +0100 (CET) Received: (qmail 7794 invoked by uid 550); 10 Mar 2024 13:14:00 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 7768 invoked from network); 10 Mar 2024 13:13:59 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710076670; bh=l4St2bQVWchdBCIiVFLPg+Jdjd5QwrNS/S4483ai1T0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=DhkU68yfuEDfZvJOj3LloLn0eI4+dOFe6g7ZOUJueU04JeuDzSMQAo5MxttPzgKmn o8grABbdz9m4DnWW57mkXh5tC7gJzVTKXQcYFmeH/KvCuT/hHW4gisKD4uzIHnhuwh +I/7MSkphf3AiYHlyljTb2uv6x/5tBnOjL6XFIoPlIxEB7IRRzIynMxyDLxX2+8W2W IuQrS/yEy53bw1BJWMnNDl2DbX2qttpzDMUY7+tykZASpRnrj+dCHWLi5lj+WDkmQe 4itoMQjlRuKg2m9gYT6/I9LxnuzhSnMEcSiWHGfyy/rmAiD/wZ7l3g8iwY/gbOBABd ppwWpg1oMDM9g== Date: Sun, 10 Mar 2024 14:17:20 +0100 From: Alejandro Colomar To: NRK Cc: Rich Felker , Guillem Jover , libc-alpha@sourceware.org, musl@lists.openwall.com, libbsd@lists.freedesktop.org, "Serge E. Hallyn" , "Skyler Ferrante (RIT Student)" , Iker Pedrosa , Christian Brauner Message-ID: References: <20240309150258.GS4163@brightrain.aerifal.cx> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="diFkh3sIapcVx8be" Content-Disposition: inline In-Reply-To: Subject: Re: [musl] Re: Tweaking the program name for functions --diFkh3sIapcVx8be Content-Type: text/plain; protected-headers=v1; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Date: Sun, 10 Mar 2024 14:17:20 +0100 From: Alejandro Colomar To: NRK Cc: Rich Felker , Guillem Jover , libc-alpha@sourceware.org, musl@lists.openwall.com, libbsd@lists.freedesktop.org, "Serge E. Hallyn" , "Skyler Ferrante (RIT Student)" , Iker Pedrosa , Christian Brauner Subject: Re: [musl] Re: Tweaking the program name for functions Hi NRK, On Sun, Mar 10, 2024 at 06:01:14AM +0000, NRK wrote: > > What do you offer to use instead? snprintf(3) + perror(3) + exit(3)? >=20 > No need to have an intermediate buffer with snprintf when you can just > use vfprintf directly. For an interface that prefixes the program name, I need to either call [v]fprintf(3) twice, or add locks; that is: lock() fprintf("%s: ", __progname); vfprintf(...); unlock(); or prepare the buffer and call it just once. Because I want to call it as foo("reason");, not having to use __progname all the time. >=20 > > I suggest you remove err.h from libc, and let a standalone library to > > implement them separately, allowing to configure them. >=20 > These are not mutually exclusive. You can have err.h in libc while also > having them as separate library. If I #include , glibc considers those as reserved names. | All other library names are reserved if your program explicitly | includes the header file that defines or declares them. I guess it would work, because of weak symbols, but the manual explicitly says don't do this. > And besides, these are not good interfaces anyways. Aside from what Rich > already said, you'll realize this soon when you need to use various > posix_* or pthread_* functions which don't set the errno and instead > return an error code. There's errc(3), and also warnc() (Guillem, libbsd is missing the link pages for warn*() variants!), to which you can pass an errno-like code. This isn't supported by glibc, but is available in libbsd (and of course, in the BSDs; at least I checked OpenBSD). And for the finctions that don't report an errno-like, like the gai_error(3) ones, you can use errx(3), and also warnx(3). These are supported in glibc. So these are actually quite well suited for different kinds of error- reporting functions. Regarding multi-threaded programs: If you're recommending writing a version because it's easy, but then you say it needs locking, well, I wouldn't say writing a locking version is easy. >=20 > Also, I don't think your fear of "NIH bug" is well grounded. This is not > some highly complicated error-prone code, it's just simple logging > facility. locking code is error-prone, I'd say. >=20 > I am aware that there exists certain programming cultures [*] where > having to write code instead of "import leftpad" is seen as taboo of the > highest order. But in this case you don't even *have to* write anything > when you can just copy err.c from musl and customize it. I think the BSD err.h functions are actually quite well designed for single-threaded programs (still the vast majority of software). And for multi-threaded versions, we just need to convince the BSD maintainers that they need to add locking. If glibc and musl don't consider these APIs as useless and legacy, and fix them, then maybe the BSDs follow. Again, is there anything better in glibc or musl? Something that prefixes "$progname: " and appends the errno message? Yeah, you could write fprintf("%s: ...", program_invocation_short_name, =2E..) all the time? or write a wrapper that calls fprintf("%s: ", program_invocation_short_name), but then you need to add locking? and then you need to set program_invocation_short_name =3D "su"? And then add *c() for functions that return an errno-like code? And then add *x() variants for functions that don't use errno-like codes? Oh well, you're basically writing the err.h interface. The interface is good. It's the implementation that has small problems, but I say let's fix them. This is certainly not what I want to be doing for every project. And as said above, having an overlay library that defines err.h is a violation of glibc's reserved names. Not too bad if done in a library, but certainly not that I'd do in every project. Have a lovely day! Alex >=20 > (* Counterculture to this also exists, such as Go's "A little copying > is better than a little dependency" proverb for example.) >=20 > - NRK --=20 --diFkh3sIapcVx8be Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEE6jqH8KTroDDkXfJAnowa+77/2zIFAmXtsuAACgkQnowa+77/ 2zJM6BAAq0uuBwiPrd6AQCPYuVDLQqXu0O7vZnxIUzOdbcDPGv/lcsuvI9QcfVhM /cZukmBbXoobbGVJIbJHOISCtp6IkLd08mH1Pg6D9LF6Yhk42yo5mLt4FwWnj2EI RF03qV3QhA/wOA1Ool1kKKVXTaErJCJYXEqRqTefqO8Cg0bX6h0/BCMTUwvBO3ES ZrBd+mVDtYJk3m9/CwZUCkuBlGEO1iy+3waS/zMMbJU0AdFRAxYDfpafna/d8EMi m5J/GSB6re/hnIazeCHd6OicDDqg2N05/xAo+UuON25+zJSa1KLqro1/3g2YqxjO c/n5VTWZvrV6eTGIKA5qsG4Tzs4xfUEU3qP7dA3X8G7mGVijnMXYIr2uMpUvlGfy dWbwgqeO/x8JXfZjPUCGlrd1V6MitoJb2hekygU1r+WZTwN9/nXPN3hI92XC9DzH 1oFoVYBErLTF58c4ZfGAINl5pn/9zKTOxQ1PG+dUwehX+jGwDJ4ukBz0E6NM1GjT rNwpSRJR9qzsYKxCZ9joa7hg1whRR/k2UjutnJhmitY+MTVBnwET8f4Bx2ocsGS3 2RnQBs6TwVqPYrA8h4ySptLGxCJiMV9cU+1C1ibctk5XMtfX3TFuKrf5XABIiaDk umd/zn+1IDyLgAzTRiiKTsq6Gx5kmq4oPw1JopMl/oa8VAu9jww= =LMHe -----END PGP SIGNATURE----- --diFkh3sIapcVx8be--