3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-12-24 15:20:35 +01:00

Introduce velocity.natives-tmpdir property for properly handling noexec /tmp

Dieser Commit ist enthalten in:
Andrew Steinborn 2019-11-29 14:26:59 -05:00
Ursprung 2f55912995
Commit 75359256b3
2 geänderte Dateien mit 17 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -13,6 +13,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
public class Natives {
@ -24,12 +25,12 @@ public class Natives {
private static Runnable copyAndLoadNative(String path) {
return () -> {
try {
Path tempFile = Files.createTempFile("native-", path.substring(path.lastIndexOf('.')));
InputStream nativeLib = Natives.class.getResourceAsStream(path);
if (nativeLib == null) {
throw new IllegalStateException("Native library " + path + " not found.");
}
Path tempFile = createTemporaryNativeFilename(path.substring(path.lastIndexOf('.')));
Files.copy(nativeLib, tempFile, StandardCopyOption.REPLACE_EXISTING);
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
@ -50,6 +51,15 @@ public class Natives {
};
}
private static Path createTemporaryNativeFilename(String ext) throws IOException {
String temporaryFolderPath = System.getProperty("velocity.natives-tmpdir");
if (temporaryFolderPath != null) {
return Files.createTempFile(Paths.get(temporaryFolderPath), "native-", ext);
} else {
return Files.createTempFile("native-", ext);
}
}
public static final NativeCodeLoader<VelocityCompressorFactory> compress = new NativeCodeLoader<>(
ImmutableList.of(
new NativeCodeLoader.Variant<>(NativeConstraints.MACOS,

Datei anzeigen

@ -23,6 +23,12 @@ public class Velocity {
if (System.getProperty("io.netty.allocator.maxOrder") == null) {
System.setProperty("io.netty.allocator.maxOrder", "9");
}
// If Velocity's natives are being extracted to a different temporary directory, make sure the
// Netty natives are extracted there as well
if (System.getProperty("velocity.natives-tmpdir") != null) {
System.setProperty("io.netty.native.workdir", System.getProperty("velocity.natives-tmpdir"));
}
}
/**