jcmd uses 
src/jdk.internal.jvmstat/linux/classes/sun/jvmstat/PlatformSupportImpl.java to 
scan temporary directories to find out processes in the container. It checks 
inode to ensure the temp directory is not conflicted. However inode maybe same 
value between the container and others. Thus we should check device id for that 
case.

For example I saw following case on [distroless 
cc-debian11](https://github.com/GoogleContainerTools/distroless/blob/main/cc/README.md)
 container. I started rescue:jdk19 container with sharing PID namespace. 
`/proc/1/root/tmp` is different from `/tmp` on rescue:jdk19, but they are same 
inode value. However we can see the differense in device id.


$ podman run -it --rm --entrypoint=sh --pid=container:fa39662f7352 rescue:jdk19
/ #
/ # stat /tmp
  File: /tmp
  Size: 29              Blocks: 0          IO Block: 4096   directory
Device: efh/239d        Inode: 135674931   Links: 1
Access: (1777/drwxrwxrwt)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-04-05 08:51:37.000000000
Modify: 2022-04-05 08:51:37.000000000
Change: 2022-04-05 08:51:37.000000000

/ # stat /proc/1/root/tmp
  File: /proc/1/root/tmp
  Size: 29              Blocks: 0          IO Block: 4096   directory
Device: e1h/225d        Inode: 135674931   Links: 1
Access: (1777/drwxrwxrwt)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-04-05 08:51:37.000000000
Modify: 2022-04-05 08:50:42.000000000
Change: 2022-04-05 08:50:42.000000000

-------------

Commit messages:
 - 8284330: jcmd may not be able to find processes in the container

Changes: https://git.openjdk.java.net/jdk/pull/8103/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=8103&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8284330
  Stats: 42 lines in 1 file changed: 27 ins; 10 del; 5 mod
  Patch: https://git.openjdk.java.net/jdk/pull/8103.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/8103/head:pull/8103

PR: https://git.openjdk.java.net/jdk/pull/8103

Reply via email to