Skip to content

Commit c413bb2

Browse files
committed
tree-wide: correct cases where return log_{error,warning} is used without value
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.
1 parent 8195283 commit c413bb2

File tree

6 files changed

+29
-13
lines changed

6 files changed

+29
-13
lines changed

src/core/execute.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6281,8 +6281,13 @@ int exec_runtime_deserialize_one(Manager *m, const char *value, FDSet *fds) {
62816281

62826282
n = strcspn(v, " ");
62836283
buf = strndupa(v, n);
6284-
if (safe_atoi(buf, &fdpair[0]) < 0 || !fdset_contains(fds, fdpair[0]))
6285-
return log_debug("Unable to process exec-runtime netns fd specification.");
6284+
6285+
r = safe_atoi(buf, &fdpair[0]);
6286+
if (r < 0)
6287+
return log_debug_errno(r, "Unable to parse exec-runtime specification netns-socket-0=%s: %m", buf);
6288+
if (!fdset_contains(fds, fdpair[0]))
6289+
return log_debug_errno(SYNTHETIC_ERRNO(EBADF),
6290+
"exec-runtime specification netns-socket-0= refers to unknown fd %d: %m", fdpair[0]);
62866291
fdpair[0] = fdset_remove(fds, fdpair[0]);
62876292
if (v[n] != ' ')
62886293
goto finalize;
@@ -6295,8 +6300,12 @@ int exec_runtime_deserialize_one(Manager *m, const char *value, FDSet *fds) {
62956300

62966301
n = strcspn(v, " ");
62976302
buf = strndupa(v, n);
6298-
if (safe_atoi(buf, &fdpair[1]) < 0 || !fdset_contains(fds, fdpair[1]))
6299-
return log_debug("Unable to process exec-runtime netns fd specification.");
6303+
r = safe_atoi(buf, &fdpair[1]);
6304+
if (r < 0)
6305+
return log_debug_errno(r, "Unable to parse exec-runtime specification netns-socket-1=%s: %m", buf);
6306+
if (!fdset_contains(fds, fdpair[0]))
6307+
return log_debug_errno(SYNTHETIC_ERRNO(EBADF),
6308+
"exec-runtime specification netns-socket-1= refers to unknown fd %d: %m", fdpair[1]);
63006309
fdpair[1] = fdset_remove(fds, fdpair[1]);
63016310
}
63026311

src/escape/escape.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,16 @@ static int run(int argc, char *argv[]) {
211211
if (r < 0)
212212
return log_error_errno(r, "Failed to extract instance: %m");
213213
if (isempty(name))
214-
return log_error("Unit %s is missing the instance name.", *i);
214+
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
215+
"Unit %s is missing the instance name.", *i);
215216

216217
r = unit_name_template(*i, &template);
217218
if (r < 0)
218219
return log_error_errno(r, "Failed to extract template: %m");
219220
if (arg_template && !streq(arg_template, template))
220-
return log_error("Unit %s template %s does not match specified template %s.",
221-
*i, template, arg_template);
221+
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
222+
"Unit %s template %s does not match specified template %s.",
223+
*i, template, arg_template);
222224
} else {
223225
name = strdup(*i);
224226
if (!name)

src/resolve/resolved-manager.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ static int determine_hostname(char **full_hostname, char **llmnr_hostname, char
350350
#if HAVE_LIBIDN2
351351
r = idn2_to_unicode_8z8z(label, &utf8, 0);
352352
if (r != IDN2_OK)
353-
return log_error("Failed to undo IDNA: %s", idn2_strerror(r));
353+
return log_error_errno(SYNTHETIC_ERRNO(EUCLEAN),
354+
"Failed to undo IDNA: %s", idn2_strerror(r));
354355
assert(utf8_is_valid(utf8));
355356

356357
r = strlen(utf8);

src/systemctl/systemctl.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,8 +2086,10 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
20862086
if (streq(key, "systemd.unit")) {
20872087
if (proc_cmdline_value_missing(key, value))
20882088
return 0;
2089-
if (!unit_name_is_valid(value, UNIT_NAME_PLAIN|UNIT_NAME_INSTANCE))
2090-
return log_warning("Unit name specified on %s= is not valid, ignoring: %s", key, value);
2089+
if (!unit_name_is_valid(value, UNIT_NAME_PLAIN|UNIT_NAME_INSTANCE)) {
2090+
log_warning("Unit name specified on %s= is not valid, ignoring: %s", key, value);
2091+
return 0;
2092+
}
20912093

20922094
return free_and_strdup_warn(ret, key);
20932095

src/update-done/update-done.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static int apply_timestamp(const char *path, struct timespec *ts) {
3131

3232
r = write_string_file_atomic_label_ts(path, message, ts);
3333
if (r == -EROFS)
34-
return log_debug("Cannot create \"%s\", file system is read-only.", path);
34+
return log_debug_errno(r, "Cannot create \"%s\", file system is read-only.", path);
3535
if (r < 0)
3636
return log_error_errno(r, "Failed to write \"%s\": %m", path);
3737
return 0;

src/update-utmp/update-utmp.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,10 @@ static int on_runlevel(Context *c) {
187187
runlevel = get_current_runlevel(c);
188188
if (runlevel < 0)
189189
return runlevel;
190-
if (runlevel == 0)
191-
return log_warning("Failed to get new runlevel, utmp update skipped.");
190+
if (runlevel == 0) {
191+
log_warning("Failed to get new runlevel, utmp update skipped.");
192+
return 0;
193+
}
192194

193195
if (previous == runlevel)
194196
return 0;

0 commit comments

Comments
 (0)