test-path-lookup.c revision c6878637502b1717a110a9a7e8bba32a8583fcdf
4f1a33dd0d62171bbeac74859642b8ff0ab547b8Zbigniew Jędrzejewski-Szmek/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4f1a33dd0d62171bbeac74859642b8ff0ab547b8Zbigniew Jędrzejewski-Szmek This file is part of systemd.
4f1a33dd0d62171bbeac74859642b8ff0ab547b8Zbigniew Jędrzejewski-Szmek Copyright 2014 Zbigniew Jędrzejewski-Szmek
4f1a33dd0d62171bbeac74859642b8ff0ab547b8Zbigniew Jędrzejewski-Szmek systemd is free software; you can redistribute it and/or modify it
4f1a33dd0d62171bbeac74859642b8ff0ab547b8Zbigniew Jędrzejewski-Szmek under the terms of the GNU Lesser General Public License as published by
4f1a33dd0d62171bbeac74859642b8ff0ab547b8Zbigniew Jędrzejewski-Szmek the Free Software Foundation; either version 2.1 of the License, or
4f1a33dd0d62171bbeac74859642b8ff0ab547b8Zbigniew Jędrzejewski-Szmek (at your option) any later version.
4f1a33dd0d62171bbeac74859642b8ff0ab547b8Zbigniew Jędrzejewski-Szmek systemd is distributed in the hope that it will be useful, but
4f1a33dd0d62171bbeac74859642b8ff0ab547b8Zbigniew Jędrzejewski-Szmek WITHOUT ANY WARRANTY; without even the implied warranty of
4f1a33dd0d62171bbeac74859642b8ff0ab547b8Zbigniew Jędrzejewski-Szmek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4f1a33dd0d62171bbeac74859642b8ff0ab547b8Zbigniew Jędrzejewski-Szmek Lesser General Public License for more details.
4f1a33dd0d62171bbeac74859642b8ff0ab547b8Zbigniew Jędrzejewski-Szmek You should have received a copy of the GNU Lesser General Public License
4f1a33dd0d62171bbeac74859642b8ff0ab547b8Zbigniew Jędrzejewski-Szmek along with systemd; If not, see <http://www.gnu.org/licenses/>.
4f1a33dd0d62171bbeac74859642b8ff0ab547b8Zbigniew Jędrzejewski-Szmekstatic void test_paths(SystemdRunningAs running_as, bool personal) {
4f1a33dd0d62171bbeac74859642b8ff0ab547b8Zbigniew Jędrzejewski-Szmek char template[] = "/tmp/test-path-lookup.XXXXXXX";
4f1a33dd0d62171bbeac74859642b8ff0ab547b8Zbigniew Jędrzejewski-Szmek _cleanup_lookup_paths_free_ LookupPaths lp = {};
4f1a33dd0d62171bbeac74859642b8ff0ab547b8Zbigniew Jędrzejewski-Szmek assert_se(mkdir(exists, 0755) == 0);
4f1a33dd0d62171bbeac74859642b8ff0ab547b8Zbigniew Jędrzejewski-Szmek assert_se(lookup_paths_init(&lp, running_as, personal, NULL, exists, not, not) == 0);
4f1a33dd0d62171bbeac74859642b8ff0ab547b8Zbigniew Jędrzejewski-Szmek assert_se(!strv_isempty(lp.unit_path));
4f1a33dd0d62171bbeac74859642b8ff0ab547b8Zbigniew Jędrzejewski-Szmek assert_se(strv_contains(lp.unit_path, exists));
4f1a33dd0d62171bbeac74859642b8ff0ab547b8Zbigniew Jędrzejewski-Szmek assert_se(strv_contains(lp.unit_path, not));
c6878637502b1717a110a9a7e8bba32a8583fcdfLennart Poettering assert_se(rm_rf(template, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0);
4f1a33dd0d62171bbeac74859642b8ff0ab547b8Zbigniew Jędrzejewski-Szmekstatic void print_generator_paths(SystemdRunningAs running_as) {
4f1a33dd0d62171bbeac74859642b8ff0ab547b8Zbigniew Jędrzejewski-Szmek _cleanup_strv_free_ char **paths;
4f1a33dd0d62171bbeac74859642b8ff0ab547b8Zbigniew Jędrzejewski-Szmek log_info("Generators dirs (%s):", running_as == SYSTEMD_SYSTEM ? "system" : "user");
4f1a33dd0d62171bbeac74859642b8ff0ab547b8Zbigniew Jędrzejewski-Szmek paths = generator_paths(running_as);
4f1a33dd0d62171bbeac74859642b8ff0ab547b8Zbigniew Jędrzejewski-Szmekint main(int argc, char **argv) {
4f1a33dd0d62171bbeac74859642b8ff0ab547b8Zbigniew Jędrzejewski-Szmek test_paths(SYSTEMD_SYSTEM, false);
4f1a33dd0d62171bbeac74859642b8ff0ab547b8Zbigniew Jędrzejewski-Szmek test_paths(SYSTEMD_SYSTEM, true);
4f1a33dd0d62171bbeac74859642b8ff0ab547b8Zbigniew Jędrzejewski-Szmek test_paths(SYSTEMD_USER, false);
4f1a33dd0d62171bbeac74859642b8ff0ab547b8Zbigniew Jędrzejewski-Szmek print_generator_paths(SYSTEMD_SYSTEM);