File: context_ns.exp

package info (click to toggle)
systemtap 3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 32,860 kB
  • ctags: 12,513
  • sloc: cpp: 58,610; ansic: 58,189; exp: 37,322; sh: 10,633; xml: 7,771; perl: 2,252; python: 2,066; tcl: 1,305; makefile: 969; lisp: 105; java: 100; awk: 94; asm: 91; sed: 16
file content (57 lines) | stat: -rw-r--r-- 1,607 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
set test_name "context namespaces"
if {! [installtest_p]} {
  untested $test_name
  return
}

# can't really test user_ns right now since we don't know other uids
set ns_tests { pid_ns }
set output_string "END\r\n"

# before we can even run the test, check that unshare is available
# probably only available in kernels >= 2.6.16
if {[catch {exec which unshare}]} {
  untested "$test_name (no unshare)"
  return
}

# weed out the kernels that don't have free_pid_ns available to us
if {![min_kernel_vers_p 3.7]} {
  untested "$test_name (kernel version is too low)"
  return
}

# Note we have to be root to run "unshare".
set effective_uid [exec /usr/bin/id -u]
if {$effective_uid != 0} {
  untested "$test_name (must be root)"
  return
}

# use unshare to generate new namespaces to use
# the returned pid is not the new proc's pid (as seen in the root ns)
spawn unshare -pf "sleep" 160
set exe_id $spawn_id

# instead, we'll use pgrep to find the sleep process. let's hope we only find one
# we'll narrow it down by specifying a parent proc id
set parent_proc [exp_pid -i $exe_id]
set child_proc [exec pgrep -P $parent_proc]

# make sure that we did find the child proc; if not, abort
if {!$child_proc || $child_proc < 0} {
  untested "$test_name (cant make child_proc)"
  return
}
verbose -log  "child (global) pid:$child_proc"

foreach ns_test $ns_tests {
    stap_run $ns_test no_load $output_string $srcdir/$subdir/$ns_test.stp -g --target-namespaces=$child_proc --disable-cache
}

# kill the parent
kill -INT -$parent_proc 2
catch {close -i $exe_id}
catch {wait -i $exe_id}

kill -INT -$child_proc 2