]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: correct cases where return log_{error,warning} is used without value
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 8 Sep 2020 10:51:23 +0000 (12:51 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 8 Sep 2020 15:40:46 +0000 (17:40 +0200)
In various cases, we would say 'return log_warning()' or 'return log_error()'. Those
functions return 0 if no error is passed in. For log_warning or log_error this doesn't
make sense, and we generally want to propagate the error. In the few cases where
the error should be ignored, I think it's better to split it in two, and call 'return 0'
on a separate line.

src/core/execute.c
src/escape/escape.c
src/resolve/resolved-manager.c
src/systemctl/systemctl.c
src/update-done/update-done.c
src/update-utmp/update-utmp.c

index e02a55e2220f439c1de35494f336d6fd33d45c0c..16aa4b30189ceadcb0b6e942a6febdb6aef46a62 100644 (file)
@@ -6281,8 +6281,13 @@ int exec_runtime_deserialize_one(Manager *m, const char *value, FDSet *fds) {
 
                 n = strcspn(v, " ");
                 buf = strndupa(v, n);
-                if (safe_atoi(buf, &fdpair[0]) < 0 || !fdset_contains(fds, fdpair[0]))
-                        return log_debug("Unable to process exec-runtime netns fd specification.");
+
+                r = safe_atoi(buf, &fdpair[0]);
+                if (r < 0)
+                        return log_debug_errno(r, "Unable to parse exec-runtime specification netns-socket-0=%s: %m", buf);
+                if (!fdset_contains(fds, fdpair[0]))
+                        return log_debug_errno(SYNTHETIC_ERRNO(EBADF),
+                                               "exec-runtime specification netns-socket-0= refers to unknown fd %d: %m", fdpair[0]);
                 fdpair[0] = fdset_remove(fds, fdpair[0]);
                 if (v[n] != ' ')
                         goto finalize;
@@ -6295,8 +6300,12 @@ int exec_runtime_deserialize_one(Manager *m, const char *value, FDSet *fds) {
 
                 n = strcspn(v, " ");
                 buf = strndupa(v, n);
-                if (safe_atoi(buf, &fdpair[1]) < 0 || !fdset_contains(fds, fdpair[1]))
-                        return log_debug("Unable to process exec-runtime netns fd specification.");
+                r = safe_atoi(buf, &fdpair[1]);
+                if (r < 0)
+                        return log_debug_errno(r, "Unable to parse exec-runtime specification netns-socket-1=%s: %m", buf);
+                if (!fdset_contains(fds, fdpair[0]))
+                        return log_debug_errno(SYNTHETIC_ERRNO(EBADF),
+                                               "exec-runtime specification netns-socket-1= refers to unknown fd %d: %m", fdpair[1]);
                 fdpair[1] = fdset_remove(fds, fdpair[1]);
         }
 
index 0c543a90f6b7994267f42f28ebe32af9642ff398..3f3dc0a89475d365eb23affb7adba90bb29b6bfd 100644 (file)
@@ -211,14 +211,16 @@ static int run(int argc, char *argv[]) {
                                 if (r < 0)
                                         return log_error_errno(r, "Failed to extract instance: %m");
                                 if (isempty(name))
-                                        return log_error("Unit %s is missing the instance name.", *i);
+                                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                                               "Unit %s is missing the instance name.", *i);
 
                                 r = unit_name_template(*i, &template);
                                 if (r < 0)
                                         return log_error_errno(r, "Failed to extract template: %m");
                                 if (arg_template && !streq(arg_template, template))
-                                        return log_error("Unit %s template %s does not match specified template %s.",
-                                                         *i, template, arg_template);
+                                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                                               "Unit %s template %s does not match specified template %s.",
+                                                               *i, template, arg_template);
                         } else {
                                 name = strdup(*i);
                                 if (!name)
index ddd336b48971ebe80bfbd5b46debb54cce12876f..fc3ab98cd63c2e910a1905c9bd33ef780a42f9a7 100644 (file)
@@ -350,7 +350,8 @@ static int determine_hostname(char **full_hostname, char **llmnr_hostname, char
 #if HAVE_LIBIDN2
         r = idn2_to_unicode_8z8z(label, &utf8, 0);
         if (r != IDN2_OK)
-                return log_error("Failed to undo IDNA: %s", idn2_strerror(r));
+                return log_error_errno(SYNTHETIC_ERRNO(EUCLEAN),
+                                       "Failed to undo IDNA: %s", idn2_strerror(r));
         assert(utf8_is_valid(utf8));
 
         r = strlen(utf8);
index e22efb92ac5058fa5aac611cfe6b689b9179bff1..f23bc6b234b668941b0c61f9c946b53075fd372f 100644 (file)
@@ -2086,8 +2086,10 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
         if (streq(key, "systemd.unit")) {
                 if (proc_cmdline_value_missing(key, value))
                         return 0;
-                if (!unit_name_is_valid(value, UNIT_NAME_PLAIN|UNIT_NAME_INSTANCE))
-                        return log_warning("Unit name specified on %s= is not valid, ignoring: %s", key, value);
+                if (!unit_name_is_valid(value, UNIT_NAME_PLAIN|UNIT_NAME_INSTANCE)) {
+                        log_warning("Unit name specified on %s= is not valid, ignoring: %s", key, value);
+                        return 0;
+                }
 
                 return free_and_strdup_warn(ret, key);
 
index c001802dc910b93eb347ef51f39b7917ecf6559d..e9d589e0e53045eaae06b213b39f1b0ce21c182c 100644 (file)
@@ -31,7 +31,7 @@ static int apply_timestamp(const char *path, struct timespec *ts) {
 
         r = write_string_file_atomic_label_ts(path, message, ts);
         if (r == -EROFS)
-                return log_debug("Cannot create \"%s\", file system is read-only.", path);
+                return log_debug_errno(r, "Cannot create \"%s\", file system is read-only.", path);
         if (r < 0)
                 return log_error_errno(r, "Failed to write \"%s\": %m", path);
         return 0;
index 47354d50129090875b799341f0a361dd25df1806..4ab90a63ed8def2a8bed4733b51d54da1f69d85a 100644 (file)
@@ -187,8 +187,10 @@ static int on_runlevel(Context *c) {
         runlevel = get_current_runlevel(c);
         if (runlevel < 0)
                 return runlevel;
-        if (runlevel == 0)
-                return log_warning("Failed to get new runlevel, utmp update skipped.");
+        if (runlevel == 0) {
+                log_warning("Failed to get new runlevel, utmp update skipped.");
+                return 0;
+        }
 
         if (previous == runlevel)
                 return 0;