【问题标题】:How to get the host name of kill signal sender in systemtap script如何在 systemtap 脚本中获取终止信号发送者的主机名
【发布时间】:2016-11-30 16:33:45
【问题描述】:

所有, 使用 systemtap 脚本时遇到问题。 我不知道如何在 systemtap 脚本中获取 kill signal sender 的主机名。 例如。我在服务器 'sf1' 中执行 kill -9 xclock_process_pid。同时,我运行 1.stap -x xclock_process_pid 来监控 xclock, 在'sf1'中发送kill -9 xclock_process_pid时,有什么方法可以在systemtap脚本中获取服务器名称'sf1'?

但我遇到了一些问题。我的 1.stap 如下图所示:

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

当我运行 'stap -g 1.stap' 时会出现以下错误你能帮帮我吗?语义错误:位置 0 的探测点不匹配(替代方案:__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): systemtap.stap 中的标识符 'oneshot': 87:7 同时解析探测点 oneshot 源:probe oneshot { ^ Pass 2:分析失败。使用另一个“--vp 01”选项重试。

【问题讨论】:

    标签: kill hostname systemtap


    【解决方案1】:

    换句话说,您是在询问如何获取当前机器的主机名。无法访问 TCP/IP 级别的主机名。 sethostname(2) 级别名称不易获得,隐藏在锁定的utsname()-> 字段后面的内核变量中。

    如果安全不是问题,您可以通过 4.8 时代内核的嵌入式 C 函数来实现:

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

    您将使用stap -g ...(大师模式)运行。

    【讨论】:

    • 首先非常感谢。
    • 当我运行 'stap -g 1.stap' 时会出现上述错误,你能帮我检查一下吗?
    • 好的,当添加“oneshot”探针别名时,您的 systemtap 版本必须早于 2.5 (2014-04-30)。请改用probe begin { log(....); exit() }
    • 当我使用探针时开始 { log(....); exit() } ,会报另一个错误:/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: 错误: 'struct task_struct' 没有名为 'nsproxy' 的成员 make[1]: *** [/tmp/stap7gFv8k/stap_169fe3892bxx99b1baeb4_802_src.o] 错误 1 ​​make: *** [_module_/tmp/stap7gFv8k ] 错误 2 警告:make exited with status: 2 Pass 4: 编译失败。使用另一个“--vp 0001”选项重试。
    • 我的 systemtap 版本是 1.6。操作系统是redhat5.8
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-20
    相关资源
    最近更新 更多