]> git.proxmox.com Git - systemd.git/blob - src/test/test-install.c
Enable seccomp support on powerpc, ppc64el, and s390x
[systemd.git] / src / test / test-install.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4 This file is part of systemd.
5
6 Copyright 2011 Lennart Poettering
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include <stdio.h>
23 #include <string.h>
24
25 #include "install.h"
26
27 static void dump_changes(UnitFileChange *c, unsigned n) {
28 unsigned i;
29
30 assert_se(n == 0 || c);
31
32 for (i = 0; i < n; i++) {
33 if (c[i].type == UNIT_FILE_UNLINK)
34 printf("rm '%s'\n", c[i].path);
35 else if (c[i].type == UNIT_FILE_SYMLINK)
36 printf("ln -s '%s' '%s'\n", c[i].source, c[i].path);
37 }
38 }
39
40 int main(int argc, char* argv[]) {
41 Hashmap *h;
42 UnitFileList *p;
43 Iterator i;
44 int r;
45 const char *const files[] = { "avahi-daemon.service", NULL };
46 const char *const files2[] = { "/home/lennart/test.service", NULL };
47 UnitFileChange *changes = NULL;
48 unsigned n_changes = 0;
49 UnitFileState state = 0;
50
51 h = hashmap_new(&string_hash_ops);
52 r = unit_file_get_list(UNIT_FILE_SYSTEM, NULL, h);
53 assert_se(r == 0);
54
55 HASHMAP_FOREACH(p, h, i) {
56 UnitFileState s = _UNIT_FILE_STATE_INVALID;
57
58 r = unit_file_get_state(UNIT_FILE_SYSTEM, NULL, basename(p->path), &s);
59
60 assert_se((r < 0 && p->state == UNIT_FILE_BAD) ||
61 (p->state == s));
62
63 fprintf(stderr, "%s (%s)\n",
64 p->path,
65 unit_file_state_to_string(p->state));
66 }
67
68 unit_file_list_free(h);
69
70 log_error("enable");
71
72 r = unit_file_enable(UNIT_FILE_SYSTEM, false, NULL, (char**) files, false, &changes, &n_changes);
73 assert_se(r >= 0);
74
75 log_error("enable2");
76
77 r = unit_file_enable(UNIT_FILE_SYSTEM, false, NULL, (char**) files, false, &changes, &n_changes);
78 assert_se(r >= 0);
79
80 dump_changes(changes, n_changes);
81 unit_file_changes_free(changes, n_changes);
82
83 r = unit_file_get_state(UNIT_FILE_SYSTEM, NULL, files[0], &state);
84 assert_se(r >= 0);
85 assert_se(state == UNIT_FILE_ENABLED);
86
87 log_error("disable");
88
89 changes = NULL;
90 n_changes = 0;
91
92 r = unit_file_disable(UNIT_FILE_SYSTEM, false, NULL, (char**) files, &changes, &n_changes);
93 assert_se(r >= 0);
94
95 dump_changes(changes, n_changes);
96 unit_file_changes_free(changes, n_changes);
97
98 r = unit_file_get_state(UNIT_FILE_SYSTEM, NULL, files[0], &state);
99 assert_se(r >= 0);
100 assert_se(state == UNIT_FILE_DISABLED);
101
102 log_error("mask");
103 changes = NULL;
104 n_changes = 0;
105
106 r = unit_file_mask(UNIT_FILE_SYSTEM, false, NULL, (char**) files, false, &changes, &n_changes);
107 assert_se(r >= 0);
108 log_error("mask2");
109 r = unit_file_mask(UNIT_FILE_SYSTEM, false, NULL, (char**) files, false, &changes, &n_changes);
110 assert_se(r >= 0);
111
112 dump_changes(changes, n_changes);
113 unit_file_changes_free(changes, n_changes);
114
115 r = unit_file_get_state(UNIT_FILE_SYSTEM, NULL, files[0], &state);
116 assert_se(r >= 0);
117 assert_se(state == UNIT_FILE_MASKED);
118
119 log_error("unmask");
120 changes = NULL;
121 n_changes = 0;
122
123 r = unit_file_unmask(UNIT_FILE_SYSTEM, false, NULL, (char**) files, &changes, &n_changes);
124 assert_se(r >= 0);
125 log_error("unmask2");
126 r = unit_file_unmask(UNIT_FILE_SYSTEM, false, NULL, (char**) files, &changes, &n_changes);
127 assert_se(r >= 0);
128
129 dump_changes(changes, n_changes);
130 unit_file_changes_free(changes, n_changes);
131
132 r = unit_file_get_state(UNIT_FILE_SYSTEM, NULL, files[0], &state);
133 assert_se(r >= 0);
134 assert_se(state == UNIT_FILE_DISABLED);
135
136 log_error("mask");
137 changes = NULL;
138 n_changes = 0;
139
140 r = unit_file_mask(UNIT_FILE_SYSTEM, false, NULL, (char**) files, false, &changes, &n_changes);
141 assert_se(r >= 0);
142
143 dump_changes(changes, n_changes);
144 unit_file_changes_free(changes, n_changes);
145
146 r = unit_file_get_state(UNIT_FILE_SYSTEM, NULL, files[0], &state);
147 assert_se(r >= 0);
148 assert_se(state == UNIT_FILE_MASKED);
149
150 log_error("disable");
151 changes = NULL;
152 n_changes = 0;
153
154 r = unit_file_disable(UNIT_FILE_SYSTEM, false, NULL, (char**) files, &changes, &n_changes);
155 assert_se(r >= 0);
156 log_error("disable2");
157 r = unit_file_disable(UNIT_FILE_SYSTEM, false, NULL, (char**) files, &changes, &n_changes);
158 assert_se(r >= 0);
159
160 dump_changes(changes, n_changes);
161 unit_file_changes_free(changes, n_changes);
162
163 r = unit_file_get_state(UNIT_FILE_SYSTEM, NULL, files[0], &state);
164 assert_se(r >= 0);
165 assert_se(state == UNIT_FILE_MASKED);
166
167 log_error("umask");
168 changes = NULL;
169 n_changes = 0;
170
171 r = unit_file_unmask(UNIT_FILE_SYSTEM, false, NULL, (char**) files, &changes, &n_changes);
172 assert_se(r >= 0);
173
174 dump_changes(changes, n_changes);
175 unit_file_changes_free(changes, n_changes);
176
177 r = unit_file_get_state(UNIT_FILE_SYSTEM, NULL, files[0], &state);
178 assert_se(r >= 0);
179 assert_se(state == UNIT_FILE_DISABLED);
180
181 log_error("enable files2");
182 changes = NULL;
183 n_changes = 0;
184
185 r = unit_file_enable(UNIT_FILE_SYSTEM, false, NULL, (char**) files2, false, &changes, &n_changes);
186 assert_se(r >= 0);
187
188 dump_changes(changes, n_changes);
189 unit_file_changes_free(changes, n_changes);
190
191 r = unit_file_get_state(UNIT_FILE_SYSTEM, NULL, basename(files2[0]), &state);
192 assert_se(r >= 0);
193 assert_se(state == UNIT_FILE_ENABLED);
194
195 log_error("disable files2");
196 changes = NULL;
197 n_changes = 0;
198
199 r = unit_file_disable(UNIT_FILE_SYSTEM, false, NULL, STRV_MAKE(basename(files2[0])), &changes, &n_changes);
200 assert_se(r >= 0);
201
202 dump_changes(changes, n_changes);
203 unit_file_changes_free(changes, n_changes);
204
205 r = unit_file_get_state(UNIT_FILE_SYSTEM, NULL, basename(files2[0]), &state);
206 assert_se(r < 0);
207
208 log_error("link files2");
209 changes = NULL;
210 n_changes = 0;
211
212 r = unit_file_link(UNIT_FILE_SYSTEM, false, NULL, (char**) files2, false, &changes, &n_changes);
213 assert_se(r >= 0);
214
215 dump_changes(changes, n_changes);
216 unit_file_changes_free(changes, n_changes);
217
218 r = unit_file_get_state(UNIT_FILE_SYSTEM, NULL, basename(files2[0]), &state);
219 assert_se(r >= 0);
220 assert_se(state == UNIT_FILE_LINKED);
221
222 log_error("disable files2");
223 changes = NULL;
224 n_changes = 0;
225
226 r = unit_file_disable(UNIT_FILE_SYSTEM, false, NULL, STRV_MAKE(basename(files2[0])), &changes, &n_changes);
227 assert_se(r >= 0);
228
229 dump_changes(changes, n_changes);
230 unit_file_changes_free(changes, n_changes);
231
232 r = unit_file_get_state(UNIT_FILE_SYSTEM, NULL, basename(files2[0]), &state);
233 assert_se(r < 0);
234
235 log_error("link files2");
236 changes = NULL;
237 n_changes = 0;
238
239 r = unit_file_link(UNIT_FILE_SYSTEM, false, NULL, (char**) files2, false, &changes, &n_changes);
240 assert_se(r >= 0);
241
242 dump_changes(changes, n_changes);
243 unit_file_changes_free(changes, n_changes);
244
245 r = unit_file_get_state(UNIT_FILE_SYSTEM, NULL, basename(files2[0]), &state);
246 assert_se(r >= 0);
247 assert_se(state == UNIT_FILE_LINKED);
248
249 log_error("reenable files2");
250 changes = NULL;
251 n_changes = 0;
252
253 r = unit_file_reenable(UNIT_FILE_SYSTEM, false, NULL, (char**) files2, false, &changes, &n_changes);
254 assert_se(r >= 0);
255
256 dump_changes(changes, n_changes);
257 unit_file_changes_free(changes, n_changes);
258
259 r = unit_file_get_state(UNIT_FILE_SYSTEM, NULL, basename(files2[0]), &state);
260 assert_se(r >= 0);
261 assert_se(state == UNIT_FILE_ENABLED);
262
263 log_error("disable files2");
264 changes = NULL;
265 n_changes = 0;
266
267 r = unit_file_disable(UNIT_FILE_SYSTEM, false, NULL, STRV_MAKE(basename(files2[0])), &changes, &n_changes);
268 assert_se(r >= 0);
269
270 dump_changes(changes, n_changes);
271 unit_file_changes_free(changes, n_changes);
272
273 r = unit_file_get_state(UNIT_FILE_SYSTEM, NULL, basename(files2[0]), &state);
274 assert_se(r < 0);
275 log_error("preset files");
276 changes = NULL;
277 n_changes = 0;
278
279 r = unit_file_preset(UNIT_FILE_SYSTEM, false, NULL, (char**) files, UNIT_FILE_PRESET_FULL, false, &changes, &n_changes);
280 assert_se(r >= 0);
281
282 dump_changes(changes, n_changes);
283 unit_file_changes_free(changes, n_changes);
284
285 r = unit_file_get_state(UNIT_FILE_SYSTEM, NULL, basename(files[0]), &state);
286 assert_se(r >= 0);
287 assert_se(state == UNIT_FILE_ENABLED);
288
289 return 0;
290 }