Bundle libseccomp 2.3.1
[linux-seccomp.git] / libseccomp / tests / 24-live-arg_allow.py
1 #!/usr/bin/env python
2
3 #
4 # Seccomp Library test program
5 #
6 # Copyright (c) 2013 Red Hat <pmoore@redhat.com>
7 # Author: Paul Moore <paul@paul-moore.com>
8 #
9
10 #
11 # This library is free software; you can redistribute it and/or modify it
12 # under the terms of version 2.1 of the GNU Lesser General Public License as
13 # published by the Free Software Foundation.
14 #
15 # This library is distributed in the hope that it will be useful, but WITHOUT
16 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
18 # for more details.
19 #
20 # You should have received a copy of the GNU Lesser General Public License
21 # along with this library; if not, see <http://www.gnu.org/licenses>.
22 #
23
24 import argparse
25 import os
26 import sys
27
28 import util
29
30 from seccomp import *
31
32 def test():
33 action = util.parse_action(sys.argv[1])
34 if not action == ALLOW:
35 quit(1)
36 util.install_trap()
37
38 fd = os.open("/dev/null", os.O_WRONLY|os.O_CREAT, 0600)
39
40 f = SyscallFilter(TRAP)
41 # NOTE: additional syscalls required for python
42 f.add_rule(ALLOW, "write", Arg(0, EQ, fd))
43 f.add_rule(ALLOW, "close")
44 f.add_rule(ALLOW, "rt_sigaction")
45 f.add_rule(ALLOW, "rt_sigreturn")
46 f.add_rule(ALLOW, "exit_group")
47 f.add_rule(ALLOW, "brk")
48 f.load()
49
50 try:
51 if not os.write(fd, "testing") == len("testing"):
52 raise IOError("failed to write the full test string")
53 quit(160)
54 except OSError as ex:
55 quit(ex.errno)
56 os.close(fd)
57
58 test()
59
60 # kate: syntax python;
61 # kate: indent-mode python; space-indent on; indent-width 4; mixedindent off;
This page took 0.023017 seconds and 4 git commands to generate.