From 54d85f123e1a103f3e491cd8310d5d4c1b4f4b15 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 24 Jul 2025 05:32:37 -0700 Subject: [PATCH] =?utf8?q?Treat=20=E2=80=98.../emacs=E2=80=99=20like=20?= =?utf8?q?=E2=80=98emacs=E2=80=99=20in=20realpath=20startup?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * src/emacs.c (find_emacs_executable): If the executable name contains a slash, use the same optimization for symlink resolution that we already use when the executable name has no slash. (cherry picked from commit d59fe6dad5667720b296569d2f6fe1b84d42fd0a) --- src/emacs.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/emacs.c b/src/emacs.c index 0e10398dc78..3689c92c8b2 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -767,15 +767,11 @@ find_emacs_executable (char const *argv0, ptrdiff_t *candidate_size) eassert (argv0); if (strchr (argv0, DIRECTORY_SEP)) { - char *real_name = realpath (argv0, NULL); - - if (real_name) - { - *candidate_size = strlen (real_name) + 1; - return real_name; - } - - char *val = xstrdup (argv0); + char *val = (readlink (argv0, linkbuf, sizeof linkbuf) < 0 + ? NULL + : realpath (argv0, NULL)); + if (!val) + val = xstrdup (argv0); *candidate_size = strlen (val) + 1; return val; } -- 2.39.5