From 36f822c4bd077f9121757e24b6516e5c7ada63b5 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Wed, 16 Jul 2014 18:27:12 -0400 Subject: Let config_parse open file where applicable Special care is needed so that we get an error message if the file failed to parse, but not when it is missing. To avoid duplicating the same error check in every caller, add an additional 'warn' boolean to tell config_parse whether a message should be issued. This makes things both shorter and more robust wrt. to error reporting. --- src/core/load-dropin.c | 5 +++-- src/core/load-fragment.c | 7 ++++--- src/core/main.c | 18 ++++-------------- 3 files changed, 11 insertions(+), 19 deletions(-) (limited to 'src/core') diff --git a/src/core/load-dropin.c b/src/core/load-dropin.c index 66547cf4bc..21c991526c 100644 --- a/src/core/load-dropin.c +++ b/src/core/load-dropin.c @@ -186,8 +186,9 @@ int unit_load_dropin(Unit *u) { STRV_FOREACH(f, u->dropin_paths) { config_parse(u->id, *f, NULL, - UNIT_VTABLE(u)->sections, config_item_perf_lookup, - load_fragment_gperf_lookup, false, false, u); + UNIT_VTABLE(u)->sections, + config_item_perf_lookup, load_fragment_gperf_lookup, + false, false, false, u); } u->dropin_mtime = now(CLOCK_REALTIME); diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 54010b804e..81f137946c 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -3368,9 +3368,10 @@ static int load_from_path(Unit *u, const char *path) { u->load_state = UNIT_LOADED; /* Now, parse the file contents */ - r = config_parse(u->id, filename, f, UNIT_VTABLE(u)->sections, - config_item_perf_lookup, - load_fragment_gperf_lookup, false, true, u); + r = config_parse(u->id, filename, f, + UNIT_VTABLE(u)->sections, + config_item_perf_lookup, load_fragment_gperf_lookup, + false, true, false, u); if (r < 0) return r; } diff --git a/src/core/main.c b/src/core/main.c index d1fb265df1..f9ee297afa 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -682,23 +682,13 @@ static int parse_config_file(void) { {} }; - _cleanup_fclose_ FILE *f; const char *fn; - int r; fn = arg_running_as == SYSTEMD_SYSTEM ? PKGSYSCONFDIR "/system.conf" : PKGSYSCONFDIR "/user.conf"; - f = fopen(fn, "re"); - if (!f) { - if (errno == ENOENT) - return 0; - - log_warning("Failed to open configuration file '%s': %m", fn); - return 0; - } - - r = config_parse(NULL, fn, f, "Manager\0", config_item_table_lookup, items, false, false, NULL); - if (r < 0) - log_warning("Failed to parse configuration file: %s", strerror(-r)); + config_parse(NULL, fn, NULL, + "Manager\0", + config_item_table_lookup, items, + false, false, true, NULL); return 0; } -- cgit v1.2.3-54-g00ecf