Subject: Re: [PATCH] Treat unreachable current directory as error

From: Paul Eggert <[email-masked]>
Date: Sat, 30 Sep 2017 17:00:06 -0700

Philipp Stephani wrote:

> +  if (!file_name_absolute_p (dir))

That doesn't look right here, since leading '~' counts as absolute to 
file_name_absolute_p, which is not what is wanted here.

> +      errno = ENOTCONN;

Why ENOTCONN? Shouldn't it be ENOENT? The failure has nothing to do with socket 
connections.

Also, I'd feel a bit better if we apply the workaround only to the function that 
has the problem.

How about the attached patch instead?
From a1f839b0c60fb345944ee39626e8645402c1f060 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Sat, 30 Sep 2017 16:53:54 -0700
Subject: [PATCH] Fix bug with unmounted directory on GNU/Linux

* src/sysdep.c (emacs_get_current_dir_name): Do not use
get_current_dir_name result unless it is absolute (Bug#27871).
---
 src/sysdep.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/sysdep.c b/src/sysdep.c
index 1e6e0d011b..a3526c3740 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -232,7 +232,18 @@ emacs_get_current_dir_name (void)
   bool use_libc = true;
 #  endif
   if (use_libc)
-    return get_current_dir_name ();
+    {
+      /* GNU/Linux get_current_dir_name can return a string starting
+	 with "(unreachable)" (Bug#27871).  */
+      char *wd = get_current_dir_name ();
+      if (wd && ! (IS_DIRECTORY_SEP (*wd) || (*wd && IS_DEVICE_SEP (wd[1]))))
+	{
+	  free (wd);
+	  errno = ENOENT;
+	  return NULL;
+	}
+      return wd;
+    }
 # endif
 
   char *buf;
-- 
2.13.5