summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-09-21 17:01:39 +0200
committerLennart Poettering <lennart@poettering.net>2012-09-21 17:03:40 +0200
commit0187f62bb5f785c22952e79c55ef0fdb87f1ad65 (patch)
treec14aa12874b6678b9067697ea96e86985dc103f0
parent77e63fafa5736c235920b8deef73afbf733a7fda (diff)
sysctl: always return the last error we encountered
-rw-r--r--src/sysctl/sysctl.c18
1 files changed, 9 insertions, 9 deletions
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);