From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 6704 invoked from network); 12 Sep 2020 20:42:05 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 12 Sep 2020 20:42:05 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1599943325; b=m8Zf/PbwnAA50K2FvEtrHflH6DPK5JL76G/RG9ELi1gAnasyZZZCkNlxxOpodSqrW5T1inwejR EwAVRt2yhSc5Ln2f8r5k81rlaVALfF+lHwmFV9F/9rPllZrPUJx3F4ChDmDcfHlw3mxfZnyyKJ HEMu2YleHcu8WRsLMmtMmmFx4gsWqgFiN1bdC7+2ay845P3qNK74ufIBWfsJ4hizqKc9zU4HE7 eQz7v62sKpFX4H1+IdSd7RUPhdsstis16DNg7ECKhdezrSPmAll8Qz8NL6Jc+n00XqAcGNvYGC 84gSx1f2EdNukUCWWg0V2/n9bJr3W6bjLwsIGqYDkIPB/A==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-oi1-f180.google.com) smtp.remote-ip=209.85.167.180; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1599943325; bh=f7pChgFuze7svTVXI/B97phj2W8Nasiq30o+9FAI0Lc=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=fYtXDC5ILy7uaL92z5+d0PP9u4T/hF3AdHjuxVWOrqC/G5OT0rH8iAOs9jUIFd25CAiWp2o+e6 XFxBNPc7czYO+UBebp2vI7BLZDQTzxLDPCa4RKUe66LSgqQc1yfqDVeX8UTKjZlIWSDa63ir3L Ihrb1kfGx5cD4hFb0Tgy/xpDOWj3TsAsbXUm0cog18J2geEjs7dWJYNHECjox62pzhEAvPMonj 5s7TZnJxEi2HvhyKP1GWPRzW/M/rqTEVbwroOspE331zz8lfc7eLoKd/cs9CI4M89f3WJIFm0l PULEszBnTPT/w0JXTYq6Js5U4mYGrfwryD+SuH0GjXH4xw==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=E4ynvyJEJRQOxTbIuZgehyg5ziuPUZ79VtTzcLg2bIc=; b=dZxJPvhSq7Pwx2SNS649OMbpcJ gXIp9IVejElu3Elk/9t5MgRr8S1GiCzAK7o5LJsA1sx4+NkPTdrkaVo6+Wp12rbrB5j1jFMT4bKx4 5BjjvxojknQNbkDHFd/hMuGlv3Z/F2hDVP79WKjvMnRQVcULOmNXTyAaM01+NiwKgLce4iXaGXJDc hw5vzoXDpdSNKBxKxQwUefpLEOfPKJsunNhNGRuH/EVdL4hsiN91BiZaAwenyZgegg3qvGJYJId+8 gnXN5ndEjnr9dMChV/qZFKfpupwzgVBZYX0BXeRCM6x3AJl5M/wHshqb1+gL43V2bfdna3u8j8AUC Sz3TlRlw==; Received: from authenticated user by zero.zsh.org with local id 1kHCLU-000Mtd-3O; Sat, 12 Sep 2020 20:42:04 +0000 Authentication-Results: zsh.org; iprev=pass (mail-oi1-f180.google.com) smtp.remote-ip=209.85.167.180; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-oi1-f180.google.com ([209.85.167.180]:36115) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1kHCLD-000Mk2-FU; Sat, 12 Sep 2020 20:41:48 +0000 Received: by mail-oi1-f180.google.com with SMTP id x19so13292974oix.3 for ; Sat, 12 Sep 2020 13:41:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=E4ynvyJEJRQOxTbIuZgehyg5ziuPUZ79VtTzcLg2bIc=; b=sle9UQTnff8fp0rXkcy3let2PX4Vd51ETdX4Qd/6aAJZLxw02UNKasBmI1fuCMD3VD A2Z+yEMZVJEROsVuOfmfcp4VaPWxk7rZT9pXUlF40hSI6czmF/vkIJYrGuXvpvZSaQCJ kVT7xwmydJiX375Miayi3/69VJYNf2NGiNiG+MnlPvGZ25+PPEAtE904H2RRyg0F0r7l xFIuaRnv4Ayecjzfsp/ngBMPnZAoz5ULdoP3s1PGftJ7wfoGVJAym8Wi69IaIm3cLWul ISnQVi+1pa6f7dLCvLtQsYGS78udMHntt/S9dSKHdXC01VPI9c0jZwrAXeqH3OxUcgYv SBpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=E4ynvyJEJRQOxTbIuZgehyg5ziuPUZ79VtTzcLg2bIc=; b=bufepsHiniAeD2KrCROrF0HGvXTE2jA2Lq13tq68fnfn0W6JHvy4NuhNFEt560tsOO dYtFSvcQNZ0igZuRtoKxcMKgYvEGSLMGeJn9sY+tGHzNduCPjK/rgbHxLuKDjU5h4R+o u3p+g4kHb88Zk0ywFpFOLtsrRI1HYQvP3hraB8D3l/g9SxazBDo3mrpq4Pl6rICw7qe5 bLzVqDr7T1Gu7m/KBsJo6ckoQGkpMCb3lEOC2sFVdpgI6VA4VRIlweheqKzPm9xfn/pV fOMNPpEhIlCRI9M/DFyqkElMhAxa1naf5scnOP0QuZ525jzpBbZK6kTw7OlzVk2+Abnz KyCA== X-Gm-Message-State: AOAM533wmTjmq2h0plT+/8oRkS89gM9CrZFDpHGV4c23Ctg0masLfEKA i2ytafvWznkvJxneeF6hOKiRZnVYUdAhMaandPXRqQ== X-Google-Smtp-Source: ABdhPJxme0XUkK734D/nHfE65oOYzIVsTIQAv23j8b0XzQKWjR0GUBVFFhqadSg1cTcfTAbSq/QfmdbrmhZgTdIPkRk= X-Received: by 2002:aca:3ac6:: with SMTP id h189mr4878116oia.132.1599943305181; Sat, 12 Sep 2020 13:41:45 -0700 (PDT) MIME-Version: 1.0 References: <20200911144852.GA1669764@fullerene.field.pennock-tech.net> <20200911161000.GA1679994@fullerene.field.pennock-tech.net> In-Reply-To: From: Bart Schaefer Date: Sat, 12 Sep 2020 13:41:34 -0700 Message-ID: Subject: Re: Possible bug: HASH_CMDS has no observable effect To: Roman Perepelitsa Cc: Zsh hackers list Content-Type: text/plain; charset="UTF-8" X-Seq: 47375 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: On Sat, Sep 12, 2020 at 1:49 AM Roman Perepelitsa wrote: > > On Sat, Sep 12, 2020 at 10:35 AM Bart Schaefer > wrote: > > The whole search-and-cache process is > > short-circuited. > > Doesn't this search happen anyway? When I type `rsync`, it gets > resolved as /usr/bin/rsync and gets executed. This requires searching > for rsync in all path directories. The cache is a mapping from command names to locations. So, if "rsync" is in the cache, then the value of that cache entry is "/usr/bin/rsync" and zsh just executes that without scanning the path again. Conversely if HASH_DIRS is set and "rsync" is NOT in the cache, but everything else from /usr/bin IS in the cache (as a byproduct of some previous search), zsh reports command not found, again without re-scanning the path. HASH_DIRS is done incrementally, e.g., if your path is "/bin:/usr/bin" and you first execute a command from /bin, zsh only populates the cache with commands in /bin, and remembers that it has not looked in /usr/bin yet. If you then execute "rsync", a cache miss causes HASH_DIRS to scan /usr/bin, add everything there to the cache, and execute /usr/bin/rsync. Eventually every directory in the path will have been scanned, and cache misses become immediately "not found". If HASH_DIRS is not set (but HASH_CMDS is). > I believe this is done in execute() > in Src/exec.c. Wouldn't it be better to search for `rsync` in the > parent shell (before forking) and hash the result? That's exactly how it works. The search in execute() is only done if an absolute file location for the command isn't provided by the parent, which only occurs if HASH_CMDS is not set. This does mean that if a command is removed from (or moved within) the path, execute() will be handed an invalid file location and will fail. Again, for most users this never happens.