2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2015-01-09 05:29:33 +01:00
|
|
|
/***
|
|
|
|
This file is part of systemd.
|
|
|
|
|
|
|
|
Copyright 2014 Zbigniew Jędrzejewski-Szmek
|
|
|
|
|
|
|
|
systemd is free software; you can redistribute it and/or modify it
|
|
|
|
under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
systemd is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
***/
|
|
|
|
|
2015-10-31 20:00:32 +01:00
|
|
|
#include <stdlib.h>
|
2015-01-09 05:29:33 +01:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include "log.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "path-lookup.h"
|
2015-04-04 11:52:57 +02:00
|
|
|
#include "rm-rf.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "string-util.h"
|
|
|
|
#include "strv.h"
|
2015-01-09 05:29:33 +01:00
|
|
|
|
2016-02-24 21:24:23 +01:00
|
|
|
static void test_paths(UnitFileScope scope) {
|
2015-01-09 05:29:33 +01:00
|
|
|
char template[] = "/tmp/test-path-lookup.XXXXXXX";
|
|
|
|
|
2015-10-31 20:00:32 +01:00
|
|
|
_cleanup_lookup_paths_free_ LookupPaths lp_without_env = {};
|
|
|
|
_cleanup_lookup_paths_free_ LookupPaths lp_with_env = {};
|
2016-02-24 15:31:33 +01:00
|
|
|
char *systemd_unit_path;
|
2015-01-09 05:29:33 +01:00
|
|
|
|
|
|
|
assert_se(mkdtemp(template));
|
|
|
|
|
2015-10-31 20:00:32 +01:00
|
|
|
assert_se(unsetenv("SYSTEMD_UNIT_PATH") == 0);
|
2016-04-07 18:48:01 +02:00
|
|
|
assert_se(lookup_paths_init(&lp_without_env, scope, 0, NULL) >= 0);
|
2016-02-24 15:31:33 +01:00
|
|
|
assert_se(!strv_isempty(lp_without_env.search_path));
|
2016-04-06 19:15:12 +02:00
|
|
|
assert_se(lookup_paths_reduce(&lp_without_env) >= 0);
|
2015-10-31 20:00:32 +01:00
|
|
|
|
|
|
|
systemd_unit_path = strjoina(template, "/systemd-unit-path");
|
|
|
|
assert_se(setenv("SYSTEMD_UNIT_PATH", systemd_unit_path, 1) == 0);
|
2016-04-07 18:48:01 +02:00
|
|
|
assert_se(lookup_paths_init(&lp_with_env, scope, 0, NULL) == 0);
|
2016-02-24 15:31:33 +01:00
|
|
|
assert_se(strv_length(lp_with_env.search_path) == 1);
|
|
|
|
assert_se(streq(lp_with_env.search_path[0], systemd_unit_path));
|
2016-02-25 02:32:19 +01:00
|
|
|
assert_se(lookup_paths_reduce(&lp_with_env) >= 0);
|
2017-11-29 12:40:22 +01:00
|
|
|
assert_se(strv_isempty(lp_with_env.search_path));
|
2015-01-09 05:29:33 +01:00
|
|
|
|
2015-04-04 11:52:57 +02:00
|
|
|
assert_se(rm_rf(template, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0);
|
2015-01-09 05:29:33 +01:00
|
|
|
}
|
|
|
|
|
2016-04-06 20:48:58 +02:00
|
|
|
static void print_generator_binary_paths(UnitFileScope scope) {
|
2015-01-09 05:29:33 +01:00
|
|
|
_cleanup_strv_free_ char **paths;
|
|
|
|
char **dir;
|
|
|
|
|
2016-02-24 21:24:23 +01:00
|
|
|
log_info("Generators dirs (%s):", scope == UNIT_FILE_SYSTEM ? "system" : "user");
|
2015-01-09 05:29:33 +01:00
|
|
|
|
2016-04-06 20:48:58 +02:00
|
|
|
paths = generator_binary_paths(scope);
|
2015-01-09 05:29:33 +01:00
|
|
|
STRV_FOREACH(dir, paths)
|
|
|
|
log_info(" %s", *dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
log_set_max_level(LOG_DEBUG);
|
|
|
|
log_parse_environment();
|
|
|
|
log_open();
|
|
|
|
|
2016-02-24 21:24:23 +01:00
|
|
|
test_paths(UNIT_FILE_SYSTEM);
|
|
|
|
test_paths(UNIT_FILE_USER);
|
|
|
|
test_paths(UNIT_FILE_GLOBAL);
|
2015-01-09 05:29:33 +01:00
|
|
|
|
2016-04-06 20:48:58 +02:00
|
|
|
print_generator_binary_paths(UNIT_FILE_SYSTEM);
|
|
|
|
print_generator_binary_paths(UNIT_FILE_USER);
|
2015-01-09 05:29:33 +01:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|