0

all, I encounter a problem when use systemtap script. I don't know how to get the host name of kill signal sender in systemtap script. for example. I am execute kill -9 xclock_process_pid in server 'sf1'. at the same time, I run 1.stap -x xclock_process_pid to monitor xclock, is there any method to obtain the server name 'sf1' in systemtap script when send a kill -9 xclock_process_pid in 'sf1'?

but I am encounter some problem. my 1.stap is shown below:

#!/usr/bin/env stap
function hostname:string () %{
    STAP_RETURN(current->nsproxy->uts_ns->name.nodename); 
%}
probe oneshot {
    log(hostname())
}

when I run 'stap -g 1.stap' will reprot the following error Could you help me? semantic error: probe point mismatch at position 0 (alternatives: __nfs __scheduler __signal __tcpmib __vm _linuxmib _signal _sunrpc _syscall _vfs begin begin(number) end end(number) error error(number) generic ioblock ioblock_trace ioscheduler ioscheduler_trace ipmib irq_handler kernel kprobe kprocess linuxmib module(string) nd_syscall netdev never nfs nfsd perf process process(number) process(string) procfs procfs(string) scheduler scsi signal socket softirq stap staprun sunrpc syscall tcp tcpmib timer tty udp vfs vm workqueue): identifier 'oneshot' at systemtap.stap:87:7 while resolving probe point oneshot source: probe oneshot { ^ Pass 2: analysis failed. Try again with another '--vp 01' option.

1 Answers1

0

In other words, you're asking how to get the hostname of the current machine. A TCP/IP-level hostname is not in reach. The sethostname(2) level name is not easy to reach, being hidden inside kernel variables behind locked utsname()-> fields.

If safety were not a problem, you could do it via an embedded-C function for 4.8 era kernels:

function hostname:string () %{
    STAP_RETURN(current->nsproxy->uts_ns->name.nodename); 
%}
probe oneshot {
    log(hostname())
}

that you would run with stap -g ... (guru mode).

fche
  • 2,641
  • 20
  • 28
  • Thanks very much firstly. – user1102185 Dec 13 '16 at 15:41
  • when I run 'stap -g 1.stap' will reprot above error, Could you help me to check? – user1102185 Dec 15 '16 at 13:40
  • OK, your version of systemtap must be older than 2.5 (2014-04-30) when the "oneshot" probe alias was added. Use `probe begin { log(....); exit() } ` instead. – fche Dec 15 '16 at 17:36
  • when I use probe begin { log(....); exit() } , will report another error: /tmp/stap7gFv8k/stap_169fxx4_802_src.c: In function ‘function_hostname’: /tmp/stap7gFv8k/stap_16yyeb4_802_src.c:211: error: implicit declaration of function ‘STAP_RETURN’ /tmp/stap7gFv8k/stap_zz_src.c:211: error: ‘struct task_struct’ has no member named ‘nsproxy’ make[1]: *** [/tmp/stap7gFv8k/stap_169fe3892bxx99b1baeb4_802_src.o] Error 1 make: *** [_module_/tmp/stap7gFv8k] Error 2 Warning: make exited with status: 2 Pass 4: compilation failed. Try again with another '--vp 0001' option. – user1102185 Dec 18 '16 at 16:31
  • my systemtap version is 1.6. OS is redhat5.8 – user1102185 Dec 18 '16 at 16:37
  • Your version of systemtap is too old to run on that kernel. There was at least a 1.8 version released by Red Hat for RHEL5, and more recent upstream stap may be built for RHEL5 too. – fche Dec 19 '16 at 17:11