Skip to content
Permalink
Browse files
8228343: JCMD and attach fail to work across Linux Container boundary
Reviewed-by: ysuenaga, sspitsyn
  • Loading branch information
Kevin Walls committed Jun 9, 2021
1 parent 408e0a9 commit bf29a0115cc67ed2926b135b6b6ade5ff5ee84f6
Showing 2 changed files with 7 additions and 7 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2019 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@@ -71,7 +71,8 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine {
File socket_file = new File(tmpdir, ".java_pid" + pid);
socket_path = socket_file.getPath();
if (!socket_file.exists()) {
File f = createAttachFile(pid);
// Keep canonical version of File, to delete, in case target process ends and /proc link has gone:
File f = createAttachFile(pid).getCanonicalFile();
try {
sendQuitTo(pid);

@@ -275,7 +276,6 @@ private File createAttachFile(int pid) throws IOException {
String path = "/proc/" + pid + "/cwd/" + fn;
File f = new File(path);
try {
f = f.getCanonicalFile();
f.createNewFile();
} catch (IOException x) {
f = new File(tmpdir, fn);
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2021, 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
@@ -76,7 +76,8 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine {
File socket_file = findSocketFile(pid, ns_pid);
socket_path = socket_file.getPath();
if (!socket_file.exists()) {
File f = createAttachFile(pid, ns_pid);
// Keep canonical version of File, to delete, in case target process ends and /proc link has gone:
File f = createAttachFile(pid, ns_pid).getCanonicalFile();
try {
sendQuitTo(pid);

@@ -290,7 +291,7 @@ private File createAttachFile(int pid, int ns_pid) throws IOException {
String path = "/proc/" + pid + "/cwd/" + fn;
File f = new File(path);
try {
f = f.getCanonicalFile();
// Do not canonicalize the file path, or we will fail to attach to a VM in a container.
f.createNewFile();
} catch (IOException x) {
String root;
@@ -303,7 +304,6 @@ private File createAttachFile(int pid, int ns_pid) throws IOException {
root = tmpdir;
}
f = new File(root, fn);
f = f.getCanonicalFile();
f.createNewFile();
}
return f;

0 comments on commit bf29a01

Please sign in to comment.