]> git.eshelyaron.com Git - emacs.git/commitdiff
* Fix native-comp startup for symliked binary (bug#44128)
authorAndrea Corallo <akrl@sdf.org>
Wed, 14 Apr 2021 13:04:19 +0000 (15:04 +0200)
committerAndrea Corallo <akrl@sdf.org>
Wed, 14 Apr 2021 13:45:20 +0000 (15:45 +0200)
* src/emacs.c (real_filename): New function.
(set_invocation_vars, load_pdump): Make use of.

src/emacs.c

index e5940ce1de64e48eade250f0d9943c68de785297..f0d75f5c20d9c07dcc02a3ccc3daa00eacea9b4f 100644 (file)
@@ -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;