2 # Seccomp Library utility code for tests
4 # Copyright (c) 2012 Red Hat <pmoore@redhat.com>
5 # Author: Paul Moore <paul@paul-moore.com>
9 # This library is free software; you can redistribute it and/or modify it
10 # under the terms of version 2.1 of the GNU Lesser General Public License as
11 # published by the Free Software Foundation.
13 # This library is distributed in the hope that it will be useful, but WITHOUT
14 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
18 # You should have received a copy of the GNU Lesser General Public License
19 # along with this library; if not, see <http://www.gnu.org/licenses>.
22 """ Python utility code for the libseccomp test suite """
31 def trap_handler(signum
, frame
):
32 """ SIGSYS signal handler, internal use only
37 """ Parse the arguments passed to main
40 Parse the arguments passed to the test from the command line. Returns
41 a parsed argparse object.
43 parser
= argparse
.ArgumentParser()
44 parser
.add_argument("-b", "--bpf", action
="store_true")
45 parser
.add_argument("-p", "--pfc", action
="store_true")
46 return parser
.parse_args()
48 def filter_output(args
, ctx
):
49 """ Output the filter in either BPF or PFC
52 args - an argparse object from UtilGetOpt()
53 ctx - a seccomp SyscallFilter object
56 Output the SyscallFilter to stdout in either BPF or PFC format depending
57 on the test's command line arguments.
60 ctx
.export_bpf(sys
.stdout
)
62 ctx
.export_pfc(sys
.stdout
)
65 """ Install a TRAP action signal handler
68 Install the TRAP action signal handler.
70 signal
.signal(signal
.SIGSYS
, trap_handler
)
72 def parse_action(action
):
73 """ Parse a filter action string into an action value
76 action - the action string
79 Parse a seccomp action string into the associated integer value.
83 elif action
== "TRAP":
85 elif action
== "ERRNO":
87 elif action
== "TRACE":
88 raise RuntimeError("the TRACE action is not currently supported")
89 elif action
== "ALLOW":
91 raise RuntimeError("invalid action string")
95 """ Write a string to a file
101 Open the specified file, write a string to the file, and close the file.
103 fd
= os
.open(path
, os
.O_WRONLY|os
.O_CREAT
, 0600)
104 if not os
.write(fd
, "testing") == len("testing"):
105 raise IOError("failed to write the full test string in write_file()")
108 # kate: syntax python;
109 # kate: indent-mode python; space-indent on; indent-width 4; mixedindent off;
This page took 0.024008 seconds and 4 git commands to generate.