Skip to content

AIX J9 attachment fails because stat is not present. #1667

@FelixMarxIBM

Description

@FelixMarxIBM

On AIX, there is no stat command and therefore the getOwnerIdOf check fails.

# ls -al /tmp/.com_ibm_tools_attach/
total 24
drwxrwxrwt    3 root     system         4096 Jul 02 06:21 .
drwxrwxrwt   45 bin      bin            8192 Jul 02 06:20 ..
drwx--x--t    2 testuser staff           256 Jul 02 06:21 8061236
-rw-rw-rw-    1 root     system            0 Jan 16 2020  _attachlock
-rw-rw-rw-    1 root     system            0 Nov 21 2023  _controller
-rw-rw-rw-    1 root     system            0 Jan 16 2020  _master
-rwxrwxrwx    1 root     system            0 Jan 16 2020  _notifier

The istat command does not offer an output to only get the Owner PID, therefore we have to use a Pattern matcher to get it.

# istat /tmp/.com_ibm_tools_attach/8061236
Inode 45058 on device 10/7      Directory
Protection: rwx--x--x   Sticky
Owner: 205(testuser)            Group: 1(staff)
Link count:   2         Length 256 bytes

Last updated:   Tue Jul  2 06:21:53 EDT 2024
Last modified:  Tue Jul  2 06:21:53 EDT 2024
Last accessed:  Tue Jul  2 06:21:52 EDT 2024

In our use case this is only relevant for J9 based JVMs running below Java 10 as they require the same user as the target JVM.
With a root user otherwise, the OwnerId is not checked and we are fine.

The Exception that we see with the current code:

2024-06-13T04:24:37.828-05:00 | ERROR | instana-executor-thread-30-7     | ExternalAttach   | com.instana.agent - 1.1.723 | java.lang.IllegalStateException: Unable to execute stat command
	at net.bytebuddy.agent.VirtualMachine$ForOpenJ9$Dispatcher$ForJnaPosixEnvironment.getOwnerIdOf(VirtualMachine.java:2182)
	at net.bytebuddy.agent.VirtualMachine$ForOpenJ9.attach(VirtualMachine.java:1695)
	at net.bytebuddy.agent.VirtualMachine$ForOpenJ9.attach(VirtualMachine.java:1663)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:90)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
	at java.lang.reflect.Method.invoke(Method.java:508)
	at com.instana.agent.loader.AgentLoaderAttach.attach(AgentLoaderAttach.java:398)
	at com.instana.agent.loader.AgentLoaderAttach.run(AgentLoaderAttach.java:150)
	at com.instana.agent.loader.AgentLoaderAttach.parseArgsAndRun(AgentLoaderAttach.java:100)
	at com.instana.agent.loader.AgentLoaderAttach.main(AgentLoaderAttach.java:83)
Caused by: java.io.IOException: Cannot run program "stat": error=2, A file or directory in the path name does not exist.
	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1059)
	at java.lang.Runtime.exec(Runtime.java:631)
	at java.lang.Runtime.exec(Runtime.java:496)
	at net.bytebuddy.agent.VirtualMachine$ForOpenJ9$Dispatcher$ForJnaPosixEnvironment.getOwnerIdOf(VirtualMachine.java:2153)
	... 10 more
Caused by: java.io.IOException: error=2, A file or directory in the path name does not exist.
	at java.lang.UNIXProcess.forkAndExec(Native Method)
	at java.lang.UNIXProcess.<init>(UNIXProcess.java:291)
	at java.lang.ProcessImpl.start(ProcessImpl.java:167)
	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1040)
	... 13 more

Metadata

Metadata

Assignees

Labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions