From 0187f62bb5f785c22952e79c55ef0fdb87f1ad65 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 21 Sep 2012 17:01:39 +0200 Subject: sysctl: always return the last error we encountered --- src/sysctl/sysctl.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/sysctl/sysctl.c b/src/sysctl/sysctl.c index 62d4c81c47..e77f496089 100644 --- a/src/sysctl/sysctl.c +++ b/src/sysctl/sysctl.c @@ -252,7 +252,7 @@ static int parse_argv(int argc, char *argv[]) { } int main(int argc, char *argv[]) { - int r = 0; + int r = 0, k; char *property, *value; Iterator it; @@ -260,8 +260,6 @@ int main(int argc, char *argv[]) { if (r <= 0) return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; - r = 0; - log_set_target(LOG_TARGET_AUTO); log_parse_environment(); log_open(); @@ -274,19 +272,18 @@ int main(int argc, char *argv[]) { goto finish; } + r = 0; + if (argc > optind) { int i; for (i = optind; i < argc; i++) { - int k; - k = parse_file(argv[i], false); - if (k < 0 && r == 0) + if (k < 0) r = k; } } else { char **files, **f; - int k; r = conf_files_list(&files, ".conf", "/etc/sysctl.d", @@ -310,14 +307,17 @@ int main(int argc, char *argv[]) { f = files + strv_length(files) - 1; STRV_FOREACH_BACKWARDS(f, files) { k = parse_file(*f, true); - if (k < 0 && r == 0) + if (k < 0) r = k; } strv_free(files); } - r = apply_all(); + k = apply_all(); + if (k < 0) + r = k; + finish: HASHMAP_FOREACH_KEY(value, property, sysctl_options, it) { hashmap_remove(sysctl_options, property); -- cgit v1.2.3-54-g00ecf