-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrebar.config.script
More file actions
160 lines (142 loc) · 3.53 KB
/
Copy pathrebar.config.script
File metadata and controls
160 lines (142 loc) · 3.53 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
%%% % @noformat
TMPDIR = os:getenv("TMPDIR", "/tmp"),
Compile = fun(Name0, Prog) ->
Name = filename:join(TMPDIR, [os:getpid(), "-", Name0]),
ok = file:write_file(Name, Prog, [write, exclusive]),
IO = case os:getenv("ALCOVE_CONFIG_VERBOSE", false) of
false -> " > /dev/null 2>&1";
_ -> ""
end,
Cmd = erlang:open_port(
{spawn, ["${CC-cc} -Werror ${ALCOVE_LDFLAGS-} -o /dev/null ", Name, IO]},
[stream, exit_status]
),
Status = receive
{Cmd, {exit_status, 0}} ->
true;
{Cmd, {exit_status, _}} ->
false
end,
ok = file:delete(Name),
Status
end,
Test = fun(Name, Prog, Supported, Unsupported) ->
case Compile(Name, Prog) of
true ->
Supported;
false ->
Unsupported
end
end,
Only = fun(OS, Name, Prog, Supported, Unsupported) ->
case os:type() of
OS ->
Test(Name, Prog, Supported, Unsupported);
_ ->
Unsupported
end
end,
Linux = fun(Name, Prog, Supported, Unsupported) ->
Only({unix,linux}, Name, Prog, Supported, Unsupported)
end,
Append = fun(Str, Flag) ->
string:join(sets:to_list(sets:add_element(Flag,
sets:from_list(string:tokens(Str, " ")))), " ")
end,
Setenv = fun(_Key, "") ->
true;
(Key, Val) ->
Cur = os:getenv(Key, ""),
os:putenv(Key, Append(Cur, Val))
end,
%%
%% Tests
%%
% Support for fexecve(3)
Fexecve = fun(Config) ->
Prog = "
#include <unistd.h>
int main(int argc, char *argv[], char *envp[]) {
(void)fexecve(0, argv, envp);
return 0;
}",
Flag = Test("test_fexecve.c", Prog, "-DHAVE_FEXECVE", ""),
true = Setenv("ALCOVE_DEFINE", Flag),
Config
end,
% Linux: support for setns(2)
Setns = fun(Config) ->
Prog = "
#define _GNU_SOURCE
#include <sched.h>
int main(int argc, char *argv[]) {
(void)setns(0,0);
return 0;
}",
Flag = Linux("test_setns.c", Prog, "-DHAVE_SETNS", ""),
true = Setenv("ALCOVE_DEFINE", Flag),
Config
end,
% Linux: support for seccomp mode using prctl(2)
PrctlSeccomp = fun(Config) ->
Prog = "
#include <linux/seccomp.h>
int main(int argc, char *argv[]) {
#ifdef SECCOMP_MODE_FILTER
return 0;
#endif
}",
Flag = Linux("test_prctl_seccomp.c", Prog, "-DHAVE_PRCTL_SECCOMP", ""),
true = Setenv("ALCOVE_DEFINE", Flag),
Config
end,
% Linux: support for seccomp mode using seccomp(2)
Seccomp = fun(Config) ->
Prog = "
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <linux/audit.h>
#include <linux/filter.h>
#include <linux/seccomp.h>
#include <sys/prctl.h>
int main(int argc, char *argv[]) {
return seccomp(SECCOMP_SET_MODE_STRICT, 0, NULL);
}",
Flag = Linux("test_seccomp.c", Prog, "-DHAVE_SECCOMP", ""),
true = Setenv("ALCOVE_DEFINE", Flag),
Config
end,
RunTests = fun() ->
case code:lib_dir(alcove, ebin) of
{error, bad_name} ->
true;
Lib ->
Path = code:get_path(),
_ = code:del_path(Lib),
try alcove_drv:progname() of
Progname ->
case file:read_file_info(Progname) of
{ok, _} -> false;
_ -> true
end
catch
_:_ ->
true
after
code:set_path(Path)
end
end
end,
case RunTests() of
true ->
lists:foldl(fun(Fun, Cfg) ->
Fun(Cfg)
end,
CONFIG,
[Fexecve, Setns, PrctlSeccomp, Seccomp]
);
false ->
CONFIG
end.