From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 110056 invoked by alias); 11 Sep 2017 17:56:16 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 110030 invoked by uid 89); 11 Sep 2017 17:56:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL,BAYES_00,RCVD_IN_SORBS_SPAM,RP_MATCHES_RCVD,SPF_PASS autolearn=no version=3.3.2 spammy= X-HELO: mailbackend.panix.com X-Gm-Message-State: AHPjjUjmK714gL7oVymHL/R9DkPSYQTAFuocraSLxSyb+jYokumxa/Pw fHT9F1FGBrsTb037Av6a0eHbsHNnkA== X-Google-Smtp-Source: AOwi7QCQTFXfMwLolMlW/g5B49zOfOuhsOapYqTU3C/slrV7co9f3WnFr8y1+chh61biRyrg/s8eM17I8fYDd7CNPVI= X-Received: by 10.202.74.143 with SMTP id x137mr11425406oia.236.1505152570953; Mon, 11 Sep 2017 10:56:10 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <7bf58b8a-afc9-b934-9a4a-1616e71c03ff@cs.ucla.edu> References: <1504643122-14874-1-git-send-email-adhemerval.zanella@linaro.org> <1504643122-14874-4-git-send-email-adhemerval.zanella@linaro.org> <878thop5fa.fsf@linux-m68k.org> <9455e298-8c48-c42a-0ec3-ffb8d166c69b@linaro.org> <450d2eab-f21a-f90c-6210-ea638787e339@cs.ucla.edu> <403decc7-e039-9be1-fb44-25d611540156@linaro.org> <7bf58b8a-afc9-b934-9a4a-1616e71c03ff@cs.ucla.edu> From: Zack Weinberg Date: Mon, 11 Sep 2017 17:56:00 -0000 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 3/9] posix: Allow glob to match dangling symlinks [BZ #866] To: Paul Eggert Cc: Joseph Myers , Adhemerval Zanella , Andreas Schwab , GNU C Library Content-Type: text/plain; charset="UTF-8" X-SW-Source: 2017-09/txt/msg00457.txt.bz2 On Mon, Sep 11, 2017 at 1:38 PM, Paul Eggert wrote: > On 09/11/2017 10:25 AM, Zack Weinberg wrote: >> >> >> It should be enough to make a dummy call, e.g. >> >> pglob->gl_lstat(".", &statbuf); >> > > Unfortunately calling lstat is quite expensive on some (non-POSIX) > platforms, even on the working directory. So we can't do the above in the > Gnulib version. I have trouble believing this will be a measurable performance hit, considering how much other expensive work glob has to do. > Besides, under the proposed patch glob is going to use > gl_lstat instead of gl_stat in almost all cases, so the dummy call won't add > much extra checking. The point is not to add _extra_ checking; the point is to ensure that gl_lstat (and gl_stat) are valid on all calls, _even if_ they wouldn't otherwise have been used. I'm trying to turn "may fail at runtime under rare circumstances" into "will definitely fail at runtime on the first use", which is the best we can do in C. > I suppose we could valid gl_stat instead, as gl_stat usage will become rare > (used only if GLOB_MARK is also specified, just before returning results). > But we don't have any code in the wild that is giving us invalid gl_stat > pointers, so it wouldn't be that helpful to try to validate gl_stat either. So here's an alternative, less thorough but perhaps also less costly approach: when GLOB_ALTDIRFUNCS is set, call both gl_stat and gl_lstat on the first name that's going to be returned, even if we have no other reason to do this. Optionally, memoize the function pointer and don't bother making the extra call again if we recognize that it's known to work. (Maybe also it would be a good idea to check up front for any NULL callbacks in the ALTDIRFUNCS case.) zw