2 This file is part of systemd.
4 Copyright 2014 Zbigniew Jędrzejewski-Szmek
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.
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.
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/>.
24 #include "path-lookup.h"
26 #include "string-util.h"
29 static void test_paths(UnitFileScope scope
) {
30 char template[] = "/tmp/test-path-lookup.XXXXXXX";
32 _cleanup_lookup_paths_free_ LookupPaths lp_without_env
= {};
33 _cleanup_lookup_paths_free_ LookupPaths lp_with_env
= {};
34 char *systemd_unit_path
;
36 assert_se(mkdtemp(template));
38 assert_se(unsetenv("SYSTEMD_UNIT_PATH") == 0);
39 assert_se(lookup_paths_init(&lp_without_env
, scope
, NULL
) >= 0);
40 assert_se(!strv_isempty(lp_without_env
.search_path
));
41 assert_se(lookup_paths_reduce(&lp_without_env
) >= 0);
43 systemd_unit_path
= strjoina(template, "/systemd-unit-path");
44 assert_se(setenv("SYSTEMD_UNIT_PATH", systemd_unit_path
, 1) == 0);
45 assert_se(lookup_paths_init(&lp_with_env
, scope
, NULL
) == 0);
46 assert_se(strv_length(lp_with_env
.search_path
) == 1);
47 assert_se(streq(lp_with_env
.search_path
[0], systemd_unit_path
));
48 assert_se(lookup_paths_reduce(&lp_with_env
) >= 0);
49 assert_se(strv_length(lp_with_env
.search_path
) == 0);
51 assert_se(rm_rf(template, REMOVE_ROOT
|REMOVE_PHYSICAL
) >= 0);
54 static void print_generator_paths(UnitFileScope scope
) {
55 _cleanup_strv_free_
char **paths
;
58 log_info("Generators dirs (%s):", scope
== UNIT_FILE_SYSTEM
? "system" : "user");
60 paths
= generator_paths(scope
);
61 STRV_FOREACH(dir
, paths
)
62 log_info(" %s", *dir
);
65 int main(int argc
, char **argv
) {
66 log_set_max_level(LOG_DEBUG
);
67 log_parse_environment();
70 test_paths(UNIT_FILE_SYSTEM
);
71 test_paths(UNIT_FILE_USER
);
72 test_paths(UNIT_FILE_GLOBAL
);
74 print_generator_paths(UNIT_FILE_SYSTEM
);
75 print_generator_paths(UNIT_FILE_USER
);