diff --git a/core/src/main/java/hudson/lifecycle/Lifecycle.java b/core/src/main/java/hudson/lifecycle/Lifecycle.java index d6c59713f481..b6f90f2d82d3 100644 --- a/core/src/main/java/hudson/lifecycle/Lifecycle.java +++ b/core/src/main/java/hudson/lifecycle/Lifecycle.java @@ -120,13 +120,13 @@ public void verifyRestartable() throws RestartNotSupportedException { // 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); } }; } diff --git a/core/src/main/java/hudson/lifecycle/UnixLifecycle.java b/core/src/main/java/hudson/lifecycle/UnixLifecycle.java index ca8f50b9f589..cb314465d09b 100644 --- a/core/src/main/java/hudson/lifecycle/UnixLifecycle.java +++ b/core/src/main/java/hudson/lifecycle/UnixLifecycle.java @@ -31,6 +31,8 @@ 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 @@ * @since 1.304 */ public class UnixLifecycle extends Lifecycle { + + @NonNull private List args; - private Throwable failedToObtainArgs; - public UnixLifecycle() throws IOException { - try { - args = JavaVMArguments.current(); - } catch (UnsupportedOperationException | LinkageError e) { - // can't restart / see JENKINS-3875 - failedToObtainArgs = e; - } + public UnixLifecycle() { + args = JavaVMArguments.current(); } @Override @@ -89,6 +87,10 @@ public void restart() throws IOException, InterruptedException { @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 void verifyRestartable() throws RestartNotSupportedException { // 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()); diff --git a/core/src/main/java/jenkins/util/JavaVMArguments.java b/core/src/main/java/jenkins/util/JavaVMArguments.java index 473849a9922e..c677df0e5827 100644 --- a/core/src/main/java/jenkins/util/JavaVMArguments.java +++ b/core/src/main/java/jenkins/util/JavaVMArguments.java @@ -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 current() { ProcessHandle.Info info = ProcessHandle.current().info(); if (info.command().isPresent() && info.arguments().isPresent()) { @@ -30,7 +31,7 @@ public static List current() { 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 args = process.getArguments();