src/jdk.attach/linux/classes/sun/tools/attach/VirtualMachineImpl.java
Index
Unified diffs
Context diffs
Sdiffs
Wdiffs
Patch
New
Old
Previous File
Next File
*** old/src/jdk.attach/linux/classes/sun/tools/attach/VirtualMachineImpl.java Thu Jan 11 13:32:19 2018
--- new/src/jdk.attach/linux/classes/sun/tools/attach/VirtualMachineImpl.java Thu Jan 11 13:32:18 2018
*** 1,7 ****
--- 1,7 ----
/*
! * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
! * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 34,43 ****
--- 34,44 ----
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.Files;
+ import jdk.internal.vm.VMSupport;
/*
* Linux implementation of HotSpotVirtualMachine
*/
public class VirtualMachineImpl extends HotSpotVirtualMachine {
*** 66,76 ****
--- 67,77 ----
} catch (NumberFormatException x) {
throw new AttachNotSupportedException("Invalid process identifier");
}
// Try to resolve to the "inner most" pid namespace
! int ns_pid = getNamespacePid(pid);
! int ns_pid = VMSupport.getNamespaceVmId(pid);
// Find the socket file. If not found then we attempt to start the
// attach mechanism in the target VM by sending it a QUIT signal.
// Then we attempt to find the socket file again.
path = findSocketFile(pid, ns_pid);
*** 324,368 ****
--- 325,334 ----
byte b[] = new byte[1];
b[0] = 0;
write(fd, b, 0, 1);
}
// Return the inner most namespaced PID if there is one,
// otherwise return the original PID.
private int getNamespacePid(int pid) throws AttachNotSupportedException, IOException {
// Assuming a real procfs sits beneath, reading this doesn't block
// nor will it consume a lot of memory.
String statusFile = "/proc/" + pid + "/status";
File f = new File(statusFile);
if (!f.exists()) {
return pid; // Likely a bad pid, but this is properly handled later.
}
Path statusPath = Paths.get(statusFile);
try {
for (String line : Files.readAllLines(statusPath, StandardCharsets.UTF_8)) {
String[] parts = line.split(":");
if (parts.length == 2 && parts[0].trim().equals("NSpid")) {
parts = parts[1].trim().split("\\s+");
// The last entry represents the PID the JVM "thinks" it is.
// Even in non-namespaced pids these entries should be
// valid. You could refer to it as the inner most pid.
int ns_pid = Integer.parseInt(parts[parts.length - 1]);
return ns_pid;
}
}
// Old kernels may not have NSpid field (i.e. 3.10).
// Fallback to original pid in the event we cannot deduce.
return pid;
} catch (NumberFormatException | IOException x) {
throw new AttachNotSupportedException("Unable to parse namespace");
}
}
//-- native methods
static native void sendQuitToChildrenOf(int pid) throws IOException;
static native void sendQuitTo(int pid) throws IOException;
src/jdk.attach/linux/classes/sun/tools/attach/VirtualMachineImpl.java
Index
Unified diffs
Context diffs
Sdiffs
Wdiffs
Patch
New
Old
Previous File
Next File