From: Philipp Stephani <p.stephani2@gmail.com>
To: emacs-devel@gnu.org, 27871@debbugs.gnu.org
Cc: Philipp Stephani <phst@google.com>
Subject: bug#27871: [PATCH] Treat unreachable current directory as error
Date: Sat, 30 Sep 2017 20:50:06 +0200 [thread overview]
Message-ID: <20170930185006.54096-1-phst__23196.6883097359$1506797472$gmane$org@google.com> (raw)
In-Reply-To: <CAArVCkQ+S_-zOdqWz8FZKibCqmJu0BO4OKk1WQihAaaoE6ACaA@mail.gmail.com>
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 | 27 +++++++++++++++++++++++----
1 file changed, 23 insertions(+), 4 deletions(-)
diff --git a/src/sysdep.c b/src/sysdep.c
index 1e6e0d011b..efc0396c93 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,27 @@ 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. */
+ if (!file_name_absolute_p (dir))
+ {
+ free (dir);
+ errno = ENOTCONN;
+ return NULL;
+ }
+ return dir;
+}
+
\f
/* Discard pending input on all input descriptors. */
--
2.14.1
next prev parent reply other threads:[~2017-09-30 18:50 UTC|newest]
Thread overview: 15+ 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
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 ` Philipp Stephani [this message]
[not found] ` <20170930185006.54096-1-phst@google.com>
2017-10-01 0:00 ` bug#27871: [PATCH] Treat unreachable current directory as error 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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='20170930185006.54096-1-phst__23196.6883097359$1506797472$gmane$org@google.com' \
--to=p.stephani2@gmail.com \
--cc=27871@debbugs.gnu.org \
--cc=emacs-devel@gnu.org \
--cc=phst@google.com \
/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.savannah.gnu.org/cgit/emacs.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).