diff options
-rw-r--r-- | src/core/bpf-firewall.c | 10 | ||||
-rw-r--r-- | src/core/cgroup.c | 16 | ||||
-rw-r--r-- | src/core/service.c | 16 | ||||
-rw-r--r-- | src/core/slice.c | 6 | ||||
-rw-r--r-- | src/core/swap.c | 4 | ||||
-rw-r--r-- | src/core/transaction.c | 15 | ||||
-rw-r--r-- | src/core/unit.h | 26 | ||||
-rw-r--r-- | src/libsystemd/sd-device/device-util.h | 28 | ||||
-rw-r--r-- | src/network/networkd-dhcp6.c | 2 | ||||
-rw-r--r-- | src/network/networkd-link.c | 12 | ||||
-rw-r--r-- | src/shared/log-link.h | 24 | ||||
-rw-r--r-- | src/udev/net/link-config.c | 3 | ||||
-rw-r--r-- | src/udev/udev-builtin-keyboard.c | 6 | ||||
-rw-r--r-- | src/udev/udev-builtin-uaccess.c | 4 | ||||
-rw-r--r-- | src/udev/udev-event.c | 2 | ||||
-rw-r--r-- | src/udev/udev-node.c | 22 | ||||
-rw-r--r-- | src/udev/udev-rules.c | 61 | ||||
-rw-r--r-- | src/udev/udev-watch.c | 6 |
18 files changed, 136 insertions, 127 deletions
diff --git a/src/core/bpf-firewall.c b/src/core/bpf-firewall.c index 5671d0c195..5da0106a33 100644 --- a/src/core/bpf-firewall.c +++ b/src/core/bpf-firewall.c @@ -899,11 +899,11 @@ void emit_bpf_firewall_warning(Unit *u) { if (!warned) { bool quiet = bpf_firewall_unsupported_reason == -EPERM && detect_container(); - log_unit_full(u, quiet ? LOG_DEBUG : LOG_WARNING, bpf_firewall_unsupported_reason, - "unit configures an IP firewall, but %s.\n" - "(This warning is only shown for the first unit using IP firewalling.)", - getuid() != 0 ? "not running as root" : - "the local system does not support BPF/cgroup firewalling"); + log_unit_full_errno(u, quiet ? LOG_DEBUG : LOG_WARNING, bpf_firewall_unsupported_reason, + "unit configures an IP firewall, but %s.\n" + "(This warning is only shown for the first unit using IP firewalling.)", + getuid() != 0 ? "not running as root" : + "the local system does not support BPF/cgroup firewalling"); warned = true; } } diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 962f821925..8b97d1514e 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -78,8 +78,8 @@ static int set_attribute_and_warn(Unit *u, const char *controller, const char *a r = cg_set_attribute(controller, u->cgroup_path, attribute, value); if (r < 0) - log_unit_full(u, LOG_LEVEL_CGROUP_WRITE(r), r, "Failed to set '%s' attribute on '%s' to '%.*s': %m", - strna(attribute), isempty(u->cgroup_path) ? "/" : u->cgroup_path, (int) strcspn(value, NEWLINE), value); + log_unit_full_errno(u, LOG_LEVEL_CGROUP_WRITE(r), r, "Failed to set '%s' attribute on '%s' to '%.*s': %m", + strna(attribute), isempty(u->cgroup_path) ? "/" : u->cgroup_path, (int) strcspn(value, NEWLINE), value); return r; } @@ -724,7 +724,7 @@ static usec_t cgroup_cpu_adjust_period_and_log(Unit *u, usec_t period, usec_t qu if (new_period != period) { char v[FORMAT_TIMESPAN_MAX]; - log_unit_full(u, u->warned_clamping_cpu_quota_period ? LOG_DEBUG : LOG_WARNING, 0, + log_unit_full(u, u->warned_clamping_cpu_quota_period ? LOG_DEBUG : LOG_WARNING, "Clamping CPU interval for cpu.max: period is now %s", format_timespan(v, sizeof(v), new_period, 1)); u->warned_clamping_cpu_quota_period = true; @@ -986,8 +986,8 @@ static int cgroup_apply_devices(Unit *u) { else r = cg_set_attribute("devices", path, "devices.allow", "a"); if (r < 0) - log_unit_full(u, IN_SET(r, -ENOENT, -EROFS, -EINVAL, -EACCES, -EPERM) ? LOG_DEBUG : LOG_WARNING, r, - "Failed to reset devices.allow/devices.deny: %m"); + log_unit_full_errno(u, IN_SET(r, -ENOENT, -EROFS, -EINVAL, -EACCES, -EPERM) ? LOG_DEBUG : LOG_WARNING, r, + "Failed to reset devices.allow/devices.deny: %m"); } bool allow_list_static = policy == CGROUP_DEVICE_POLICY_CLOSED || @@ -1351,8 +1351,8 @@ static void cgroup_context_apply( else r = 0; if (r < 0) - log_unit_full(u, LOG_LEVEL_CGROUP_WRITE(r), r, - "Failed to write to tasks limit sysctls: %m"); + log_unit_full_errno(u, LOG_LEVEL_CGROUP_WRITE(r), r, + "Failed to write to tasks limit sysctls: %m"); } /* The attribute itself is not available on the host root cgroup, and in the container case we want to @@ -2435,7 +2435,7 @@ void unit_prune_cgroup(Unit *u) { * the containing slice is stopped. So even if we failed now, this unit shouldn't assume * that the cgroup is still realized the next time it is started. Do not return early * on error, continue cleanup. */ - log_unit_full(u, r == -EBUSY ? LOG_DEBUG : LOG_WARNING, r, "Failed to destroy cgroup %s, ignoring: %m", u->cgroup_path); + log_unit_full_errno(u, r == -EBUSY ? LOG_DEBUG : LOG_WARNING, r, "Failed to destroy cgroup %s, ignoring: %m", u->cgroup_path); if (is_root_slice) return; diff --git a/src/core/service.c b/src/core/service.c index 14c90c26df..03493fd04b 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -918,17 +918,17 @@ static int service_is_suitable_main_pid(Service *s, pid_t pid, int prio) { * good */ if (pid == getpid_cached() || pid == 1) { - log_unit_full(UNIT(s), prio, 0, "New main PID "PID_FMT" is the manager, refusing.", pid); + log_unit_full(UNIT(s), prio, "New main PID "PID_FMT" is the manager, refusing.", pid); return -EPERM; } if (pid == s->control_pid) { - log_unit_full(UNIT(s), prio, 0, "New main PID "PID_FMT" is the control process, refusing.", pid); + log_unit_full(UNIT(s), prio, "New main PID "PID_FMT" is the control process, refusing.", pid); return -EPERM; } if (!pid_is_alive(pid)) { - log_unit_full(UNIT(s), prio, 0, "New main PID "PID_FMT" does not exist or is a zombie.", pid); + log_unit_full(UNIT(s), prio, "New main PID "PID_FMT" does not exist or is a zombie.", pid); return -ESRCH; } @@ -958,16 +958,16 @@ static int service_load_pid_file(Service *s, bool may_warn) { r = chase_symlinks(s->pid_file, NULL, CHASE_SAFE, NULL, &fd); if (r == -ENOLINK) { - log_unit_full(UNIT(s), LOG_DEBUG, r, - "Potentially unsafe symlink chain, will now retry with relaxed checks: %s", s->pid_file); + log_unit_debug_errno(UNIT(s), r, + "Potentially unsafe symlink chain, will now retry with relaxed checks: %s", s->pid_file); questionable_pid_file = true; r = chase_symlinks(s->pid_file, NULL, 0, NULL, &fd); } if (r < 0) - return log_unit_full(UNIT(s), prio, fd, - "Can't open PID file %s (yet?) after %s: %m", s->pid_file, service_state_to_string(s->state)); + return log_unit_full_errno(UNIT(s), prio, fd, + "Can't open PID file %s (yet?) after %s: %m", s->pid_file, service_state_to_string(s->state)); /* Let's read the PID file now that we chased it down. But we need to convert the O_PATH fd * chase_symlinks() returned us into a proper fd first. */ @@ -980,7 +980,7 @@ static int service_load_pid_file(Service *s, bool may_warn) { r = parse_pid(k, &pid); if (r < 0) - return log_unit_full(UNIT(s), prio, r, "Failed to parse PID from file %s: %m", s->pid_file); + return log_unit_full_errno(UNIT(s), prio, r, "Failed to parse PID from file %s: %m", s->pid_file); if (s->main_pid_known && pid == s->main_pid) return 0; diff --git a/src/core/slice.c b/src/core/slice.c index aa7e7555e5..49541aacab 100644 --- a/src/core/slice.c +++ b/src/core/slice.c @@ -381,8 +381,10 @@ static int slice_freezer_action(Unit *s, FreezerAction action) { assert(s); assert(IN_SET(action, FREEZER_FREEZE, FREEZER_THAW)); - if (!slice_freezer_action_supported_by_children(s)) - return log_unit_warning(s, "Requested freezer operation is not supported by all children of the slice"); + if (!slice_freezer_action_supported_by_children(s)) { + log_unit_warning(s, "Requested freezer operation is not supported by all children of the slice"); + return 0; + } HASHMAP_FOREACH_KEY(v, member, s->dependencies[UNIT_BEFORE]) { if (UNIT_DEREF(member->slice) != s) diff --git a/src/core/swap.c b/src/core/swap.c index e8bf0ad12d..fa600a9797 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -284,8 +284,8 @@ static int swap_load_devnode(Swap *s) { r = device_new_from_stat_rdev(&d, &st); if (r < 0) { - log_unit_full(UNIT(s), r == -ENOENT ? LOG_DEBUG : LOG_WARNING, r, - "Failed to allocate device for swap %s: %m", s->what); + log_unit_full_errno(UNIT(s), r == -ENOENT ? LOG_DEBUG : LOG_WARNING, r, + "Failed to allocate device for swap %s: %m", s->what); return 0; } diff --git a/src/core/transaction.c b/src/core/transaction.c index ab07c80f1d..6cf305f4b5 100644 --- a/src/core/transaction.c +++ b/src/core/transaction.c @@ -998,10 +998,9 @@ int transaction_add_job_and_dependencies( SET_FOREACH(dep, following) { r = transaction_add_job_and_dependencies(tr, type, dep, ret, false, false, false, ignore_order, e); if (r < 0) { - log_unit_full(dep, - r == -ERFKILL ? LOG_INFO : LOG_WARNING, - r, "Cannot add dependency job, ignoring: %s", - bus_error_message(e, r)); + log_unit_full_errno(dep, r == -ERFKILL ? LOG_INFO : LOG_WARNING, r, + "Cannot add dependency job, ignoring: %s", + bus_error_message(e, r)); sd_bus_error_free(e); } } @@ -1035,10 +1034,10 @@ int transaction_add_job_and_dependencies( r = transaction_add_job_and_dependencies(tr, JOB_START, dep, ret, false, false, false, ignore_order, e); if (r < 0) { /* unit masked, job type not applicable and unit not found are not considered as errors. */ - log_unit_full(dep, - IN_SET(r, -ERFKILL, -EBADR, -ENOENT) ? LOG_DEBUG : LOG_WARNING, - r, "Cannot add dependency job, ignoring: %s", - bus_error_message(e, r)); + log_unit_full_errno(dep, + IN_SET(r, -ERFKILL, -EBADR, -ENOENT) ? LOG_DEBUG : LOG_WARNING, + r, "Cannot add dependency job, ignoring: %s", + bus_error_message(e, r)); sd_bus_error_free(e); } } diff --git a/src/core/unit.h b/src/core/unit.h index 5a75136e3d..2205b7b163 100644 --- a/src/core/unit.h +++ b/src/core/unit.h @@ -896,7 +896,7 @@ int unit_thaw_vtable_common(Unit *u); /* Macros which append UNIT= or USER_UNIT= to the message */ -#define log_unit_full(unit, level, error, ...) \ +#define log_unit_full_errno(unit, level, error, ...) \ ({ \ const Unit *_u = (unit); \ (log_get_max_level() < LOG_PRI(level)) ? -ERRNO_VALUE(error) : \ @@ -904,17 +904,19 @@ int unit_thaw_vtable_common(Unit *u); log_internal(level, error, PROJECT_FILE, __LINE__, __func__, ##__VA_ARGS__); \ }) -#define log_unit_debug(unit, ...) log_unit_full(unit, LOG_DEBUG, 0, ##__VA_ARGS__) -#define log_unit_info(unit, ...) log_unit_full(unit, LOG_INFO, 0, ##__VA_ARGS__) -#define log_unit_notice(unit, ...) log_unit_full(unit, LOG_NOTICE, 0, ##__VA_ARGS__) -#define log_unit_warning(unit, ...) log_unit_full(unit, LOG_WARNING, 0, ##__VA_ARGS__) -#define log_unit_error(unit, ...) log_unit_full(unit, LOG_ERR, 0, ##__VA_ARGS__) - -#define log_unit_debug_errno(unit, error, ...) log_unit_full(unit, LOG_DEBUG, error, ##__VA_ARGS__) -#define log_unit_info_errno(unit, error, ...) log_unit_full(unit, LOG_INFO, error, ##__VA_ARGS__) -#define log_unit_notice_errno(unit, error, ...) log_unit_full(unit, LOG_NOTICE, error, ##__VA_ARGS__) -#define log_unit_warning_errno(unit, error, ...) log_unit_full(unit, LOG_WARNING, error, ##__VA_ARGS__) -#define log_unit_error_errno(unit, error, ...) log_unit_full(unit, LOG_ERR, error, ##__VA_ARGS__) +#define log_unit_full(unit, level, ...) (void) log_unit_full_errno(unit, level, 0, __VA_ARGS__) + +#define log_unit_debug(unit, ...) log_unit_full_errno(unit, LOG_DEBUG, 0, __VA_ARGS__) +#define log_unit_info(unit, ...) log_unit_full(unit, LOG_INFO, __VA_ARGS__) +#define log_unit_notice(unit, ...) log_unit_full(unit, LOG_NOTICE, __VA_ARGS__) +#define log_unit_warning(unit, ...) log_unit_full(unit, LOG_WARNING, __VA_ARGS__) +#define log_unit_error(unit, ...) log_unit_full(unit, LOG_ERR, __VA_ARGS__) + +#define log_unit_debug_errno(unit, error, ...) log_unit_full_errno(unit, LOG_DEBUG, error, __VA_ARGS__) +#define log_unit_info_errno(unit, error, ...) log_unit_full_errno(unit, LOG_INFO, error, __VA_ARGS__) +#define log_unit_notice_errno(unit, error, ...) log_unit_full_errno(unit, LOG_NOTICE, error, __VA_ARGS__) +#define log_unit_warning_errno(unit, error, ...) log_unit_full_errno(unit, LOG_WARNING, error, __VA_ARGS__) +#define log_unit_error_errno(unit, error, ...) log_unit_full_errno(unit, LOG_ERR, error, __VA_ARGS__) #define LOG_UNIT_MESSAGE(unit, fmt, ...) "MESSAGE=%s: " fmt, (unit)->id, ##__VA_ARGS__ #define LOG_UNIT_ID(unit) (unit)->manager->unit_log_format_string, (unit)->id diff --git a/src/libsystemd/sd-device/device-util.h b/src/libsystemd/sd-device/device-util.h index eda0f2f49e..032d1dc8b8 100644 --- a/src/libsystemd/sd-device/device-util.h +++ b/src/libsystemd/sd-device/device-util.h @@ -36,7 +36,7 @@ device; \ device = sd_device_enumerator_get_subsystem_next(enumerator)) -#define log_device_full(device, level, error, ...) \ +#define log_device_full_errno(device, level, error, ...) \ ({ \ const char *_sysname = NULL; \ sd_device *_d = (device); \ @@ -46,17 +46,19 @@ (void) sd_device_get_sysname(_d, &_sysname); \ log_object_internal(_level, _error, PROJECT_FILE, __LINE__, __func__, \ _sysname ? "DEVICE=" : NULL, _sysname, \ - NULL, NULL, ##__VA_ARGS__); \ + NULL, NULL, __VA_ARGS__); \ }) -#define log_device_debug(device, ...) log_device_full(device, LOG_DEBUG, 0, ##__VA_ARGS__) -#define log_device_info(device, ...) log_device_full(device, LOG_INFO, 0, ##__VA_ARGS__) -#define log_device_notice(device, ...) log_device_full(device, LOG_NOTICE, 0, ##__VA_ARGS__) -#define log_device_warning(device, ...) log_device_full(device, LOG_WARNING, 0, ##__VA_ARGS__) -#define log_device_error(device, ...) log_device_full(device, LOG_ERR, 0, ##__VA_ARGS__) - -#define log_device_debug_errno(device, error, ...) log_device_full(device, LOG_DEBUG, error, ##__VA_ARGS__) -#define log_device_info_errno(device, error, ...) log_device_full(device, LOG_INFO, error, ##__VA_ARGS__) -#define log_device_notice_errno(device, error, ...) log_device_full(device, LOG_NOTICE, error, ##__VA_ARGS__) -#define log_device_warning_errno(device, error, ...) log_device_full(device, LOG_WARNING, error, ##__VA_ARGS__) -#define log_device_error_errno(device, error, ...) log_device_full(device, LOG_ERR, error, ##__VA_ARGS__) +#define log_device_full(device, level, ...) (void) log_device_full_errno(device, level, 0, __VA_ARGS__) + +#define log_device_debug(device, ...) log_device_full_errno(device, LOG_DEBUG, 0, __VA_ARGS__) +#define log_device_info(device, ...) log_device_full(device, LOG_INFO, __VA_ARGS__) +#define log_device_notice(device, ...) log_device_full(device, LOG_NOTICE, __VA_ARGS__) +#define log_device_warning(device, ...) log_device_full(device, LOG_WARNING, __VA_ARGS__) +#define log_device_error(device, ...) log_device_full(device, LOG_ERR, __VA_ARGS__) + +#define log_device_debug_errno(device, error, ...) log_device_full_errno(device, LOG_DEBUG, error, __VA_ARGS__) +#define log_device_info_errno(device, error, ...) log_device_full_errno(device, LOG_INFO, error, __VA_ARGS__) +#define log_device_notice_errno(device, error, ...) log_device_full_errno(device, LOG_NOTICE, error, __VA_ARGS__) +#define log_device_warning_errno(device, error, ...) log_device_full_errno(device, LOG_WARNING, error, __VA_ARGS__) +#define log_device_error_errno(device, error, ...) log_device_full_errno(device, LOG_ERR, error, __VA_ARGS__) diff --git a/src/network/networkd-dhcp6.c b/src/network/networkd-dhcp6.c index 839f51b254..05fe679fcf 100644 --- a/src/network/networkd-dhcp6.c +++ b/src/network/networkd-dhcp6.c @@ -983,7 +983,7 @@ static int dhcp6_update_address( addr->cinfo.ifa_valid = lifetime_valid; (void) in_addr_to_string(addr->family, &addr->in_addr, &buffer); - log_link_full(link, set_contains(link->dhcp6_addresses, addr) ? LOG_DEBUG : LOG_INFO, 0, + log_link_full(link, set_contains(link->dhcp6_addresses, addr) ? LOG_DEBUG : LOG_INFO, "DHCPv6 address %s/%u timeout preferred %d valid %d", strna(buffer), addr->prefixlen, lifetime_preferred, lifetime_valid); diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index a1c961442e..47af15b6b3 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -4660,10 +4660,10 @@ int log_link_message_full_errno(Link *link, sd_netlink_message *m, int level, in const char *err_msg = NULL; (void) sd_netlink_message_read_string(m, NLMSGERR_ATTR_MSG, &err_msg); - return log_link_full(link, level, err, - "%s: %s%s%s%m", - msg, - strempty(err_msg), - err_msg && !endswith(err_msg, ".") ? "." : "", - err_msg ? " " : ""); + return log_link_full_errno(link, level, err, + "%s: %s%s%s%m", + msg, + strempty(err_msg), + err_msg && !endswith(err_msg, ".") ? "." : "", + err_msg ? " " : ""); } diff --git a/src/shared/log-link.h b/src/shared/log-link.h index 2d03802690..b844f9ef81 100644 --- a/src/shared/log-link.h +++ b/src/shared/log-link.h @@ -14,24 +14,26 @@ * See, network/networkd-link.h for example. */ -#define log_link_full(link, level, error, ...) \ +#define log_link_full_errno(link, level, error, ...) \ ({ \ const Link *_l = (link); \ (_l && _l->ifname) ? log_object_internal(level, error, PROJECT_FILE, __LINE__, __func__, "INTERFACE=", _l->ifname, NULL, NULL, ##__VA_ARGS__) : \ log_internal(level, error, PROJECT_FILE, __LINE__, __func__, ##__VA_ARGS__); \ }) \ -#define log_link_debug(link, ...) log_link_full(link, LOG_DEBUG, 0, ##__VA_ARGS__) -#define log_link_info(link, ...) log_link_full(link, LOG_INFO, 0, ##__VA_ARGS__) -#define log_link_notice(link, ...) log_link_full(link, LOG_NOTICE, 0, ##__VA_ARGS__) -#define log_link_warning(link, ...) log_link_full(link, LOG_WARNING, 0, ##__VA_ARGS__) -#define log_link_error(link, ...) log_link_full(link, LOG_ERR, 0, ##__VA_ARGS__) +#define log_link_full(link, level, ...) (void) log_link_full_errno(link, level, 0, __VA_ARGS__) -#define log_link_debug_errno(link, error, ...) log_link_full(link, LOG_DEBUG, error, ##__VA_ARGS__) -#define log_link_info_errno(link, error, ...) log_link_full(link, LOG_INFO, error, ##__VA_ARGS__) -#define log_link_notice_errno(link, error, ...) log_link_full(link, LOG_NOTICE, error, ##__VA_ARGS__) -#define log_link_warning_errno(link, error, ...) log_link_full(link, LOG_WARNING, error, ##__VA_ARGS__) -#define log_link_error_errno(link, error, ...) log_link_full(link, LOG_ERR, error, ##__VA_ARGS__) +#define log_link_debug(link, ...) log_link_full_errno(link, LOG_DEBUG, 0, __VA_ARGS__) +#define log_link_info(link, ...) log_link_full(link, LOG_INFO, __VA_ARGS__) +#define log_link_notice(link, ...) log_link_full(link, LOG_NOTICE, __VA_ARGS__) +#define log_link_warning(link, ...) log_link_full(link, LOG_WARNING, __VA_ARGS__) +#define log_link_error(link, ...) log_link_full(link, LOG_ERR, __VA_ARGS__) + +#define log_link_debug_errno(link, error, ...) log_link_full_errno(link, LOG_DEBUG, error, __VA_ARGS__) +#define log_link_info_errno(link, error, ...) log_link_full_errno(link, LOG_INFO, error, __VA_ARGS__) +#define log_link_notice_errno(link, error, ...) log_link_full_errno(link, LOG_NOTICE, error, __VA_ARGS__) +#define log_link_warning_errno(link, error, ...) log_link_full_errno(link, LOG_WARNING, error, __VA_ARGS__) +#define log_link_error_errno(link, error, ...) log_link_full_errno(link, LOG_ERR, error, __VA_ARGS__) #define LOG_LINK_MESSAGE(link, fmt, ...) "MESSAGE=%s: " fmt, (link)->ifname, ##__VA_ARGS__ #define LOG_LINK_INTERFACE(link) "INTERFACE=%s", (link)->ifname diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index 72ef0c56be..03fd429b27 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -320,7 +320,8 @@ static int get_mac(sd_device *device, MACAddressPolicy policy, struct ether_addr case NET_ADDR_PERM: break; default: - return log_device_warning(device, "Unknown addr_assign_type %u, ignoring", addr_type); + log_device_warning(device, "Unknown addr_assign_type %u, ignoring", addr_type); + return 0; } if (want_random == (addr_type == NET_ADDR_RANDOM)) diff --git a/src/udev/udev-builtin-keyboard.c b/src/udev/udev-builtin-keyboard.c index bb82e8ae97..eb980cb980 100644 --- a/src/udev/udev-builtin-keyboard.c +++ b/src/udev/udev-builtin-keyboard.c @@ -87,7 +87,7 @@ static int map_keycode(sd_device *dev, int fd, int scancode, const char *keycode return 0; } -static char* parse_token(const char *current, int32_t *val_out) { +static const char* parse_token(const char *current, int32_t *val_out) { char *next; int32_t val; @@ -109,7 +109,7 @@ static char* parse_token(const char *current, int32_t *val_out) { static int override_abs(sd_device *dev, int fd, unsigned evcode, const char *value) { struct input_absinfo absinfo; - char *next; + const char *next; int r; r = ioctl(fd, EVIOCGABS(evcode), &absinfo); @@ -122,7 +122,7 @@ static int override_abs(sd_device *dev, int fd, unsigned evcode, const char *val next = parse_token(next, &absinfo.fuzz); next = parse_token(next, &absinfo.flat); if (!next) - return log_device_error(dev, "Failed to parse EV_ABS override '%s'", value); + return log_device_error_errno(dev, SYNTHETIC_ERRNO(EINVAL), "Failed to parse EV_ABS override '%s'", value); log_device_debug(dev, "keyboard: %x overridden with %"PRIi32"/%"PRIi32"/%"PRIi32"/%"PRIi32"/%"PRIi32, evcode, absinfo.minimum, absinfo.maximum, absinfo.resolution, absinfo.fuzz, absinfo.flat); diff --git a/src/udev/udev-builtin-uaccess.c b/src/udev/udev-builtin-uaccess.c index 63401a570e..d552316eee 100644 --- a/src/udev/udev-builtin-uaccess.c +++ b/src/udev/udev-builtin-uaccess.c @@ -50,7 +50,7 @@ static int builtin_uaccess(sd_device *dev, int argc, char *argv[], bool test) { r = devnode_acl(path, true, false, 0, true, uid); if (r < 0) { - log_device_full(dev, r == -ENOENT ? LOG_DEBUG : LOG_ERR, r, "Failed to apply ACL: %m"); + log_device_full_errno(dev, r == -ENOENT ? LOG_DEBUG : LOG_ERR, r, "Failed to apply ACL: %m"); goto finish; } @@ -64,7 +64,7 @@ finish: /* Better be safe than sorry and reset ACL */ k = devnode_acl(path, true, false, 0, false, 0); if (k < 0) { - log_device_full(dev, k == -ENOENT ? LOG_DEBUG : LOG_ERR, k, "Failed to apply ACL: %m"); + log_device_full_errno(dev, k == -ENOENT ? LOG_DEBUG : LOG_ERR, k, "Failed to apply ACL: %m"); if (r >= 0) r = k; } diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c index 3fe4ac7e6a..e7208c62b0 100644 --- a/src/udev/udev-event.c +++ b/src/udev/udev-event.c @@ -633,7 +633,7 @@ static int on_spawn_sigchld(sd_event_source *s, const siginfo_t *si, void *userd if (si->si_status == 0) log_device_debug(spawn->device, "Process '%s' succeeded.", spawn->cmd); else - log_device_full(spawn->device, spawn->accept_failure ? LOG_DEBUG : LOG_WARNING, 0, + log_device_full(spawn->device, spawn->accept_failure ? LOG_DEBUG : LOG_WARNING, "Process '%s' failed with exit code %i.", spawn->cmd, si->si_status); ret = si->si_status; break; diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c index 541d48189f..bc259dd6f6 100644 --- a/src/udev/udev-node.c +++ b/src/udev/udev-node.c @@ -324,13 +324,13 @@ static int node_permissions_apply(sd_device *dev, bool apply_mac, r = chmod_and_chown(devnode, mode, uid, gid); if (r < 0) - log_device_full(dev, r == -ENOENT ? LOG_DEBUG : LOG_ERR, r, - "Failed to set owner/mode of %s to uid=" UID_FMT - ", gid=" GID_FMT ", mode=%#o: %m", - devnode, - uid_is_valid(uid) ? uid : stats.st_uid, - gid_is_valid(gid) ? gid : stats.st_gid, - mode != MODE_INVALID ? mode & 0777 : stats.st_mode & 0777); + log_device_full_errno(dev, r == -ENOENT ? LOG_DEBUG : LOG_ERR, r, + "Failed to set owner/mode of %s to uid=" UID_FMT + ", gid=" GID_FMT ", mode=%#o: %m", + devnode, + uid_is_valid(uid) ? uid : stats.st_uid, + gid_is_valid(gid) ? gid : stats.st_gid, + mode != MODE_INVALID ? mode & 0777 : stats.st_mode & 0777); } else log_device_debug(dev, "Preserve permissions of %s, uid=" UID_FMT ", gid=" GID_FMT ", mode=%#o", devnode, @@ -347,8 +347,8 @@ static int node_permissions_apply(sd_device *dev, bool apply_mac, q = mac_selinux_apply(devnode, label); if (q < 0) - log_device_full(dev, q == -ENOENT ? LOG_DEBUG : LOG_ERR, q, - "SECLABEL: failed to set SELinux label '%s': %m", label); + log_device_full_errno(dev, q == -ENOENT ? LOG_DEBUG : LOG_ERR, q, + "SECLABEL: failed to set SELinux label '%s': %m", label); else log_device_debug(dev, "SECLABEL: set SELinux label '%s'", label); @@ -357,8 +357,8 @@ static int node_permissions_apply(sd_device *dev, bool apply_mac, q = mac_smack_apply(devnode, SMACK_ATTR_ACCESS, label); if (q < 0) - log_device_full(dev, q == -ENOENT ? LOG_DEBUG : LOG_ERR, q, - "SECLABEL: failed to set SMACK label '%s': %m", label); + log_device_full_errno(dev, q == -ENOENT ? LOG_DEBUG : LOG_ERR, q, + "SECLABEL: failed to set SMACK label '%s': %m", label); else log_device_debug(dev, "SECLABEL: set SMACK label '%s'", label); diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index 018478c986..437429a3e0 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -182,43 +182,46 @@ struct UdevRules { /*** Logging helpers ***/ -#define log_rule_full(device, rules, level, error, fmt, ...) \ +#define log_rule_full_errno(device, rules, level, error, fmt, ...) \ ({ \ UdevRules *_r = (rules); \ UdevRuleFile *_f = _r ? _r->current_file : NULL; \ UdevRuleLine *_l = _f ? _f->current_line : NULL; \ const char *_n = _f ? _f->filename : NULL; \ \ - log_device_full(device, level, error, "%s:%u " fmt, \ - strna(_n), _l ? _l->line_number : 0, \ - ##__VA_ARGS__); \ + log_device_full_errno(device, level, error, "%s:%u " fmt, \ + strna(_n), _l ? _l->line_number : 0, \ + ##__VA_ARGS__); \ }) -#define log_rule_debug(device, rules, ...) log_rule_full(device, rules, LOG_DEBUG, 0, ##__VA_ARGS__) -#define log_rule_info(device, rules, ...) log_rule_full(device, rules, LOG_INFO, 0, ##__VA_ARGS__) -#define log_rule_notice(device, rules, ...) log_rule_full(device, rules, LOG_NOTICE, 0, ##__VA_ARGS__) -#define log_rule_warning(device, rules, ...) log_rule_full(device, rules, LOG_WARNING, 0, ##__VA_ARGS__) -#define log_rule_error(device, rules, ...) log_rule_full(device, rules, LOG_ERR, 0, ##__VA_ARGS__) - -#define log_rule_debug_errno(device, rules, error, ...) log_rule_full(device, rules, LOG_DEBUG, error, ##__VA_ARGS__) -#define log_rule_info_errno(device, rules, error, ...) log_rule_full(device, rules, LOG_INFO, error, ##__VA_ARGS__) -#define log_rule_notice_errno(device, rules, error, ...) log_rule_full(device, rules, LOG_NOTICE, error, ##__VA_ARGS__) -#define log_rule_warning_errno(device, rules, error, ...) log_rule_full(device, rules, LOG_WARNING, error, ##__VA_ARGS__) -#define log_rule_error_errno(device, rules, error, ...) log_rule_full(device, rules, LOG_ERR, error, ##__VA_ARGS__) - -#define log_token_full(rules, ...) log_rule_full(NULL, rules, ##__VA_ARGS__) - -#define log_token_debug(rules, ...) log_token_full(rules, LOG_DEBUG, 0, ##__VA_ARGS__) -#define log_token_info(rules, ...) log_token_full(rules, LOG_INFO, 0, ##__VA_ARGS__) -#define log_token_notice(rules, ...) log_token_full(rules, LOG_NOTICE, 0, ##__VA_ARGS__) -#define log_token_warning(rules, ...) log_token_full(rules, LOG_WARNING, 0, ##__VA_ARGS__) -#define log_token_error(rules, ...) log_token_full(rules, LOG_ERR, 0, ##__VA_ARGS__) - -#define log_token_debug_errno(rules, error, ...) log_token_full(rules, LOG_DEBUG, error, ##__VA_ARGS__) -#define log_token_info_errno(rules, error, ...) log_token_full(rules, LOG_INFO, error, ##__VA_ARGS__) -#define log_token_notice_errno(rules, error, ...) log_token_full(rules, LOG_NOTICE, error, ##__VA_ARGS__) -#define log_token_warning_errno(rules, error, ...) log_token_full(rules, LOG_WARNING, error, ##__VA_ARGS__) -#define log_token_error_errno(rules, error, ...) log_token_full(rules, LOG_ERR, error, ##__VA_ARGS__) +#define log_rule_full(device, rules, level, ...) (void) log_rule_full_errno(device, rules, level, 0, __VA_ARGS__) + +#define log_rule_debug(device, rules, ...) log_rule_full_errno(device, rules, LOG_DEBUG, 0, __VA_ARGS__) +#define log_rule_info(device, rules, ...) log_rule_full(device, rules, LOG_INFO, __VA_ARGS__) +#define log_rule_notice(device, rules, ...) log_rule_full(device, rules, LOG_NOTICE, __VA_ARGS__) +#define log_rule_warning(device, rules, ...) log_rule_full(device, rules, LOG_WARNING, __VA_ARGS__) +#define log_rule_error(device, rules, ...) log_rule_full(device, rules, LOG_ERR, __VA_ARGS__) + +#define log_rule_debug_errno(device, rules, error, ...) log_rule_full_errno(device, rules, LOG_DEBUG, error, __VA_ARGS__) +#define log_rule_info_errno(device, rules, error, ...) log_rule_full_errno(device, rules, LOG_INFO, error, __VA_ARGS__) +#define log_rule_notice_errno(device, rules, error, ...) log_rule_full_errno(device, rules, LOG_NOTICE, error, __VA_ARGS__) +#define log_rule_warning_errno(device, rules, error, ...) log_rule_full_errno(device, rules, LOG_WARNING, error, __VA_ARGS__) +#define log_rule_error_errno(device, rules, error, ...) log_rule_full_errno(device, rules, LOG_ERR, error, __VA_ARGS__) + +#define log_token_full_errno(rules, level, error, ...) log_rule_full_errno(NULL, rules, level, error, __VA_ARGS__) +#define log_token_full(rules, level, ...) (void) log_token_full_errno(rules, level, 0, __VA_ARGS__) + +#define log_token_debug(rules, ...) log_token_full_errno(rules, LOG_DEBUG, 0, __VA_ARGS__) +#define log_token_info(rules, ...) log_token_full(rules, LOG_INFO, __VA_ARGS__) +#define log_token_notice(rules, ...) log_token_full(rules, LOG_NOTICE, __VA_ARGS__) +#define log_token_warning(rules, ...) log_token_full(rules, LOG_WARNING, __VA_ARGS__) +#define log_token_error(rules, ...) log_token_full(rules, LOG_ERR, __VA_ARGS__) + +#define log_token_debug_errno(rules, error, ...) log_token_full_errno(rules, LOG_DEBUG, error, __VA_ARGS__) +#define log_token_info_errno(rules, error, ...) log_token_full_errno(rules, LOG_INFO, error, __VA_ARGS__) +#define log_token_notice_errno(rules, error, ...) log_token_full_errno(rules, LOG_NOTICE, error, __VA_ARGS__) +#define log_token_warning_errno(rules, error, ...) log_token_full_errno(rules, LOG_WARNING, error, __VA_ARGS__) +#define log_token_error_errno(rules, error, ...) log_token_full_errno(rules, LOG_ERR, error, __VA_ARGS__) #define _log_token_invalid(rules, key, type) \ log_token_error_errno(rules, SYNTHETIC_ERRNO(EINVAL), \ diff --git a/src/udev/udev-watch.c b/src/udev/udev-watch.c index 96a25ddf7c..d87a43537c 100644 --- a/src/udev/udev-watch.c +++ b/src/udev/udev-watch.c @@ -97,10 +97,8 @@ int udev_watch_begin(sd_device *dev) { log_device_debug(dev, "Adding watch on '%s'", devnode); wd = inotify_add_watch(inotify_fd, devnode, IN_CLOSE_WRITE); if (wd < 0) - return log_device_full(dev, - errno == ENOENT ? LOG_DEBUG : LOG_ERR, - errno, - "Failed to add device '%s' to watch: %m", devnode); + return log_device_full_errno(dev, errno == ENOENT ? LOG_DEBUG : LOG_ERR, errno, + "Failed to add device '%s' to watch: %m", devnode); device_set_watch_handle(dev, wd); |