Skip to content

Commit

Permalink
Added auto resolve of symbolic links (for homebrew)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpurdy committed Jun 3, 2022
1 parent c886757 commit 69367ad
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
Binary file modified javatools_launcher/build/exe/macos_launcher
Binary file not shown.
5 changes: 4 additions & 1 deletion javatools_launcher/src/main/c/launcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ int main(int argc, const char* argv[])
const char* execPath = findLauncherPath();

// next, load the optional config for the executable
const char* execDir = extractDir(execPath);
const char* execDir = extractDir(resolveLinks(execPath));
const char* execFile = removeExtension(extractFile(execPath));
const char* cfgPath = buildPath(execDir, withExtension(execFile, ".cfg"));
const char* cfg = readFile(cfgPath);
Expand All @@ -54,6 +54,9 @@ static int garbageCount = 0;
*/
static void init()
{
// for any debug output, stdout must not be buffered
setbuf(stdout, NULL);

memset(garbage, 0, MAX_GARBAGE * sizeof(void*));
}

Expand Down
9 changes: 9 additions & 0 deletions javatools_launcher/src/main/c/os_specific.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@
*/
extern const char* findLauncherPath();

/**
* If the file is a link, follow the link until a real file is found.
*
* @param path the path to a file that may be a link
*
* @return the file at the end of the linked list of links
*/
extern const char* resolveLinks(const char* path);

/**
* Execute the JVM against the specified JAR.
*
Expand Down
18 changes: 18 additions & 0 deletions javatools_launcher/src/main/c/os_unux.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
Expand All @@ -9,6 +10,23 @@

// shared code for Linux and macos implementations

const char* resolveLinks(const char* path)
{
char ach[PATH_MAX];
if (!realpath(path, ach))
{
abortLaunch("Unresolvable link");
}

if (strcmp(path, ach) == 0)
{
return path;
}

char* result = allocBuffer(strlen(ach)+1);
strcpy(result, ach);
return result;
}

void execJava(const char* javaPath,
const char* javaOpts,
Expand Down

0 comments on commit 69367ad

Please sign in to comment.