summaryrefslogtreecommitdiff
path: root/src/emacs.c
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2022-04-17 17:20:03 +0300
committerEli Zaretskii <eliz@gnu.org>2022-04-17 17:20:03 +0300
commit5a63af876bc131b07e066aa9d60780de0562bcb0 (patch)
tree5897563f39ec6da237688abc887572d042bc73be /src/emacs.c
parent56d5a4079423aa22d2203a342439df7359eb1c18 (diff)
downloademacs-5a63af876bc131b07e066aa9d60780de0562bcb0.tar.gz
emacs-5a63af876bc131b07e066aa9d60780de0562bcb0.tar.bz2
emacs-5a63af876bc131b07e066aa9d60780de0562bcb0.zip
Fix 'restart-emacs' on MS-Windows
* src/w32.c (w32_reexec_emacs): New function, emulation of 'execvp' on Posix systems. * src/w32.h (w32_reexec_emacs): Add prototype. * src/emacs.c (main) [WINDOWSNT]: Save the original command line and working directory. (Fkill_emacs) [WINDOWSNT]: Call 'w32_reexec_emacs' instead of 'execvp'. (Bug#17036)
Diffstat (limited to 'src/emacs.c')
-rw-r--r--src/emacs.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/emacs.c b/src/emacs.c
index a16e702ab7b..8c897762a2b 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -159,6 +159,10 @@ Lisp_Object empty_unibyte_string, empty_multibyte_string;
#ifdef WINDOWSNT
/* Cache for externally loaded libraries. */
Lisp_Object Vlibrary_cache;
+/* Original command line string as received from the OS. */
+static char *initial_cmdline;
+/* Original working directory when invoked. */
+static const char *initial_wd;
#endif
struct gflags gflags;
@@ -1319,6 +1323,7 @@ main (int argc, char **argv)
}
}
init_heap (use_dynamic_heap);
+ initial_cmdline = GetCommandLine ();
#endif
#if defined WINDOWSNT || defined HAVE_NTGUI
/* Set global variables used to detect Windows version. Do this as
@@ -1465,6 +1470,9 @@ main (int argc, char **argv)
#endif
emacs_wd = emacs_get_current_dir_name ();
+#ifdef WINDOWSNT
+ initial_wd = emacs_wd;
+#endif
#ifdef HAVE_PDUMPER
if (dumped_with_pdumper_p ())
pdumper_record_wd (emacs_wd);
@@ -2811,7 +2819,11 @@ killed. */
(on some systems) with no argv. */
if (initial_argc < 1)
error ("No command line arguments known; unable to re-execute Emacs");
+#ifdef WINDOWSNT
+ if (w32_reexec_emacs (initial_cmdline, initial_wd) < 1)
+#else
if (execvp (*initial_argv, initial_argv) < 1)
+#endif
error ("Unable to re-execute Emacs");
}