coccinelle: also mark previous synthetic errnos as such

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2018-11-21 08:23:20 +01:00
parent baaa35ad70
commit 886cf317c4
8 changed files with 47 additions and 21 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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)

View File

@ -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);

View File

@ -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)

View File

@ -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;

View File

@ -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);

View File

@ -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)