From 0c1fc9d581ad64efc96c1efccbb4d057796ef807 Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Wed, 14 Apr 2021 15:04:19 +0200 Subject: [PATCH] * Fix native-comp startup for symliked binary (bug#44128) * src/emacs.c (real_filename): New function. (set_invocation_vars, load_pdump): Make use of. --- src/emacs.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/src/emacs.c b/src/emacs.c index e5940ce1de6..f0d75f5c20d 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -440,6 +440,28 @@ terminate_due_to_signal (int sig, int backtrace_limit) exit (1); } +/* Return the real filename following symlinks in case. + The caller should deallocate the returned buffer. */ + +static char * +real_filename (char *filename) +{ + char *real_name; +#ifdef WINDOWSNT + /* w32_my_exename resolves symlinks internally, so no need to + call realpath. */ + real_name = xmalloc (strlen (filename)); + strcpy (real_name, filename); + return real_name; +#else + real_name = realpath (filename, NULL); + if (!real_name) + fatal ("could not resolve realpath of \"%s\": %s", + filename, strerror (errno)); + return real_name; +#endif +} + /* Set `invocation-name' `invocation-directory'. */ static void @@ -475,6 +497,10 @@ set_invocation_vars (char *argv0, char const *original_pwd) if (! NILP (handler)) raw_name = concat2 (slash_colon, raw_name); + char *filename = real_filename (SSDATA (raw_name)); + raw_name = build_unibyte_string (filename); + xfree (filename); + Vinvocation_name = Ffile_name_nondirectory (raw_name); Vinvocation_directory = Ffile_name_directory (raw_name); @@ -888,17 +914,9 @@ load_pdump (int argc, char **argv, char const *original_pwd) the dump in the hardcoded location. */ if (dump_file && *dump_file) { -#ifdef WINDOWSNT - /* w32_my_exename resolves symlinks internally, so no need to - call realpath. */ -#else - char *real_exename = realpath (dump_file, NULL); - if (!real_exename) - fatal ("could not resolve realpath of \"%s\": %s", - dump_file, strerror (errno)); + char *real_exename = real_filename (dump_file); xfree (dump_file); dump_file = real_exename; -#endif ptrdiff_t exenamelen = strlen (dump_file); #ifndef WINDOWSNT bufsize = exenamelen + 1; -- 2.39.5