@@ -917,6 +917,22 @@ static int parse_input_section(struct flb_cf_section *section,
917917 return -1 ;
918918 }
919919
920+ routes_var = cfl_kvlist_fetch (kvlist , "routes" );
921+ if (!routes_var ) {
922+ /* No router configuration for this input section */
923+ return 0 ;
924+ }
925+
926+ if (routes_var -> type != CFL_VARIANT_KVLIST ) {
927+ return -1 ;
928+ }
929+
930+ routes_kvlist = routes_var -> data .as_kvlist ;
931+ if (cfl_list_is_empty (& routes_kvlist -> list ) == 1 ) {
932+ /* routes field present but empty, nothing to configure */
933+ return 0 ;
934+ }
935+
920936 name_var = cfl_kvlist_fetch (kvlist , "name" );
921937 if (!name_var || name_var -> type != CFL_VARIANT_STRING ) {
922938 return -1 ;
@@ -945,16 +961,6 @@ static int parse_input_section(struct flb_cf_section *section,
945961 }
946962 }
947963
948- routes_var = cfl_kvlist_fetch (kvlist , "routes" );
949- if (!routes_var || routes_var -> type != CFL_VARIANT_KVLIST ) {
950- goto error ;
951- }
952-
953- routes_kvlist = routes_var -> data .as_kvlist ;
954- if (cfl_list_is_empty (& routes_kvlist -> list ) == 1 ) {
955- goto error ;
956- }
957-
958964 cfl_list_foreach (head , & routes_kvlist -> list ) {
959965 pair = cfl_list_entry (head , struct cfl_kvpair , _head );
960966 if (!pair || !pair -> key ) {
@@ -978,15 +984,19 @@ static int parse_input_section(struct flb_cf_section *section,
978984 }
979985
980986 if (cfl_list_is_empty (& input -> routes ) == 1 ) {
981- goto error ;
987+ goto skip ;
982988 }
983989
984990 cfl_list_add (& input -> _head , input_routes );
985- return 0 ;
991+ return 1 ;
986992
987993error :
988994 input_routes_destroy (input );
989995 return -1 ;
996+
997+ skip :
998+ input_routes_destroy (input );
999+ return 0 ;
9901000}
9911001
9921002int flb_router_config_parse (struct flb_cf * cf ,
@@ -995,6 +1005,8 @@ int flb_router_config_parse(struct flb_cf *cf,
9951005{
9961006 struct mk_list * head ;
9971007 struct flb_cf_section * section ;
1008+ int routes_found = FLB_FALSE ;
1009+ int ret ;
9981010
9991011 if (!cf || !input_routes ) {
10001012 return -1 ;
@@ -1004,17 +1016,24 @@ int flb_router_config_parse(struct flb_cf *cf,
10041016
10051017 mk_list_foreach (head , & cf -> inputs ) {
10061018 section = mk_list_entry (head , struct flb_cf_section , _head_section );
1007- if (parse_input_section (section , input_routes , config ) != 0 ) {
1019+ ret = parse_input_section (section , input_routes , config );
1020+ if (ret == -1 ) {
10081021 flb_router_routes_destroy (input_routes );
10091022 cfl_list_init (input_routes );
10101023 return -1 ;
10111024 }
1025+ else if (ret == 1 ) {
1026+ routes_found = FLB_TRUE ;
1027+ }
10121028 }
10131029
10141030 if (cfl_list_is_empty (input_routes ) == 1 ) {
1015- flb_router_routes_destroy (input_routes );
1016- cfl_list_init (input_routes );
1017- return -1 ;
1031+ if (routes_found == FLB_TRUE ) {
1032+ flb_router_routes_destroy (input_routes );
1033+ cfl_list_init (input_routes );
1034+ return -1 ;
1035+ }
1036+ return 0 ;
10181037 }
10191038
10201039 return 0 ;
0 commit comments