Skip to content

Commit 47ffb90

Browse files
committed
patch 8.0.0450: v:progpath is not reliably set
Problem: v:progpath is not reliably set. Solution: Read /proc/self/exe if possible. (idea by Michal Grochmal) Also fixes missing #if.
1 parent abb4d5f commit 47ffb90

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

src/config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,9 @@
446446
/* Define if fcntl()'s F_SETFD command knows about FD_CLOEXEC */
447447
#undef HAVE_FD_CLOEXEC
448448

449+
/* Define if /proc/self/exe can be read */
450+
#undef HAVE_PROC_SELF_EXE
451+
449452
/* Define if you want Cygwin to use the WIN32 clipboard, not compatible with X11*/
450453
#undef FEAT_CYGWIN_WIN32_CLIPBOARD
451454

src/main.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3539,16 +3539,27 @@ set_progpath(char_u *argv0)
35393539
{
35403540
char_u *val = argv0;
35413541

3542+
# ifdef HAVE_PROC_SELF_EXE
3543+
char buf[PATH_MAX + 1];
3544+
ssize_t len;
3545+
3546+
len = readlink("/proc/self/exe", buf, PATH_MAX);
3547+
if (len > 0)
3548+
{
3549+
buf[len] = NUL;
3550+
val = (char_u *)buf;
3551+
}
3552+
# else
35423553
/* A relative path containing a "/" will become invalid when using ":cd",
35433554
* turn it into a full path.
35443555
* On MS-Windows "vim" should be expanded to "vim.exe", thus always do
35453556
* this. */
3546-
# ifdef WIN32
3557+
# ifdef WIN32
35473558
char_u *path = NULL;
35483559

35493560
if (mch_can_exe(argv0, &path, FALSE) && path != NULL)
35503561
val = path;
3551-
# else
3562+
# else
35523563
char_u buf[MAXPATHL];
35533564

35543565
if (!mch_isFullName(argv0))

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
450,
767769
/**/
768770
449,
769771
/**/

0 commit comments

Comments
 (0)