Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: cwd unintentionally changed
- X-seq: zsh-workers 44256
- From: Yannic Schröder <schroeder@xxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: cwd unintentionally changed
- Date: Fri, 26 Apr 2019 08:12:51 +0200
- Autocrypt: addr=schroeder@xxxxxxxxxxxxxxx; prefer-encrypt=mutual; keydata= mQINBFXCFbsBEACtUbQRsveNjGTSinBkR+9Zbh+abIOHzUJeixIWBB2prt3OaZS07XjA2241 0HIPCytbrqpD45ORu67txBR7VInBpU6dyaAqcZ3oj2Xfd1VZReatMhu2LriqaP+oIPQuoAz/ S7hAAb/e04+jTWSV5d8rkn94mzkx5CYLMOIJh2/F7/e1q/ifypeen6GDUdf1C+yVR+3qYUXM TZqQwFvCYdUeX2CWqmRVBfjdWucDTS6xuq/9cc0Y+ep05eHxGLxX+grIiklU8Z+gUH3U0T6G C64lZ9KYi6JTshVzhwK8Zi7dueJPTo94H25kw08rlccv7hAXQxfofSA5J0ssWxRGzRe60SKn hpqUuVie6511TzfqN56Ahdj8AaBq6hAZu6QE94oTdfGyoYgL6/MsDIs3oqnWDYZ9IVFsRsAM 9RkQ94iSgSu6uKvXeVFd6oZZ+0T6vdybp5Uq/3nn9pKUDolsY8TWBx9NatOy9tLb+8CBRpgk 5kurmujwks6b3/iHDfv7MXRa43WtwFE0Wv9JQWCt5GCT589bMRfPx61yROf4+2q2D1VZwbEp O/9HCSqK0tHsEJH4HbEzg4WBYmXIVoP7gHwgPgOrxQM2JTWTkLlPJWOzJ2k+3zZKVlpKFwmX 9LDvGo4JUrzpoAC+nRxKqbRQTowpAfv19eS/cQOjd9CcNd9/7QARAQABtCxZYW5uaWMgU2No csO2ZGVyIDxzY2hyb2VkZXJAaWJyLmNzLnR1LWJzLmRlPokCQAQTAQgAKgIbIwUJCWYBgAUL CQgHAgYVCAkKCwIEFgIDAQIeAQIXgAUCVsGLEwIZAQAKCRAjX1I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==
- In-reply-to: <1556199068.2667.13.camel@samsung.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- Openpgp: preference=signencrypt
- References: <CGME20190425120502epcas5p21b83b94136e0b2fae1002220c7d52656@epcas5p2.samsung.com> <f6d8b44f-84be-0102-5ab8-b56824e23f87@ibr.cs.tu-bs.de> <1556199068.2667.13.camel@samsung.com>
I applied the provided patch and indeed it stops cwd from changing.
I loaded a zshrc that uses vcs_info and it now prints
VCS_INFO_bydir_detect:9: Failed to get current directory: path invalid
with every new prompt after the umount (which might be confusing for
users). However, cwd stays intact.
I could live with this solution (maybe suppress the error in vcs_info).
Regards,
Yannic
On 25.04.19 15:31, Peter Stephenson wrote:
> On Thu, 2019-04-25 at 14:03 +0200, Yannic Schröder wrote:
>> Hi *,
>>
>> I got myself into a situation where zsh changed my working directory to
>> "/" without further notice. Unfortunately, the next command I issued was
>> "sudo rm -rf *", which did not end well with cwd being "/" :-(
>>
>> My colleagues and me started to track down the bug. Our efforts are
>> documented here:
>> https://github.com/grml/grml-etc-core/issues/76
>>
>> (We initially though it was a bug with grml zsh config.)
>>
>> A minimal example that triggers the bug looks like this:
>>
>> $ mkdir /tmp/tmp.0HnyRZ1iXv/
>> $ cd /tmp/tmp.0HnyRZ1iXv/
>> $ mkdir a
>> $ sudo zsh -f -c 'mount -t tmpfs tmpfs a; cd a; touch x; ls; umount
>> --lazy ../a; ls; foo=.; echo ${foo:a}; ls; realpath .; echo $PWD;'
>
> Thanks, easy to follow.
>
> That's certainly not pleasant as it's silent.
>
> The source of the problem is in zgetdir(). We attempt to climb the
> directory hierarchy until we get to /. In this case we appear to get
> there immediately. Then, fatally, we call zchdir() to the place where we
> think we are, but actually we aren't.
>
> The patch below fixes up this case so we make quite sure we're in /.
> This looks safe, but I'm not sure it's necessarily the limit of
> what we can do to make things as safe as possible...
>
> I'm not quite sure why we need to zchdir(). It seems to be a side
> effect rather than a basic part of the call. In particular I don't see
> why it's a good idea in this case --- maybe we just add an argument
> saying "not actually changing directory"?
>
> Or should we be using getcwd() nowadays? Presumably this is fine on most
> modern systems?
>
> pws
>
> diff --git a/Src/compat.c b/Src/compat.c
> index 7b5c4411c..7131d91a4 100644
> --- a/Src/compat.c
> +++ b/Src/compat.c
> @@ -361,8 +361,18 @@ zgetdir(struct dirsav *d)
> pino = sbuf.st_ino;
> pdev = sbuf.st_dev;
>
> - /* If they're the same, we've reached the root directory. */
> + /* If they're the same, we've reached the root directory... */
> if (ino == pino && dev == pdev) {
> + /*
> + * ...well, probably. If this was an orphaned . after
> + * an unmount, or something such, we could be in trouble...
> + */
> + if (stat("/", &sbuf) < 0 ||
> + sbuf.st_ino != ino ||
> + sbuf.st_dev != dev) {
> + zerr("Failed to get current directory: path invalid");
> + return NULL;
> + }
> if (!buf[pos])
> buf[--pos] = '/';
> if (d) {
>
--
Yannic Schröder, M.Sc.
Technische Universität Braunschweig
Institut für Betriebssysteme und Rechnerverbund
Mühlenpfordtstr. 23
38106 Braunschweig
Fon: +49 (531) 391 - 3249
Fax: +49 (531) 391 - 5936
E-Mail: schroeder@xxxxxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author