]>
git.proxmox.com Git - systemd.git/blob - src/test/test-install.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2011 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
27 static void dump_changes(UnitFileChange
*c
, unsigned n
) {
30 assert_se(n
== 0 || c
);
32 for (i
= 0; i
< n
; i
++) {
33 if (c
[i
].type
== UNIT_FILE_UNLINK
)
34 printf("rm '%s'\n", c
[i
].path
);
35 else if (c
[i
].type
== UNIT_FILE_SYMLINK
)
36 printf("ln -s '%s' '%s'\n", c
[i
].source
, c
[i
].path
);
40 int main(int argc
, char* argv
[]) {
45 const char *const files
[] = { "avahi-daemon.service", NULL
};
46 const char *const files2
[] = { "/home/lennart/test.service", NULL
};
47 UnitFileChange
*changes
= NULL
;
48 unsigned n_changes
= 0;
49 UnitFileState state
= 0;
51 h
= hashmap_new(&string_hash_ops
);
52 r
= unit_file_get_list(UNIT_FILE_SYSTEM
, NULL
, h
);
55 HASHMAP_FOREACH(p
, h
, i
) {
56 UnitFileState s
= _UNIT_FILE_STATE_INVALID
;
58 r
= unit_file_get_state(UNIT_FILE_SYSTEM
, NULL
, basename(p
->path
), &s
);
60 assert_se((r
< 0 && p
->state
== UNIT_FILE_BAD
) ||
63 fprintf(stderr
, "%s (%s)\n",
65 unit_file_state_to_string(p
->state
));
68 unit_file_list_free(h
);
72 r
= unit_file_enable(UNIT_FILE_SYSTEM
, false, NULL
, (char**) files
, false, &changes
, &n_changes
);
77 r
= unit_file_enable(UNIT_FILE_SYSTEM
, false, NULL
, (char**) files
, false, &changes
, &n_changes
);
80 dump_changes(changes
, n_changes
);
81 unit_file_changes_free(changes
, n_changes
);
83 r
= unit_file_get_state(UNIT_FILE_SYSTEM
, NULL
, files
[0], &state
);
85 assert_se(state
== UNIT_FILE_ENABLED
);
92 r
= unit_file_disable(UNIT_FILE_SYSTEM
, false, NULL
, (char**) files
, &changes
, &n_changes
);
95 dump_changes(changes
, n_changes
);
96 unit_file_changes_free(changes
, n_changes
);
98 r
= unit_file_get_state(UNIT_FILE_SYSTEM
, NULL
, files
[0], &state
);
100 assert_se(state
== UNIT_FILE_DISABLED
);
106 r
= unit_file_mask(UNIT_FILE_SYSTEM
, false, NULL
, (char**) files
, false, &changes
, &n_changes
);
109 r
= unit_file_mask(UNIT_FILE_SYSTEM
, false, NULL
, (char**) files
, false, &changes
, &n_changes
);
112 dump_changes(changes
, n_changes
);
113 unit_file_changes_free(changes
, n_changes
);
115 r
= unit_file_get_state(UNIT_FILE_SYSTEM
, NULL
, files
[0], &state
);
117 assert_se(state
== UNIT_FILE_MASKED
);
123 r
= unit_file_unmask(UNIT_FILE_SYSTEM
, false, NULL
, (char**) files
, &changes
, &n_changes
);
125 log_error("unmask2");
126 r
= unit_file_unmask(UNIT_FILE_SYSTEM
, false, NULL
, (char**) files
, &changes
, &n_changes
);
129 dump_changes(changes
, n_changes
);
130 unit_file_changes_free(changes
, n_changes
);
132 r
= unit_file_get_state(UNIT_FILE_SYSTEM
, NULL
, files
[0], &state
);
134 assert_se(state
== UNIT_FILE_DISABLED
);
140 r
= unit_file_mask(UNIT_FILE_SYSTEM
, false, NULL
, (char**) files
, false, &changes
, &n_changes
);
143 dump_changes(changes
, n_changes
);
144 unit_file_changes_free(changes
, n_changes
);
146 r
= unit_file_get_state(UNIT_FILE_SYSTEM
, NULL
, files
[0], &state
);
148 assert_se(state
== UNIT_FILE_MASKED
);
150 log_error("disable");
154 r
= unit_file_disable(UNIT_FILE_SYSTEM
, false, NULL
, (char**) files
, &changes
, &n_changes
);
156 log_error("disable2");
157 r
= unit_file_disable(UNIT_FILE_SYSTEM
, false, NULL
, (char**) files
, &changes
, &n_changes
);
160 dump_changes(changes
, n_changes
);
161 unit_file_changes_free(changes
, n_changes
);
163 r
= unit_file_get_state(UNIT_FILE_SYSTEM
, NULL
, files
[0], &state
);
165 assert_se(state
== UNIT_FILE_MASKED
);
171 r
= unit_file_unmask(UNIT_FILE_SYSTEM
, false, NULL
, (char**) files
, &changes
, &n_changes
);
174 dump_changes(changes
, n_changes
);
175 unit_file_changes_free(changes
, n_changes
);
177 r
= unit_file_get_state(UNIT_FILE_SYSTEM
, NULL
, files
[0], &state
);
179 assert_se(state
== UNIT_FILE_DISABLED
);
181 log_error("enable files2");
185 r
= unit_file_enable(UNIT_FILE_SYSTEM
, false, NULL
, (char**) files2
, false, &changes
, &n_changes
);
188 dump_changes(changes
, n_changes
);
189 unit_file_changes_free(changes
, n_changes
);
191 r
= unit_file_get_state(UNIT_FILE_SYSTEM
, NULL
, basename(files2
[0]), &state
);
193 assert_se(state
== UNIT_FILE_ENABLED
);
195 log_error("disable files2");
199 r
= unit_file_disable(UNIT_FILE_SYSTEM
, false, NULL
, STRV_MAKE(basename(files2
[0])), &changes
, &n_changes
);
202 dump_changes(changes
, n_changes
);
203 unit_file_changes_free(changes
, n_changes
);
205 r
= unit_file_get_state(UNIT_FILE_SYSTEM
, NULL
, basename(files2
[0]), &state
);
208 log_error("link files2");
212 r
= unit_file_link(UNIT_FILE_SYSTEM
, false, NULL
, (char**) files2
, false, &changes
, &n_changes
);
215 dump_changes(changes
, n_changes
);
216 unit_file_changes_free(changes
, n_changes
);
218 r
= unit_file_get_state(UNIT_FILE_SYSTEM
, NULL
, basename(files2
[0]), &state
);
220 assert_se(state
== UNIT_FILE_LINKED
);
222 log_error("disable files2");
226 r
= unit_file_disable(UNIT_FILE_SYSTEM
, false, NULL
, STRV_MAKE(basename(files2
[0])), &changes
, &n_changes
);
229 dump_changes(changes
, n_changes
);
230 unit_file_changes_free(changes
, n_changes
);
232 r
= unit_file_get_state(UNIT_FILE_SYSTEM
, NULL
, basename(files2
[0]), &state
);
235 log_error("link files2");
239 r
= unit_file_link(UNIT_FILE_SYSTEM
, false, NULL
, (char**) files2
, false, &changes
, &n_changes
);
242 dump_changes(changes
, n_changes
);
243 unit_file_changes_free(changes
, n_changes
);
245 r
= unit_file_get_state(UNIT_FILE_SYSTEM
, NULL
, basename(files2
[0]), &state
);
247 assert_se(state
== UNIT_FILE_LINKED
);
249 log_error("reenable files2");
253 r
= unit_file_reenable(UNIT_FILE_SYSTEM
, false, NULL
, (char**) files2
, false, &changes
, &n_changes
);
256 dump_changes(changes
, n_changes
);
257 unit_file_changes_free(changes
, n_changes
);
259 r
= unit_file_get_state(UNIT_FILE_SYSTEM
, NULL
, basename(files2
[0]), &state
);
261 assert_se(state
== UNIT_FILE_ENABLED
);
263 log_error("disable files2");
267 r
= unit_file_disable(UNIT_FILE_SYSTEM
, false, NULL
, STRV_MAKE(basename(files2
[0])), &changes
, &n_changes
);
270 dump_changes(changes
, n_changes
);
271 unit_file_changes_free(changes
, n_changes
);
273 r
= unit_file_get_state(UNIT_FILE_SYSTEM
, NULL
, basename(files2
[0]), &state
);
275 log_error("preset files");
279 r
= unit_file_preset(UNIT_FILE_SYSTEM
, false, NULL
, (char**) files
, UNIT_FILE_PRESET_FULL
, false, &changes
, &n_changes
);
282 dump_changes(changes
, n_changes
);
283 unit_file_changes_free(changes
, n_changes
);
285 r
= unit_file_get_state(UNIT_FILE_SYSTEM
, NULL
, basename(files
[0]), &state
);
287 assert_se(state
== UNIT_FILE_ENABLED
);