-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[JENKINS-72833] Do not attempt to self-exec
on systems without libc
#9025
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can never be null, so annotate it as such. |
||
private List<String> args; | ||
private Throwable failedToObtainArgs; | ||
|
||
public UnixLifecycle() throws IOException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can never throw |
||
try { | ||
args = JavaVMArguments.current(); | ||
} catch (UnsupportedOperationException | LinkageError e) { | ||
// can't restart / see JENKINS-3875 | ||
failedToObtainArgs = e; | ||
} | ||
Comment on lines
-57
to
-62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was based on the old implementation, which used Akuma. That was ripped out a long time ago, and these exceptions shouldn't be thrown in the current implementation. But just to be on the safe side, we're now catching |
||
public UnixLifecycle() { | ||
args = JavaVMArguments.current(); | ||
} | ||
|
||
@Override | ||
|
@@ -89,6 +87,10 @@ | |
|
||
@Override | ||
public void verifyRestartable() throws RestartNotSupportedException { | ||
if (!Functions.isGlibcSupported()) { | ||
throw new RestartNotSupportedException("Restart is not supported on platforms without libc"); | ||
} | ||
Comment on lines
+90
to
+92
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fix for JENKINS-72833: do not attempt to use |
||
|
||
// 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 @@ | |
// according to http://www.mail-archive.com/[email protected]/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); | ||
Comment on lines
-100
to
-101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dead code, since |
||
} | ||
|
||
private static final Logger LOGGER = Logger.getLogger(UnixLifecycle.class.getName()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 static List<String> current() { | |
return args; | ||
} else if (Functions.isGlibcSupported()) { | ||
// Native approach | ||
int pid = Ints.checkedCast(ProcessHandle.current().pid()); | ||
int pid = Math.toIntExact(ProcessHandle.current().pid()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary use of Guava. |
||
ProcessTree.OSProcess process = ProcessTree.get().get(pid); | ||
if (process != null) { | ||
List<String> args = process.getArguments(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dead code, since this constructor could never in fact throw
IOException
, but I thought it best to keep this fallback since any unanticipated errors here should not be fatal.