From dc0cf16c7a60f36aafcf9b56513a855cefa7e1ad Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Sat, 26 Sep 2020 15:12:30 +0200 Subject: [PATCH] Always set 'Vexec_path' before 'Vinvocation_directory' (bug#43137) Do this as depending on the OS if argv0 is not populated 'Vexec_path' is used to infer 'Vinvocation_directory'. * src/pdumper.c (pdumper_load): Invoke 'init_vars_for_load' instead of 'set_invocation_vars'. * src/lisp.h: Extern 'init_vars_for_load' instead of 'set_invocation_vars' . * src/emacs.c (set_invocation_vars): Make it static and remove double invocation guard. (init_vars_for_load): Wrap 'init_callproc_1' and 'set_invocation_vars' calls + add double invocation guard. (init_cmdargs): Move out 'set_invocation_vars' invocation. (main): Call 'init_vars_for_load' instead of 'init_callproc_1'. --- src/emacs.c | 32 +++++++++++++++++++++----------- src/lisp.h | 2 +- src/pdumper.c | 3 ++- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/emacs.c b/src/emacs.c index 07e40fdc8bd..1f7f5eabc56 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -413,16 +413,9 @@ terminate_due_to_signal (int sig, int backtrace_limit) /* Set `invocation-name' `invocation-directory'. */ -void +static void set_invocation_vars (char *argv0, char const *original_pwd) { - /* 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, "/:"); @@ -480,6 +473,25 @@ set_invocation_vars (char *argv0, char const *original_pwd) } } +/* Initialize a number of variables (ultimately + 'Vinvocation_directory') needed by pdumper to complete native code + load. */ + +void +init_vars_for_load (char *argv0, char const *original_pwd) +{ + /* This function is called from within pdumper while loading (as + soon as we are able to allocate) or later during boot if pdumper + is not used. No need to run it twice. */ + static bool double_run_guard; + if (double_run_guard) + return; + double_run_guard = true; + + init_callproc_1 (); /* Must precede init_cmdargs and init_sys_modes. */ + set_invocation_vars (argv0, original_pwd); +} + /* Code for dealing with Lisp access to the Unix command line. */ static void @@ -492,8 +504,6 @@ init_cmdargs (int argc, char **argv, int skip_args, char const *original_pwd) initial_argv = argv; initial_argc = argc; - set_invocation_vars (argv[0], original_pwd); - Vinstallation_directory = Qnil; if (!NILP (Vinvocation_directory)) @@ -1788,7 +1798,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem /* Init buffer storage and default directory of main buffer. */ init_buffer (); - init_callproc_1 (); /* Must precede init_cmdargs and init_sys_modes. */ + init_vars_for_load (argv[0], original_pwd); /* Must precede init_lread. */ init_cmdargs (argc, argv, skip_args, original_pwd); diff --git a/src/lisp.h b/src/lisp.h index 452f48f3468..e33577b5633 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4430,7 +4430,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); +extern void init_vars_for_load (char *, char const *); #ifdef WINDOWSNT extern Lisp_Object Vlibrary_cache; #endif diff --git a/src/pdumper.c b/src/pdumper.c index 0a7e0388f1d..03391c49505 100644 --- a/src/pdumper.c +++ b/src/pdumper.c @@ -5587,7 +5587,8 @@ pdumper_load (const char *dump_filename, char *argv0, char const *original_pwd) /* 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); + init_vars_for_load (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; -- 2.39.5