diff --git a/shell-completion/bash/busctl b/shell-completion/bash/busctl index c357c25bc3..1ac8ac7eca 100644 --- a/shell-completion/bash/busctl +++ b/shell-completion/bash/busctl @@ -28,20 +28,23 @@ __contains_word () { __get_machines() { local a b - machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; }; + machinectl list --no-legend --no-pager 2>/dev/null | + { while read a b; do echo " $a"; done; }; } __get_busnames() { local mode=$1 local a b - busctl $mode list --no-legend --no-pager | { while read a b; do echo " $a"; done; }; + busctl $mode list --no-legend --no-pager 2>/dev/null | + { while read a b; do echo " $a"; done; }; } __get_objects() { local mode=$1 local busname=$2 local a b - busctl $mode tree --list --no-legend --no-pager $busname | { while read a b; do echo " $a"; done; }; + busctl $mode tree --list --no-legend --no-pager $busname 2>/dev/null | + { while read a b; do echo " $a"; done; }; } __get_interfaces() { @@ -49,7 +52,8 @@ __get_interfaces() { local busname=$2 local path=$3 local a b c - busctl $mode introspect --list --no-legend --no-pager $busname $path | { while read a b c; do [[ "$b" == "interface" ]] && echo " $a"; done; }; + busctl $mode introspect --list --no-legend --no-pager $busname $path 2>/dev/null | + { while read a b c; do [[ "$b" == "interface" ]] && echo " $a"; done; }; } __get_members() { @@ -60,7 +64,9 @@ __get_members() { local type=$5 local flags=$6 local a b c d e - busctl $mode introspect --list --no-legend --no-pager $busname $path $interface | sed -e 's/^\.//' | { while read a b c d e; do [[ "$b" == "$type" && ( -z $flags || "$e" == "$flags" ) ]] && echo " $a"; done; }; + busctl $mode introspect --list --no-legend --no-pager $busname $path $interface 2>/dev/null | + sed -e 's/^\.//' | + { while read a b c d e; do [[ "$b" == "$type" && ( -z $flags || "$e" == "$flags" ) ]] && echo " $a"; done; }; } __get_signature() { @@ -70,7 +76,8 @@ __get_signature() { local interface=$4 local member=$5 local a b c d - busctl $mode introspect --list --no-legend --no-pager $busname $path $interface | sed -e 's/^\.//' | { while read a b c d; do [[ "$a" == "$member" && "$c" != '-' ]] && echo " \"$c\""; done; }; + busctl $mode introspect --list --no-legend --no-pager $busname $path $interface 2>/dev/null | + sed -e 's/^\.//' | { while read a b c d; do [[ "$a" == "$member" && "$c" != '-' ]] && echo " \"$c\""; done; }; } _busctl() { diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index 7d788515cc..fc220b4808 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -242,7 +242,7 @@ int fchmod_umask(int fd, mode_t m) { } int fchmod_opath(int fd, mode_t m) { - char procfs_path[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(int)]; + char procfs_path[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int)]; /* This function operates also on fd that might have been opened with * O_PATH. Indeed fchmodat() doesn't have the AT_EMPTY_PATH flag like diff --git a/src/basic/ratelimit.c b/src/basic/ratelimit.c index 6598b1a812..6804364f30 100644 --- a/src/basic/ratelimit.c +++ b/src/basic/ratelimit.c @@ -13,7 +13,7 @@ /* Modelled after Linux' lib/ratelimit.c by Dave Young * , which is licensed GPLv2. */ -bool ratelimit_test(RateLimit *r) { +bool ratelimit_below(RateLimit *r) { usec_t ts; assert(r); diff --git a/src/basic/ratelimit.h b/src/basic/ratelimit.h index 6abab8f290..5a9aeb6486 100644 --- a/src/basic/ratelimit.h +++ b/src/basic/ratelimit.h @@ -43,4 +43,4 @@ typedef struct RateLimit { _r->begin = 0; \ } while (false) -bool ratelimit_test(RateLimit *r); +bool ratelimit_below(RateLimit *r); diff --git a/src/core/dbus.c b/src/core/dbus.c index 9e39d8ab7f..4df898f963 100644 --- a/src/core/dbus.c +++ b/src/core/dbus.c @@ -230,7 +230,6 @@ static int mac_selinux_filter(sd_bus_message *message, void *userdata, sd_bus_er path = sd_bus_message_get_path(message); if (object_path_startswith("/org/freedesktop/systemd1", path)) { - r = mac_selinux_access_check(message, verb, error); if (r < 0) return r; @@ -258,7 +257,6 @@ static int mac_selinux_filter(sd_bus_message *message, void *userdata, sd_bus_er else manager_load_unit_from_dbus_path(m, path, NULL, &u); } - if (!u) return 0; diff --git a/src/core/device.c b/src/core/device.c index 3387820a6d..a775e8bb95 100644 --- a/src/core/device.c +++ b/src/core/device.c @@ -845,7 +845,7 @@ static int device_dispatch_io(sd_event_source *source, int fd, uint32_t revents, if (revents != EPOLLIN) { static RATELIMIT_DEFINE(limit, 10*USEC_PER_SEC, 5); - if (ratelimit_test(&limit)) + if (ratelimit_below(&limit)) log_warning("Failed to get udev event"); if (!(revents & EPOLLIN)) return 0; diff --git a/src/core/manager.c b/src/core/manager.c index 4a2f68b567..204fc8b819 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -2338,7 +2338,7 @@ static void manager_handle_ctrl_alt_del(Manager *m) { * 7 times within 2s, we reboot/shutdown immediately, * unless it was disabled in system.conf */ - if (ratelimit_test(&m->ctrl_alt_del_ratelimit) || m->cad_burst_action == EMERGENCY_ACTION_NONE) + if (ratelimit_below(&m->ctrl_alt_del_ratelimit) || m->cad_burst_action == EMERGENCY_ACTION_NONE) manager_start_target(m, SPECIAL_CTRL_ALT_DEL_TARGET, JOB_REPLACE_IRREVERSIBLY); else emergency_action(m, m->cad_burst_action, NULL, @@ -2633,7 +2633,7 @@ int manager_loop(Manager *m) { if (m->runtime_watchdog > 0 && m->runtime_watchdog != USEC_INFINITY && MANAGER_IS_SYSTEM(m)) watchdog_ping(); - if (!ratelimit_test(&rl)) { + if (!ratelimit_below(&rl)) { /* Yay, something is going seriously wrong, pause a little */ log_warning("Looping too fast. Throttling execution a little."); sleep(1); @@ -2697,12 +2697,19 @@ int manager_load_unit_from_dbus_path(Manager *m, const char *s, sd_bus_error *e, return 0; } - return sd_bus_error_setf(e, BUS_ERROR_NO_UNIT_FOR_INVOCATION_ID, "No unit with the specified invocation ID " SD_ID128_FORMAT_STR " known.", SD_ID128_FORMAT_VAL(invocation_id)); + return sd_bus_error_setf(e, BUS_ERROR_NO_UNIT_FOR_INVOCATION_ID, + "No unit with the specified invocation ID " SD_ID128_FORMAT_STR " known.", + SD_ID128_FORMAT_VAL(invocation_id)); } /* If this didn't work, we check if this is a unit name */ - if (!unit_name_is_valid(n, UNIT_NAME_PLAIN|UNIT_NAME_INSTANCE)) - return sd_bus_error_setf(e, SD_BUS_ERROR_INVALID_ARGS, "Unit name %s is neither a valid invocation ID nor unit name.", n); + if (!unit_name_is_valid(n, UNIT_NAME_PLAIN|UNIT_NAME_INSTANCE)) { + _cleanup_free_ char *nn = NULL; + + nn = cescape(n); + return sd_bus_error_setf(e, SD_BUS_ERROR_INVALID_ARGS, + "Unit name %s is neither a valid invocation ID nor unit name.", strnull(nn)); + } r = manager_load_unit(m, n, NULL, e, &u); if (r < 0) diff --git a/src/core/socket.c b/src/core/socket.c index 15a7c13149..45c49eac49 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -2245,7 +2245,7 @@ static void socket_enter_running(Socket *s, int cfd) { return; } - if (!ratelimit_test(&s->trigger_limit)) { + if (!ratelimit_below(&s->trigger_limit)) { safe_close(cfd); log_unit_warning(UNIT(s), "Trigger limit hit, refusing further activation."); socket_enter_stop_pre(s, SOCKET_FAILURE_TRIGGER_LIMIT_HIT); diff --git a/src/core/unit.c b/src/core/unit.c index c7320240f7..2567365937 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -1696,7 +1696,7 @@ void unit_status_emit_starting_stopping_reloading(Unit *u, JobType t) { int unit_start_limit_test(Unit *u) { assert(u); - if (ratelimit_test(&u->start_limit)) { + if (ratelimit_below(&u->start_limit)) { u->start_limit_hit = false; return 0; } @@ -1989,7 +1989,7 @@ static void unit_check_unneeded(Unit *u) { /* If stopping a unit fails continuously we might enter a stop * loop here, hence stop acting on the service being * unnecessary after a while. */ - if (!ratelimit_test(&u->auto_stop_ratelimit)) { + if (!ratelimit_below(&u->auto_stop_ratelimit)) { log_unit_warning(u, "Unit not needed anymore, but not stopping since we tried this too often recently."); return; } @@ -2039,7 +2039,7 @@ static void unit_check_binds_to(Unit *u) { /* If stopping a unit fails continuously we might enter a stop * loop here, hence stop acting on the service being * unnecessary after a while. */ - if (!ratelimit_test(&u->auto_stop_ratelimit)) { + if (!ratelimit_below(&u->auto_stop_ratelimit)) { log_unit_warning(u, "Unit is bound to inactive unit %s, but not stopping since we tried this too often recently.", other->id); return; } diff --git a/src/import/export-raw.c b/src/import/export-raw.c index 2ae146fd32..c9070acf20 100644 --- a/src/import/export-raw.c +++ b/src/import/export-raw.c @@ -126,7 +126,7 @@ static void raw_export_report_progress(RawExport *e) { if (percent == e->last_percent) return; - if (!ratelimit_test(&e->progress_rate_limit)) + if (!ratelimit_below(&e->progress_rate_limit)) return; sd_notifyf(false, "X_IMPORT_PROGRESS=%u", percent); diff --git a/src/import/export-tar.c b/src/import/export-tar.c index 72c48c68d7..4c60854972 100644 --- a/src/import/export-tar.c +++ b/src/import/export-tar.c @@ -134,7 +134,7 @@ static void tar_export_report_progress(TarExport *e) { if (percent == e->last_percent) return; - if (!ratelimit_test(&e->progress_rate_limit)) + if (!ratelimit_below(&e->progress_rate_limit)) return; sd_notifyf(false, "X_IMPORT_PROGRESS=%u", percent); diff --git a/src/import/import-raw.c b/src/import/import-raw.c index 6b79d8f170..02ff289c1a 100644 --- a/src/import/import-raw.c +++ b/src/import/import-raw.c @@ -149,7 +149,7 @@ static void raw_import_report_progress(RawImport *i) { if (percent == i->last_percent) return; - if (!ratelimit_test(&i->progress_rate_limit)) + if (!ratelimit_below(&i->progress_rate_limit)) return; sd_notifyf(false, "X_IMPORT_PROGRESS=%u", percent); diff --git a/src/import/import-tar.c b/src/import/import-tar.c index 81b96662d3..2e748c629d 100644 --- a/src/import/import-tar.c +++ b/src/import/import-tar.c @@ -156,7 +156,7 @@ static void tar_import_report_progress(TarImport *i) { if (percent == i->last_percent) return; - if (!ratelimit_test(&i->progress_rate_limit)) + if (!ratelimit_below(&i->progress_rate_limit)) return; sd_notifyf(false, "X_IMPORT_PROGRESS=%u", percent); diff --git a/src/resolve/resolved-dns-scope.c b/src/resolve/resolved-dns-scope.c index 395dd2c5f4..763789c450 100644 --- a/src/resolve/resolved-dns-scope.c +++ b/src/resolve/resolved-dns-scope.c @@ -221,7 +221,7 @@ static int dns_scope_emit_one(DnsScope *s, int fd, DnsPacket *p) { if (DNS_PACKET_QDCOUNT(p) > 1) return -EOPNOTSUPP; - if (!ratelimit_test(&s->ratelimit)) + if (!ratelimit_below(&s->ratelimit)) return -EBUSY; family = s->family; @@ -246,7 +246,7 @@ static int dns_scope_emit_one(DnsScope *s, int fd, DnsPacket *p) { case DNS_PROTOCOL_MDNS: assert(fd < 0); - if (!ratelimit_test(&s->ratelimit)) + if (!ratelimit_below(&s->ratelimit)) return -EBUSY; family = s->family; @@ -759,7 +759,7 @@ void dns_scope_process_query(DnsScope *s, DnsStream *stream, DnsPacket *p) { } else { int fd; - if (!ratelimit_test(&s->ratelimit)) + if (!ratelimit_below(&s->ratelimit)) return; if (p->family == AF_INET) diff --git a/src/resolve/resolved-mdns.c b/src/resolve/resolved-mdns.c index e27b0f4b70..f54a204c93 100644 --- a/src/resolve/resolved-mdns.c +++ b/src/resolve/resolved-mdns.c @@ -251,7 +251,7 @@ static int mdns_scope_process_query(DnsScope *s, DnsPacket *p) { if (r < 0) return log_debug_errno(r, "Failed to build reply packet: %m"); - if (!ratelimit_test(&s->ratelimit)) + if (!ratelimit_below(&s->ratelimit)) return 0; r = dns_scope_emit_udp(s, -1, reply); diff --git a/src/test/test-ratelimit.c b/src/test/test-ratelimit.c index 3871452232..7001e82178 100644 --- a/src/test/test-ratelimit.c +++ b/src/test/test-ratelimit.c @@ -11,24 +11,24 @@ #include "ratelimit.h" #include "time-util.h" -static void test_ratelimit_test(void) { +static void test_ratelimit_below(void) { int i; RATELIMIT_DEFINE(ratelimit, 1 * USEC_PER_SEC, 10); for (i = 0; i < 10; i++) - assert_se(ratelimit_test(&ratelimit)); - assert_se(!ratelimit_test(&ratelimit)); + assert_se(ratelimit_below(&ratelimit)); + assert_se(!ratelimit_below(&ratelimit)); sleep(1); for (i = 0; i < 10; i++) - assert_se(ratelimit_test(&ratelimit)); + assert_se(ratelimit_below(&ratelimit)); RATELIMIT_INIT(ratelimit, 0, 10); for (i = 0; i < 10000; i++) - assert_se(ratelimit_test(&ratelimit)); + assert_se(ratelimit_below(&ratelimit)); } int main(int argc, char *argv[]) { - test_ratelimit_test(); + test_ratelimit_below(); return 0; } diff --git a/src/timesync/timesyncd-manager.c b/src/timesync/timesyncd-manager.c index 4f639577ad..f76f07e655 100644 --- a/src/timesync/timesyncd-manager.c +++ b/src/timesync/timesyncd-manager.c @@ -804,7 +804,7 @@ int manager_connect(Manager *m) { manager_disconnect(m); m->event_retry = sd_event_source_unref(m->event_retry); - if (!ratelimit_test(&m->ratelimit)) { + if (!ratelimit_below(&m->ratelimit)) { log_debug("Slowing down attempts to contact servers."); r = sd_event_add_time(m->event, &m->event_retry, clock_boottime_or_monotonic(), now(clock_boottime_or_monotonic()) + RETRY_USEC, 0, manager_retry_connect, m); diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 672405897b..9a9cfdd8a2 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -1307,7 +1307,7 @@ static int item_do(Item *i, int fd, const struct stat *st, fdaction_t action) { r = action(i, fd, st); if (S_ISDIR(st->st_mode)) { - char procfs_path[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(int)]; + char procfs_path[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int)]; _cleanup_closedir_ DIR *d = NULL; struct dirent *de;