emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

finding the pdmp file again


From: Madhu
Subject: finding the pdmp file again
Date: Sun, 26 May 2019 12:21:47 +0530

How about the following changes to the way emacs finds the pdmp file:

The existing algorithm remains unchanged as far as how the pdmp files
are named and the order in which they are looked up.  But when emacs
tries to guess the pdmp location, it does not fail if it finds a bad
pdmp signature but it continues searching.  (This would accomodate
having multiple variants of the same emacs installed on the system:
eg. /usr/bin/emacs-nox, /usr/bin/emacs-motif, /usr/bin/emacs-athena ...)

Then on GNU/Linux if the pdmp is still not loaded, emacs can try to
find the real argv[0] by looking at /proc/self/exe and retry the
search effort.  This would take care of the case where, say,
~/bin/emacs is a symlink to /build/emacs/src/emacs.

The idea is illustrated in the patch.  Maybe an improved version could
be added to emacs ---Madhu

klugde finding emacs.pdump

        * src/emacs.c: (load_pdump): keep going when looking for pdump
        if one doesn't load because of a bad signature.  On linux if
        basename(argv[0]).pdump isnt found then look at proc/self/exe
        for the path to the actual executable and try that once that
        instead of argv[0]. This works if emacs is a symlink.

diff --git a/src/emacs.c b/src/emacs.c
index fd46540ce2..b95bea7ab1 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -749,6 +749,15 @@ load_pdump (int argc, char **argv)
   /* Look for a dump file in the same directory as the executable; it
      should have the same basename.  */
 
+#if defined GNU_LINUX
+  /* if argv[0].pdmp is not found and argv[0] is a symlink, retry once
+     with argv[0] set to the link resolved by readlink(2). Lose if
+     readlink truncates output. */
+  char buf[PATH_MAX];
+  int ntries = 0;
+ retry:
+#endif
+
   dump_file = alloca (strlen (argv[0]) + strlen (suffix) + 1);
 #ifdef DOS_NT
   /* Remove the .exe extension if present.  */
@@ -764,7 +773,7 @@ load_pdump (int argc, char **argv)
     goto out;
 
   if (result != PDUMPER_LOAD_FILE_NOT_FOUND)
-    fatal ("could not load dump file \"%s\": %s",
+    fprintf (stderr, "could not load dump file \"%s\": %s",
            dump_file, dump_error_to_string (result));
 
 #ifdef WINDOWSNT
@@ -788,7 +797,7 @@ load_pdump (int argc, char **argv)
   if (result == PDUMPER_LOAD_SUCCESS)
     goto out;
 
-  if (result == PDUMPER_LOAD_FILE_NOT_FOUND)
+  if (result != PDUMPER_LOAD_SUCCESS)
     {
       /* Finally, look for basename(argv[0])+".pdmp" in PATH_EXEC.
         This way, they can rename both the executable and its pdump
@@ -819,6 +828,20 @@ load_pdump (int argc, char **argv)
       result = pdumper_load (dump_file);
     }
 
+#if defined GNU_LINUX
+  if (result != PDUMPER_LOAD_SUCCESS) {
+    if (++ntries == 2) goto out;
+    int nbytes = readlink("/proc/self/exe", buf, PATH_MAX);
+    if (nbytes == -1) {
+      perror("readlink /proc/self/exe");
+      goto out;
+    }
+    if (nbytes < sizeof(buf)) buf[nbytes] = 0;
+    argv[0] = buf;             /* XXX use argv0=argv[0] */
+    goto retry;
+  }
+#endif
+
   if (result != PDUMPER_LOAD_SUCCESS)
     {
       if (result != PDUMPER_LOAD_FILE_NOT_FOUND)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]