mirror of
https://github.com/Interlisp/maiko.git
synced 2026-01-13 23:27:12 +00:00
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
This commit is contained in:
parent
b265d3a917
commit
41ae0162da
@ -12,6 +12,7 @@
|
||||
|
||||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h> // for PATH_MAX
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user