mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-13 12:02:20 +00:00
[JENKINS-72833] Do not attempt to self-exec on systems without libc (#9025)
This commit is contained in:
1 parent
c9af352f6f
commit
434bf2b0f8
3 files changed
+17
-16
No files matched your search
@@ -120,13 +120,13 @@ public abstract class Lifecycle implements ExtensionPoint {
|
||||
// if run on Unix, we can do restart
|
||||
try {
|
||||
instance = new UnixLifecycle();
|
||||
} catch (final IOException e) {
|
||||
LOGGER.log(Level.WARNING, "Failed to install embedded lifecycle implementation", e);
|
||||
} catch (final Throwable t) {
|
||||
LOGGER.log(Level.WARNING, "Failed to install embedded lifecycle implementation", t);
|
||||
instance = new Lifecycle() {
|
||||
@Override
|
||||
public void verifyRestartable() throws RestartNotSupportedException {
|
||||
throw new RestartNotSupportedException(
|
||||
"Failed to install embedded lifecycle implementation, so cannot restart: " + e, e);
|
||||
"Failed to install embedded lifecycle implementation, so cannot restart: " + t, t);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ import static hudson.util.jna.GNUCLibrary.LIBC;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.StringArray;
|
||||
import edu.umd.cs.findbugs.annotations.NonNull;
|
||||
import hudson.Functions;
|
||||
import hudson.Platform;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
@@ -50,16 +52,12 @@ import jenkins.util.JavaVMArguments;
|
||||
* @since 1.304
|
||||
*/
|
||||
public class UnixLifecycle extends Lifecycle {
|
||||
private List<String> args;
|
||||
private Throwable failedToObtainArgs;
|
||||
|
||||
public UnixLifecycle() throws IOException {
|
||||
try {
|
||||
args = JavaVMArguments.current();
|
||||
} catch (UnsupportedOperationException | LinkageError e) {
|
||||
// can't restart / see JENKINS-3875
|
||||
failedToObtainArgs = e;
|
||||
}
|
||||
@NonNull
|
||||
private List<String> args;
|
||||
|
||||
public UnixLifecycle() {
|
||||
args = JavaVMArguments.current();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -89,6 +87,10 @@ public class UnixLifecycle extends Lifecycle {
|
||||
|
||||
@Override
|
||||
public void verifyRestartable() throws RestartNotSupportedException {
|
||||
if (!Functions.isGlibcSupported()) {
|
||||
throw new RestartNotSupportedException("Restart is not supported on platforms without libc");
|
||||
}
|
||||
|
||||
// see http://lists.apple.com/archives/cocoa-dev/2005/Oct/msg00836.html and
|
||||
// http://factor-language.blogspot.com/2007/07/execve-returning-enotsup-on-mac-os-x.html
|
||||
// on Mac, execv fails with ENOTSUP if the caller is multi-threaded, resulting in an error like
|
||||
@@ -97,8 +99,6 @@ public class UnixLifecycle extends Lifecycle {
|
||||
// according to http://www.mail-archive.com/wine-devel@winehq.org/msg66797.html this now works on Snow Leopard
|
||||
if (Platform.isDarwin() && !Platform.isSnowLeopardOrLater())
|
||||
throw new RestartNotSupportedException("Restart is not supported on Mac OS X");
|
||||
if (args == null)
|
||||
throw new RestartNotSupportedException("Failed to obtain the command line arguments of the process", failedToObtainArgs);
|
||||
}
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(UnixLifecycle.class.getName());
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package jenkins.util;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import edu.umd.cs.findbugs.annotations.NonNull;
|
||||
import hudson.Functions;
|
||||
import hudson.util.ProcessTree;
|
||||
import java.lang.management.ManagementFactory;
|
||||
@@ -20,6 +20,7 @@ public class JavaVMArguments {
|
||||
/**
|
||||
* Gets the process argument list of the current process.
|
||||
*/
|
||||
@NonNull
|
||||
public static List<String> current() {
|
||||
ProcessHandle.Info info = ProcessHandle.current().info();
|
||||
if (info.command().isPresent() && info.arguments().isPresent()) {
|
||||
@@ -30,7 +31,7 @@ public class JavaVMArguments {
|
||||
return args;
|
||||
} else if (Functions.isGlibcSupported()) {
|
||||
// Native approach
|
||||
int pid = Ints.checkedCast(ProcessHandle.current().pid());
|
||||
int pid = Math.toIntExact(ProcessHandle.current().pid());
|
||||
ProcessTree.OSProcess process = ProcessTree.get().get(pid);
|
||||
if (process != null) {
|
||||
List<String> args = process.getArguments();
|
||||
|
||||
Reference in new issue
Block a user