From 238d604b71ccb421a9167b17de527dcd1ab4f7e5 Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Sun, 28 Apr 2019 15:42:51 +0300 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=D0=90=D0=B2=D1=82=D0=BE=D0=BC?= =?UTF-8?q?=D0=B0=D1=82=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=B0=D1=8F=20=D1=83?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D0=BD=D0=BE=D0=B2=D0=BA=D0=B0=20=D1=84=D0=BB?= =?UTF-8?q?=D0=B0=D0=B3=D0=B0=20executable=20=D0=BD=D0=B0=20=D0=BB=D0=B8?= =?UTF-8?q?=D0=BD=D1=83=D0=BA=D1=81=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ru/gravit/launchserver/StarterAgent.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) 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); + } }