]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-path-lookup.c
util: rework rm_rf() logic
[thirdparty/systemd.git] / src / test / test-path-lookup.c
CommitLineData
4f1a33dd
ZJS
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3/***
4 This file is part of systemd.
5
6 Copyright 2014 Zbigniew Jędrzejewski-Szmek
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 <sys/stat.h>
4f1a33dd
ZJS
23
24#include "path-lookup.h"
25#include "log.h"
26#include "strv.h"
c6878637 27#include "rm-rf.h"
4f1a33dd
ZJS
28
29static void test_paths(SystemdRunningAs running_as, bool personal) {
30 char template[] = "/tmp/test-path-lookup.XXXXXXX";
31
32 _cleanup_lookup_paths_free_ LookupPaths lp = {};
33 char *exists, *not;
34
35 assert_se(mkdtemp(template));
63c372cb 36 exists = strjoina(template, "/exists");
4f1a33dd 37 assert_se(mkdir(exists, 0755) == 0);
63c372cb 38 not = strjoina(template, "/not");
4f1a33dd
ZJS
39
40 assert_se(lookup_paths_init(&lp, running_as, personal, NULL, exists, not, not) == 0);
41
42 assert_se(!strv_isempty(lp.unit_path));
43 assert_se(strv_contains(lp.unit_path, exists));
44 assert_se(strv_contains(lp.unit_path, not));
45
c6878637 46 assert_se(rm_rf(template, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0);
4f1a33dd
ZJS
47}
48
49static void print_generator_paths(SystemdRunningAs running_as) {
50 _cleanup_strv_free_ char **paths;
51 char **dir;
52
53 log_info("Generators dirs (%s):", running_as == SYSTEMD_SYSTEM ? "system" : "user");
54
55 paths = generator_paths(running_as);
56 STRV_FOREACH(dir, paths)
57 log_info(" %s", *dir);
58}
59
60int main(int argc, char **argv) {
61 log_set_max_level(LOG_DEBUG);
62 log_parse_environment();
63 log_open();
64
65 test_paths(SYSTEMD_SYSTEM, false);
66 test_paths(SYSTEMD_SYSTEM, true);
67 test_paths(SYSTEMD_USER, false);
68 test_paths(SYSTEMD_USER, true);
69
70 print_generator_paths(SYSTEMD_SYSTEM);
71 print_generator_paths(SYSTEMD_USER);
72
73 return EXIT_SUCCESS;
74}