zsh-workers
 help / color / mirror / code / Atom feed
From: Kyle Laker <kyle@laker.email>
To: zsh-workers@zsh.org
Subject: Re: [PATCH] Re: `pwd -P` with systemd-homed causes inconsistent cwd state
Date: Wed, 1 Nov 2023 22:54:14 -0400	[thread overview]
Message-ID: <6f0cc0e8-665f-4c90-ba6e-6180ebcf9d60@laker.email> (raw)
In-Reply-To: <CAH+w=7bcBOGxYzVYSxaNu_8hEE2mtL7GS0vbAjWfQrYs2R1juA@mail.gmail.com>


On 10/30/23 23:46, Bart Schaefer wrote:
> On Sun, Oct 22, 2023 at 11:59 AM Bart Schaefer 
> <schaefer@brasslantern.com> wrote:
>> 
>> So this reaches the "return NULL" at the end of zgetdir(), after 
>> the comment "Something bad happened." ?

>> Or conversely this is a consequence of zgetdir() not checking the 
>> return value from zchdir(), which it doesn't in a couple of 
>> places?

This is caused by not checking the return value. zgetdir() is returning
`buf + pos` so the error handling logic for `!ret` in zgetcwd() isn't hit.

> Lacking a response to this and unable to test this directly, I offer
>  the following patch, which attempts to cover all those cases.

Sorry for the delay. This patch does ensure that zgetdir() returns NULL
when the current working directory is clobbered. So it does fix that
part of the issue.

> I forced HAVE_GETCWD to be false and ran make check with no issues.

It seems like this does in fact fix the case where _both_ HAVE_GETCWD
and USE_GETCWD are false; however, in 5.9, even if HAVE_GETCWD is true,
USE_GETCWD is false (and this same setup can be induced on master where
the same behavior happens). In that case, the new error handling is
never hit because after zgetdir() now returns NULL, getcwd() is called
as a fallback (which sets ret so the subsequent logic to use pwd isnt
hit). But because at that point cwd has been lost by zgetdir()/zchdir(),
calling getcwd() just returns "/" so the value isn't useful. `pwd -P`
will print "/" but no error message.

With this patch so long as HAVE_GETCWD == USE_GETCWD it seems like
things work as expected; however, if USE is false and HAVE is true,
there are still issues with losing the working directory without
printing the error message.


  reply	other threads:[~2023-11-02  2:54 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
2023-10-22 18:59     ` Bart Schaefer
2023-10-31  3:46       ` [PATCH] " Bart Schaefer
2023-11-02  2:54         ` Kyle Laker [this message]
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=6f0cc0e8-665f-4c90-ba6e-6180ebcf9d60@laker.email \
    --to=kyle@laker.email \
    --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).