diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/StarterAgent.java b/LaunchServer/src/main/java/ru/gravit/launchserver/StarterAgent.java index ed8b85c5..f0eb5170 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/StarterAgent.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/StarterAgent.java @@ -2,6 +2,7 @@ import java.io.IOException; import java.lang.instrument.Instrumentation; +import java.lang.management.ManagementFactory; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import java.util.Collections; @@ -24,7 +25,8 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO } } - public static Instrumentation inst; + public static Instrumentation inst = null; + public static Path libraries = null; private static boolean isStarted = false; public static boolean isAgentStarted() { @@ -35,9 +37,20 @@ public static void premain(String agentArgument, Instrumentation inst) { StarterAgent.inst = inst; isStarted = true; try { - Files.walkFileTree(Paths.get("libraries"), Collections.singleton(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new StarterVisitor(inst)); - } catch (IOException e) { + libraries = Paths.get("libraries"); + if (ManagementFactory.getOperatingSystemMXBean().getName().startsWith("Linux")) + fixLibsPerms(); + Files.walkFileTree(libraries, Collections.singleton(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new StarterVisitor(inst)); + } catch (IOException | InterruptedException e) { e.printStackTrace(System.err); } } + + private static void fixLibsPerms() throws InterruptedException, IOException { + Path file = libraries.resolve(".libraries_chmoded"); + if (Files.exists(file)) return; + Files.deleteIfExists(file); + Runtime.getRuntime().exec(new String[] {"chmod", "-R", "+x", "libraries"}, null, libraries.toAbsolutePath().normalize().toFile().getParentFile()).waitFor(); + Files.createFile(file); + } }