zsh-workers
 help / color / mirror / code / Atom feed
From: Kyle Laker <kyle@laker.email>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: zsh-workers@zsh.org
Subject: Re: `pwd -P` with systemd-homed causes inconsistent cwd state
Date: Sat, 21 Oct 2023 12:26:37 -0400	[thread overview]
Message-ID: <e3adbc41-1cba-46d7-99a7-552a14882c59@laker.email> (raw)
In-Reply-To: <CAH+w=7YepkrZ1EYkovCvH-Qib4LCqFMGaw+j3EG8Cn3bTaE+XQ@mail.gmail.com>

On 10/21/23 00:05, Bart Schaefer wrote:
> On Fri, Oct 20, 2023 at 8:18 PM Kyle Laker <kyle@laker.email> wrote:
>>
> When you run `pwd -P`, zsh invokes the getcwd() system call and prints
> whatever it returns.  That's literally all it does.  So, although I
> don't have BTRFS to test with, this looks from here like a problem
> with getcwd() internally changing the process current directory to the
> root when crossing a BTRFS link.  That would be invisible to $PWD and
> therefore to the pwd command (without -P).

Thanks for the context! So it seems like the issue is in the 
non-getcwd() zgetdir() code path. Checking against master, this issue is 
no longer present with a default configure after workers/50287 enabled 
using getcwd() by default just after the 5.9 release. getcwd() seems to 
handle this case correctly.

For situations where getcwd() isn't used, the actual errant `cd`ing 
happens at the end of the `while` loop in zgetdir(). This continuously 
calls `chdir("..")`. Eventually, this puts us at `/`. Typically, the 
call to `zchdir(buf + pos)` would take us back to the directory we 
started in; however, because ZSH determined the path was 
`/home/kyle.homedir` (using the homed image path) instead of 
`/home/kyle` (the actual mounted home directory), that fails. The 
`.homedir` folder is owned by nobody:nobody so when zchdir() calls 
chdir(3) the latter fails with an EACCES error. This leaves the process 
in `/`, where it was put by zgetdir() but without any of the other 
environment variables updated.

I'm not sure how these btrfs homedir mounts can be determined in 
situations like this (or how valuable it would be since nearly everyone 
with btrfs probably has a working getcwd(3)). But perhaps if the final 
zchdir() fails, zgetdir() could chdir(3) back to the original path 
rather than the resolved path?


  reply	other threads:[~2023-10-21 16:27 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-21  3:18 Kyle Laker
2023-10-21  4:05 ` Bart Schaefer
2023-10-21 16:26   ` Kyle Laker [this message]
2023-10-22 18:59     ` Bart Schaefer
2023-10-31  3:46       ` [PATCH] " Bart Schaefer
2023-11-02  2:54         ` Kyle Laker
2023-11-03  4:28           ` Bart Schaefer
2023-11-05 14:16             ` Kyle Laker
2023-11-05 16:17               ` Bart Schaefer
2023-11-05 21:10                 ` Bart Schaefer
2023-11-20 22:23                   ` Jan Alexander Steffens (heftig)
2023-11-23 17:53                     ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e3adbc41-1cba-46d7-99a7-552a14882c59@laker.email \
    --to=kyle@laker.email \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).