From 41ae0162da439bcd1912a9cb65aae5d655fe95cd Mon Sep 17 00:00:00 2001 From: Nick Briggs Date: Sun, 7 May 2023 15:10:01 -0700 Subject: [PATCH] Construct path for invoking display executable to match original path of lde The pathname for the display program is constructed to parallel the path for "lde", which makes it more likely that the correct display program will get run rather than (a) not being found because "lde" wasn't found from the PATH, or (b) a different version of the display program which was found from the PATH --- src/ldeboot.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/ldeboot.c b/src/ldeboot.c index 1fd356d..6e18927 100644 --- a/src/ldeboot.c +++ b/src/ldeboot.c @@ -12,6 +12,7 @@ #include #include +#include // for PATH_MAX #include #include #include @@ -59,6 +60,8 @@ int main(int argc, char *argv[]) { int i; char *filetorun = NULL; + char filetorunpath[PATH_MAX]; + char *dirsepp = NULL; char *displayName = (char *)NULL; int doFork = 1; #ifdef USESUNSCREEN @@ -187,7 +190,21 @@ int main(int argc, char *argv[]) { fprintf(stderr, "Unable to determine what display program to run.\n"); exit(1); } - argv[0] = filetorun; + + /* construct invocation path of display program parallel to this one, + * so that it will have higher probability of finding a corresponding + * display program if there are multiple versions findable via PATH + */ + dirsepp = strrchr(argv[0], '/'); + if (dirsepp == NULL) { + argv[0] = filetorun; + } else { + /* copy up to and including the final "/" in the path */ + dirsepp = stpncpy(filetorunpath, argv[0], dirsepp + 1 - argv[0]); + /* dirsepp now points to the trailing null in the copy */ + strncpy(dirsepp, filetorun, PATH_MAX - (dirsepp - filetorunpath)); + argv[0] = filetorunpath; + } execvp(argv[0], argv); perror(argv[0]); exit(1);