GNU bug report logs - #18232
24.3.92; Filename completion changes the current working directory

Previous Next

Package: emacs;

Reported by: Harald Hanche-Olsen <hanche <at> math.ntnu.no>

Date: Sat, 9 Aug 2014 19:57:01 UTC

Severity: minor

Found in version 24.3.92

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 18232 in the body.
You can then email your comments to 18232 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#18232; Package emacs. (Sat, 09 Aug 2014 19:57:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Harald Hanche-Olsen <hanche <at> math.ntnu.no>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 09 Aug 2014 19:57:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Harald Hanche-Olsen <hanche <at> math.ntnu.no>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.3.92; Filename completion changes the current working directory
Date: Sat, 09 Aug 2014 21:56:01 +0200 (CEST)
C-x C-f (find-file) with filename completion changes the current
working directory (cwd) of emacs.

This is annoying for the following reason:

If you temporarily mount a filesystem and then visit a file in that
filesystem, you cannot unmount the filesystem because it is now the
cwd of a running process.

The obvious workaround is to first visit a file not in this
filesystem, but that is annoying and should be unnecessary.

I have narrowed the cause down to filename completion:

Starting with emacs -Q:

 - Find the PID of the running emacs process.
 - In a root shell, run “lsof -p PID | grep cwd”.
 - Evaluate (read-file-name-default "Filename: ") and don't hit RETURN
 - Navigate to some other directory, and cause filename completion to
   happen. For example, type “/tmp/” and follow up with TAB.
 - Run the lsof command again, and note that the current working
   directory has changed.


In GNU Emacs 24.3.92.2 (x86_64-apple-darwin13.3.0, NS apple-appkit-1265.21)
 of 2014-08-08 on airy
Windowing system distributor `Apple', version 10.3.1265
Configured using:
 `configure --with-ns'

Important settings:
  value of $LC_CTYPE: en_US.UTF-8
  value of $LANG: C
  locale-coding-system: utf-8-unix




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18232; Package emacs. (Sun, 10 Aug 2014 02:46:01 GMT) Full text and rfc822 format available.

Message #8 received at 18232 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Harald Hanche-Olsen <hanche <at> math.ntnu.no>
Cc: 18232 <at> debbugs.gnu.org
Subject: Re: bug#18232: 24.3.92;
 Filename completion changes the current working directory
Date: Sat, 09 Aug 2014 22:45:48 -0400
Harald Hanche-Olsen wrote:

> Starting with emacs -Q:
>
>  - Find the PID of the running emacs process.
>  - In a root shell, run "lsof -p PID | grep cwd".
>  - Evaluate (read-file-name-default "Filename: ") and don't hit RETURN
>  - Navigate to some other directory, and cause filename completion to
>    happen. For example, type "/tmp/" and follow up with TAB.
>  - Run the lsof command again, and note that the current working
>    directory has changed.

I can't reproduce that on GNU/Linux.

In general, if you visit files and then unmount the hosting
filesystems, you are going to have problems.

> In GNU Emacs 24.3.92.2 (x86_64-apple-darwin13.3.0, NS apple-appkit-1265.21)





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18232; Package emacs. (Sun, 10 Aug 2014 08:04:02 GMT) Full text and rfc822 format available.

Message #11 received at 18232 <at> debbugs.gnu.org (full text, mbox):

From: Harald Hanche-Olsen <hanche <at> math.ntnu.no>
To: rgm <at> gnu.org
Cc: 18232 <at> debbugs.gnu.org
Subject: Re: bug#18232: 24.3.92; Filename completion changes the current
 working directory
Date: Sun, 10 Aug 2014 10:03:15 +0200 (CEST)
[Glenn Morris <rgm <at> gnu.org> (2014-08-10 02:45:48 UTC)]

> I can't reproduce that on GNU/Linux.

So it's OS X specific, then.

I suspected it might be; thanks for checking it out.

> In general, if you visit files and then unmount the hosting
> filesystems, you are going to have problems.

Only if you unmount before saving your changes.
Why would you do that?

(I do this several times a week, typically to edit a file on some web
server. I mount the filesystems using sshfs. It is not practical to
leave them mounted, as this is a laptop and moves about a lot.)

– Harald




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18232; Package emacs. (Sun, 10 Aug 2014 13:03:02 GMT) Full text and rfc822 format available.

Message #14 received at 18232 <at> debbugs.gnu.org (full text, mbox):

From: Jan Djärv <jan.h.d <at> swipnet.se>
To: Harald Hanche-Olsen <hanche <at> math.ntnu.no>
Cc: Glenn Morris <rgm <at> gnu.org>, 18232 <at> debbugs.gnu.org,
 Paul Eggert <eggert <at> cs.ucla.edu>
Subject: Re: bug#18232: 24.3.92;
 Filename completion changes the current working directory
Date: Sun, 10 Aug 2014 15:02:38 +0200
Hello.

10 aug 2014 kl. 10:03 skrev Harald Hanche-Olsen <hanche <at> math.ntnu.no>:

> [Glenn Morris <rgm <at> gnu.org> (2014-08-10 02:45:48 UTC)]
> 
>> I can't reproduce that on GNU/Linux.
> 
> So it's OS X specific, then.
> 
> I suspected it might be; thanks for checking it out.

It is a bug introduced by bringing in GNULib.  The GNULib in Emacs makes wrong assumptions, from lib/save-cwd.h:

/* Gnulib needs to save and restore the current working directory to
   fully emulate functions like fstatat.  But Emacs doesn't care what
   the current working directory is; it always uses absolute file
   names.  This module replaces the Gnulib module by omitting the code
   that Emacs does not need.  */

Given that fchdir is called many times per file when completing, no wonder the current working directory gets screwed up.

This bug needs to be fixed in the GNULib code, by really use restore_cwd as it was intended and not make false assumptions and take shortcuts like this:

SAVE_CWD_INLINE int restore_cwd (struct saved_cwd const *cwd) { return 0; }

	Jan D.

>> In general, if you visit files and then unmount the hosting
>> filesystems, you are going to have problems.
> 
> Only if you unmount before saving your changes.
> Why would you do that?
> 
> (I do this several times a week, typically to edit a file on some web
> server. I mount the filesystems using sshfs. It is not practical to
> leave them mounted, as this is a laptop and moves about a lot.)
> 
> – Harald
> 
> 





Reply sent to Paul Eggert <eggert <at> cs.ucla.edu>:
You have taken responsibility. (Sun, 10 Aug 2014 21:09:01 GMT) Full text and rfc822 format available.

Notification sent to Harald Hanche-Olsen <hanche <at> math.ntnu.no>:
bug acknowledged by developer. (Sun, 10 Aug 2014 21:09:02 GMT) Full text and rfc822 format available.

Message #19 received at 18232-done <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Jan Djärv <jan.h.d <at> swipnet.se>, 
 Harald Hanche-Olsen <hanche <at> math.ntnu.no>
Cc: Glenn Morris <rgm <at> gnu.org>, 18232-done <at> debbugs.gnu.org
Subject: Re: bug#18232: 24.3.92;
 Filename completion changes the current working directory
Date: Sun, 10 Aug 2014 14:08:15 -0700
Jan Djärv wrote:
> This bug needs to be fixed in the GNULib code, by really use restore_cwd as it was intended

Just to clarify, the bug is Emacs's little substitute for Gnulib, not in 
Gnulib itself.  Perhaps at some point Emacs should just use Gnulib here, 
but for now it's safer to migrate a bit more of Gnulib into Emacs to 
avoid this regression.  I reproduced the problem on Fedora 20 by 
building an Emacs that was crippled to not use readlinkat etc., and 
installed a patch that worked for me as emacs-24 bzr 117437 (simplified 
in 117438).




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18232; Package emacs. (Mon, 11 Aug 2014 05:07:02 GMT) Full text and rfc822 format available.

Message #22 received at 18232-done <at> debbugs.gnu.org (full text, mbox):

From: Jan Djärv <jan.h.d <at> swipnet.se>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: Glenn Morris <rgm <at> gnu.org>, Harald Hanche-Olsen <hanche <at> math.ntnu.no>,
 18232-done <at> debbugs.gnu.org
Subject: Re: bug#18232: 24.3.92;
 Filename completion changes the current working directory
Date: Mon, 11 Aug 2014 07:06:42 +0200
10 aug 2014 kl. 23:08 skrev Paul Eggert <eggert <at> cs.ucla.edu>:

> Jan Djärv wrote:
>> This bug needs to be fixed in the GNULib code, by really use restore_cwd as it was intended
> 
> Just to clarify, the bug is Emacs's little substitute for Gnulib, not in Gnulib itself.  Perhaps at some point Emacs should just use Gnulib here, but for now it's safer to migrate a bit more of Gnulib into Emacs to avoid this regression.  I reproduced the problem on Fedora 20 by building an Emacs that was crippled to not use readlinkat etc., and installed a patch that worked for me as emacs-24 bzr 117437 (simplified in 117438).

Confirmed OK on OSX as well.

	Jan D.





bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 08 Sep 2014 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 9 years and 234 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.