From 886cf317c4cace1874e251e54bfe5d1e01d6591a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 21 Nov 2018 08:23:20 +0100 Subject: [PATCH] coccinelle: also mark previous synthetic errnos as such --- coccinelle/synthetic-errno.cocci | 7 ++++++ src/coredump/coredumpctl.c | 3 ++- src/id128/id128.c | 3 ++- src/libsystemd/sd-device/device-monitor.c | 27 +++++++++++++++-------- src/libsystemd/sd-event/event-util.c | 7 ++++-- src/tmpfiles/tmpfiles.c | 2 +- src/udev/udev-watch.c | 15 ++++++++----- src/udev/udevd.c | 4 ++-- 8 files changed, 47 insertions(+), 21 deletions(-) diff --git a/coccinelle/synthetic-errno.cocci b/coccinelle/synthetic-errno.cocci index c5533dd7fb..645bfc945f 100644 --- a/coccinelle/synthetic-errno.cocci +++ b/coccinelle/synthetic-errno.cocci @@ -33,3 +33,10 @@ expression list args; - log_emergency(args); - return -e; + return log_emergency_errno(SYNTHETIC_ERRNO(e), args); +@@ +identifier log_LEVEL_errno =~ "^log_(debug|info|notice|warning|error|emergency)_errno$"; +identifier ERRNO =~ "^E[A-Z]+$"; +expression list args; +@@ +- return log_LEVEL_errno(ERRNO, args); ++ return log_LEVEL_errno(SYNTHETIC_ERRNO(ERRNO), args); diff --git a/src/coredump/coredumpctl.c b/src/coredump/coredumpctl.c index 1f85d3deab..de26bee931 100644 --- a/src/coredump/coredumpctl.c +++ b/src/coredump/coredumpctl.c @@ -796,7 +796,8 @@ static int save_core(sd_journal *j, FILE *file, char **path, bool *unlink_temp) */ if (!file) { if (on_tty()) - return log_error_errno(ENOTTY, "Refusing to dump core to tty" + return log_error_errno(SYNTHETIC_ERRNO(ENOTTY), + "Refusing to dump core to tty" " (use shell redirection or specify --output)."); file = stdout; } diff --git a/src/id128/id128.c b/src/id128/id128.c index 3c40dd6e5d..06049e7ba2 100644 --- a/src/id128/id128.c +++ b/src/id128/id128.c @@ -52,7 +52,8 @@ static int verb_invocation_id(int argc, char **argv, void *userdata) { int r; if (!sd_id128_is_null(arg_app)) - return log_error_errno(EINVAL, "Verb \"invocation-id\" cannot be combined with --app-specific=."); + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "Verb \"invocation-id\" cannot be combined with --app-specific=."); r = sd_id128_get_invocation(&id); if (r < 0) diff --git a/src/libsystemd/sd-device/device-monitor.c b/src/libsystemd/sd-device/device-monitor.c index da99971b02..bb50257a0d 100644 --- a/src/libsystemd/sd-device/device-monitor.c +++ b/src/libsystemd/sd-device/device-monitor.c @@ -389,35 +389,42 @@ int device_monitor_receive_device(sd_device_monitor *m, sd_device **ret) { } if (buflen < 32 || (smsg.msg_flags & MSG_TRUNC)) - return log_debug_errno(EINVAL, "sd-device-monitor: Invalid message length."); + return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), + "sd-device-monitor: Invalid message length."); if (snl.nl.nl_groups == MONITOR_GROUP_NONE) { /* unicast message, check if we trust the sender */ if (m->snl_trusted_sender.nl.nl_pid == 0 || snl.nl.nl_pid != m->snl_trusted_sender.nl.nl_pid) - return log_debug_errno(EAGAIN, "sd-device-monitor: Unicast netlink message ignored."); + return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN), + "sd-device-monitor: Unicast netlink message ignored."); } else if (snl.nl.nl_groups == MONITOR_GROUP_KERNEL) { if (snl.nl.nl_pid > 0) - return log_debug_errno(EAGAIN, "sd-device-monitor: Multicast kernel netlink message from PID %"PRIu32" ignored.", snl.nl.nl_pid); + return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN), + "sd-device-monitor: Multicast kernel netlink message from PID %"PRIu32" ignored.", snl.nl.nl_pid); } cmsg = CMSG_FIRSTHDR(&smsg); if (!cmsg || cmsg->cmsg_type != SCM_CREDENTIALS) - return log_debug_errno(EAGAIN, "sd-device-monitor: No sender credentials received, message ignored."); + return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN), + "sd-device-monitor: No sender credentials received, message ignored."); cred = (struct ucred*) CMSG_DATA(cmsg); if (cred->uid != 0) - return log_debug_errno(EAGAIN, "sd-device-monitor: Sender uid="UID_FMT", message ignored.", cred->uid); + return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN), + "sd-device-monitor: Sender uid="UID_FMT", message ignored.", cred->uid); if (streq(buf.raw, "libudev")) { /* udev message needs proper version magic */ if (buf.nlh.magic != htobe32(UDEV_MONITOR_MAGIC)) - return log_debug_errno(EAGAIN, "sd-device-monitor: Invalid message signature (%x != %x)", + return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN), + "sd-device-monitor: Invalid message signature (%x != %x)", buf.nlh.magic, htobe32(UDEV_MONITOR_MAGIC)); if (buf.nlh.properties_off+32 > (size_t) buflen) - return log_debug_errno(EAGAIN, "sd-device-monitor: Invalid message length (%u > %zd)", + return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN), + "sd-device-monitor: Invalid message length (%u > %zd)", buf.nlh.properties_off+32, buflen); bufpos = buf.nlh.properties_off; @@ -429,11 +436,13 @@ int device_monitor_receive_device(sd_device_monitor *m, sd_device **ret) { /* kernel message with header */ bufpos = strlen(buf.raw) + 1; if ((size_t) bufpos < sizeof("a@/d") || bufpos >= buflen) - return log_debug_errno(EAGAIN, "sd-device-monitor: Invalid message length"); + return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN), + "sd-device-monitor: Invalid message length"); /* check message header */ if (!strstr(buf.raw, "@/")) - return log_debug_errno(EAGAIN, "sd-device-monitor: Invalid message header"); + return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN), + "sd-device-monitor: Invalid message header"); } r = device_new_from_nulstr(&device, (uint8_t*) &buf.raw[bufpos], buflen - bufpos); diff --git a/src/libsystemd/sd-event/event-util.c b/src/libsystemd/sd-event/event-util.c index 488a0230ea..43e73d55e1 100644 --- a/src/libsystemd/sd-event/event-util.c +++ b/src/libsystemd/sd-event/event-util.c @@ -42,8 +42,11 @@ int event_reset_time( return log_debug_errno(r, "sd-event: Failed to get clock id of event source \"%s\": %m", strna((*s)->description ?: description)); if (c != clock) - return log_debug_errno(EINVAL, "sd-event: Current clock id %i of event source \"%s\" is different from specified one %i.", - (int) c, strna((*s)->description ?: description), (int) clock); + return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), + "sd-event: Current clock id %i of event source \"%s\" is different from specified one %i.", + (int)c, + strna((*s)->description ? : description), + (int)clock); r = sd_event_source_set_time(*s, usec); if (r < 0) diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 6de06a8589..eeeb1d1850 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -989,7 +989,7 @@ static int parse_acls_from_arg(Item *item) { if (r < 0) log_warning_errno(r, "Failed to parse ACL \"%s\": %m. Ignoring", item->argument); #else - log_warning_errno(ENOSYS, "ACLs are not supported. Ignoring"); + log_warning_errno(SYNTHETIC_ERRNO(ENOSYS), "ACLs are not supported. Ignoring"); #endif return 0; diff --git a/src/udev/udev-watch.c b/src/udev/udev-watch.c index 3f8715709a..68b51d04a3 100644 --- a/src/udev/udev-watch.c +++ b/src/udev/udev-watch.c @@ -36,7 +36,8 @@ int udev_watch_restore(void) { int r; if (inotify_fd < 0) - return log_debug_errno(EINVAL, "Invalid inotify descriptor."); + return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), + "Invalid inotify descriptor."); if (rename("/run/udev/watch", "/run/udev/watch.old") < 0) { if (errno != ENOENT) @@ -86,7 +87,8 @@ int udev_watch_begin(sd_device *dev) { int wd, r; if (inotify_fd < 0) - return log_debug_errno(EINVAL, "Invalid inotify descriptor."); + return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), + "Invalid inotify descriptor."); r = sd_device_get_devname(dev, &devnode); if (r < 0) @@ -123,7 +125,8 @@ int udev_watch_end(sd_device *dev) { int wd, r; if (inotify_fd < 0) - return log_debug_errno(EINVAL, "Invalid inotify descriptor."); + return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), + "Invalid inotify descriptor."); r = device_get_watch_handle(dev, &wd); if (r == -ENOENT) @@ -150,10 +153,12 @@ int udev_watch_lookup(int wd, sd_device **ret) { assert(ret); if (inotify_fd < 0) - return log_debug_errno(EINVAL, "Invalid inotify descriptor."); + return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), + "Invalid inotify descriptor."); if (wd < 0) - return log_debug_errno(EINVAL, "Invalid watch handle."); + return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), + "Invalid watch handle."); xsprintf(filename, "/run/udev/watch/%d", wd); r = readlink_malloc(filename, &device); diff --git a/src/udev/udevd.c b/src/udev/udevd.c index 1f7b66c7da..6e7bd83d11 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -1612,11 +1612,11 @@ static int manager_new(Manager **ret, int fd_ctrl, int fd_uevent, const char *cg manager->rules = udev_rules_new(arg_resolve_name_timing); if (!manager->rules) - return log_error_errno(ENOMEM, "Failed to read udev rules"); + return log_error_errno(SYNTHETIC_ERRNO(ENOMEM), "Failed to read udev rules"); manager->ctrl = udev_ctrl_new_from_fd(fd_ctrl); if (!manager->ctrl) - return log_error_errno(EINVAL, "Failed to initialize udev control socket"); + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Failed to initialize udev control socket"); r = udev_ctrl_enable_receiving(manager->ctrl); if (r < 0)