Debian Codegraph @

doc/SystemTap_Beginners_Guide/testsuite/systemtap.base/task_paths.stp

raw
1 probe begin
2 {
3 # First we'll print the value of cwd/exe for the current task.
4 try
5 {
6 task = task_current()
7 path = task_cwd_path(task)
8 printf("current cwd: %s\n", fullpath_struct_path(path))
9 }
10 catch (msg) {
11 printf("ERROR: %s\n", msg)
12 }
13 try
14 {
15 file = current_exe_file()
16 printf("current exe: %s\n", fullpath_struct_file(task_current(), file))
17 }
18 catch (msg) {
19 printf("ERROR: %s\n", msg)
20 }
21
22 # Let's try using a task pointer of 0, which should fail.
23 try
24 {
25 task = 0
26 path = task_cwd_path(task)
27 printf("path: %p\n", path)
28 printf("%s\n", fullpath_struct_path(path))
29 }
30 catch (msg) {
31 printf("ERROR: %s\n", msg)
32 }
33
34 # Now let's try using a task pointer of -1, which should also
35 # fail.
36 try
37 {
38 task = -1
39 path = task_cwd_path(task)
40 printf("%s\n", fullpath_struct_path(path))
41 }
42 catch (msg) {
43 printf("ERROR: %s\n", msg)
44 }
45 }
46
47 probe syscall.geteuid, syscall.getuid
48 {
49 # Now print the value of cwd/exe for our target pid. At this
50 # point, we should be executing 'whoami', since stapio should have
51 # forked, then exec'ed 'whoami'.
52 if (pid() != target()) next
53 try
54 {
55 task = task_current()
56 path = task_cwd_path(task)
57 printf("current cwd: %s\n", fullpath_struct_path(path))
58 }
59 catch (msg) {
60 printf("ERROR: %s\n", msg)
61 }
62 try
63 {
64 file = current_exe_file()
65 printf("current exe: %s\n", fullpath_struct_file(task_current(), file))
66 }
67 catch (msg) {
68 printf("ERROR: %s\n", msg)
69 }
70 exit()
71 }