From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Madhu Newsgroups: gmane.emacs.devel Subject: finding the pdmp file again Date: Sun, 26 May 2019 12:21:47 +0530 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="227183"; mail-complaints-to="usenet@blaine.gmane.org" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon May 27 12:20:19 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hVCjq-000wv6-1u for ged-emacs-devel@m.gmane.org; Mon, 27 May 2019 12:20:18 +0200 Original-Received: from localhost ([127.0.0.1]:43199 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hVCjp-0004HF-26 for ged-emacs-devel@m.gmane.org; Mon, 27 May 2019 06:20:17 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:50891) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hVCji-0004H8-77 for emacs-devel@gnu.org; Mon, 27 May 2019 06:20:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hVCje-0007ly-K9 for emacs-devel@gnu.org; Mon, 27 May 2019 06:20:08 -0400 Original-Received: from [195.159.176.226] (port=56562 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hVCje-0007kY-Dv for emacs-devel@gnu.org; Mon, 27 May 2019 06:20:06 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.89) (envelope-from ) id 1hVCja-000wYr-3p for emacs-devel@gnu.org; Mon, 27 May 2019 12:20:02 +0200 X-Injected-Via-Gmane: http://gmane.org/ In-Reply-To: Cancel-Lock: sha1:Qj9ei5dehjeodg3kbDgldkByIp8= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:237037 Archived-At: --=-=-= Content-Type: text/plain 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 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=emacs-27-pdmp-kludge.diff Content-Description: find-pdmp-kludge 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) --=-=-=--