Thu 1 Oct 2009
I always wondered how Oracle Client knows to send my program name to the server process to be stored in x$ksuse (v$session). I had my assumptions but finally I had a chance to verify them as a fellow developer asked me this question.
I’ve created a simple ocitest C program to connect to Oracle and select the program name from v$session and then started experimenting.
The first test was just overwriting argv with a different value at the beginning of the program. The name was immediately changed in the Oracle session.
The second test was running the program with strace since there are several ways you can get the process name on Linux. It turns out that Oracle client chooses the simplest way:
open(“/proc/self/cmdline”, O_RDONLY) = 3
read(3, “xxxxxxxxx\0002\0”, 255) = 12
close(3) = 0
So, it looked to me that all I had to do is to intercept (interpose) the open call and replace it with my own version so that if the open tries to read /proc/self/cmdline I will return my own file containing my own chosen program name.
Which I immediately proceeded to test (ocitest2) and of course it worked.
Ha, try this to confuse the administrator – Oracle saying that program X is connected but in the processes list you cannot find program X (of course you can always check the process at the end of the socket).