Merge pull request #12871 from keszybz/various-printing-fixes

Various printing/logging fixes
This commit is contained in:
Yu Watanabe
2019-06-25 13:02:33 +09:00
committed by GitHub
4 changed files with 74 additions and 67 deletions
+14 -2
View File
@@ -25,6 +25,7 @@
#include "copy.h"
#include "dirent-util.h"
#include "efivars.h"
#include "escape.h"
#include "fd-util.h"
#include "fileio.h"
#include "fs-util.h"
@@ -377,13 +378,24 @@ static int boot_entry_show(const BootEntry *e, bool show_as_default) {
*s,
&status);
if (!strv_isempty(e->options)) {
_cleanup_free_ char *t;
_cleanup_free_ char *t = NULL, *t2 = NULL;
_cleanup_strv_free_ char **ts = NULL;
t = strv_join(e->options, " ");
if (!t)
return log_oom();
printf(" options: %s\n", t);
ts = strv_split_newlines(t);
if (!ts)
return log_oom();
t2 = strv_join(ts, "\n ");
if (!t2)
return log_oom();
printf(" options: %s\n", t2);
}
if (e->device_tree)
boot_entry_file_list("devicetree", e->root, e->device_tree, &status);
+25 -30
View File
@@ -61,12 +61,8 @@ int manager_handle_action(
int r;
assert(m);
/* If the key handling is turned off, don't do anything */
if (handle == HANDLE_IGNORE) {
log_debug("Refusing operation, as it is turned off.");
return 0;
}
/* We should be called only with valid actions different than HANDLE_IGNORE. */
assert(handle > HANDLE_IGNORE && handle < _HANDLE_ACTION_MAX);
if (inhibit_key == INHIBIT_HANDLE_LID_SWITCH) {
/* If the last system suspend or startup is too close,
@@ -82,7 +78,9 @@ int manager_handle_action(
/* If the key handling is inhibited, don't do anything */
if (inhibit_key > 0) {
if (manager_is_inhibited(m, inhibit_key, INHIBIT_BLOCK, NULL, true, false, 0, NULL)) {
log_debug("Refusing operation, %s is inhibited.", inhibit_what_to_string(inhibit_key));
log_debug("Refusing %s operation, %s is inhibited.",
handle_action_to_string(handle),
inhibit_what_to_string(inhibit_key));
return 0;
}
}
@@ -113,20 +111,21 @@ int manager_handle_action(
if (!supported && IN_SET(handle, HANDLE_HIBERNATE, HANDLE_HYBRID_SLEEP, HANDLE_SUSPEND_THEN_HIBERNATE)) {
supported = can_sleep("suspend") > 0;
if (supported) {
log_notice("Operation '%s' requested but not supported, using regular suspend instead.", handle_action_to_string(handle));
log_notice("Requested %s operation is not supported, using regular suspend instead.",
handle_action_to_string(handle));
handle = HANDLE_SUSPEND;
}
}
if (!supported) {
log_warning("Requested operation not supported, ignoring.");
return -EOPNOTSUPP;
}
if (!supported)
return log_warning_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"Requested %s operation not supported, ignoring.", handle_action_to_string(handle));
if (m->action_what > 0) {
log_debug("Action already in progress, ignoring.");
return -EALREADY;
}
if (m->action_what > 0)
return log_debug_errno(SYNTHETIC_ERRNO(EALREADY),
"Action already in progress (%s), ignoring requested %s operation.",
inhibit_what_to_string(m->action_what),
handle_action_to_string(handle));
assert_se(target = manager_target_for_action(handle));
@@ -143,27 +142,23 @@ int manager_handle_action(
u = uid_to_name(offending->uid);
/* If this is just a recheck of the lid switch then don't warn about anything */
if (!is_edge) {
log_debug("Refusing operation, %s is inhibited by UID "UID_FMT"/%s, PID "PID_FMT"/%s.",
inhibit_what_to_string(inhibit_operation),
offending->uid, strna(u),
offending->pid, strna(comm));
return 0;
}
log_full(is_edge ? LOG_ERR : LOG_DEBUG,
"Refusing %s operation, %s is inhibited by UID "UID_FMT"/%s, PID "PID_FMT"/%s.",
handle_action_to_string(handle),
inhibit_what_to_string(inhibit_operation),
offending->uid, strna(u),
offending->pid, strna(comm));
log_error("Refusing operation, %s is inhibited by UID "UID_FMT"/%s, PID "PID_FMT"/%s.",
inhibit_what_to_string(inhibit_operation),
offending->uid, strna(u),
offending->pid, strna(comm));
return -EPERM;
return is_edge ? -EPERM : 0;
}
log_info("%s", message_table[handle]);
r = bus_manager_shutdown_or_sleep_now_or_later(m, target, inhibit_operation, &error);
if (r < 0)
return log_error_errno(r, "Failed to execute operation: %s", bus_error_message(&error, r));
return log_error_errno(r, "Failed to execute %s operation: %s",
handle_action_to_string(handle),
bus_error_message(&error, r));
return 1;
}
+1 -1
View File
@@ -1021,7 +1021,7 @@ static int manager_dispatch_idle_action(sd_event_source *s, uint64_t t, void *us
if (n >= since.monotonic + m->idle_action_usec &&
(m->idle_action_not_before_usec <= 0 || n >= m->idle_action_not_before_usec + m->idle_action_usec)) {
log_info("System idle. Taking action.");
log_info("System idle. Doing %s operation.", handle_action_to_string(m->idle_action));
manager_handle_action(m, 0, m->idle_action, false, false);
m->idle_action_not_before_usec = n;
+34 -34
View File
@@ -499,7 +499,7 @@ int manager_rtnl_process_address(sd_netlink *rtnl, sd_netlink_message *message,
if (sd_netlink_message_is_error(message)) {
r = sd_netlink_message_get_errno(message);
if (r < 0)
log_warning_errno(r, "rtnl: failed to receive address, ignoring: %m");
log_warning_errno(r, "rtnl: failed to receive address message, ignoring: %m");
return 0;
}
@@ -509,49 +509,49 @@ int manager_rtnl_process_address(sd_netlink *rtnl, sd_netlink_message *message,
log_warning_errno(r, "rtnl: could not get message type, ignoring: %m");
return 0;
} else if (!IN_SET(type, RTM_NEWADDR, RTM_DELADDR)) {
log_warning("rtnl: received unexpected message type when processing address, ignoring");
log_warning("rtnl: received unexpected message type %d when processing address, ignoring.", type);
return 0;
}
r = sd_rtnl_message_addr_get_ifindex(message, &ifindex);
if (r < 0) {
log_warning_errno(r, "rtnl: could not get ifindex from address, ignoring: %m");
log_warning_errno(r, "rtnl: could not get ifindex from message, ignoring: %m");
return 0;
} else if (ifindex <= 0) {
log_warning("rtnl: received address message with invalid ifindex, ignoring: %d", ifindex);
return 0;
} else {
r = link_get(m, ifindex, &link);
if (r < 0 || !link) {
/* when enumerating we might be out of sync, but we will
* get the address again, so just ignore it */
if (!m->enumerating)
log_warning("rtnl: received address for nonexistent link (%d), ignoring", ifindex);
return 0;
}
}
r = link_get(m, ifindex, &link);
if (r < 0 || !link) {
/* when enumerating we might be out of sync, but we will get the address again, so just
* ignore it */
if (!m->enumerating)
log_warning("rtnl: received address for link %d we don't know about, ignoring", ifindex);
return 0;
}
r = sd_rtnl_message_addr_get_family(message, &family);
if (r < 0 || !IN_SET(family, AF_INET, AF_INET6)) {
log_link_warning(link, "rtnl: received address with invalid family, ignoring");
log_link_warning(link, "rtnl: received address message with invalid family, ignoring.");
return 0;
}
r = sd_rtnl_message_addr_get_prefixlen(message, &prefixlen);
if (r < 0) {
log_link_warning_errno(link, r, "rtnl: received address with invalid prefixlen, ignoring: %m");
log_link_warning_errno(link, r, "rtnl: received address message with invalid prefixlen, ignoring: %m");
return 0;
}
r = sd_rtnl_message_addr_get_scope(message, &scope);
if (r < 0) {
log_link_warning_errno(link, r, "rtnl: received address with invalid scope, ignoring: %m");
log_link_warning_errno(link, r, "rtnl: received address message with invalid scope, ignoring: %m");
return 0;
}
r = sd_rtnl_message_addr_get_flags(message, &flags);
if (r < 0) {
log_link_warning_errno(link, r, "rtnl: received address with invalid flags, ignoring: %m");
log_link_warning_errno(link, r, "rtnl: received address message with invalid flags, ignoring: %m");
return 0;
}
@@ -559,7 +559,7 @@ int manager_rtnl_process_address(sd_netlink *rtnl, sd_netlink_message *message,
case AF_INET:
r = sd_netlink_message_read_in_addr(message, IFA_LOCAL, &in_addr.in);
if (r < 0) {
log_link_warning_errno(link, r, "rtnl: received address without valid address, ignoring: %m");
log_link_warning_errno(link, r, "rtnl: received address message without valid address, ignoring: %m");
return 0;
}
@@ -568,7 +568,7 @@ int manager_rtnl_process_address(sd_netlink *rtnl, sd_netlink_message *message,
case AF_INET6:
r = sd_netlink_message_read_in6_addr(message, IFA_ADDRESS, &in_addr.in6);
if (r < 0) {
log_link_warning_errno(link, r, "rtnl: received address without valid address, ignoring: %m");
log_link_warning_errno(link, r, "rtnl: received address message without valid address, ignoring: %m");
return 0;
}
@@ -579,10 +579,8 @@ int manager_rtnl_process_address(sd_netlink *rtnl, sd_netlink_message *message,
}
r = in_addr_to_string(family, &in_addr, &buf);
if (r < 0) {
log_link_warning_errno(link, r, "Could not print address, ignoring: %m");
return 0;
}
if (r < 0)
log_link_warning_errno(link, r, "Could not print address: %m");
r = sd_netlink_message_read_cache_info(message, IFA_CACHEINFO, &cinfo);
if (r < 0 && r != -ENODATA) {
@@ -598,38 +596,40 @@ int manager_rtnl_process_address(sd_netlink *rtnl, sd_netlink_message *message,
switch (type) {
case RTM_NEWADDR:
if (address)
log_link_debug(link, "Updating address: %s/%u (valid %s%s)", buf, prefixlen,
log_link_debug(link, "Remembering updated address: %s/%u (valid %s%s)",
strnull(buf), prefixlen,
valid_str ? "for " : "forever", strempty(valid_str));
else {
/* An address appeared that we did not request */
r = address_add_foreign(link, family, &in_addr, prefixlen, &address);
if (r < 0) {
log_link_warning_errno(link, r, "Failed to add address %s/%u, ignoring: %m", buf, prefixlen);
log_link_warning_errno(link, r, "Failed to remember foreign address %s/%u, ignoring: %m",
strnull(buf), prefixlen);
return 0;
} else
log_link_debug(link, "Adding address: %s/%u (valid %s%s)", buf, prefixlen,
log_link_debug(link, "Remembering foreign address: %s/%u (valid %s%s)",
strnull(buf), prefixlen,
valid_str ? "for " : "forever", strempty(valid_str));
}
r = address_update(address, flags, scope, &cinfo);
if (r < 0) {
log_link_warning_errno(link, r, "Failed to update address %s/%u, ignoring: %m", buf, prefixlen);
return 0;
}
/* address_update() logs internally, so we don't need to. */
(void) address_update(address, flags, scope, &cinfo);
break;
case RTM_DELADDR:
if (address) {
log_link_debug(link, "Removing address: %s/%u (valid %s%s)", buf, prefixlen,
log_link_debug(link, "Forgetting address: %s/%u (valid %s%s)",
strnull(buf), prefixlen,
valid_str ? "for " : "forever", strempty(valid_str));
(void) address_drop(address);
} else
log_link_warning(link, "Removing non-existent address: %s/%u (valid %s%s), ignoring", buf, prefixlen,
valid_str ? "for " : "forever", strempty(valid_str));
log_link_info(link, "Kernel removed an address we don't remember: %s/%u (valid %s%s), ignoring.",
strnull(buf), prefixlen,
valid_str ? "for " : "forever", strempty(valid_str));
break;
default:
assert_not_reached("Received invalid RTNL message type");
}