diff --git a/src/parser.rs b/src/parser.rs index c82444a82..b9a6fb2d0 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -274,8 +274,14 @@ pub struct LibraryData { /// the command line. pub transient_commandline: ScopedRefCell>, - /// A file descriptor holding the current working directory, for use in openat(). - /// This is never null and never invalid. + /// A file descriptor holding the current working directory. + /// Note that the long-term design of fish will implement subshells using threads; + /// these subshells necessarily may have distinct CWDs. The process-wide CWD is only + /// used for transitory checks, such as surrounding fork(). + /// fish code should generally NOT assume that the process-wide CWD matches this. + /// Either resolve full paths, or use the _at() family of syscalls with this fd. + /// This is never null and never invalid except in crazy error conditions + /// (e.g. starting fish in a chmod 000 directory) which have yet to be rationalized. pub cwd_fd: Option>, /// Variables supporting the "status" builtin. diff --git a/tests/checks/init-unreadable-cwd.fish b/tests/checks/init-unreadable-cwd.fish index 3710498bd..8c9e69dc1 100644 --- a/tests/checks/init-unreadable-cwd.fish +++ b/tests/checks/init-unreadable-cwd.fish @@ -12,6 +12,11 @@ chmod 000 . $fish -c 'echo Look Ma! No crashing!' 2>/dev/null #CHECK: Look Ma! No crashing! +# Verify fish reports the unreadable cwd on stderr instead of silently leaving cwd_fd unset. +$fish -c 'true' 2>&1 1>/dev/null | string match -q '*Unable to open the current working directory*' +and echo "cwd error reported" +#CHECK: cwd error reported + # Careful here, Solaris' rm tests if the directory is in $PWD, so we need to cd back cd $oldpwd rmdir $tmpdir