]>
Commit | Line | Data |
---|---|---|
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 | 23 | |
4f1a33dd | 24 | #include "log.h" |
07630cea | 25 | #include "path-lookup.h" |
c6878637 | 26 | #include "rm-rf.h" |
07630cea LP |
27 | #include "string-util.h" |
28 | #include "strv.h" | |
4f1a33dd | 29 | |
b2c23da8 | 30 | static void test_paths(ManagerRunningAs running_as, bool personal) { |
4f1a33dd ZJS |
31 | char template[] = "/tmp/test-path-lookup.XXXXXXX"; |
32 | ||
33 | _cleanup_lookup_paths_free_ LookupPaths lp = {}; | |
34 | char *exists, *not; | |
35 | ||
36 | assert_se(mkdtemp(template)); | |
63c372cb | 37 | exists = strjoina(template, "/exists"); |
4f1a33dd | 38 | assert_se(mkdir(exists, 0755) == 0); |
63c372cb | 39 | not = strjoina(template, "/not"); |
4f1a33dd ZJS |
40 | |
41 | assert_se(lookup_paths_init(&lp, running_as, personal, NULL, exists, not, not) == 0); | |
42 | ||
43 | assert_se(!strv_isempty(lp.unit_path)); | |
44 | assert_se(strv_contains(lp.unit_path, exists)); | |
45 | assert_se(strv_contains(lp.unit_path, not)); | |
46 | ||
c6878637 | 47 | assert_se(rm_rf(template, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0); |
4f1a33dd ZJS |
48 | } |
49 | ||
b2c23da8 | 50 | static void print_generator_paths(ManagerRunningAs running_as) { |
4f1a33dd ZJS |
51 | _cleanup_strv_free_ char **paths; |
52 | char **dir; | |
53 | ||
b2c23da8 | 54 | log_info("Generators dirs (%s):", running_as == MANAGER_SYSTEM ? "system" : "user"); |
4f1a33dd ZJS |
55 | |
56 | paths = generator_paths(running_as); | |
57 | STRV_FOREACH(dir, paths) | |
58 | log_info(" %s", *dir); | |
59 | } | |
60 | ||
61 | int main(int argc, char **argv) { | |
62 | log_set_max_level(LOG_DEBUG); | |
63 | log_parse_environment(); | |
64 | log_open(); | |
65 | ||
b2c23da8 LP |
66 | test_paths(MANAGER_SYSTEM, false); |
67 | test_paths(MANAGER_SYSTEM, true); | |
68 | test_paths(MANAGER_USER, false); | |
69 | test_paths(MANAGER_USER, true); | |
4f1a33dd | 70 | |
b2c23da8 LP |
71 | print_generator_paths(MANAGER_SYSTEM); |
72 | print_generator_paths(MANAGER_USER); | |
4f1a33dd ZJS |
73 | |
74 | return EXIT_SUCCESS; | |
75 | } |