all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Philipp Stephani <p.stephani2@gmail.com>
To: 27871@debbugs.gnu.org
Subject: bug#27871: 26.0.50; Bad handling of unmounted directory
Date: Sat, 23 Sep 2017 10:19:19 +0000	[thread overview]
Message-ID: <CAArVCkQ4zX60FnRtiFHJVdpJaj197Uny5kgFG3efyy=PZh5P9Q@mail.gmail.com> (raw)
In-Reply-To: <wvr48tj70x7r.fsf@phst-glaptop>


[-- Attachment #1.1: Type: text/plain, Size: 3131 bytes --]

Philipp <p.stephani2@gmail.com> schrieb am Sa., 29. Juli 2017 um 23:08 Uhr:

>
> Create a FUSE mount point, e.g.
>
> cd /tmp
> mkdir a a/a b
> touch a/a/a
> bindfs -f a b
>
> While bindfs(1) is running, cd to the mounted directory in a second
> shell:
>
> cd /tmp/b/a
>
> Now kill bindfs, e.g. by hitting ^C in the first shell.  The second
> shell will now be in an unmounted directory.  From that directory, start
> Emacs:
>
> $ emacs -Q -batch a
> Apparent cycle of symbolic links for (unreachable)
>
> or, with stack trace
>
> $ emacs -Q -batch -f toggle-debug-on-error a
> Debug on Error enabled globally
> ...
>   file-truename("(unreachable)" (-1) (nil))
>   file-truename("(unreachable)/a" (-1) (nil))
>   file-truename("(unreachable)" (-1) (nil))
>   file-truename("(unreachable)/a" (-1) (nil))
>   file-truename("(unreachable)" (-1) (nil))
>   file-truename("(unreachable)/a" (-1) (nil))
>   file-truename("(unreachable)" (-1) (nil))
>   file-truename("(unreachable)/a" (-1) (nil))
>   file-truename("(unreachable)" (-1) (nil))
>   file-truename("(unreachable)/a" (-1) (nil))
>   file-truename("(unreachable)" (-1) (nil))
>   file-truename("(unreachable)/a" (-1) (nil))
>   file-truename("(unreachable)" (-1) (nil))
>   file-truename("(unreachable)/a" (-1) (nil))
>   file-truename("(unreachable)" (-1) (nil))
>   file-truename("(unreachable)/a" (-1) (nil))
>   file-truename("(unreachable)" (-1) (nil))
>   file-truename("(unreachable)/a" (-1) (nil))
>   file-truename("(unreachable)" (-1) (nil))
>   file-truename("(unreachable)/a" (-1) (nil))
>   file-truename("(unreachable)" (-1) (nil))
>   file-truename("(unreachable)/a" (-1) (nil))
>   file-truename("(unreachable)" (-1) (nil))
>   file-truename("(unreachable)/a" (-1) (nil))
>   file-truename("(unreachable)" (-1) (nil))
>   file-truename("(unreachable)/a" (-1) (nil))
>   file-truename("(unreachable)" (-1) (nil))
>   file-truename("(unreachable)/a" (-1) (nil))
>   file-truename("(unreachable)/a/(unreachable)" (-1) (nil))
>   file-truename("(unreachable)/a/(unreachable)/a" (-1) (nil))
>   file-truename("(unreachable)/a/(unreachable)/a/(unreachable)" (-1) (nil))
>   file-truename("(unreachable)/a/(unreachable)/a/(unreachable)/a" (-1)
> (nil))
>
> file-truename("(unreachable)/a/(unreachable)/a/(unreachable)/a/(unreachable)"
> (-1) (nil))
>
> file-truename("(unreachable)/a/(unreachable)/a/(unreachable)/a/(unreachable)/a"
> (-1) (nil))
>
> file-truename("(unreachable)/a/(unreachable)/a/(unreachable)/a/(unreachable)/a/a")
>   find-file-noselect("(unreachable)/a/(unreachable)/a/a")
>   #f(compiled-function (displayable-buffers dir line column name)
> #<bytecode>)((nil) "(unreachable)/a/" (0) (0) "a")
>   command-line-1(("-f" "toggle-debug-on-error" "a"))
>   command-line()
>   normal-top-level()
>
> It seems like the logic for `default-directory' and/or `file-truename'
> should be improved for unmounted filesystems.
>
>
Here's a patch. With the patch, the output is

 Error getting directory: Transport endpoint is not connected
Warning (initialization): Error setting default-directory
Ignoring relative file name (a) due to nil default-directory

[-- Attachment #1.2: Type: text/html, Size: 4143 bytes --]

[-- Attachment #2: 0001-Treat-unreachable-current-directory-as-error.txt --]
[-- Type: text/plain, Size: 2118 bytes --]

From b3541b3bc936bbb8e9950d1aed14d2571e03c1fe Mon Sep 17 00:00:00 2001
From: Philipp Stephani <phst@google.com>
Date: Sat, 23 Sep 2017 12:13:39 +0200
Subject: [PATCH] Treat unreachable current directory as error

Linux prefixes an unreachable (e.g. unmounted) current directory with
the special string "(unreachable)", cf. Bug#27871.  Treat such
directories as error because they wouldn't work anyway.

* src/sysdep.c (emacs_get_current_dir_name_1): Renamed from
emacs_get_current_dir_name.
(emacs_get_current_dir_name): Check for prefix "(unreachable)".
---
 src/sysdep.c | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/src/sysdep.c b/src/sysdep.c
index 1e6e0d011b..6c76f16242 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -220,10 +220,8 @@ init_standard_fds (void)
   force_open (STDERR_FILENO, O_RDONLY);
 }
 
-/* Return the current working directory.  The result should be freed
-   with 'free'.  Return NULL on errors.  */
-char *
-emacs_get_current_dir_name (void)
+static char *
+emacs_get_current_dir_name_1 (void)
 {
 # if HAVE_GET_CURRENT_DIR_NAME && !BROKEN_GET_CURRENT_DIR_NAME
 #  ifdef HYBRID_MALLOC
@@ -283,6 +281,29 @@ emacs_get_current_dir_name (void)
   return buf;
 }
 
+/* Return the current working directory.  The result should be freed
+   with 'free'.  Return NULL on errors.  */
+char *
+emacs_get_current_dir_name (void)
+{
+  char *dir = emacs_get_current_dir_name_1 ();
+  if (dir == NULL)
+    return NULL;
+  /* On Linux, getcwd and get_current_dir_name return a string
+     starting with "(unreachable)" if the current directory doesn't
+     exist, e.g. because it was unmounted.  Treat that as an error.
+     See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27871.  */
+  const char *prefix = "(unreachable)";
+  size_t dir_len = strlen (dir);
+  size_t prefix_len = strlen (prefix);
+  if (dir_len >= prefix_len && strncmp (dir, prefix, prefix_len) == 0)
+    {
+      errno = ENOTCONN;
+      return NULL;
+    }
+  return dir;
+}
+
 \f
 /* Discard pending input on all input descriptors.  */
 
-- 
2.14.1.821.g8fa685d3b7-goog


  reply	other threads:[~2017-09-23 10:19 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-29 21:06 bug#27871: 26.0.50; Bad handling of unmounted directory Philipp
2017-09-23 10:19 ` Philipp Stephani [this message]
2017-09-23 10:39   ` Eli Zaretskii
2017-09-23 11:30     ` Andreas Schwab
2017-09-23 11:33       ` Philipp Stephani
2017-09-23 11:38         ` Eli Zaretskii
2017-09-23 11:41           ` Eli Zaretskii
2017-09-30 18:49             ` Philipp Stephani
2017-09-30 18:50               ` bug#27871: [PATCH] Treat unreachable current directory as error Philipp Stephani
2017-09-30 18:50               ` Philipp Stephani
2017-10-01  0:00                 ` bug#27871: " Paul Eggert
2017-10-05 10:13                   ` Eli Zaretskii
2017-10-05 23:06                     ` Paul Eggert
2017-10-07  8:49                   ` Philipp Stephani
2017-10-08  6:04                     ` Paul Eggert
2017-10-08 14:56                       ` Philipp Stephani

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='CAArVCkQ4zX60FnRtiFHJVdpJaj197Uny5kgFG3efyy=PZh5P9Q@mail.gmail.com' \
    --to=p.stephani2@gmail.com \
    --cc=27871@debbugs.gnu.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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.