chiark / gitweb /
importd: add new bus calls for importing local tar and raw images
[elogind.git] / src / test / test-path-lookup.c
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>
23
24 #include "path-lookup.h"
25 #include "log.h"
26 #include "strv.h"
27
28 static void test_paths(SystemdRunningAs running_as, bool personal) {
29         char template[] = "/tmp/test-path-lookup.XXXXXXX";
30
31         _cleanup_lookup_paths_free_ LookupPaths lp = {};
32         char *exists, *not;
33
34         assert_se(mkdtemp(template));
35         exists = strjoina(template, "/exists");
36         assert_se(mkdir(exists, 0755) == 0);
37         not = strjoina(template, "/not");
38
39         assert_se(lookup_paths_init(&lp, running_as, personal, NULL, exists, not, not) == 0);
40
41         assert_se(!strv_isempty(lp.unit_path));
42         assert_se(strv_contains(lp.unit_path, exists));
43         assert_se(strv_contains(lp.unit_path, not));
44
45         assert_se(rm_rf_dangerous(template, false, true, false) >= 0);
46 }
47
48 static void print_generator_paths(SystemdRunningAs running_as) {
49         _cleanup_strv_free_ char **paths;
50         char **dir;
51
52         log_info("Generators dirs (%s):", running_as == SYSTEMD_SYSTEM ? "system" : "user");
53
54         paths = generator_paths(running_as);
55         STRV_FOREACH(dir, paths)
56                 log_info("        %s", *dir);
57 }
58
59 int main(int argc, char **argv) {
60         log_set_max_level(LOG_DEBUG);
61         log_parse_environment();
62         log_open();
63
64         test_paths(SYSTEMD_SYSTEM, false);
65         test_paths(SYSTEMD_SYSTEM, true);
66         test_paths(SYSTEMD_USER, false);
67         test_paths(SYSTEMD_USER, true);
68
69         print_generator_paths(SYSTEMD_SYSTEM);
70         print_generator_paths(SYSTEMD_USER);
71
72         return EXIT_SUCCESS;
73 }