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.2 required=5.0 tests=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 AC3B826AE2 for ; Sun, 10 Mar 2024 15:01:43 +0100 (CET) Received: (qmail 8092 invoked by uid 550); 10 Mar 2024 13:57:36 -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 8066 invoked from network); 10 Mar 2024 13:57:35 -0000 X-Virus-Scanned: SPAM Filter at disroot.org Date: Sun, 10 Mar 2024 14:01:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1710079285; bh=fOLbPlAerEURgzRgxssPwmx6eOFxl4LFblv4XKYqp98=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=CgQu01GGJBeQP1hxNXfhlo1nFalNwg+7QyDWCOKgmN9ACpqUWmqXC3qlusX1N6Xag N5dVz/CHSoJqKI5sOZhl7sULl0hhayOpYh/sOyAzmizCFdzZh/BpiS9q7hnRHUS8Mv a7KmHDGwdsxXe/kk55J3alhMJgzZYOOuxzwXcnPJFwgs6Yg27KY5oIEQtqf+thQelx 8UVdhUTnVdRlRazyspXBwwkAlSES376hxRNCNxJ6CskOoHXa+GdT4TxhLxNkuSdyHn WwFxleVR0Vj9usBzV6nfm3I2+kcugZwU51f27H0b2PXaJGa+CNifjFc1FhQ/EGUxeO YwsLGcCjO1EjA== From: NRK To: Alejandro Colomar 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: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: Re: [musl] Re: Tweaking the program name for functions > or add locks; that is: > > lock() > fprintf("%s: ", __progname); > vfprintf(...); > unlock(); > > [...] > > locking code is error-prone, I'd say. These interfaces do not guarantee the output to be atomic. If you were expecting it to be atomic then that's just *another* reason to roll it yourself because a good ton of existing implementation doesn't lock. https://github.com/bminor/musl/blob/master/src/legacy/err.c https://github.com/freebsd/freebsd-src/blob/main/lib/libc/gen/err.c https://github.com/openbsd/src/blob/master/lib/libc/gen/verr.c https://cgit.freedesktop.org/libbsd/tree/src/err.c musl doesn't, freebsd doesn't, openbsd doesn't, libbsd doesn't. Out of the 5 implementations I checked, only glibc seems to lock. > There's errc(3) Which doesn't exist on musl, I don't think it exists on glibc either. So you're back to "DIY or depend on libbsd" land if you use this function. > Again, is there anything better in glibc or musl? > Something that prefixes "$progname: " and appends the errno message? > [...] > 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? glibc has error(3), and program_invocation_name(3) to customize $progname. Interface wise, I find it more pleasant than the err.h gang. Having an explicit `errnum` argument serves all 3 usecases (no errno, errno, errno-like return code) without having multiple functions with x/y/z/c suffix. (One issue I have with glibc's error() interface is that doing both warning and fatal error through same function weakens static analyzers. I'd split up the two and mark the fatal version with _Noreturn for better warnings/static-analysis.) But this function is even less portable (no musl or *BSD support last I checked). So you're back to square one. - NRK