emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r114880: Fix setting of invocation-directory with --


From: Glenn Morris
Subject: [Emacs-diffs] trunk r114880: Fix setting of invocation-directory with --chdir and relative argv[0]
Date: Thu, 31 Oct 2013 07:18:58 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 114880
revision-id: address@hidden
parent: address@hidden
fixes bug: http://debbugs.gnu.org/15768
committer: Glenn Morris <address@hidden>
branch nick: trunk
timestamp: Thu 2013-10-31 00:18:42 -0700
message:
  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.
modified:
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/emacs.c                    emacs.c-20091113204419-o5vbwnq5f7feedwu-241
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2013-10-29 21:05:35 +0000
+++ b/src/ChangeLog     2013-10-31 07:18:42 +0000
@@ -1,3 +1,10 @@
+2013-10-31  Glenn Morris  <address@hidden>
+
+       * 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  <address@hidden>
 
        * keyboard.c (command_loop_1): If command is nil, call `undefined'.

=== modified file 'src/emacs.c'
--- a/src/emacs.c       2013-10-26 13:43:58 +0000
+++ b/src/emacs.c       2013-10-31 07:18:42 +0000
@@ -202,6 +202,9 @@
    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 @@
       && 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 @@
     }
 
   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);


reply via email to

[Prev in Thread] Current Thread [Next in Thread]