0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering This file is part of systemd.
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering Copyright 2011 Lennart Poettering
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering systemd is free software; you can redistribute it and/or modify it
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering under the terms of the GNU Lesser General Public License as published by
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering (at your option) any later version.
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering systemd is distributed in the hope that it will be useful, but
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering Lesser General Public License for more details.
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering You should have received a copy of the GNU Lesser General Public License
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poetteringstatic void test_basic_mask_and_enable(const char *root) {
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering const char *p;
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "a.service", NULL) == -ENOENT);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "b.service", NULL) == -ENOENT);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "c.service", NULL) == -ENOENT);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "d.service", NULL) == -ENOENT);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, "/usr/lib/systemd/system/a.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering "WantedBy=multi-user.target\n", WRITE_STRING_FILE_CREATE) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "a.service", NULL) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "a.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, "/usr/lib/systemd/system/b.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "b.service", NULL) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "b.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, "/usr/lib/systemd/system/c.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(symlink("/usr/lib/systemd/system/a.service", p) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "c.service", NULL) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "c.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, "/usr/lib/systemd/system/d.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering /* This one is interesting, as d follows a relative, then an absolute symlink */
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "d.service", NULL) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "d.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_mask(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("a.service"), false, &changes, &n_changes) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(changes[0].type == UNIT_FILE_SYMLINK);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(streq(changes[0].source, "/dev/null"));
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/a.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering unit_file_changes_free(changes, n_changes);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "a.service", &state) >= 0 && state == UNIT_FILE_MASKED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "b.service", &state) >= 0 && state == UNIT_FILE_MASKED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "c.service", &state) >= 0 && state == UNIT_FILE_MASKED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "d.service", &state) >= 0 && state == UNIT_FILE_MASKED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering /* Enabling a masked unit should fail! */
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_enable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("a.service"), false, &changes, &n_changes) == -ESHUTDOWN);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering unit_file_changes_free(changes, n_changes);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_unmask(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("a.service"), &changes, &n_changes) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(changes[0].type == UNIT_FILE_UNLINK);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/a.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering unit_file_changes_free(changes, n_changes);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_enable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("a.service"), false, &changes, &n_changes) == 1);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(changes[0].type == UNIT_FILE_SYMLINK);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(streq(changes[0].source, "/usr/lib/systemd/system/a.service"));
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/a.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering unit_file_changes_free(changes, n_changes);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "a.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "b.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "c.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "d.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering /* Enabling it again should succeed but be a NOP */
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_enable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("a.service"), false, &changes, &n_changes) == 1);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering unit_file_changes_free(changes, n_changes);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_disable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("a.service"), &changes, &n_changes) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(changes[0].type == UNIT_FILE_UNLINK);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/a.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering unit_file_changes_free(changes, n_changes);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "a.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "b.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "c.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "d.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering /* Disabling a disabled unit must suceed but be a NOP */
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_disable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("a.service"), &changes, &n_changes) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering unit_file_changes_free(changes, n_changes);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering /* Let's enable this indirectly via a symlink */
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_enable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("d.service"), false, &changes, &n_changes) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(changes[0].type == UNIT_FILE_SYMLINK);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(streq(changes[0].source, "/usr/lib/systemd/system/a.service"));
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/a.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering unit_file_changes_free(changes, n_changes);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "a.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "b.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "c.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "d.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering /* Let's try to reenable */
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_reenable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("b.service"), false, &changes, &n_changes) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(changes[0].type == UNIT_FILE_UNLINK);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/a.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(changes[1].type == UNIT_FILE_SYMLINK);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(streq(changes[1].source, "/usr/lib/systemd/system/a.service"));
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering unit_file_changes_free(changes, n_changes);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "a.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "b.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "c.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "d.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poetteringstatic void test_linked_units(const char *root) {
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering const char *p, *q;
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering * We'll test three cases here:
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering * a) a unit file in /opt, that we use "systemctl link" and
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering * "systemctl enable" on to make it available to the system
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering * b) a unit file in /opt, that is statically linked into
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering * /usr/lib/systemd/system, that "enable" should work on
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering * c) a unit file in /opt, that is linked into
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering * /etc/systemd/system, and where "enable" should result in
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering * -ELOOP, since using information from /etc to generate
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering * information in /etc should not be allowed.
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, "/opt/linked.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering "WantedBy=multi-user.target\n", WRITE_STRING_FILE_CREATE) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, "/opt/linked2.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering "WantedBy=multi-user.target\n", WRITE_STRING_FILE_CREATE) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, "/opt/linked3.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering "WantedBy=multi-user.target\n", WRITE_STRING_FILE_CREATE) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "linked.service", NULL) == -ENOENT);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "linked2.service", NULL) == -ENOENT);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "linked3.service", NULL) == -ENOENT);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, "/usr/lib/systemd/system/linked2.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(symlink("/opt/linked2.service", p) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/linked3.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(symlink("/opt/linked3.service", p) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "linked.service", &state) == -ENOENT);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "linked2.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "linked3.service", &state) >= 0 && state == UNIT_FILE_LINKED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering /* First, let's link the unit into the search path */
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_link(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("/opt/linked.service"), false, &changes, &n_changes) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(changes[0].type == UNIT_FILE_SYMLINK);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(streq(changes[0].source, "/opt/linked.service"));
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/linked.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering unit_file_changes_free(changes, n_changes);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "linked.service", &state) >= 0 && state == UNIT_FILE_LINKED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering /* Let's unlink it from the search path again */
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_disable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("linked.service"), &changes, &n_changes) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(changes[0].type == UNIT_FILE_UNLINK);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/linked.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering unit_file_changes_free(changes, n_changes);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "linked.service", NULL) == -ENOENT);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering /* Now, let's not just link it, but also enable it */
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_enable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("/opt/linked.service"), false, &changes, &n_changes) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/linked.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering q = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/linked.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering for (i = 0 ; i < n_changes; i++) {
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(changes[i].type == UNIT_FILE_SYMLINK);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(streq(changes[i].source, "/opt/linked.service"));
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering unit_file_changes_free(changes, n_changes);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "linked.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering /* And let's unlink it again */
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_disable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("linked.service"), &changes, &n_changes) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/linked.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering q = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/linked.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering for (i = 0; i < n_changes; i++) {
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(changes[i].type == UNIT_FILE_UNLINK);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering unit_file_changes_free(changes, n_changes);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "linked.service", NULL) == -ENOENT);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_enable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("linked2.service"), false, &changes, &n_changes) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/linked2.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering q = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/linked2.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering for (i = 0 ; i < n_changes; i++) {
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(changes[i].type == UNIT_FILE_SYMLINK);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(streq(changes[i].source, "/opt/linked2.service"));
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering unit_file_changes_free(changes, n_changes);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_enable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("linked3.service"), false, &changes, &n_changes) == -ELOOP);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering unit_file_changes_free(changes, n_changes);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poetteringstatic void test_default(const char *root) {
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering const char *p;
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, "/usr/lib/systemd/system/test-default-real.target");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(write_string_file(p, "# pretty much empty", WRITE_STRING_FILE_CREATE) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, "/usr/lib/systemd/system/test-default.target");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(symlink("test-default-real.target", p) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_default(UNIT_FILE_SYSTEM, root, &def) == -ENOENT);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_set_default(UNIT_FILE_SYSTEM, root, "idontexist.target", false, &changes, &n_changes) == -ENOENT);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering unit_file_changes_free(changes, n_changes);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_default(UNIT_FILE_SYSTEM, root, &def) == -ENOENT);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_set_default(UNIT_FILE_SYSTEM, root, "test-default.target", false, &changes, &n_changes) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(changes[0].type == UNIT_FILE_SYMLINK);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(streq(changes[0].source, "/usr/lib/systemd/system/test-default-real.target"));
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/default.target");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering unit_file_changes_free(changes, n_changes);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_default(UNIT_FILE_SYSTEM, root, &def) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(streq_ptr(def, "test-default-real.target"));
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poetteringstatic void test_add_dependency(const char *root) {
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering const char *p;
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, "/usr/lib/systemd/system/real-add-dependency-test-target.target");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(write_string_file(p, "# pretty much empty", WRITE_STRING_FILE_CREATE) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, "/usr/lib/systemd/system/add-dependency-test-target.target");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(symlink("real-add-dependency-test-target.target", p) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, "/usr/lib/systemd/system/real-add-dependency-test-service.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(write_string_file(p, "# pretty much empty", WRITE_STRING_FILE_CREATE) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, "/usr/lib/systemd/system/add-dependency-test-service.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(symlink("real-add-dependency-test-service.service", p) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_add_dependency(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("add-dependency-test-service.service"), "add-dependency-test-target.target", UNIT_WANTS, false, &changes, &n_changes) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(changes[0].type == UNIT_FILE_SYMLINK);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(streq(changes[0].source, "/usr/lib/systemd/system/real-add-dependency-test-service.service"));
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/real-add-dependency-test-target.target.wants/real-add-dependency-test-service.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering unit_file_changes_free(changes, n_changes);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poetteringstatic void test_template_enable(const char *root) {
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering const char *p;
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@.service", &state) == -ENOENT);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@def.service", &state) == -ENOENT);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@foo.service", &state) == -ENOENT);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@foo.service", &state) == -ENOENT);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, "/usr/lib/systemd/system/template@.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering "DefaultInstance=def\n"
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering "WantedBy=multi-user.target\n", WRITE_STRING_FILE_CREATE) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, "/usr/lib/systemd/system/template-symlink@.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(symlink("template@.service", p) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@def.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@foo.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@def.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@foo.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_enable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("template@.service"), false, &changes, &n_changes) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(changes[0].type == UNIT_FILE_SYMLINK);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(streq(changes[0].source, "/usr/lib/systemd/system/template@.service"));
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/template@def.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering unit_file_changes_free(changes, n_changes);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@def.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@foo.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@def.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@foo.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_disable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("template@.service"), &changes, &n_changes) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(changes[0].type == UNIT_FILE_UNLINK);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering unit_file_changes_free(changes, n_changes);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@def.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@foo.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@def.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@foo.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_enable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("template@foo.service"), false, &changes, &n_changes) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(changes[0].type == UNIT_FILE_SYMLINK);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(streq(changes[0].source, "/usr/lib/systemd/system/template@.service"));
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/template@foo.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering unit_file_changes_free(changes, n_changes);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@def.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@foo.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@foo.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@def.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@foo.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_disable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("template@foo.service"), &changes, &n_changes) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(changes[0].type == UNIT_FILE_UNLINK);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering unit_file_changes_free(changes, n_changes);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@def.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@foo.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@quux.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@def.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@foo.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@quux.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_enable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("template-symlink@quux.service"), false, &changes, &n_changes) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(changes[0].type == UNIT_FILE_SYMLINK);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(streq(changes[0].source, "/usr/lib/systemd/system/template@.service"));
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/template@quux.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering unit_file_changes_free(changes, n_changes);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@def.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@foo.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@quux.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@def.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@foo.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@quux.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poetteringstatic void test_indirect(const char *root) {
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering const char *p;
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "indirecta.service", &state) == -ENOENT);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "indirectb.service", &state) == -ENOENT);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "indirectc.service", &state) == -ENOENT);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, "/usr/lib/systemd/system/indirecta.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering "Also=indirectb.service\n", WRITE_STRING_FILE_CREATE) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, "/usr/lib/systemd/system/indirectb.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering "WantedBy=multi-user.target\n", WRITE_STRING_FILE_CREATE) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, "/usr/lib/systemd/system/indirectc.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(symlink("indirecta.service", p) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "indirecta.service", &state) >= 0 && state == UNIT_FILE_INDIRECT);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "indirectb.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "indirectc.service", &state) >= 0 && state == UNIT_FILE_INDIRECT);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_enable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("indirectc.service"), false, &changes, &n_changes) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(changes[0].type == UNIT_FILE_SYMLINK);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(streq(changes[0].source, "/usr/lib/systemd/system/indirectb.service"));
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/indirectb.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering unit_file_changes_free(changes, n_changes);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "indirecta.service", &state) >= 0 && state == UNIT_FILE_INDIRECT);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "indirectb.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "indirectc.service", &state) >= 0 && state == UNIT_FILE_INDIRECT);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_disable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("indirectc.service"), &changes, &n_changes) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(changes[0].type == UNIT_FILE_UNLINK);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/indirectb.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering unit_file_changes_free(changes, n_changes);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poetteringstatic void test_preset_and_list(const char *root) {
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering const char *p, *q;
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "preset-yes.service", &state) == -ENOENT);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "preset-no.service", &state) == -ENOENT);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, "/usr/lib/systemd/system/preset-yes.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering "WantedBy=multi-user.target\n", WRITE_STRING_FILE_CREATE) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, "/usr/lib/systemd/system/preset-no.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering "WantedBy=multi-user.target\n", WRITE_STRING_FILE_CREATE) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, "/usr/lib/systemd/system-preset/test.preset");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering "enable *-yes.*\n"
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering "disable *\n", WRITE_STRING_FILE_CREATE) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "preset-yes.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "preset-no.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_preset(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("preset-yes.service"), UNIT_FILE_PRESET_FULL, false, &changes, &n_changes) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(changes[0].type == UNIT_FILE_SYMLINK);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(streq(changes[0].source, "/usr/lib/systemd/system/preset-yes.service"));
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/preset-yes.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering unit_file_changes_free(changes, n_changes);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "preset-yes.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "preset-no.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_disable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("preset-yes.service"), &changes, &n_changes) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(changes[0].type == UNIT_FILE_UNLINK);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/preset-yes.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering unit_file_changes_free(changes, n_changes);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "preset-yes.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "preset-no.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_preset(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("preset-no.service"), UNIT_FILE_PRESET_FULL, false, &changes, &n_changes) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering unit_file_changes_free(changes, n_changes);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "preset-yes.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "preset-no.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_preset_all(UNIT_FILE_SYSTEM, false, root, UNIT_FILE_PRESET_FULL, false, &changes, &n_changes) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/preset-yes.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering for (i = 0; i < n_changes; i++) {
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering if (changes[i].type == UNIT_FILE_SYMLINK) {
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(streq(changes[i].source, "/usr/lib/systemd/system/preset-yes.service"));
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(changes[i].type == UNIT_FILE_UNLINK);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering unit_file_changes_free(changes, n_changes);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "preset-yes.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "preset-no.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(h = hashmap_new(&string_hash_ops));
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_list(UNIT_FILE_SYSTEM, root, h) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, "/usr/lib/systemd/system/preset-yes.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering q = strjoina(root, "/usr/lib/systemd/system/preset-no.service");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, basename(fl->path), &state) >= 0);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(fl->state == UNIT_FILE_ENABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(fl->state == UNIT_FILE_DISABLED);
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering assert_se(IN_SET(fl->state, UNIT_FILE_DISABLED, UNIT_FILE_STATIC, UNIT_FILE_INDIRECT));
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering const char *p;
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, "/usr/lib/systemd/system/");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, "/run/systemd/system/");
0ec0deaa30d0e68430f03fa6f32affa576481d18Lennart Poettering p = strjoina(root, "/usr/lib/systemd/system-preset/");