unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Alan Third <alan@idiocy.org>, Sean Devlin <spd@toadstyle.org>,
	42836@debbugs.gnu.org
Subject: bug#42836: 27.1; default-directory is set to "/" after startup
Date: Thu, 13 Aug 2020 12:54:00 -0700	[thread overview]
Message-ID: <f2dedd0c-2163-a6ab-a026-ef6e0d67d99f@cs.ucla.edu> (raw)
In-Reply-To: <20200813145237.GA26932@breton.holly.idiocy.org>

[-- Attachment #1: Type: text/plain, Size: 416 bytes --]

On 8/13/20 7:52 AM, Alan Third wrote:
> I suspect the best solution here is to move the code at line
> emacs.c:1623 to before emacs_wd is set. What do you think, Paul?

It's probably safer to leave the code where it is, and to update emacs_wd if 
Emacs chdirs successfully.

Does the attached patch work for you? If so, I can install it into the emacs-27 
branch. (I don't use macOS so can't easily test it myself.)

[-- Attachment #2: 0001-Fix-startup-working-dir-bug-on-NeXTSTEP.patch --]
[-- Type: text/x-patch, Size: 1623 bytes --]

From 5bf06fd09669d4b48dc0e3f3f756006d0ca2059b Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Thu, 13 Aug 2020 12:48:57 -0700
Subject: [PATCH] Fix startup working dir bug on NeXTSTEP

* src/emacs.c (main) [NS_IMPL_COCOA]: Update emacs_wd
after a NS GUI chdirs successfully (Bug#42836).
---
 src/emacs.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/emacs.c b/src/emacs.c
index 1dcf195891..11dcdb33fe 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -1638,23 +1638,27 @@ main (int argc, char **argv)
     {
 #ifdef NS_IMPL_COCOA
       /* Started from GUI? */
-      /* FIXME: Do the right thing if get_homedir returns "", or if
-         chdir fails.  */
-      if (! inhibit_window_system && ! isatty (STDIN_FILENO) && ! ch_to_dir)
-        chdir (get_homedir ());
+      bool go_home = (!ch_to_dir && !inhibit_window_system
+		      && !isatty (STDIN_FILENO));
       if (skip_args < argc)
         {
           if (!strncmp (argv[skip_args], "-psn", 4))
             {
               skip_args += 1;
-              if (! ch_to_dir) chdir (get_homedir ());
+	      go_home |= !ch_to_dir;
             }
           else if (skip_args+1 < argc && !strncmp (argv[skip_args+1], "-psn", 4))
             {
               skip_args += 2;
-              if (! ch_to_dir) chdir (get_homedir ());
+	      go_home |= !ch_to_dir;
             }
         }
+      if (go_home)
+	{
+	  char const *home = get_homedir ();
+	  if (*home && chdir (home) == 0)
+	    emacs_wd = emacs_get_current_dir_name ();
+	}
 #endif  /* COCOA */
     }
 #endif /* HAVE_NS */
-- 
2.17.1


  reply	other threads:[~2020-08-13 19:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-12 20:53 bug#42836: 27.1; default-directory is set to "/" after startup Sean Devlin
     [not found] ` <handler.42836.B.15972656459719.ack@debbugs.gnu.org>
2020-08-12 21:17   ` Sean Devlin
2020-08-12 22:52     ` Alan Third
2020-08-13 14:52       ` Alan Third
2020-08-13 19:54         ` Paul Eggert [this message]
2020-08-13 21:18           ` Sean Devlin
2020-08-13 22:06           ` Alan Third
2020-08-13 22:44             ` Paul Eggert
2020-08-13  2:32     ` Eli Zaretskii
2020-08-13  4:08       ` Sean Devlin

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=f2dedd0c-2163-a6ab-a026-ef6e0d67d99f@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=42836@debbugs.gnu.org \
    --cc=alan@idiocy.org \
    --cc=spd@toadstyle.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 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).