]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/core/load-dropin.c
tree-wide: sort includes
[thirdparty/systemd.git] / src / core / load-dropin.c
CommitLineData
d6c9574f 1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
5cb5a6ff 2
a7334b09
LP
3/***
4 This file is part of systemd.
5
6 Copyright 2010 Lennart Poettering
7
8 systemd is free software; you can redistribute it and/or modify it
5430f7f2
LP
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
a7334b09
LP
11 (at your option) any later version.
12
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
5430f7f2 16 Lesser General Public License for more details.
a7334b09 17
5430f7f2 18 You should have received a copy of the GNU Lesser General Public License
a7334b09
LP
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
0301abf4 22
cf0fbc49 23#include "conf-parser.h"
5cb5a6ff 24#include "load-dropin.h"
cf0fbc49 25#include "load-fragment.h"
b952f2e1 26#include "log.h"
036643a2 27#include "strv.h"
9e2f7c11 28#include "unit-name.h"
cf0fbc49 29#include "unit.h"
8afbb8e1 30
1a7f1b38 31static int add_dependency_consumer(
aa96c6cb 32 UnitDependency dependency,
1a7f1b38
ZJS
33 const char *entry,
34 const char* filepath,
35 void *arg) {
36 Unit *u = arg;
9e2f7c11
LP
37 int r;
38
99f08d14 39 assert(u);
9e2f7c11 40
1a7f1b38
ZJS
41 r = unit_add_dependency_by_name(u, dependency, entry, filepath, true);
42 if (r < 0)
43 log_error_errno(r, "Cannot add dependency %s to %s, ignoring: %m", entry, u->id);
9e2f7c11 44
8afbb8e1 45 return 0;
9e2f7c11 46}
5cb5a6ff 47
ae7a7182
OS
48int unit_load_dropin(Unit *u) {
49 Iterator i;
50 char *t, **f;
1a7f1b38 51 int r;
99f08d14
LP
52
53 assert(u);
54
55 /* Load dependencies from supplementary drop-in directories */
036643a2 56
ac155bb8 57 SET_FOREACH(t, u->names, i) {
99f08d14
LP
58 char **p;
59
ac155bb8 60 STRV_FOREACH(p, u->manager->lookup_paths.unit_path) {
1a7f1b38
ZJS
61 unit_file_process_dir(u->manager->unit_path_cache, *p, t, ".wants", UNIT_WANTS,
62 add_dependency_consumer, u, NULL);
63 unit_file_process_dir(u->manager->unit_path_cache, *p, t, ".requires", UNIT_REQUIRES,
64 add_dependency_consumer, u, NULL);
036643a2 65 }
0301abf4
LP
66 }
67
1a7f1b38
ZJS
68 r = unit_find_dropin_paths(u, &u->dropin_paths);
69 if (r <= 0)
ae7a7182 70 return 0;
5926ccca 71
ae7a7182 72 STRV_FOREACH(f, u->dropin_paths) {
bcd816bd 73 config_parse(u->id, *f, NULL,
36f822c4
ZJS
74 UNIT_VTABLE(u)->sections,
75 config_item_perf_lookup, load_fragment_gperf_lookup,
76 false, false, false, u);
5926ccca
LP
77 }
78
ae7a7182
OS
79 u->dropin_mtime = now(CLOCK_REALTIME);
80
5cb5a6ff
LP
81 return 0;
82}