]>
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" |
95778782 | 25 | #include "stat-util.h" |
036643a2 | 26 | #include "strv.h" |
9e2f7c11 | 27 | #include "unit-name.h" |
cf0fbc49 | 28 | #include "unit.h" |
8afbb8e1 | 29 | |
95778782 ZJS |
30 | static int process_deps(Unit *u, UnitDependency dependency, const char *dir_suffix) { |
31 | _cleanup_strv_free_ char **paths = NULL; | |
32 | char **p; | |
9e2f7c11 LP |
33 | int r; |
34 | ||
95778782 ZJS |
35 | r = unit_file_find_dropin_paths(NULL, |
36 | u->manager->lookup_paths.search_path, | |
37 | u->manager->unit_path_cache, | |
38 | dir_suffix, | |
39 | NULL, | |
40 | u->names, | |
41 | &paths); | |
1a7f1b38 | 42 | if (r < 0) |
95778782 ZJS |
43 | return r; |
44 | ||
45 | STRV_FOREACH(p, paths) { | |
46 | const char *entry; | |
47 | ||
48 | entry = basename(*p); | |
49 | ||
5be5d39b ZJS |
50 | if (null_or_empty_path(*p) > 0) { |
51 | /* an error usually means an invalid symlink, which is not a mask */ | |
52 | log_unit_debug(u, "%s dependency on %s is masked by %s, ignoring.", | |
53 | unit_dependency_to_string(dependency), entry, *p); | |
54 | continue; | |
55 | } | |
56 | ||
95778782 ZJS |
57 | r = is_symlink(*p); |
58 | if (r < 0) { | |
59 | log_unit_warning_errno(u, r, "%s dropin %s unreadable, ignoring: %m", | |
60 | unit_dependency_to_string(dependency), *p); | |
61 | continue; | |
62 | } | |
63 | if (r == 0) { | |
64 | log_unit_warning(u, "%s dependency dropin %s is not a symlink, ignoring.", | |
65 | unit_dependency_to_string(dependency), *p); | |
66 | continue; | |
67 | } | |
68 | ||
69 | /* TODO: add more checks on the symlink name and target here */ | |
70 | ||
71 | r = unit_add_dependency_by_name(u, dependency, entry, *p, true); | |
72 | if (r < 0) | |
73 | log_unit_error_errno(u, r, "cannot add %s dependency on %s, ignoring: %m", | |
74 | unit_dependency_to_string(dependency), entry); | |
75 | } | |
9e2f7c11 | 76 | |
8afbb8e1 | 77 | return 0; |
9e2f7c11 | 78 | } |
5cb5a6ff | 79 | |
ae7a7182 | 80 | int unit_load_dropin(Unit *u) { |
d7e0da1d | 81 | _cleanup_strv_free_ char **l = NULL; |
95778782 | 82 | char **f; |
1a7f1b38 | 83 | int r; |
99f08d14 LP |
84 | |
85 | assert(u); | |
86 | ||
95778782 ZJS |
87 | /* Load dependencies from .wants and .requires directories */ |
88 | r = process_deps(u, UNIT_WANTS, ".wants"); | |
89 | if (r < 0) | |
90 | return r; | |
99f08d14 | 91 | |
95778782 ZJS |
92 | r = process_deps(u, UNIT_REQUIRES, ".requires"); |
93 | if (r < 0) | |
94 | return r; | |
0301abf4 | 95 | |
95778782 | 96 | /* Load .conf dropins */ |
d7e0da1d | 97 | r = unit_find_dropin_paths(u, &l); |
1a7f1b38 | 98 | if (r <= 0) |
ae7a7182 | 99 | return 0; |
5926ccca | 100 | |
d7e0da1d LP |
101 | if (!u->dropin_paths) { |
102 | u->dropin_paths = l; | |
103 | l = NULL; | |
104 | } else { | |
105 | r = strv_extend_strv(&u->dropin_paths, l, true); | |
106 | if (r < 0) | |
107 | return log_oom(); | |
108 | } | |
109 | ||
ae7a7182 | 110 | STRV_FOREACH(f, u->dropin_paths) { |
bcd816bd | 111 | config_parse(u->id, *f, NULL, |
36f822c4 ZJS |
112 | UNIT_VTABLE(u)->sections, |
113 | config_item_perf_lookup, load_fragment_gperf_lookup, | |
114 | false, false, false, u); | |
5926ccca LP |
115 | } |
116 | ||
ae7a7182 OS |
117 | u->dropin_mtime = now(CLOCK_REALTIME); |
118 | ||
5cb5a6ff LP |
119 | return 0; |
120 | } |