From 8fd0741784e0cbaa3fd5b9c0c69bf3397818586b Mon Sep 17 00:00:00 2001 From: Glenn Morris Date: Thu, 31 Oct 2013 00:18:42 -0700 Subject: [PATCH] Fix setting of invocation-directory with --chdir and relative argv[0] * src/emacs.c (original_pwd): New char. (main): If using --chdir, store original_pwd. (init_cmdargs): When setting Vinvocation_directory based on a relative argv[0], use original_pwd if set. Fixes: debbugs:15768 --- src/ChangeLog | 7 +++++++ src/emacs.c | 23 ++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 7dab8c0d64e..64d7ea5c181 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2013-10-31 Glenn Morris + + * emacs.c (original_pwd): New char. + (main): If using --chdir, store original_pwd. + (init_cmdargs): When setting Vinvocation_directory based on a + relative argv[0], use original_pwd if set. (Bug#15768) + 2013-10-29 Stefan Monnier * keyboard.c (command_loop_1): If command is nil, call `undefined'. diff --git a/src/emacs.c b/src/emacs.c index b5d281da317..e2b47bddb32 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -202,6 +202,9 @@ static char *daemon_name; startup. */ int daemon_pipe[2]; +/* If we use --chdir, this records the original directory. */ +char *original_pwd; + /* Save argv and argc. */ char **initial_argv; int initial_argc; @@ -426,7 +429,10 @@ init_cmdargs (int argc, char **argv, int skip_args) && NILP (Ffile_name_absolute_p (Vinvocation_directory))) /* Emacs was started with relative path, like ./emacs. Make it absolute. */ - Vinvocation_directory = Fexpand_file_name (Vinvocation_directory, Qnil); + { + Lisp_Object odir = original_pwd ? build_string (original_pwd) : Qnil; + Vinvocation_directory = Fexpand_file_name (Vinvocation_directory, odir); + } Vinstallation_directory = Qnil; @@ -786,12 +792,15 @@ main (int argc, char **argv) } if (argmatch (argv, argc, "-chdir", "--chdir", 4, &ch_to_dir, &skip_args)) - if (chdir (ch_to_dir) == -1) - { - fprintf (stderr, "%s: Can't chdir to %s: %s\n", - argv[0], ch_to_dir, strerror (errno)); - exit (1); - } + { + original_pwd = get_current_dir_name (); + if (chdir (ch_to_dir) == -1) + { + fprintf (stderr, "%s: Can't chdir to %s: %s\n", + argv[0], ch_to_dir, strerror (errno)); + exit (1); + } + } dumping = !initialized && (strcmp (argv[argc - 1], "dump") == 0 || strcmp (argv[argc - 1], "bootstrap") == 0); -- 2.39.2