]> git.eshelyaron.com Git - emacs.git/commitdiff
Set invocation variables during dump load.
authorAndrea Corallo <akrl@sdf.org>
Sun, 12 Apr 2020 11:38:46 +0000 (12:38 +0100)
committerAndrea Corallo <akrl@sdf.org>
Sun, 12 Apr 2020 15:52:05 +0000 (16:52 +0100)
Vinvocation_directory must be set during dump load process to support
.eln load.

* src/pdumper.h: (pdumper_load): Add argv0 and original_pwd
parameters.

* src/pdumper.c (pdumper_load): Add argv0 and original_pwd
parameter plus call 'set_invocation_vars'.

* src/lisp.h (set_invocation_vars): New function.

* src/emacs.c (set_invocation_vars): New function.
(init_cmdargs): Move logic into 'set_invocation_vars' and call it.
(load_pdump): Add 'original_pwd' parameter and update calls to
'pdumper_load'.
(main): Set emacs_wd earlier and update call to 'pdumper_load'.

src/emacs.c
src/lisp.h
src/pdumper.c
src/pdumper.h

index fcc02a3a874a94c90bd87f3fe397dacdb7054afe..2c908257422f4ab03c2bd614ab62613e4e812b32 100644 (file)
@@ -403,34 +403,35 @@ terminate_due_to_signal (int sig, int backtrace_limit)
   /* This shouldn't be executed, but it prevents a warning.  */
   exit (1);
 }
-\f
-/* Code for dealing with Lisp access to the Unix command line.  */
 
-static void
-init_cmdargs (int argc, char **argv, int skip_args, char const *original_pwd)
+/* Set `invocation-name' `invocation-directory'.  */
+
+void
+set_invocation_vars (char *argv0, char const *original_pwd)
 {
-  int i;
-  Lisp_Object name, dir, handler;
-  ptrdiff_t count = SPECPDL_INDEX ();
-  Lisp_Object raw_name;
+  /* This function can be called from within pdumper or later during
+     boot.  No need to run it twice.  */
+  static bool double_run_guard;
+  if (double_run_guard)
+    return;
+  double_run_guard = true;
+
+  Lisp_Object raw_name, handler;
   AUTO_STRING (slash_colon, "/:");
 
-  initial_argv = argv;
-  initial_argc = argc;
-
 #ifdef WINDOWSNT
-  /* Must use argv[0] converted to UTF-8, as it begets many standard
+  /* Must use argv0 converted to UTF-8, as it begets many standard
      file and directory names.  */
   {
-    char argv0[MAX_UTF8_PATH];
+    char argv0_1[MAX_UTF8_PATH];
 
-    if (filename_from_ansi (argv[0], argv0) == 0)
-      raw_name = build_unibyte_string (argv0);
+    if (filename_from_ansi (argv0, argv0_1) == 0)
+      raw_name = build_unibyte_string (argv0_1);
     else
-      raw_name = build_unibyte_string (argv[0]);
+      raw_name = build_unibyte_string (argv0);
   }
 #else
-  raw_name = build_unibyte_string (argv[0]);
+  raw_name = build_unibyte_string (argv0);
 #endif
 
   /* Add /: to the front of the name
@@ -442,7 +443,7 @@ init_cmdargs (int argc, char **argv, int skip_args, char const *original_pwd)
   Vinvocation_name = Ffile_name_nondirectory (raw_name);
   Vinvocation_directory = Ffile_name_directory (raw_name);
 
-  /* If we got no directory in argv[0], search PATH to find where
+  /* If we got no directory in argv0, search PATH to find where
      Emacs actually came from.  */
   if (NILP (Vinvocation_directory))
     {
@@ -470,6 +471,21 @@ init_cmdargs (int argc, char **argv, int skip_args, char const *original_pwd)
 
       Vinvocation_directory = Fexpand_file_name (Vinvocation_directory, odir);
     }
+}
+
+\f
+/* Code for dealing with Lisp access to the Unix command line.  */
+static void
+init_cmdargs (int argc, char **argv, int skip_args, char const *original_pwd)
+{
+  int i;
+  Lisp_Object name, dir;
+  ptrdiff_t count = SPECPDL_INDEX ();
+
+  initial_argv = argv;
+  initial_argc = argc;
+
+  set_invocation_vars (argv[0], original_pwd);
 
   Vinstallation_directory = Qnil;
 
@@ -758,7 +774,7 @@ load_pdump_find_executable (char const *argv0, ptrdiff_t *candidate_size)
 }
 
 static void
-load_pdump (int argc, char **argv)
+load_pdump (int argc, char **argv, char const *original_pwd)
 {
   const char *const suffix = ".pdmp";
   int result;
@@ -793,7 +809,7 @@ load_pdump (int argc, char **argv)
 
   if (dump_file)
     {
-      result = pdumper_load (dump_file);
+      result = pdumper_load (dump_file, argv[0], original_pwd);
 
       if (result != PDUMPER_LOAD_SUCCESS)
         fatal ("could not load dump file \"%s\": %s",
@@ -842,7 +858,7 @@ load_pdump (int argc, char **argv)
       if (bufsize < needed)
        dump_file = xpalloc (dump_file, &bufsize, needed - bufsize, -1, 1);
       strcpy (dump_file + exenamelen, suffix);
-      result = pdumper_load (dump_file);
+      result = pdumper_load (dump_file, argv[0], original_pwd);
       if (result == PDUMPER_LOAD_SUCCESS)
         goto out;
 
@@ -873,7 +889,7 @@ load_pdump (int argc, char **argv)
     }
   sprintf (dump_file, "%s%c%s%s",
            path_exec, DIRECTORY_SEP, argv0_base, suffix);
-  result = pdumper_load (dump_file);
+  result = pdumper_load (dump_file, argv[0], original_pwd);
 
   if (result == PDUMPER_LOAD_FILE_NOT_FOUND)
     {
@@ -908,7 +924,7 @@ load_pdump (int argc, char **argv)
 #endif
       sprintf (dump_file, "%s%c%s%s",
               path_exec, DIRECTORY_SEP, argv0_base, suffix);
-      result = pdumper_load (dump_file);
+      result = pdumper_load (dump_file, argv[0], original_pwd);
     }
 
   if (result != PDUMPER_LOAD_SUCCESS)
@@ -929,7 +945,6 @@ main (int argc, char **argv)
   /* Variable near the bottom of the stack, and aligned appropriately
      for pointers.  */
   void *stack_bottom_variable;
-
   bool no_loadup = false;
   char *junk = 0;
   char *dname_arg = 0;
@@ -1048,9 +1063,10 @@ main (int argc, char **argv)
   w32_init_main_thread ();
 #endif
 
+  emacs_wd = emacs_get_current_dir_name ();
 #ifdef HAVE_PDUMPER
   if (attempt_load_pdump)
-    load_pdump (argc, argv);
+    load_pdump (argc, argv, emacs_wd);
 #endif
 
   argc = maybe_disable_address_randomization (argc, argv);
@@ -1122,7 +1138,6 @@ main (int argc, char **argv)
       exit (0);
     }
 
-  emacs_wd = emacs_get_current_dir_name ();
 #ifdef HAVE_PDUMPER
   if (dumped_with_pdumper_p ())
     pdumper_record_wd (emacs_wd);
index 9eccbd2f794d224a18e4f91c592cc7f2d0b5feab..5456b9cce8f551e666f2e90e9e3428ecaf92e718 100644 (file)
@@ -4423,6 +4423,7 @@ extern bool display_arg;
 extern Lisp_Object decode_env_path (const char *, const char *, bool);
 extern Lisp_Object empty_unibyte_string, empty_multibyte_string;
 extern AVOID terminate_due_to_signal (int, int);
+extern void set_invocation_vars (char *argv0, char const *original_pwd);
 #ifdef WINDOWSNT
 extern Lisp_Object Vlibrary_cache;
 #endif
index 7fbacfe4a1a9093fc71c3c0daf8424f2008ec470..69594b51c597ed9007f11029a621c3dc315bf094 100644 (file)
@@ -5428,7 +5428,7 @@ enum dump_section
    N.B. We run very early in initialization, so we can't use lisp,
    unwinding, xmalloc, and so on.  */
 int
-pdumper_load (const char *dump_filename)
+pdumper_load (const char *dump_filename, char *argv0, char const *original_pwd)
 {
   intptr_t dump_size;
   struct stat stat;
@@ -5574,6 +5574,9 @@ pdumper_load (const char *dump_filename)
   for (int i = 0; i < nr_dump_hooks; ++i)
     dump_hooks[i] ();
 
+  /* Once we can allocate and before loading .eln files we must set
+     Vinvocation_directory (.eln paths are relative to it). */
+  set_invocation_vars (argv0, original_pwd);
   dump_do_all_dump_reloc_for_phase (header, dump_base, LATE_RELOCS);
   dump_do_all_dump_reloc_for_phase (header, dump_base, VERY_LATE_RELOCS);
   initialized = true;
index 6a99b511f2f6dca8b3ded04107d4388bb367a319..b92958e12bca74db79a9a765e9114019e9ea43e5 100644 (file)
@@ -127,7 +127,8 @@ enum pdumper_load_result
     PDUMPER_LOAD_ERROR /* Must be last, as errno may be added.  */
   };
 
-int pdumper_load (const char *dump_filename);
+int pdumper_load (const char *dump_filename, char *argv0,
+                 char const *original_pwd);
 
 struct pdumper_loaded_dump
 {