Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 37 additions & 15 deletions src/main/java/org/sqlite/util/OSInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,22 +145,44 @@ public static boolean isAndroidTermux() {
}

public static boolean isMusl() {
Path mapFilesDir = Paths.get("/proc/self/map_files");
try (Stream<Path> dirStream = Files.list(mapFilesDir)) {
return dirStream
.map(
path -> {
try {
return path.toRealPath().toString();
} catch (IOException e) {
return "";
}
})
.anyMatch(s -> s.toLowerCase().contains("musl"));
if (hasMuslLoader()) {
return true;
}

if (mapsContainMusl()) {
return true;
}

// fallback check Alpine
return isAlpineLinux();
}

private static boolean hasMuslLoader() {
return checkMuslLoaderInDir("/lib") || checkMuslLoaderInDir("/usr/lib");
}

private static boolean checkMuslLoaderInDir(String dir) {
try (Stream<Path> paths = Files.list(Paths.get(dir))) {
return paths
.map(Path::getFileName)
.map(Path::toString)
.anyMatch(name ->
name.startsWith("ld-musl-") && name.endsWith(".so.1"));
} catch (Exception ignored) {
// fall back to checking for alpine linux in the event we're using an older kernel which
// may not fail the above check
return isAlpineLinux();
return false;
}
}

private static boolean mapsContainMusl() {
return checkMapsContainMusl("/proc/self/maps") || checkMapsContainMusl("/proc/self/map_files");
}

private static boolean checkMapsContainMusl(String dir) {
try (Stream<String> lines = Files.lines(Paths.get(dir))) {
return lines.anyMatch(line ->
line.toLowerCase(Locale.US).contains("musl"));
} catch (Exception ignored) {
return false;
}
}

Expand Down
Loading