Use ProcessHandle.current().pid in more places (#6746)

This commit is contained in:
Basil Crow authored and GitHub committed 2022-07-02 09:13:15 -07:00
1 parent 6b17e392cd
commit aba473fd8c
2 files changed
+7 -8

No files matched your search

@@ -67,7 +67,7 @@ public class UnixSlaveRestarter extends SlaveRestarter {
* Gets the current executable name.
*/
private static String getCurrentExecutable() {
int pid = LIBC.getpid();
long pid = ProcessHandle.current().pid();
String name = "/proc/" + pid + "/exe";
File exe = new File(name);
if (exe.exists()) {
@@ -36,7 +36,6 @@ import hudson.remoting.Channel;
import hudson.remoting.ChannelClosedException;
import hudson.remoting.PingThread;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.lang.reflect.Method;
import java.util.concurrent.TimeoutException;
import jenkins.security.MasterToSlaveCallable;
@@ -59,7 +58,7 @@ public class PingThreadTest {
DumbSlave slave = j.createOnlineSlave();
Computer computer = slave.toComputer();
Channel channel = (Channel) slave.getChannel();
String pid = channel.call(new GetPid());
long pid = channel.call(new GetPid());
PingThread pingThread = null;
for (Thread it : Thread.getAllStackTraces().keySet()) {
@@ -70,7 +69,7 @@ public class PingThreadTest {
assertNotNull(pingThread);
// Simulate lost connection
assertEquals(0, new ProcessBuilder("kill", "-TSTP", pid).start().waitFor());
assertEquals(0, new ProcessBuilder("kill", "-TSTP", Long.toString(pid)).start().waitFor());
try {
// ... do not wait for Ping Thread to notice
Method onDead = PingThread.class.getDeclaredMethod("onDead", Throwable.class);
@@ -82,13 +81,13 @@ public class PingThreadTest {
assertNull(slave.getComputer().getChannel());
assertNull(computer.getChannel());
} finally {
assertEquals(0, new ProcessBuilder("kill", "-CONT", pid).start().waitFor());
assertEquals(0, new ProcessBuilder("kill", "-CONT", Long.toString(pid)).start().waitFor());
}
}
private static final class GetPid extends MasterToSlaveCallable<String, IOException> {
@Override public String call() {
return ManagementFactory.getRuntimeMXBean().getName().replaceAll("@.*", "");
private static final class GetPid extends MasterToSlaveCallable<Long, IOException> {
@Override public Long call() {
return ProcessHandle.current().pid();
}
}
}