]>
Commit | Line | Data |
---|---|---|
a7334b09 LP |
1 | /*** |
2 | This file is part of systemd. | |
3 | ||
4 | Copyright 2010 Lennart Poettering | |
5 | ||
6 | systemd is free software; you can redistribute it and/or modify it | |
5430f7f2 LP |
7 | under the terms of the GNU Lesser General Public License as published by |
8 | the Free Software Foundation; either version 2.1 of the License, or | |
a7334b09 LP |
9 | (at your option) any later version. |
10 | ||
11 | systemd is distributed in the hope that it will be useful, but | |
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
5430f7f2 | 14 | Lesser General Public License for more details. |
a7334b09 | 15 | |
5430f7f2 | 16 | You should have received a copy of the GNU Lesser General Public License |
a7334b09 LP |
17 | along with systemd; If not, see <http://www.gnu.org/licenses/>. |
18 | ***/ | |
19 | ||
0301abf4 | 20 | |
cf0fbc49 | 21 | #include "conf-parser.h" |
5cb5a6ff | 22 | #include "load-dropin.h" |
cf0fbc49 | 23 | #include "load-fragment.h" |
b952f2e1 | 24 | #include "log.h" |
036643a2 | 25 | #include "strv.h" |
9e2f7c11 | 26 | #include "unit-name.h" |
cf0fbc49 | 27 | #include "unit.h" |
8afbb8e1 | 28 | |
1a7f1b38 | 29 | static int add_dependency_consumer( |
aa96c6cb | 30 | UnitDependency dependency, |
1a7f1b38 ZJS |
31 | const char *entry, |
32 | const char* filepath, | |
33 | void *arg) { | |
34 | Unit *u = arg; | |
9e2f7c11 LP |
35 | int r; |
36 | ||
99f08d14 | 37 | assert(u); |
9e2f7c11 | 38 | |
1a7f1b38 ZJS |
39 | r = unit_add_dependency_by_name(u, dependency, entry, filepath, true); |
40 | if (r < 0) | |
41 | log_error_errno(r, "Cannot add dependency %s to %s, ignoring: %m", entry, u->id); | |
9e2f7c11 | 42 | |
8afbb8e1 | 43 | return 0; |
9e2f7c11 | 44 | } |
5cb5a6ff | 45 | |
ae7a7182 | 46 | int unit_load_dropin(Unit *u) { |
d7e0da1d | 47 | _cleanup_strv_free_ char **l = NULL; |
ae7a7182 OS |
48 | Iterator i; |
49 | char *t, **f; | |
1a7f1b38 | 50 | int r; |
99f08d14 LP |
51 | |
52 | assert(u); | |
53 | ||
54 | /* Load dependencies from supplementary drop-in directories */ | |
036643a2 | 55 | |
ac155bb8 | 56 | SET_FOREACH(t, u->names, i) { |
99f08d14 LP |
57 | char **p; |
58 | ||
a3c4eb07 | 59 | STRV_FOREACH(p, u->manager->lookup_paths.search_path) { |
17e78d18 ZJS |
60 | unit_file_process_dir(NULL, u->manager->unit_path_cache, *p, t, |
61 | ".wants", UNIT_WANTS, | |
1a7f1b38 | 62 | add_dependency_consumer, u, NULL); |
17e78d18 ZJS |
63 | unit_file_process_dir(NULL, u->manager->unit_path_cache, *p, t, |
64 | ".requires", UNIT_REQUIRES, | |
1a7f1b38 | 65 | add_dependency_consumer, u, NULL); |
036643a2 | 66 | } |
0301abf4 LP |
67 | } |
68 | ||
d7e0da1d | 69 | r = unit_find_dropin_paths(u, &l); |
1a7f1b38 | 70 | if (r <= 0) |
ae7a7182 | 71 | return 0; |
5926ccca | 72 | |
d7e0da1d LP |
73 | if (!u->dropin_paths) { |
74 | u->dropin_paths = l; | |
75 | l = NULL; | |
76 | } else { | |
77 | r = strv_extend_strv(&u->dropin_paths, l, true); | |
78 | if (r < 0) | |
79 | return log_oom(); | |
80 | } | |
81 | ||
ae7a7182 | 82 | STRV_FOREACH(f, u->dropin_paths) { |
bcd816bd | 83 | config_parse(u->id, *f, NULL, |
36f822c4 ZJS |
84 | UNIT_VTABLE(u)->sections, |
85 | config_item_perf_lookup, load_fragment_gperf_lookup, | |
86 | false, false, false, u); | |
5926ccca LP |
87 | } |
88 | ||
ae7a7182 OS |
89 | u->dropin_mtime = now(CLOCK_REALTIME); |
90 | ||
5cb5a6ff LP |
91 | return 0; |
92 | } |