Skip to content

Commit 69367ad

Browse files
committed
Added auto resolve of symbolic links (for homebrew)
1 parent c886757 commit 69367ad

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed
272 Bytes
Binary file not shown.

javatools_launcher/src/main/c/launcher.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ int main(int argc, const char* argv[])
3030
const char* execPath = findLauncherPath();
3131

3232
// next, load the optional config for the executable
33-
const char* execDir = extractDir(execPath);
33+
const char* execDir = extractDir(resolveLinks(execPath));
3434
const char* execFile = removeExtension(extractFile(execPath));
3535
const char* cfgPath = buildPath(execDir, withExtension(execFile, ".cfg"));
3636
const char* cfg = readFile(cfgPath);
@@ -54,6 +54,9 @@ static int garbageCount = 0;
5454
*/
5555
static void init()
5656
{
57+
// for any debug output, stdout must not be buffered
58+
setbuf(stdout, NULL);
59+
5760
memset(garbage, 0, MAX_GARBAGE * sizeof(void*));
5861
}
5962

javatools_launcher/src/main/c/os_specific.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@
2323
*/
2424
extern const char* findLauncherPath();
2525

26+
/**
27+
* If the file is a link, follow the link until a real file is found.
28+
*
29+
* @param path the path to a file that may be a link
30+
*
31+
* @return the file at the end of the linked list of links
32+
*/
33+
extern const char* resolveLinks(const char* path);
34+
2635
/**
2736
* Execute the JVM against the specified JAR.
2837
*

javatools_launcher/src/main/c/os_unux.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <limits.h>
12
#include <stdio.h>
23
#include <string.h>
34
#include <stdlib.h>
@@ -9,6 +10,23 @@
910

1011
// shared code for Linux and macos implementations
1112

13+
const char* resolveLinks(const char* path)
14+
{
15+
char ach[PATH_MAX];
16+
if (!realpath(path, ach))
17+
{
18+
abortLaunch("Unresolvable link");
19+
}
20+
21+
if (strcmp(path, ach) == 0)
22+
{
23+
return path;
24+
}
25+
26+
char* result = allocBuffer(strlen(ach)+1);
27+
strcpy(result, ach);
28+
return result;
29+
}
1230

1331
void execJava(const char* javaPath,
1432
const char* javaOpts,

0 commit comments

Comments
 (0)