test-install-root.c revision 0ec0deaa30d0e68430f03fa6f32affa576481d18
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt This file is part of systemd.
7bd8e95d44977833d0de3fc4e893eb3bc84351d6Patrik Flykt Copyright 2011 Lennart Poettering
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt systemd is free software; you can redistribute it and/or modify it
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt under the terms of the GNU Lesser General Public License as published by
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt the Free Software Foundation; either version 2.1 of the License, or
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt (at your option) any later version.
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt systemd is distributed in the hope that it will be useful, but
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt WITHOUT ANY WARRANTY; without even the implied warranty of
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt Lesser General Public License for more details.
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt You should have received a copy of the GNU Lesser General Public License
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt along with systemd; If not, see <http://www.gnu.org/licenses/>.
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flyktstatic void test_basic_mask_and_enable(const char *root) {
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt const char *p;
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "a.service", NULL) == -ENOENT);
f12abb48fc510b8b349c05e35ba048134debaf25Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "b.service", NULL) == -ENOENT);
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "c.service", NULL) == -ENOENT);
764aad6258eec3bd4ae62ea341ea507bd69ce628Tom Gundersen assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "d.service", NULL) == -ENOENT);
76253e73f9c9c24fec755e485516f3b55d0707b4Dan Williams p = strjoina(root, "/usr/lib/systemd/system/a.service");
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt "[Install]\n"
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt "WantedBy=multi-user.target\n", WRITE_STRING_FILE_CREATE) >= 0);
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "a.service", NULL) >= 0);
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "a.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt p = strjoina(root, "/usr/lib/systemd/system/b.service");
76253e73f9c9c24fec755e485516f3b55d0707b4Dan Williams assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "b.service", NULL) >= 0);
f12abb48fc510b8b349c05e35ba048134debaf25Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "b.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
346e13a25dc6f76d3bc9d8decd40dc4782b02d2aPatrik Flykt p = strjoina(root, "/usr/lib/systemd/system/c.service");
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt assert_se(symlink("/usr/lib/systemd/system/a.service", p) >= 0);
bbfa43ca37df0718287c25a8e39ee7477ebf33f6Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "c.service", NULL) >= 0);
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "c.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt p = strjoina(root, "/usr/lib/systemd/system/d.service");
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt /* This one is interesting, as d follows a relative, then an absolute symlink */
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "d.service", NULL) >= 0);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "d.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt assert_se(unit_file_mask(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("a.service"), false, &changes, &n_changes) >= 0);
66eac1201a9c1596f5901f8dbbf24bda7e350878Dan Williams assert_se(changes[0].type == UNIT_FILE_SYMLINK);
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt assert_se(streq(changes[0].source, "/dev/null"));
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/a.service");
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "a.service", &state) >= 0 && state == UNIT_FILE_MASKED);
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "b.service", &state) >= 0 && state == UNIT_FILE_MASKED);
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "c.service", &state) >= 0 && state == UNIT_FILE_MASKED);
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "d.service", &state) >= 0 && state == UNIT_FILE_MASKED);
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt /* Enabling a masked unit should fail! */
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt assert_se(unit_file_enable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("a.service"), false, &changes, &n_changes) == -ESHUTDOWN);
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt assert_se(unit_file_unmask(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("a.service"), &changes, &n_changes) >= 0);
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt assert_se(changes[0].type == UNIT_FILE_UNLINK);
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/a.service");
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt assert_se(unit_file_enable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("a.service"), false, &changes, &n_changes) == 1);
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt assert_se(changes[0].type == UNIT_FILE_SYMLINK);
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt assert_se(streq(changes[0].source, "/usr/lib/systemd/system/a.service"));
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/a.service");
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "a.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "b.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "c.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
631bbe71298ec892f77f44f94feb612646fe6853Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "d.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
3f0c075f8ef3344da5a6bda524540201f9204e61Patrik Flykt /* Enabling it again should succeed but be a NOP */
3f0c075f8ef3344da5a6bda524540201f9204e61Patrik Flykt assert_se(unit_file_enable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("a.service"), false, &changes, &n_changes) == 1);
c3e2adeaba8e043caed0ef139eeaea016bd152d0Patrik Flykt assert_se(unit_file_disable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("a.service"), &changes, &n_changes) >= 0);
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt assert_se(changes[0].type == UNIT_FILE_UNLINK);
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/a.service");
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "a.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "b.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "c.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "d.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt /* Disabling a disabled unit must suceed but be a NOP */
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt assert_se(unit_file_disable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("a.service"), &changes, &n_changes) >= 0);
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt /* Let's enable this indirectly via a symlink */
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt assert_se(unit_file_enable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("d.service"), false, &changes, &n_changes) >= 0);
76253e73f9c9c24fec755e485516f3b55d0707b4Dan Williams assert_se(changes[0].type == UNIT_FILE_SYMLINK);
76253e73f9c9c24fec755e485516f3b55d0707b4Dan Williams assert_se(streq(changes[0].source, "/usr/lib/systemd/system/a.service"));
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/a.service");
76253e73f9c9c24fec755e485516f3b55d0707b4Dan Williams assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "a.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
76253e73f9c9c24fec755e485516f3b55d0707b4Dan Williams assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "b.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
76253e73f9c9c24fec755e485516f3b55d0707b4Dan Williams assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "c.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
76253e73f9c9c24fec755e485516f3b55d0707b4Dan Williams assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "d.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt /* Let's try to reenable */
76253e73f9c9c24fec755e485516f3b55d0707b4Dan Williams assert_se(unit_file_reenable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("b.service"), false, &changes, &n_changes) >= 0);
76253e73f9c9c24fec755e485516f3b55d0707b4Dan Williams assert_se(changes[0].type == UNIT_FILE_UNLINK);
76253e73f9c9c24fec755e485516f3b55d0707b4Dan Williams p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/a.service");
76253e73f9c9c24fec755e485516f3b55d0707b4Dan Williams assert_se(changes[1].type == UNIT_FILE_SYMLINK);
76253e73f9c9c24fec755e485516f3b55d0707b4Dan Williams assert_se(streq(changes[1].source, "/usr/lib/systemd/system/a.service"));
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "a.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
cc22955cfefb4bd6e7a135f1ec95fb5a07ba9ce3Thomas Haller assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "b.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
cc22955cfefb4bd6e7a135f1ec95fb5a07ba9ce3Thomas Haller assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "c.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
cc22955cfefb4bd6e7a135f1ec95fb5a07ba9ce3Thomas Haller assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "d.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
cc22955cfefb4bd6e7a135f1ec95fb5a07ba9ce3Thomas Hallerstatic void test_linked_units(const char *root) {
cc22955cfefb4bd6e7a135f1ec95fb5a07ba9ce3Thomas Haller const char *p, *q;
66eac1201a9c1596f5901f8dbbf24bda7e350878Dan Williams unsigned n_changes = 0, i;
66eac1201a9c1596f5901f8dbbf24bda7e350878Dan Williams * We'll test three cases here:
fe4b2156256c5bdf52341576571ce9f095d9f085Tom Gundersen * a) a unit file in /opt, that we use "systemctl link" and
fe4b2156256c5bdf52341576571ce9f095d9f085Tom Gundersen * "systemctl enable" on to make it available to the system
fe4b2156256c5bdf52341576571ce9f095d9f085Tom Gundersen * b) a unit file in /opt, that is statically linked into
fe4b2156256c5bdf52341576571ce9f095d9f085Tom Gundersen * /usr/lib/systemd/system, that "enable" should work on
fe4b2156256c5bdf52341576571ce9f095d9f085Tom Gundersen * c) a unit file in /opt, that is linked into
fe4b2156256c5bdf52341576571ce9f095d9f085Tom Gundersen * /etc/systemd/system, and where "enable" should result in
fe4b2156256c5bdf52341576571ce9f095d9f085Tom Gundersen * -ELOOP, since using information from /etc to generate
764aad6258eec3bd4ae62ea341ea507bd69ce628Tom Gundersen * information in /etc should not be allowed.
fe4b2156256c5bdf52341576571ce9f095d9f085Tom Gundersen "[Install]\n"
fe4b2156256c5bdf52341576571ce9f095d9f085Tom Gundersen "WantedBy=multi-user.target\n", WRITE_STRING_FILE_CREATE) >= 0);
fe4b2156256c5bdf52341576571ce9f095d9f085Tom Gundersen "[Install]\n"
fe4b2156256c5bdf52341576571ce9f095d9f085Tom Gundersen "WantedBy=multi-user.target\n", WRITE_STRING_FILE_CREATE) >= 0);
66eac1201a9c1596f5901f8dbbf24bda7e350878Dan Williams "[Install]\n"
66eac1201a9c1596f5901f8dbbf24bda7e350878Dan Williams "WantedBy=multi-user.target\n", WRITE_STRING_FILE_CREATE) >= 0);
66eac1201a9c1596f5901f8dbbf24bda7e350878Dan Williams assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "linked.service", NULL) == -ENOENT);
bbfa43ca37df0718287c25a8e39ee7477ebf33f6Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "linked2.service", NULL) == -ENOENT);
bbfa43ca37df0718287c25a8e39ee7477ebf33f6Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "linked3.service", NULL) == -ENOENT);
bbfa43ca37df0718287c25a8e39ee7477ebf33f6Patrik Flykt p = strjoina(root, "/usr/lib/systemd/system/linked2.service");
bbfa43ca37df0718287c25a8e39ee7477ebf33f6Patrik Flykt assert_se(symlink("/opt/linked2.service", p) >= 0);
bbfa43ca37df0718287c25a8e39ee7477ebf33f6Patrik Flykt p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/linked3.service");
bbfa43ca37df0718287c25a8e39ee7477ebf33f6Patrik Flykt assert_se(symlink("/opt/linked3.service", p) >= 0);
bbfa43ca37df0718287c25a8e39ee7477ebf33f6Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "linked.service", &state) == -ENOENT);
bbfa43ca37df0718287c25a8e39ee7477ebf33f6Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "linked2.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
bbfa43ca37df0718287c25a8e39ee7477ebf33f6Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "linked3.service", &state) >= 0 && state == UNIT_FILE_LINKED);
bbfa43ca37df0718287c25a8e39ee7477ebf33f6Patrik Flykt /* First, let's link the unit into the search path */
bbfa43ca37df0718287c25a8e39ee7477ebf33f6Patrik Flykt assert_se(unit_file_link(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("/opt/linked.service"), false, &changes, &n_changes) >= 0);
bbfa43ca37df0718287c25a8e39ee7477ebf33f6Patrik Flykt assert_se(changes[0].type == UNIT_FILE_SYMLINK);
bbfa43ca37df0718287c25a8e39ee7477ebf33f6Patrik Flykt assert_se(streq(changes[0].source, "/opt/linked.service"));
bbfa43ca37df0718287c25a8e39ee7477ebf33f6Patrik Flykt p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/linked.service");
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "linked.service", &state) >= 0 && state == UNIT_FILE_LINKED);
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt /* Let's unlink it from the search path again */
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt assert_se(unit_file_disable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("linked.service"), &changes, &n_changes) >= 0);
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt assert_se(changes[0].type == UNIT_FILE_UNLINK);
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/linked.service");
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "linked.service", NULL) == -ENOENT);
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt /* Now, let's not just link it, but also enable it */
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt assert_se(unit_file_enable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("/opt/linked.service"), false, &changes, &n_changes) >= 0);
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/linked.service");
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt q = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/linked.service");
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt for (i = 0 ; i < n_changes; i++) {
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt assert_se(changes[i].type == UNIT_FILE_SYMLINK);
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt assert_se(streq(changes[i].source, "/opt/linked.service"));
ea3b3a75abb3f8b853f7da454b9b8e258a120eeaPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "linked.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
ea3b3a75abb3f8b853f7da454b9b8e258a120eeaPatrik Flykt /* And let's unlink it again */
ea3b3a75abb3f8b853f7da454b9b8e258a120eeaPatrik Flykt assert_se(unit_file_disable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("linked.service"), &changes, &n_changes) >= 0);
ea3b3a75abb3f8b853f7da454b9b8e258a120eeaPatrik Flykt p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/linked.service");
3f0c075f8ef3344da5a6bda524540201f9204e61Patrik Flykt q = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/linked.service");
3f0c075f8ef3344da5a6bda524540201f9204e61Patrik Flykt for (i = 0; i < n_changes; i++) {
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt assert_se(changes[i].type == UNIT_FILE_UNLINK);
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "linked.service", NULL) == -ENOENT);
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt assert_se(unit_file_enable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("linked2.service"), false, &changes, &n_changes) >= 0);
346e13a25dc6f76d3bc9d8decd40dc4782b02d2aPatrik Flykt p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/linked2.service");
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt q = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/linked2.service");
f12abb48fc510b8b349c05e35ba048134debaf25Patrik Flykt for (i = 0 ; i < n_changes; i++) {
f12abb48fc510b8b349c05e35ba048134debaf25Patrik Flykt assert_se(changes[i].type == UNIT_FILE_SYMLINK);
f12abb48fc510b8b349c05e35ba048134debaf25Patrik Flykt assert_se(streq(changes[i].source, "/opt/linked2.service"));
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt assert_se(unit_file_enable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("linked3.service"), false, &changes, &n_changes) == -ELOOP);
139b011ab81ccea1d51f09e0261a1c390115c6ffPatrik Flykt const char *p;
346e13a25dc6f76d3bc9d8decd40dc4782b02d2aPatrik Flykt p = strjoina(root, "/usr/lib/systemd/system/test-default-real.target");
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt assert_se(write_string_file(p, "# pretty much empty", WRITE_STRING_FILE_CREATE) >= 0);
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt p = strjoina(root, "/usr/lib/systemd/system/test-default.target");
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt assert_se(symlink("test-default-real.target", p) >= 0);
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt assert_se(unit_file_get_default(UNIT_FILE_SYSTEM, root, &def) == -ENOENT);
346e13a25dc6f76d3bc9d8decd40dc4782b02d2aPatrik Flykt assert_se(unit_file_set_default(UNIT_FILE_SYSTEM, root, "idontexist.target", false, &changes, &n_changes) == -ENOENT);
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt assert_se(unit_file_get_default(UNIT_FILE_SYSTEM, root, &def) == -ENOENT);
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt assert_se(unit_file_set_default(UNIT_FILE_SYSTEM, root, "test-default.target", false, &changes, &n_changes) >= 0);
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt assert_se(changes[0].type == UNIT_FILE_SYMLINK);
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt assert_se(streq(changes[0].source, "/usr/lib/systemd/system/test-default-real.target"));
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/default.target");
bbfa43ca37df0718287c25a8e39ee7477ebf33f6Patrik Flykt assert_se(unit_file_get_default(UNIT_FILE_SYSTEM, root, &def) >= 0);
bbfa43ca37df0718287c25a8e39ee7477ebf33f6Patrik Flykt assert_se(streq_ptr(def, "test-default-real.target"));
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flyktstatic void test_add_dependency(const char *root) {
ed6ee21953dac9c78383da00bc4514ece6b75ab5Patrik Flykt p = strjoina(root, "/usr/lib/systemd/system/real-add-dependency-test-target.target");
7246333cb803b03440d3bd0bdaa233564d09b5aePatrik Flykt assert_se(write_string_file(p, "# pretty much empty", WRITE_STRING_FILE_CREATE) >= 0);
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt p = strjoina(root, "/usr/lib/systemd/system/add-dependency-test-target.target");
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt assert_se(symlink("real-add-dependency-test-target.target", p) >= 0);
7246333cb803b03440d3bd0bdaa233564d09b5aePatrik Flykt p = strjoina(root, "/usr/lib/systemd/system/real-add-dependency-test-service.service");
7246333cb803b03440d3bd0bdaa233564d09b5aePatrik Flykt assert_se(write_string_file(p, "# pretty much empty", WRITE_STRING_FILE_CREATE) >= 0);
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt p = strjoina(root, "/usr/lib/systemd/system/add-dependency-test-service.service");
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt assert_se(symlink("real-add-dependency-test-service.service", p) >= 0);
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt 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);
7246333cb803b03440d3bd0bdaa233564d09b5aePatrik Flykt assert_se(changes[0].type == UNIT_FILE_SYMLINK);
7246333cb803b03440d3bd0bdaa233564d09b5aePatrik Flykt assert_se(streq(changes[0].source, "/usr/lib/systemd/system/real-add-dependency-test-service.service"));
7246333cb803b03440d3bd0bdaa233564d09b5aePatrik Flykt p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/real-add-dependency-test-target.target.wants/real-add-dependency-test-service.service");
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flyktstatic void test_template_enable(const char *root) {
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt const char *p;
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@.service", &state) == -ENOENT);
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@def.service", &state) == -ENOENT);
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@foo.service", &state) == -ENOENT);
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@foo.service", &state) == -ENOENT);
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt p = strjoina(root, "/usr/lib/systemd/system/template@.service");
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt "[Install]\n"
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt "DefaultInstance=def\n"
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flykt "WantedBy=multi-user.target\n", WRITE_STRING_FILE_CREATE) >= 0);
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt p = strjoina(root, "/usr/lib/systemd/system/template-symlink@.service");
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt assert_se(symlink("template@.service", p) >= 0);
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@def.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@foo.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
da6fe470e17fa02f3adedc779585caf8669252bdPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@def.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
cc22955cfefb4bd6e7a135f1ec95fb5a07ba9ce3Thomas Haller assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@foo.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
66eac1201a9c1596f5901f8dbbf24bda7e350878Dan Williams assert_se(unit_file_enable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("template@.service"), false, &changes, &n_changes) >= 0);
7246333cb803b03440d3bd0bdaa233564d09b5aePatrik Flykt assert_se(changes[0].type == UNIT_FILE_SYMLINK);
7246333cb803b03440d3bd0bdaa233564d09b5aePatrik Flykt assert_se(streq(changes[0].source, "/usr/lib/systemd/system/template@.service"));
346e13a25dc6f76d3bc9d8decd40dc4782b02d2aPatrik Flykt p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/template@def.service");
346e13a25dc6f76d3bc9d8decd40dc4782b02d2aPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
346e13a25dc6f76d3bc9d8decd40dc4782b02d2aPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@def.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
346e13a25dc6f76d3bc9d8decd40dc4782b02d2aPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@foo.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
346e13a25dc6f76d3bc9d8decd40dc4782b02d2aPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
346e13a25dc6f76d3bc9d8decd40dc4782b02d2aPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@def.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
346e13a25dc6f76d3bc9d8decd40dc4782b02d2aPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@foo.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt assert_se(unit_file_disable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("template@.service"), &changes, &n_changes) >= 0);
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt assert_se(changes[0].type == UNIT_FILE_UNLINK);
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@def.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@foo.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@def.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@foo.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flykt assert_se(unit_file_enable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("template@foo.service"), false, &changes, &n_changes) >= 0);
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flykt assert_se(changes[0].type == UNIT_FILE_SYMLINK);
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flykt assert_se(streq(changes[0].source, "/usr/lib/systemd/system/template@.service"));
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flykt p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/template@foo.service");
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@def.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@foo.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@foo.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@def.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@foo.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flykt assert_se(unit_file_disable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("template@foo.service"), &changes, &n_changes) >= 0);
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flykt assert_se(changes[0].type == UNIT_FILE_UNLINK);
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@def.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@foo.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@quux.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@def.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@foo.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@quux.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
a34b57c0d43b8bf819ccd4f62c314b41b625454dPatrik Flykt assert_se(unit_file_enable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("template-symlink@quux.service"), false, &changes, &n_changes) >= 0);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(changes[0].type == UNIT_FILE_SYMLINK);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(streq(changes[0].source, "/usr/lib/systemd/system/template@.service"));
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/template@quux.service");
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@def.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@foo.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template@quux.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@def.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@foo.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@quux.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt const char *p;
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "indirecta.service", &state) == -ENOENT);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "indirectb.service", &state) == -ENOENT);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "indirectc.service", &state) == -ENOENT);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt p = strjoina(root, "/usr/lib/systemd/system/indirecta.service");
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt "[Install]\n"
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt "Also=indirectb.service\n", WRITE_STRING_FILE_CREATE) >= 0);
5e91345094a9e983e7abb2313334e7808bcd2cc2Tom Gundersen p = strjoina(root, "/usr/lib/systemd/system/indirectb.service");
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt "[Install]\n"
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt "WantedBy=multi-user.target\n", WRITE_STRING_FILE_CREATE) >= 0);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt p = strjoina(root, "/usr/lib/systemd/system/indirectc.service");
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(symlink("indirecta.service", p) >= 0);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "indirecta.service", &state) >= 0 && state == UNIT_FILE_INDIRECT);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "indirectb.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "indirectc.service", &state) >= 0 && state == UNIT_FILE_INDIRECT);
bbfa43ca37df0718287c25a8e39ee7477ebf33f6Patrik Flykt assert_se(unit_file_enable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("indirectc.service"), false, &changes, &n_changes) >= 0);
bbfa43ca37df0718287c25a8e39ee7477ebf33f6Patrik Flykt assert_se(changes[0].type == UNIT_FILE_SYMLINK);
bbfa43ca37df0718287c25a8e39ee7477ebf33f6Patrik Flykt assert_se(streq(changes[0].source, "/usr/lib/systemd/system/indirectb.service"));
bbfa43ca37df0718287c25a8e39ee7477ebf33f6Patrik Flykt p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/indirectb.service");
7246333cb803b03440d3bd0bdaa233564d09b5aePatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "indirecta.service", &state) >= 0 && state == UNIT_FILE_INDIRECT);
7246333cb803b03440d3bd0bdaa233564d09b5aePatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "indirectb.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
7246333cb803b03440d3bd0bdaa233564d09b5aePatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "indirectc.service", &state) >= 0 && state == UNIT_FILE_INDIRECT);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(unit_file_disable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("indirectc.service"), &changes, &n_changes) >= 0);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(changes[0].type == UNIT_FILE_UNLINK);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/indirectb.service");
7246333cb803b03440d3bd0bdaa233564d09b5aePatrik Flyktstatic void test_preset_and_list(const char *root) {
7246333cb803b03440d3bd0bdaa233564d09b5aePatrik Flykt unsigned n_changes = 0, i;
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt const char *p, *q;
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "preset-yes.service", &state) == -ENOENT);
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "preset-no.service", &state) == -ENOENT);
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt p = strjoina(root, "/usr/lib/systemd/system/preset-yes.service");
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt "[Install]\n"
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt "WantedBy=multi-user.target\n", WRITE_STRING_FILE_CREATE) >= 0);
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt p = strjoina(root, "/usr/lib/systemd/system/preset-no.service");
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt "[Install]\n"
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt "WantedBy=multi-user.target\n", WRITE_STRING_FILE_CREATE) >= 0);
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt p = strjoina(root, "/usr/lib/systemd/system-preset/test.preset");
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt "enable *-yes.*\n"
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt "disable *\n", WRITE_STRING_FILE_CREATE) >= 0);
3dc34fcc97b41f8b7b019027225b121dfbb9871dPatrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "preset-yes.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "preset-no.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(unit_file_preset(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("preset-yes.service"), UNIT_FILE_PRESET_FULL, false, &changes, &n_changes) >= 0);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(changes[0].type == UNIT_FILE_SYMLINK);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(streq(changes[0].source, "/usr/lib/systemd/system/preset-yes.service"));
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/preset-yes.service");
fa94c34b083b5b4019975624453e53d0cbad2a5dTom Gundersen assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "preset-yes.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "preset-no.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(unit_file_disable(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("preset-yes.service"), &changes, &n_changes) >= 0);
346e13a25dc6f76d3bc9d8decd40dc4782b02d2aPatrik Flykt assert_se(changes[0].type == UNIT_FILE_UNLINK);
346e13a25dc6f76d3bc9d8decd40dc4782b02d2aPatrik Flykt p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/preset-yes.service");
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "preset-yes.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "preset-no.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
a9aff3615b430f86bd0a824214d95f634efaf894Patrik Flykt assert_se(unit_file_preset(UNIT_FILE_SYSTEM, false, root, STRV_MAKE("preset-no.service"), UNIT_FILE_PRESET_FULL, false, &changes, &n_changes) >= 0);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "preset-yes.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "preset-no.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(unit_file_preset_all(UNIT_FILE_SYSTEM, false, root, UNIT_FILE_PRESET_FULL, false, &changes, &n_changes) >= 0);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/preset-yes.service");
fa94c34b083b5b4019975624453e53d0cbad2a5dTom Gundersen for (i = 0; i < n_changes; i++) {
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(streq(changes[i].source, "/usr/lib/systemd/system/preset-yes.service"));
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(changes[i].type == UNIT_FILE_UNLINK);
356779df90a2ecab5da2cb310ad0f8ebc9ca9f46Lennart Poettering assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "preset-yes.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
9021bb9f935c93b516b10c88db2a212a9e3a8140Tom Gundersen assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "preset-no.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(unit_file_get_list(UNIT_FILE_SYSTEM, root, h) >= 0);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt p = strjoina(root, "/usr/lib/systemd/system/preset-yes.service");
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt q = strjoina(root, "/usr/lib/systemd/system/preset-no.service");
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, basename(fl->path), &state) >= 0);
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt assert_se(IN_SET(fl->state, UNIT_FILE_DISABLED, UNIT_FILE_STATIC, UNIT_FILE_INDIRECT));
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt const char *p;
d1b0afe3653b4316a6361d204169620726d468a0Patrik Flykt p = strjoina(root, "/usr/lib/systemd/system/");
f12abb48fc510b8b349c05e35ba048134debaf25Patrik Flykt p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/");
f12abb48fc510b8b349c05e35ba048134debaf25Patrik Flykt p = strjoina(root, "/usr/lib/systemd/system-preset/");