Debian Codegraph @

tapset/linux/target_set.stp

raw
1
2 @__private30 global _target_set # map: target-set-pid -> ancestor-pid
3
4 /**
5 * sfunction target_set_pid - Does pid descend from target process?
6 *
7 * @pid: The pid of the process to query
8 *
9 * Description: This function returns whether the given process-id is
10 * within the "target set", that is whether it is a descendant of the
11 * top-level target() process.
12 */
13 function target_set_pid (pid)
14 {
15 return ([pid] in _target_set)
16 }
17
18 probe init
19 {
20 if (target())
21 _target_set[target()] = stp_pid()
22 }
23
24
25 # pre-2.6.18 systems don't support dwarfless probes,
26 # so we'll use 'syscall' probes instead of 'nd_syscall' probes.
27
28 probe process.begin !,
29 %( kernel_v >= "2.6.18" %?
30 nd_syscall.fork.return ?, nd_syscall.vfork.return ?,
31 nd_syscall.clone.return !,
32 %)
33 syscall.fork.return, syscall.vfork.return, syscall.clone.return
34 {
35 if (is_return()) {
36 # fork.return runs in parent context
37 pid = @choose_defined($return, returnval())
38 ppid = pid()
39 } else {
40 # process.begin runs in child context
41 pid = pid()
42 ppid = ppid()
43 }
44
45 # NB: when using process.*, if target() execs we'll see a process.end
46 # (removing it) then a new process.begin. The target's ppid (stp_pid)
47 # is not part of the target set, so check for this case.
48 if (pid == target() || ppid in _target_set)
49 _target_set[pid] = ppid
50 }
51
52 probe process.end !,
53 %( kernel_v >= "2.6.18" %?
54 nd_syscall.exit !,
55 %)
56 syscall.exit
57 {
58 delete _target_set[pid()]
59 }
60
61
62 /**
63 * sfunction target_set_report - Print a report about the target set
64 *
65 * Description: This function prints a report about the processes in the
66 * target set, and their ancestry.
67 */
68 function target_set_report ()
69 {
70 printf("target set:\n")
71 foreach (pid in _target_set+)
72 printf("%d begat %d\n", _target_set[pid], pid)
73 }