Debian Codegraph @

testsuite/systemtap.examples/process/procmod_watcher.stp

raw
1 #! /usr/bin/env stap
2
3 /*
4 * Copyright (C) 2014, 2016 Red Hat Inc.
5 *
6 * This copyrighted material is made available to anyone wishing to use,
7 * modify, copy, or redistribute it subject to the terms and conditions
8 * of the GNU General Public License v.2.
9 *
10 * You should have received a copy of the GNU General Public License
11 * along with this program. If not, see <http://www.gnu.org/licenses/>.
12 *
13 * Print out all calls to fork(), exec(), exit(), init_module(), and
14 * delete_module(). This script does not require debuginfo.
15 *
16 * Format is:
17 * timestamp: EVENT: ( pid) <event details>
18 *
19 * 2.843626: FORK: ( 410) firewalld: pid 868
20 * 2.843831: EXEC: ( 868) firewalld: file /sbin/iptables
21 * 2.844514: EXIT: ( 868) iptables: exit code 0
22 * 2.844829: FORK: ( 410) firewalld: pid 869
23 * 2.845034: EXEC: ( 869) firewalld: file /sbin/iptables
24 * 2.845722: EXIT: ( 869) iptables: exit code 0
25 * 2.846036: FORK: ( 410) firewalld: pid 870
26 * 2.846240: EXEC: ( 870) firewalld: file /sbin/iptables
27 *
28 */
29
30 function print_time() {
31 timer = read_stopwatch_us("timer")
32 printf("%4d.%.6d: ", timer/1000000, timer%1000000)
33 }
34
35 probe begin {
36 start_stopwatch("timer")
37 printf(" 0.000000: Started procmod_watcher on %s\n",
38 ctime(gettimeofday_s()))
39 }
40
41 probe nd_syscall.execve {
42 print_time()
43 printf("EXEC: (%4d) %s: file %s\n",
44 pid(), execname(), argstr)
45 }
46
47 probe nd_syscall.fork.return ?, nd_syscall.clone.return ? {
48 print_time()
49 printf("FORK: (%4d) %s: pid %s\n",
50 pid(), execname(), retstr)
51 }
52
53 probe nd_syscall.exit, nd_syscall.exit_group {
54 print_time()
55 sig = status & 0x7F
56 code = sig ? sig : status >> 8
57 printf("EXIT: (%4d) %s: %s %d\n",
58 pid(), execname(),
59 sig ? "signal" : "exit code", code)
60 }
61
62 probe kernel.trace("module_load") {
63 print_time()
64 printf("LOAD: (%4d) %s: module %s",
65 pid(), execname(),
66 kernel_string(@cast($mod, "struct module", "kernel<linux/module.h>")->name))
67 args = kernel_string(@cast($mod, "struct module", "kernel<linux/module.h>")->args)
68 if (args != "")
69 printf(" with args \"%s\"", args)
70 println("")
71 }
72
73 probe nd_syscall.delete_module {
74 print_time()
75 printf("UNLD: (%4d) %s: module %s with flags 0x%x\n",
76 pid(), execname(), name_user, flags);
77 }
78
79 probe end {
80 print_time()
81 printf("Exiting procmod_watcher on %s\n",
82 ctime(gettimeofday_s()))
83 }