]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-execute.c
tree-wide: use IN_SET where possible
[thirdparty/systemd.git] / src / test / test-execute.c
CommitLineData
281e05b6
RC
1/***
2 This file is part of systemd.
3
4 Copyright 2014 Ronny Chevalier
5
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
18***/
19
cc7fa4fb
RC
20#include <grp.h>
21#include <pwd.h>
ff4ca461 22#include <stdio.h>
70d7aea5 23#include <sys/prctl.h>
ff4ca461 24#include <sys/types.h>
281e05b6 25
03bd70dd 26#include "fileio.h"
f4f15635 27#include "fs-util.h"
281e05b6 28#include "macro.h"
f4f15635 29#include "manager.h"
281e05b6 30#include "mkdir.h"
ff4ca461 31#include "path-util.h"
c6878637 32#include "rm-rf.h"
83f12b27
FS
33#ifdef HAVE_SECCOMP
34#include "seccomp-util.h"
35#endif
34b86909 36#include "stat-util.h"
8b3aa503 37#include "test-helper.h"
cc100a5a 38#include "tests.h"
f4f15635
LP
39#include "unit.h"
40#include "util.h"
4dd4cb8f 41#include "virt.h"
281e05b6
RC
42
43typedef void (*test_function_t)(Manager *m);
44
45static void check(Manager *m, Unit *unit, int status_expected, int code_expected) {
46 Service *service = NULL;
47 usec_t ts;
48 usec_t timeout = 2 * USEC_PER_SEC;
49
50 assert_se(m);
51 assert_se(unit);
52
53 service = SERVICE(unit);
54 printf("%s\n", unit->id);
55 exec_context_dump(&service->exec_context, stdout, "\t");
56 ts = now(CLOCK_MONOTONIC);
57 while (service->state != SERVICE_DEAD && service->state != SERVICE_FAILED) {
58 int r;
59 usec_t n;
60
61 r = sd_event_run(m->event, 100 * USEC_PER_MSEC);
62 assert_se(r >= 0);
63
64 n = now(CLOCK_MONOTONIC);
65 if (ts + timeout < n) {
66 log_error("Test timeout when testing %s", unit->id);
67 exit(EXIT_FAILURE);
68 }
69 }
70 exec_status_dump(&service->main_exec_status, stdout, "\t");
71 assert_se(service->main_exec_status.status == status_expected);
72 assert_se(service->main_exec_status.code == code_expected);
73}
74
6086d2da
DP
75static bool is_inaccessible_available(void) {
76 char *p;
77
78 FOREACH_STRING(p,
79 "/run/systemd/inaccessible/reg",
80 "/run/systemd/inaccessible/dir",
81 "/run/systemd/inaccessible/chr",
82 "/run/systemd/inaccessible/blk",
83 "/run/systemd/inaccessible/fifo",
84 "/run/systemd/inaccessible/sock"
85 ) {
86 if (access(p, F_OK) < 0)
87 return false;
88 }
89
90 return true;
91}
92
281e05b6
RC
93static void test(Manager *m, const char *unit_name, int status_expected, int code_expected) {
94 Unit *unit;
95
96 assert_se(unit_name);
97
98 assert_se(manager_load_unit(m, unit_name, NULL, NULL, &unit) >= 0);
99 assert_se(UNIT_VTABLE(unit)->start(unit) >= 0);
100 check(m, unit, status_expected, code_expected);
101}
102
103static void test_exec_workingdirectory(Manager *m) {
104 assert_se(mkdir_p("/tmp/test-exec_workingdirectory", 0755) >= 0);
105
106 test(m, "exec-workingdirectory.service", 0, CLD_EXITED);
107
c6878637 108 (void) rm_rf("/tmp/test-exec_workingdirectory", REMOVE_ROOT|REMOVE_PHYSICAL);
281e05b6
RC
109}
110
111static void test_exec_personality(Manager *m) {
281e05b6
RC
112#if defined(__x86_64__)
113 test(m, "exec-personality-x86-64.service", 0, CLD_EXITED);
7517f51e
HB
114
115#elif defined(__s390__)
116 test(m, "exec-personality-s390.service", 0, CLD_EXITED);
117
12591863
JS
118#elif defined(__powerpc64__)
119# if __BYTE_ORDER == __BIG_ENDIAN
120 test(m, "exec-personality-ppc64.service", 0, CLD_EXITED);
121# else
122 test(m, "exec-personality-ppc64le.service", 0, CLD_EXITED);
123# endif
124
125#elif defined(__aarch64__)
126 test(m, "exec-personality-aarch64.service", 0, CLD_EXITED);
127
5798eb4c 128#elif defined(__i386__)
7517f51e 129 test(m, "exec-personality-x86.service", 0, CLD_EXITED);
281e05b6
RC
130#endif
131}
132
133static void test_exec_ignoresigpipe(Manager *m) {
134 test(m, "exec-ignoresigpipe-yes.service", 0, CLD_EXITED);
135 test(m, "exec-ignoresigpipe-no.service", SIGPIPE, CLD_KILLED);
136}
137
138static void test_exec_privatetmp(Manager *m) {
139 assert_se(touch("/tmp/test-exec_privatetmp") >= 0);
140
141 test(m, "exec-privatetmp-yes.service", 0, CLD_EXITED);
142 test(m, "exec-privatetmp-no.service", 0, CLD_EXITED);
143
144 unlink("/tmp/test-exec_privatetmp");
145}
146
147static void test_exec_privatedevices(Manager *m) {
4dd4cb8f 148 if (detect_container() > 0) {
303c0bf8 149 log_notice("testing in container, skipping %s", __func__);
4dd4cb8f
SM
150 return;
151 }
6086d2da 152 if (!is_inaccessible_available()) {
303c0bf8 153 log_notice("testing without inaccessible, skipping %s", __func__);
6086d2da
DP
154 return;
155 }
156
281e05b6
RC
157 test(m, "exec-privatedevices-yes.service", 0, CLD_EXITED);
158 test(m, "exec-privatedevices-no.service", 0, CLD_EXITED);
159}
160
615a1f4b 161static void test_exec_privatedevices_capabilities(Manager *m) {
0608ba98
ZJS
162 int r;
163
615a1f4b 164 if (detect_container() > 0) {
303c0bf8 165 log_notice("testing in container, skipping %s", __func__);
615a1f4b
DH
166 return;
167 }
6086d2da 168 if (!is_inaccessible_available()) {
303c0bf8 169 log_notice("testing without inaccessible, skipping %s", __func__);
6086d2da
DP
170 return;
171 }
172
0608ba98
ZJS
173 /* We use capsh to test if the capabilities are
174 * properly set, so be sure that it exists */
175 r = find_binary("capsh", NULL);
176 if (r < 0) {
177 log_error_errno(r, "Skipping %s, could not find capsh binary: %m", __func__);
6086d2da
DP
178 return;
179 }
180
615a1f4b
DH
181 test(m, "exec-privatedevices-yes-capability-mknod.service", 0, CLD_EXITED);
182 test(m, "exec-privatedevices-no-capability-mknod.service", 0, CLD_EXITED);
625d8769
DH
183 test(m, "exec-privatedevices-yes-capability-sys-rawio.service", 0, CLD_EXITED);
184 test(m, "exec-privatedevices-no-capability-sys-rawio.service", 0, CLD_EXITED);
615a1f4b
DH
185}
186
4982dbcc 187static void test_exec_protectkernelmodules(Manager *m) {
0608ba98
ZJS
188 int r;
189
3ae33295 190 if (detect_container() > 0) {
303c0bf8 191 log_notice("testing in container, skipping %s", __func__);
3ae33295
DH
192 return;
193 }
6086d2da 194 if (!is_inaccessible_available()) {
303c0bf8 195 log_notice("testing without inaccessible, skipping %s", __func__);
6086d2da
DP
196 return;
197 }
3ae33295 198
0608ba98
ZJS
199 r = find_binary("capsh", NULL);
200 if (r < 0) {
201 log_error_errno(r, "Skipping %s, could not find capsh binary: %m", __func__);
202 return;
203 }
204
205
3ae33295
DH
206 test(m, "exec-protectkernelmodules-no-capabilities.service", 0, CLD_EXITED);
207 test(m, "exec-protectkernelmodules-yes-capabilities.service", 0, CLD_EXITED);
4982dbcc 208 test(m, "exec-protectkernelmodules-yes-mount-propagation.service", 0, CLD_EXITED);
3ae33295
DH
209}
210
f78b36f0 211static void test_exec_readonlypaths(Manager *m) {
34b86909
LP
212
213 if (path_is_read_only_fs("/var") > 0)
214 return;
215
f78b36f0 216 test(m, "exec-readonlypaths.service", 0, CLD_EXITED);
cdfbd1fb
DH
217 test(m, "exec-readonlypaths-mount-propagation.service", 0, CLD_EXITED);
218}
219
220static void test_exec_readwritepaths(Manager *m) {
34b86909
LP
221
222 if (path_is_read_only_fs("/") > 0)
223 return;
224
cdfbd1fb
DH
225 test(m, "exec-readwritepaths-mount-propagation.service", 0, CLD_EXITED);
226}
227
228static void test_exec_inaccessiblepaths(Manager *m) {
34b86909
LP
229
230 if (path_is_read_only_fs("/") > 0)
231 return;
232
cdfbd1fb 233 test(m, "exec-inaccessiblepaths-mount-propagation.service", 0, CLD_EXITED);
f78b36f0
DH
234}
235
c090d74d 236static void test_exec_inaccessiblepaths_proc(Manager *m) {
af4af186
EV
237 if (!is_inaccessible_available()) {
238 log_notice("testing without inaccessible, skipping %s", __func__);
239 return;
240 }
241
c090d74d
TR
242 test(m, "exec-inaccessiblepaths-proc.service", 0, CLD_EXITED);
243}
244
281e05b6
RC
245static void test_exec_systemcallfilter(Manager *m) {
246#ifdef HAVE_SECCOMP
83f12b27
FS
247 if (!is_seccomp_available())
248 return;
281e05b6
RC
249 test(m, "exec-systemcallfilter-not-failing.service", 0, CLD_EXITED);
250 test(m, "exec-systemcallfilter-not-failing2.service", 0, CLD_EXITED);
251 test(m, "exec-systemcallfilter-failing.service", SIGSYS, CLD_KILLED);
252 test(m, "exec-systemcallfilter-failing2.service", SIGSYS, CLD_KILLED);
83f12b27 253
281e05b6
RC
254#endif
255}
256
257static void test_exec_systemcallerrornumber(Manager *m) {
258#ifdef HAVE_SECCOMP
83f12b27
FS
259 if (is_seccomp_available())
260 test(m, "exec-systemcallerrornumber.service", 1, CLD_EXITED);
281e05b6
RC
261#endif
262}
263
97e60383
DH
264static void test_exec_restrict_namespaces(Manager *m) {
265#ifdef HAVE_SECCOMP
266 if (!is_seccomp_available())
267 return;
268
269 test(m, "exec-restrict-namespaces-no.service", 0, CLD_EXITED);
270 test(m, "exec-restrict-namespaces-yes.service", 1, CLD_EXITED);
271 test(m, "exec-restrict-namespaces-mnt.service", 0, CLD_EXITED);
272 test(m, "exec-restrict-namespaces-mnt-blacklist.service", 1, CLD_EXITED);
273#endif
274}
275
19c0b0b9
RC
276static void test_exec_systemcall_system_mode_with_user(Manager *m) {
277#ifdef HAVE_SECCOMP
83f12b27
FS
278 if (!is_seccomp_available())
279 return;
19c0b0b9
RC
280 if (getpwnam("nobody"))
281 test(m, "exec-systemcallfilter-system-user.service", 0, CLD_EXITED);
50f130c2
RC
282 else if (getpwnam("nfsnobody"))
283 test(m, "exec-systemcallfilter-system-user-nfsnobody.service", 0, CLD_EXITED);
19c0b0b9 284 else
303c0bf8 285 log_error_errno(errno, "Skipping %s, could not find nobody/nfsnobody user: %m", __func__);
19c0b0b9
RC
286#endif
287}
288
281e05b6 289static void test_exec_user(Manager *m) {
cc7fa4fb
RC
290 if (getpwnam("nobody"))
291 test(m, "exec-user.service", 0, CLD_EXITED);
50f130c2
RC
292 else if (getpwnam("nfsnobody"))
293 test(m, "exec-user-nfsnobody.service", 0, CLD_EXITED);
ff4ca461 294 else
303c0bf8 295 log_error_errno(errno, "Skipping %s, could not find nobody/nfsnobody user: %m", __func__);
281e05b6
RC
296}
297
298static void test_exec_group(Manager *m) {
cc7fa4fb
RC
299 if (getgrnam("nobody"))
300 test(m, "exec-group.service", 0, CLD_EXITED);
50f130c2
RC
301 else if (getgrnam("nfsnobody"))
302 test(m, "exec-group-nfsnobody.service", 0, CLD_EXITED);
ff4ca461 303 else
303c0bf8 304 log_error_errno(errno, "Skipping %s, could not find nobody/nfsnobody group: %m", __func__);
281e05b6
RC
305}
306
86b838ea
DH
307static void test_exec_supplementary_groups(Manager *m) {
308 test(m, "exec-supplementarygroups.service", 0, CLD_EXITED);
bf9ace96
DH
309 test(m, "exec-supplementarygroups-single-group.service", 0, CLD_EXITED);
310 test(m, "exec-supplementarygroups-single-group-user.service", 0, CLD_EXITED);
50ca7a35
DH
311 test(m, "exec-supplementarygroups-multiple-groups-default-group-user.service", 0, CLD_EXITED);
312 test(m, "exec-supplementarygroups-multiple-groups-withgid.service", 0, CLD_EXITED);
313 test(m, "exec-supplementarygroups-multiple-groups-withuid.service", 0, CLD_EXITED);
86b838ea
DH
314}
315
2b9ac11e
DH
316static void test_exec_dynamic_user(Manager *m) {
317 test(m, "exec-dynamicuser-fixeduser.service", 0, CLD_EXITED);
318 test(m, "exec-dynamicuser-fixeduser-one-supplementarygroup.service", 0, CLD_EXITED);
5c67067f 319 test(m, "exec-dynamicuser-supplementarygroups.service", 0, CLD_EXITED);
2b9ac11e
DH
320}
321
281e05b6
RC
322static void test_exec_environment(Manager *m) {
323 test(m, "exec-environment.service", 0, CLD_EXITED);
324 test(m, "exec-environment-multiple.service", 0, CLD_EXITED);
325 test(m, "exec-environment-empty.service", 0, CLD_EXITED);
326}
327
03bd70dd
RC
328static void test_exec_environmentfile(Manager *m) {
329 static const char e[] =
330 "VAR1='word1 word2'\n"
331 "VAR2=word3 \n"
332 "# comment1\n"
333 "\n"
334 "; comment2\n"
335 " ; # comment3\n"
336 "line without an equal\n"
337 "VAR3='$word 5 6'\n";
338 int r;
339
340 r = write_string_file("/tmp/test-exec_environmentfile.conf", e, WRITE_STRING_FILE_CREATE);
341 assert_se(r == 0);
342
343 test(m, "exec-environmentfile.service", 0, CLD_EXITED);
344
345 unlink("/tmp/test-exec_environmentfile.conf");
346}
347
4c80d201 348static void test_exec_passenvironment(Manager *m) {
e1abca2e
FB
349 /* test-execute runs under MANAGER_USER which, by default, forwards all
350 * variables present in the environment, but only those that are
351 * present _at the time it is created_!
352 *
353 * So these PassEnvironment checks are still expected to work, since we
354 * are ensuring the variables are not present at manager creation (they
355 * are unset explicitly in main) and are only set here.
356 *
357 * This is still a good approximation of how a test for MANAGER_SYSTEM
358 * would work.
359 */
4c80d201
FB
360 assert_se(setenv("VAR1", "word1 word2", 1) == 0);
361 assert_se(setenv("VAR2", "word3", 1) == 0);
362 assert_se(setenv("VAR3", "$word 5 6", 1) == 0);
363 test(m, "exec-passenvironment.service", 0, CLD_EXITED);
364 test(m, "exec-passenvironment-repeated.service", 0, CLD_EXITED);
365 test(m, "exec-passenvironment-empty.service", 0, CLD_EXITED);
366 assert_se(unsetenv("VAR1") == 0);
367 assert_se(unsetenv("VAR2") == 0);
368 assert_se(unsetenv("VAR3") == 0);
369 test(m, "exec-passenvironment-absent.service", 0, CLD_EXITED);
370}
371
27c5347c
RC
372static void test_exec_umask(Manager *m) {
373 test(m, "exec-umask-default.service", 0, CLD_EXITED);
374 test(m, "exec-umask-0177.service", 0, CLD_EXITED);
375}
376
cc3ddc85
RC
377static void test_exec_runtimedirectory(Manager *m) {
378 test(m, "exec-runtimedirectory.service", 0, CLD_EXITED);
379 test(m, "exec-runtimedirectory-mode.service", 0, CLD_EXITED);
cc7fa4fb
RC
380 if (getgrnam("nobody"))
381 test(m, "exec-runtimedirectory-owner.service", 0, CLD_EXITED);
50f130c2
RC
382 else if (getgrnam("nfsnobody"))
383 test(m, "exec-runtimedirectory-owner-nfsnobody.service", 0, CLD_EXITED);
ff4ca461 384 else
303c0bf8 385 log_error_errno(errno, "Skipping %s, could not find nobody/nfsnobody group: %m", __func__);
ff4ca461
RC
386}
387
388static void test_exec_capabilityboundingset(Manager *m) {
389 int r;
390
ff4ca461
RC
391 r = find_binary("capsh", NULL);
392 if (r < 0) {
0608ba98 393 log_error_errno(r, "Skipping %s, could not find capsh binary: %m", __func__);
ff4ca461
RC
394 return;
395 }
396
397 test(m, "exec-capabilityboundingset-simple.service", 0, CLD_EXITED);
398 test(m, "exec-capabilityboundingset-reset.service", 0, CLD_EXITED);
399 test(m, "exec-capabilityboundingset-merge.service", 0, CLD_EXITED);
400 test(m, "exec-capabilityboundingset-invert.service", 0, CLD_EXITED);
cc3ddc85
RC
401}
402
70d7aea5
IP
403static void test_exec_capabilityambientset(Manager *m) {
404 int r;
405
406 /* Check if the kernel has support for ambient capabilities. Run
407 * the tests only if that's the case. Clearing all ambient
408 * capabilities is fine, since we are expecting them to be unset
409 * in the first place for the tests. */
410 r = prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_CLEAR_ALL, 0, 0, 0);
411 if (r >= 0 || errno != EINVAL) {
50f130c2 412 if (getpwnam("nobody")) {
50f130c2
RC
413 test(m, "exec-capabilityambientset.service", 0, CLD_EXITED);
414 test(m, "exec-capabilityambientset-merge.service", 0, CLD_EXITED);
34f5ff46
RC
415 } else if (getpwnam("nfsnobody")) {
416 test(m, "exec-capabilityambientset-nfsnobody.service", 0, CLD_EXITED);
417 test(m, "exec-capabilityambientset-merge-nfsnobody.service", 0, CLD_EXITED);
50f130c2 418 } else
303c0bf8 419 log_error_errno(errno, "Skipping %s, could not find nobody/nfsnobody user: %m", __func__);
50f130c2 420 } else
303c0bf8 421 log_error_errno(errno, "Skipping %s, the kernel does not support ambient capabilities: %m", __func__);
70d7aea5
IP
422}
423
63447f11
RC
424static void test_exec_privatenetwork(Manager *m) {
425 int r;
426
427 r = find_binary("ip", NULL);
428 if (r < 0) {
303c0bf8 429 log_error_errno(r, "Skipping %s, could not find ip binary: %m", __func__);
63447f11
RC
430 return;
431 }
432
433 test(m, "exec-privatenetwork-yes.service", 0, CLD_EXITED);
434}
435
c388dfea
RC
436static void test_exec_oomscoreadjust(Manager *m) {
437 test(m, "exec-oomscoreadjust-positive.service", 0, CLD_EXITED);
438 test(m, "exec-oomscoreadjust-negative.service", 0, CLD_EXITED);
439}
440
a6226758
RC
441static void test_exec_ioschedulingclass(Manager *m) {
442 test(m, "exec-ioschedulingclass-none.service", 0, CLD_EXITED);
443 test(m, "exec-ioschedulingclass-idle.service", 0, CLD_EXITED);
444 test(m, "exec-ioschedulingclass-realtime.service", 0, CLD_EXITED);
445 test(m, "exec-ioschedulingclass-best-effort.service", 0, CLD_EXITED);
446}
447
25254999
EV
448static void test_exec_spec_interpolation(Manager *m) {
449 test(m, "exec-spec-interpolation.service", 0, CLD_EXITED);
450}
451
6818c54c
LP
452static void test_exec_read_only_path_suceed(Manager *m) {
453 test(m, "exec-read-only-path-succeed.service", 0, CLD_EXITED);
454}
455
42cc99d5
LP
456static void test_exec_unset_environment(Manager *m) {
457 test(m, "exec-unset-environment.service", 0, CLD_EXITED);
458}
459
ea9cfad1
LP
460static int run_tests(UnitFileScope scope, const test_function_t *tests) {
461 const test_function_t *test = NULL;
19c0b0b9
RC
462 Manager *m = NULL;
463 int r;
464
465 assert_se(tests);
466
e0a3da1f 467 r = manager_new(scope, MANAGER_TEST_RUN_MINIMAL, &m);
19c0b0b9 468 if (MANAGER_SKIP_TEST(r)) {
2179fd10 469 log_notice_errno(r, "Skipping test: manager_new: %m");
19c0b0b9
RC
470 return EXIT_TEST_SKIP;
471 }
472 assert_se(r >= 0);
473 assert_se(manager_startup(m, NULL, NULL) >= 0);
474
475 for (test = tests; test && *test; test++)
476 (*test)(m);
477
478 manager_free(m);
479
480 return 0;
481}
482
281e05b6 483int main(int argc, char *argv[]) {
ea9cfad1 484 static const test_function_t user_tests[] = {
281e05b6
RC
485 test_exec_workingdirectory,
486 test_exec_personality,
487 test_exec_ignoresigpipe,
488 test_exec_privatetmp,
489 test_exec_privatedevices,
615a1f4b 490 test_exec_privatedevices_capabilities,
4982dbcc 491 test_exec_protectkernelmodules,
f78b36f0 492 test_exec_readonlypaths,
cdfbd1fb
DH
493 test_exec_readwritepaths,
494 test_exec_inaccessiblepaths,
c090d74d 495 test_exec_inaccessiblepaths_proc,
63447f11 496 test_exec_privatenetwork,
281e05b6
RC
497 test_exec_systemcallfilter,
498 test_exec_systemcallerrornumber,
97e60383 499 test_exec_restrict_namespaces,
281e05b6
RC
500 test_exec_user,
501 test_exec_group,
86b838ea 502 test_exec_supplementary_groups,
2b9ac11e 503 test_exec_dynamic_user,
281e05b6 504 test_exec_environment,
03bd70dd 505 test_exec_environmentfile,
4c80d201 506 test_exec_passenvironment,
27c5347c 507 test_exec_umask,
cc3ddc85 508 test_exec_runtimedirectory,
ff4ca461 509 test_exec_capabilityboundingset,
70d7aea5 510 test_exec_capabilityambientset,
c388dfea 511 test_exec_oomscoreadjust,
a6226758 512 test_exec_ioschedulingclass,
25254999 513 test_exec_spec_interpolation,
6818c54c 514 test_exec_read_only_path_suceed,
42cc99d5 515 test_exec_unset_environment,
281e05b6
RC
516 NULL,
517 };
ea9cfad1 518 static const test_function_t system_tests[] = {
19c0b0b9
RC
519 test_exec_systemcall_system_mode_with_user,
520 NULL,
521 };
281e05b6
RC
522 int r;
523
469830d1 524 log_set_max_level(LOG_DEBUG);
281e05b6
RC
525 log_parse_environment();
526 log_open();
527
607ff5f9
DH
528 /* It is needed otherwise cgroup creation fails */
529 if (getuid() != 0) {
530 printf("Skipping test: not root\n");
531 return EXIT_TEST_SKIP;
532 }
533
8c759b33
LP
534 enter_cgroup_subroot();
535
cc3ddc85 536 assert_se(setenv("XDG_RUNTIME_DIR", "/tmp/", 1) == 0);
cc100a5a 537 assert_se(set_unit_path(get_testdata_dir("/test-execute")) >= 0);
281e05b6 538
e1abca2e
FB
539 /* Unset VAR1, VAR2 and VAR3 which are used in the PassEnvironment test
540 * cases, otherwise (and if they are present in the environment),
541 * `manager_default_environment` will copy them into the default
542 * environment which is passed to each created job, which will make the
543 * tests that expect those not to be present to fail.
544 */
545 assert_se(unsetenv("VAR1") == 0);
546 assert_se(unsetenv("VAR2") == 0);
547 assert_se(unsetenv("VAR3") == 0);
548
463d0d15 549 r = run_tests(UNIT_FILE_USER, user_tests);
19c0b0b9
RC
550 if (r != 0)
551 return r;
281e05b6 552
463d0d15 553 return run_tests(UNIT_FILE_SYSTEM, system_tests);
281e05b6 554}