1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-12 09:17:44 +03:00

core: include error cause in log message

This commit is contained in:
Yu Watanabe 2018-10-20 01:40:42 +09:00
parent 486d76bd7e
commit 5e1ee764e1
8 changed files with 36 additions and 36 deletions

View File

@ -1948,7 +1948,7 @@ void unit_release_cgroup(Unit *u) {
if (u->cgroup_inotify_wd >= 0) {
if (inotify_rm_watch(u->manager->cgroup_inotify_fd, u->cgroup_inotify_wd) < 0)
log_unit_debug_errno(u, errno, "Failed to remove cgroup inotify watch %i for %s, ignoring", u->cgroup_inotify_wd, u->id);
log_unit_debug_errno(u, errno, "Failed to remove cgroup inotify watch %i for %s, ignoring: %m", u->cgroup_inotify_wd, u->id);
(void) hashmap_remove(u->manager->cgroup_inotify_wd_unit, INT_TO_PTR(u->cgroup_inotify_wd));
u->cgroup_inotify_wd = -1;

View File

@ -254,7 +254,7 @@ static int device_deserialize_item(Unit *u, const char *key, const char *value,
} else if (streq(key, "found")) {
r = device_found_from_string_many(value, &d->deserialized_found);
if (r < 0)
log_unit_debug_errno(u, r, "Failed to parse found value, ignoring: %s", value);
log_unit_debug_errno(u, r, "Failed to parse found value '%s', ignoring: %m", value);
} else
log_unit_debug(u, "Unknown serialization key: %s", key);

View File

@ -73,7 +73,7 @@ static int generate_machine_id(const char *root, sd_id128_t *ret) {
/* If that didn't work, generate a random machine id */
r = sd_id128_randomize(ret);
if (r < 0)
return log_error_errno(r, "Failed to generate randomized : %m");
return log_error_errno(r, "Failed to generate randomized machine ID: %m");
log_info("Initializing machine ID from random generator.");
return 0;
@ -108,8 +108,7 @@ int machine_id_setup(const char *root, sd_id128_t machine_id, sd_id128_t *ret) {
"2) /etc/machine-id exists and is empty.\n"
"3) /etc/machine-id is missing and /etc is writable.\n");
else
return log_error_errno(errno,
"Cannot open %s: %m", etc_machine_id);
return log_error_errno(errno, "Cannot open %s: %m", etc_machine_id);
}
writable = false;
@ -208,7 +207,7 @@ int machine_id_commit(const char *root) {
r = id128_read_fd(fd, ID128_PLAIN, &id);
if (r < 0)
return log_error_errno(r, "We didn't find a valid machine ID in %s.", etc_machine_id);
return log_error_errno(r, "We didn't find a valid machine ID in %s: %m", etc_machine_id);
fd = safe_close(fd);

View File

@ -349,7 +349,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
r = value ? parse_boolean(value) : true;
if (r < 0)
log_warning("Failed to parse dump core switch %s. Ignoring.", value);
log_warning_errno(r, "Failed to parse dump core switch %s, ignoring: %m", value);
else
arg_dump_core = r;
@ -367,14 +367,17 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
if (!value)
arg_crash_chvt = 0; /* turn on */
else if (parse_crash_chvt(value) < 0)
log_warning("Failed to parse crash chvt switch %s. Ignoring.", value);
else {
r = parse_crash_chvt(value);
if (r < 0)
log_warning_errno(r, "Failed to parse crash chvt switch %s, ignoring: %m", value);
}
} else if (proc_cmdline_key_streq(key, "systemd.crash_shell")) {
r = value ? parse_boolean(value) : true;
if (r < 0)
log_warning("Failed to parse crash shell switch %s. Ignoring.", value);
log_warning_errno(r, "Failed to parse crash shell switch %s, ignoring: %m", value);
else
arg_crash_shell = r;
@ -382,7 +385,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
r = value ? parse_boolean(value) : true;
if (r < 0)
log_warning("Failed to parse crash reboot switch %s. Ignoring.", value);
log_warning_errno(r, "Failed to parse crash reboot switch %s, ignoring: %m", value);
else
arg_crash_reboot = r;
@ -391,17 +394,15 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
r = parse_confirm_spawn(value, &s);
if (r < 0)
log_warning_errno(r, "Failed to parse confirm_spawn switch %s. Ignoring.", value);
else {
free(arg_confirm_spawn);
arg_confirm_spawn = s;
}
log_warning_errno(r, "Failed to parse confirm_spawn switch %s, ignoring: %m", value);
else
free_and_replace(arg_confirm_spawn, s);
} else if (proc_cmdline_key_streq(key, "systemd.service_watchdogs")) {
r = value ? parse_boolean(value) : true;
if (r < 0)
log_warning("Failed to parse service watchdog switch %s. Ignoring.", value);
log_warning_errno(r, "Failed to parse service watchdog switch %s, ignoring: %m", value);
else
arg_service_watchdogs = r;
@ -410,7 +411,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
if (value) {
r = parse_show_status(value, &arg_show_status);
if (r < 0)
log_warning("Failed to parse show status switch %s. Ignoring.", value);
log_warning_errno(r, "Failed to parse show status switch %s, ignoring: %m", value);
} else
arg_show_status = SHOW_STATUS_YES;
@ -421,7 +422,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
r = exec_output_from_string(value);
if (r < 0)
log_warning("Failed to parse default standard output switch %s. Ignoring.", value);
log_warning_errno(r, "Failed to parse default standard output switch %s, ignoring: %m", value);
else
arg_default_std_output = r;
@ -432,7 +433,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
r = exec_output_from_string(value);
if (r < 0)
log_warning("Failed to parse default standard error switch %s. Ignoring.", value);
log_warning_errno(r, "Failed to parse default standard error switch %s, ignoring: %m", value);
else
arg_default_std_error = r;
@ -459,7 +460,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
r = set_machine_id(value);
if (r < 0)
log_warning("MachineID '%s' is not valid. Ignoring.", value);
log_warning_errno(r, "MachineID '%s' is not valid, ignoring: %m", value);
} else if (proc_cmdline_key_streq(key, "systemd.default_timeout_start_sec")) {
@ -468,7 +469,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
r = parse_sec(value, &arg_default_timeout_start_usec);
if (r < 0)
log_warning_errno(r, "Failed to parse default start timeout: %s, ignoring.", value);
log_warning_errno(r, "Failed to parse default start timeout '%s', ignoring: %m", value);
if (arg_default_timeout_start_usec <= 0)
arg_default_timeout_start_usec = USEC_INFINITY;

View File

@ -1784,7 +1784,7 @@ static int mount_dispatch_io(sd_event_source *source, int fd, uint32_t revents,
if (r == 0)
rescan = true;
else if (r < 0)
return log_error_errno(r, "Failed to drain libmount events");
return log_error_errno(r, "Failed to drain libmount events: %m");
} while (r == 0);
log_debug("libmount event [rescan: %s]", yes_no(rescan));

View File

@ -2754,7 +2754,7 @@ static int service_deserialize_item(Unit *u, const char *key, const char *value,
r = cunescape(value, 0, &t);
if (r < 0)
log_unit_debug_errno(u, r, "Failed to unescape status text: %s", value);
log_unit_debug_errno(u, r, "Failed to unescape status text '%s': %m", value);
else
free_and_replace(s->status_text, t);
@ -2763,7 +2763,7 @@ static int service_deserialize_item(Unit *u, const char *key, const char *value,
r = manager_load_unit(u->manager, value, NULL, NULL, &socket);
if (r < 0)
log_unit_debug_errno(u, r, "Failed to load accept-socket unit: %s", value);
log_unit_debug_errno(u, r, "Failed to load accept-socket unit '%s': %m", value);
else {
unit_ref_set(&s->accept_socket, u, socket);
SOCKET(socket)->n_connections++;
@ -3735,7 +3735,7 @@ static void service_notify_message(
status_errno = parse_errno(e);
if (status_errno < 0)
log_unit_warning_errno(u, status_errno,
"Failed to parse ERRNO= field in notification message: %s", e);
"Failed to parse ERRNO= field value '%s' in notification message: %m", e);
else if (s->status_errno != status_errno) {
s->status_errno = status_errno;
notify_dbus = true;

View File

@ -77,14 +77,14 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_LOG_LEVEL:
r = log_set_max_level_from_string(optarg);
if (r < 0)
log_error_errno(r, "Failed to parse log level %s, ignoring.", optarg);
log_error_errno(r, "Failed to parse log level %s, ignoring: %m", optarg);
break;
case ARG_LOG_TARGET:
r = log_set_target_from_string(optarg);
if (r < 0)
log_error_errno(r, "Failed to parse log target %s, ignoring", optarg);
log_error_errno(r, "Failed to parse log target %s, ignoring: %m", optarg);
break;
@ -93,7 +93,7 @@ static int parse_argv(int argc, char *argv[]) {
if (optarg) {
r = log_show_color_from_string(optarg);
if (r < 0)
log_error_errno(r, "Failed to parse log color setting %s, ignoring", optarg);
log_error_errno(r, "Failed to parse log color setting %s, ignoring: %m", optarg);
} else
log_show_color(true);
@ -103,7 +103,7 @@ static int parse_argv(int argc, char *argv[]) {
if (optarg) {
r = log_show_location_from_string(optarg);
if (r < 0)
log_error_errno(r, "Failed to parse log location setting %s, ignoring", optarg);
log_error_errno(r, "Failed to parse log location setting %s, ignoring: %m", optarg);
} else
log_show_location(true);
@ -112,14 +112,14 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_EXIT_CODE:
r = safe_atou8(optarg, &arg_exit_code);
if (r < 0)
log_error_errno(r, "Failed to parse exit code %s, ignoring", optarg);
log_error_errno(r, "Failed to parse exit code %s, ignoring: %m", optarg);
break;
case ARG_TIMEOUT:
r = parse_sec(optarg, &arg_timeout);
if (r < 0)
log_error_errno(r, "Failed to parse shutdown timeout %s, ignoring", optarg);
log_error_errno(r, "Failed to parse shutdown timeout %s, ignoring: %m", optarg);
break;

View File

@ -106,7 +106,7 @@ static int write_access2_rules(const char* srcdir) {
if (write(isempty(acc2) ? load2_fd : change_fd, buf, strlen(buf)) < 0) {
if (r == 0)
r = -errno;
log_error_errno(errno, "Failed to write '%s' to '%s' in '%s'",
log_error_errno(errno, "Failed to write '%s' to '%s' in '%s': %m",
buf, isempty(acc2) ? "/sys/fs/smackfs/load2" : "/sys/fs/smackfs/change-rule", entry->d_name);
}
}
@ -181,7 +181,7 @@ static int write_cipso2_rules(const char* srcdir) {
if (write(cipso2_fd, buf, strlen(buf)) < 0) {
if (r == 0)
r = -errno;
log_error_errno(errno, "Failed to write '%s' to '/sys/fs/smackfs/cipso2' in '%s'",
log_error_errno(errno, "Failed to write '%s' to '/sys/fs/smackfs/cipso2' in '%s': %m",
buf, entry->d_name);
break;
}
@ -253,7 +253,7 @@ static int write_netlabel_rules(const char* srcdir) {
if (!fputs(buf, dst)) {
if (r == 0)
r = -EINVAL;
log_error_errno(errno, "Failed to write line to /sys/fs/smackfs/netlabel");
log_error_errno(errno, "Failed to write line to /sys/fs/smackfs/netlabel: %m");
break;
}
q = fflush_and_check(dst);
@ -410,7 +410,7 @@ int mac_smack_setup(bool *loaded_policy) {
log_info("Successfully wrote Smack onlycap list.");
break;
default:
log_emergency_errno(r, "Failed to write Smack onlycap list.");
log_emergency_errno(r, "Failed to write Smack onlycap list: %m");
return r;
}