From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/6958 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.busybox,gmane.linux.lib.musl.general Subject: Re: [PATCH] linedit, deluser: use POSIX getpwent instead of getpwent_r Date: Sat, 7 Feb 2015 11:52:19 -0500 Message-ID: <20150207165219.GB23507@brightrain.aerifal.cx> References: <1398411394-19971-1-git-send-email-ncopa@alpinelinux.org> <20150205184601.GK23507@brightrain.aerifal.cx> <20150205205224.GN23507@brightrain.aerifal.cx> <20150207013229.GT23507@brightrain.aerifal.cx> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1423327953 17570 80.91.229.3 (7 Feb 2015 16:52:33 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 7 Feb 2015 16:52:33 +0000 (UTC) Cc: busybox , musl@lists.openwall.com To: Denys Vlasenko Original-X-From: busybox-bounces@busybox.net Sat Feb 07 17:52:28 2015 Return-path: Envelope-to: glb-busybox-78@gmane.org Original-Received: from silver.osuosl.org ([140.211.166.136]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YK8cN-0000kt-M9 for glb-busybox-78@gmane.org; Sat, 07 Feb 2015 17:52:28 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 7E8E531AAE; Sat, 7 Feb 2015 16:52:25 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Original-Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VtNxzWjDFX3Y; Sat, 7 Feb 2015 16:52:23 +0000 (UTC) Original-Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id 7D007312BE; Sat, 7 Feb 2015 16:52:23 +0000 (UTC) Original-Received: from whitealder.osuosl.org (whitealder.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id ABB9C1C2327 for ; Sat, 7 Feb 2015 16:52:22 +0000 (UTC) Original-Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id A63A18C1C1 for ; Sat, 7 Feb 2015 16:52:22 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Original-Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Na-t5ABt-8u3 for ; Sat, 7 Feb 2015 16:52:21 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Original-Received: from brightrain.aerifal.cx (216-12-86-13.cv.mvl.ntelos.net [216.12.86.13]) by whitealder.osuosl.org (Postfix) with ESMTP id 5F21C8C1BB for ; Sat, 7 Feb 2015 16:52:21 +0000 (UTC) Original-Received: from dalias by brightrain.aerifal.cx with local (Exim 3.15 #2) id 1YK8cF-0005Sk-00; Sat, 07 Feb 2015 16:52:19 +0000 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: busybox@busybox.net X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion and development of BusyBox List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: busybox-bounces@busybox.net Original-Sender: "busybox" Xref: news.gmane.org gmane.linux.busybox:40671 gmane.linux.lib.musl.general:6958 Archived-At: On Sat, Feb 07, 2015 at 03:14:10PM +0100, Denys Vlasenko wrote: > On Sat, Feb 7, 2015 at 2:32 AM, Rich Felker wrote: > >> > the _r functions are for thread-safe > >> > versions of their corresponding legacy functions, but getpwent_r has > >> > inherent global state -- the iterator. Whoever made it just wasn't > >> > thinking. To make a correct interface like this the caller would need > >> > to have an iterator object to pass to the function, but I can't see > >> > much merit in inventing a new interface for this. > >> > >> It doesn't matter that it makes no sense. It's glibc compat. > >> If you want more programs rather than less to build > >> against musl, you have to strive to be glibc-compatible where practical. > > > > So far we haven't hit anything wanting to use it except busybox. I'm > > all for compatibility, but it doesn't look easy to provide without > > ugly code duplication or similar. We're in the middle of reworking > > some of this code anyway to add alternate backend support, so I just > > asked about how easy it would be to get getpwent_r too, but we didn't > > see any obvious clean ways to do it. This is basically a consequence > > of the way musl uses a dynamic buffer for the strings (line from the > > file) so as not to impose an arbitrary line limit, > > How about this implementation? > > int getpwent_r(struct passwd *pwbuf, char *buf, size_t buflen, struct > passwd **pwbufp) > { > char *line=0; > size_t size=0; > if (!f) f = fopen("/etc/passwd", "rbe"); > if (!f) return 0; > *pwbufp = __getpwent_a(f, pwbuf, &line, &size); > if (!*pwbufp) > return 0; /* success (eof) */ > if (size < buflen) > strcpy(buf, line); > free(line); > if (size < buflen) > return 0; /* success */ > *pwbufp = 0; > errno = ERANGE; > return ERANGE; > } Now *pwbuf contains a bunch of invalid ("dangling") pointers. They need to be fixed-up the same way getpw_r.c is doing it right now, which is where the code duplication comes in. It's not huge but it's ugly having the same logic repeated two places (and again for groups once you do groups too). Rich