Skip to content

AIX: add istat parser as stat is absent#1668

Merged
raphw merged 1 commit intoraphw:masterfrom
instana:aix-istat
Jul 8, 2024
Merged

AIX: add istat parser as stat is absent#1668
raphw merged 1 commit intoraphw:masterfrom
instana:aix-istat

Conversation

@FelixMarxIBM
Copy link
Copy Markdown
Contributor

@FelixMarxIBM FelixMarxIBM commented Jul 2, 2024

Fixes #1667

Why:

  • stat is absent on AIX

What:

  • use istat instead and pasre the Owner of the output

Example output

# 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

The Exception that is seen prior to this fix on AIX:

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

@FelixMarxIBM
Copy link
Copy Markdown
Contributor Author

After creating a temp build with these attach-tools, the attachment works without any issues:

2024-07-02T06:39:30.350-04:00 | INFO  | instana-executor-thread-2-3      | ExternalAttach   | com.instana.agent - 1.1.727 | Executing: su testuser -c "/opt/java/semeru/jdk8u402-b06/bin/java -Xms16m -Xmx16m -Dcom.ibm.tools.attach.enable=no -Duser.dir=/ -cp /tmp/.instana/attach-tools-1.14.18.jar:/tmp/.instana/javaagent-loader-1.3.62.jar com.instana.agent.loader.AgentLoaderAttach agent=/tmp/.instana/javaagent-loader-1.3.62.jar verify=true pid=8061246 host=127.0.0.1 port=42699 boot=/com.instana.agent.artifact/com.instana/instrumentation-boot/1.1.29/jar shared=/com.instana.agent.artifact/com.instana/instrumentation-shared/1.0.141/jar inMemoryClassLoader=true agentSocket=true"
2024-07-02T06:39:32.300-04:00 | INFO  | nstana-socket-client-thread--6-4 | tClientIdDecoder | com.instana.agent - 1.1.727 | 8061246:com.instana.agent.main.javaagentloader connection established
2024-07-02T06:39:32.333-04:00 | INFO  | instana-executor-thread-2-3      | aagentLoaderImpl | com.instana.agent - 1.1.727 | Initial attach to JVM with PID 8061246 successful

@raphw raphw self-assigned this Jul 2, 2024
@raphw raphw added this to the 1.14.18 milestone Jul 2, 2024
@raphw
Copy link
Copy Markdown
Owner

raphw commented Jul 2, 2024

Looks good. I'm currently on vacation but will merge once I'm on a machine again.

@raphw raphw merged commit e597414 into raphw:master Jul 8, 2024
@FelixMarxIBM FelixMarxIBM deleted the aix-istat branch December 12, 2025 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AIX J9 attachment fails because stat is not present.

2 participants