2010-02-03 15:03:47 +03:00
/***
This file is part of systemd .
Copyright 2010 Lennart Poettering
systemd is free software ; you can redistribute it and / or modify it
2012-04-12 02:20:58 +04:00
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation ; either version 2.1 of the License , or
2010-02-03 15:03:47 +03:00
( at your option ) any later version .
systemd is distributed in the hope that it will be useful , but
WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
2012-04-12 02:20:58 +04:00
Lesser General Public License for more details .
2010-02-03 15:03:47 +03:00
2012-04-12 02:20:58 +04:00
You should have received a copy of the GNU Lesser General Public License
2010-02-03 15:03:47 +03:00
along with systemd ; If not , see < http : //www.gnu.org/licenses/>.
* * */
2010-01-27 02:15:56 +03:00
2015-11-17 00:09:36 +03:00
# include "conf-parser.h"
2010-01-23 03:52:57 +03:00
# include "load-dropin.h"
2015-11-17 00:09:36 +03:00
# include "load-fragment.h"
2010-01-27 06:55:19 +03:00
# include "log.h"
2010-02-13 03:07:02 +03:00
# include "strv.h"
2010-04-15 05:11:11 +04:00
# include "unit-name.h"
2015-11-17 00:09:36 +03:00
# include "unit.h"
2013-01-11 03:21:06 +04:00
2014-12-15 07:12:40 +03:00
static int add_dependency_consumer (
2013-04-30 01:39:12 +04:00
UnitDependency dependency ,
2014-12-15 07:12:40 +03:00
const char * entry ,
const char * filepath ,
void * arg ) {
Unit * u = arg ;
2010-04-15 05:11:11 +04:00
int r ;
2010-11-15 06:24:04 +03:00
assert ( u ) ;
2010-04-15 05:11:11 +04:00
2014-12-15 07:12:40 +03:00
r = unit_add_dependency_by_name ( u , dependency , entry , filepath , true ) ;
if ( r < 0 )
log_error_errno ( r , " Cannot add dependency %s to %s, ignoring: %m " , entry , u - > id ) ;
2010-04-15 05:11:11 +04:00
2013-01-11 03:21:06 +04:00
return 0 ;
2010-04-15 05:11:11 +04:00
}
2010-01-23 03:52:57 +03:00
2013-04-01 14:32:35 +04:00
int unit_load_dropin ( Unit * u ) {
2016-02-26 19:05:33 +03:00
_cleanup_strv_free_ char * * l = NULL ;
2013-04-01 14:32:35 +04:00
Iterator i ;
char * t , * * f ;
2014-12-15 07:12:40 +03:00
int r ;
2010-11-15 06:24:04 +03:00
assert ( u ) ;
/* Load dependencies from supplementary drop-in directories */
2010-02-13 03:07:02 +03:00
2012-01-15 15:04:08 +04:00
SET_FOREACH ( t , u - > names , i ) {
2010-11-15 06:24:04 +03:00
char * * p ;
2016-02-24 17:31:33 +03:00
STRV_FOREACH ( p , u - > manager - > lookup_paths . search_path ) {
2014-12-15 07:12:40 +03:00
unit_file_process_dir ( u - > manager - > unit_path_cache , * p , t , " .wants " , UNIT_WANTS ,
add_dependency_consumer , u , NULL ) ;
unit_file_process_dir ( u - > manager - > unit_path_cache , * p , t , " .requires " , UNIT_REQUIRES ,
add_dependency_consumer , u , NULL ) ;
2010-02-13 03:07:02 +03:00
}
2010-01-27 02:15:56 +03:00
}
2016-02-26 19:05:33 +03:00
r = unit_find_dropin_paths ( u , & l ) ;
2014-12-15 07:12:40 +03:00
if ( r < = 0 )
2013-04-01 14:32:35 +04:00
return 0 ;
2013-01-11 04:04:11 +04:00
2016-02-26 19:05:33 +03:00
if ( ! u - > dropin_paths ) {
u - > dropin_paths = l ;
l = NULL ;
} else {
r = strv_extend_strv ( & u - > dropin_paths , l , true ) ;
if ( r < 0 )
return log_oom ( ) ;
}
2013-04-01 14:32:35 +04:00
STRV_FOREACH ( f , u - > dropin_paths ) {
2014-05-22 11:49:12 +04:00
config_parse ( u - > id , * f , NULL ,
2014-07-17 02:27:12 +04:00
UNIT_VTABLE ( u ) - > sections ,
config_item_perf_lookup , load_fragment_gperf_lookup ,
false , false , false , u ) ;
2013-01-11 04:04:11 +04:00
}
2013-04-01 14:32:35 +04:00
u - > dropin_mtime = now ( CLOCK_REALTIME ) ;
2010-01-23 03:52:57 +03:00
return 0 ;
}