unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Madhu <enometh@meer.net>
To: emacs-devel@gnu.org
Subject: finding the pdmp file again
Date: Sun, 26 May 2019 12:21:47 +0530	[thread overview]
Message-ID: <m336l1908s.fsf_-_@leonis4.robolove.meer.net> (raw)
In-Reply-To: <m37ec6xui9.fsf@leonis4.robolove.meer.net>

[-- Attachment #1: Type: text/plain, Size: 834 bytes --]

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: find-pdmp-kludge --]
[-- Type: text/x-diff, Size: 2224 bytes --]

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)

  parent reply	other threads:[~2019-05-26  6:51 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-07  2:11 (select-window nil) crash with gcc-8.2.0 Madhu
2019-04-07  3:50 ` Eli Zaretskii
2019-04-07  5:19   ` Madhu
2019-04-07  7:13     ` Andreas Schwab
2019-04-07 16:16       ` Eli Zaretskii
2019-04-07 18:33     ` Paul Eggert
2019-04-07 18:38       ` Eli Zaretskii
2019-04-07 18:42         ` Paul Eggert
2019-04-08 22:08           ` Richard Stallman
2019-04-09  4:39             ` Paul Eggert
2019-04-09 23:13               ` Richard Stallman
2019-04-10  2:01                 ` Paul Eggert
2019-04-11 18:38                   ` Paul Eggert
2019-05-26  6:51     ` Madhu [this message]
2019-05-27 10:32       ` finding the pdmp file again Andreas Schwab
2019-05-27 20:13       ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m336l1908s.fsf_-_@leonis4.robolove.meer.net \
    --to=enometh@meer.net \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).