From: Lennart Poettering Date: Tue, 8 Jul 2025 01:08:56 +0000 (+0200) Subject: tree-wide: switch a bunch of sd_bus_error_setf() to sd_bus_error_set() X-Git-Tag: v258-rc1~143 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a5ddad27959f226f19fa25dfb431041dd5d3a4ad;p=thirdparty%2Fsystemd.git tree-wide: switch a bunch of sd_bus_error_setf() to sd_bus_error_set() --- diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c index d1cb46a1690..b1e3df1688a 100644 --- a/src/core/dbus-execute.c +++ b/src/core/dbus-execute.c @@ -2402,8 +2402,8 @@ int bus_exec_context_set_transient_property( STRV_FOREACH(p, l) if (!isempty(*p) && !valid_user_group_name(*p, VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX|VALID_USER_WARN)) - return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, - "Invalid supplementary group names"); + return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, + "Invalid supplementary group names"); if (!UNIT_WRITE_FLAGS_NOOP(flags)) { if (strv_isempty(l)) { diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index 330d3cea2ea..1b8fd3a0570 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -989,7 +989,7 @@ static int transient_unit_from_message( t = unit_name_to_type(name); if (t < 0) return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, - "Invalid unit name or type."); + "Invalid unit name or type: %s", name); if (!unit_vtable[t]->can_transient) return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, @@ -1542,9 +1542,9 @@ static int method_reload(sd_bus_message *message, void *userdata, sd_bus_error * /* Check the rate limit after the authorization succeeds, to avoid denial-of-service issues. */ if (!ratelimit_below(&m->reload_reexec_ratelimit)) { log_warning("Reloading request rejected due to rate limit."); - return sd_bus_error_setf(error, - SD_BUS_ERROR_LIMITS_EXCEEDED, - "Reload() request rejected due to rate limit."); + return sd_bus_error_set(error, + SD_BUS_ERROR_LIMITS_EXCEEDED, + "Reload() request rejected due to rate limit."); } /* Instead of sending the reply back right away, we just @@ -1584,9 +1584,9 @@ static int method_reexecute(sd_bus_message *message, void *userdata, sd_bus_erro /* Check the rate limit after the authorization succeeds, to avoid denial-of-service issues. */ if (!ratelimit_below(&m->reload_reexec_ratelimit)) { log_warning("Reexecution request rejected due to rate limit."); - return sd_bus_error_setf(error, - SD_BUS_ERROR_LIMITS_EXCEEDED, - "Reexecute() request rejected due to rate limit."); + return sd_bus_error_set(error, + SD_BUS_ERROR_LIMITS_EXCEEDED, + "Reexecute() request rejected due to rate limit."); } /* We don't send a reply back here, the client should @@ -1883,8 +1883,8 @@ static int method_unset_environment(sd_bus_message *message, void *userdata, sd_ return r; if (!strv_env_name_or_assignment_is_valid(minus)) - return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, - "Invalid environment variable names or assignments"); + return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, + "Invalid environment variable names or assignments"); r = bus_verify_set_environment_async(m, message, error); if (r < 0) @@ -1919,11 +1919,11 @@ static int method_unset_and_set_environment(sd_bus_message *message, void *userd return r; if (!strv_env_name_or_assignment_is_valid(minus)) - return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, - "Invalid environment variable names or assignments"); + return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, + "Invalid environment variable names or assignments"); if (!strv_env_is_valid(plus)) - return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, - "Invalid environment assignments"); + return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, + "Invalid environment assignments"); r = bus_verify_set_environment_async(m, message, error); if (r < 0) @@ -1971,8 +1971,8 @@ static int method_lookup_dynamic_user_by_name(sd_bus_message *message, void *use return r; if (!MANAGER_IS_SYSTEM(m)) - return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, - "Dynamic users are only supported in the system instance."); + return sd_bus_error_set(error, SD_BUS_ERROR_NOT_SUPPORTED, + "Dynamic users are only supported in the system instance."); if (!valid_user_group_name(name, VALID_USER_RELAX)) return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "User name invalid: %s", name); @@ -2001,8 +2001,8 @@ static int method_lookup_dynamic_user_by_uid(sd_bus_message *message, void *user return r; if (!MANAGER_IS_SYSTEM(m)) - return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, - "Dynamic users are only supported in the system instance."); + return sd_bus_error_set(error, SD_BUS_ERROR_NOT_SUPPORTED, + "Dynamic users are only supported in the system instance."); if (!uid_is_valid(uid)) return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "User ID invalid: " UID_FMT, uid); @@ -2028,8 +2028,8 @@ static int method_get_dynamic_users(sd_bus_message *message, void *userdata, sd_ assert_cc(sizeof(uid_t) == sizeof(uint32_t)); if (!MANAGER_IS_SYSTEM(m)) - return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, - "Dynamic users are only supported in the system instance."); + return sd_bus_error_set(error, SD_BUS_ERROR_NOT_SUPPORTED, + "Dynamic users are only supported in the system instance."); r = sd_bus_message_new_method_return(message, &reply); if (r < 0) @@ -2046,8 +2046,8 @@ static int method_get_dynamic_users(sd_bus_message *message, void *userdata, sd_ if (r == -EAGAIN) /* not realized yet? */ continue; if (r < 0) - return sd_bus_error_setf(error, SD_BUS_ERROR_FAILED, - "Failed to look up a dynamic user."); + return sd_bus_error_set(error, SD_BUS_ERROR_FAILED, + "Failed to look up a dynamic user."); r = sd_bus_message_append(reply, "(us)", uid, d->name); if (r < 0) @@ -2229,7 +2229,7 @@ static int method_get_default_target(sd_bus_message *message, void *userdata, sd r = unit_file_get_default(m->runtime_scope, NULL, &default_target); if (r == -ERFKILL) - sd_bus_error_setf(error, BUS_ERROR_UNIT_MASKED, "Unit file is masked."); + return sd_bus_error_set(error, BUS_ERROR_UNIT_MASKED, "Default target unit file is masked."); if (r < 0) return r; diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c index dc5fbfbf2a8..0633e52bf66 100644 --- a/src/core/dbus-unit.c +++ b/src/core/dbus-unit.c @@ -1619,7 +1619,7 @@ int bus_unit_method_remove_subgroup(sd_bus_message *message, void *userdata, sd_ /* Allow this only if the client is privileged, is us, or is the user of the unit itself. */ if (sender_uid != 0 && sender_uid != getuid() && sender_uid != u->ref_uid) - return sd_bus_error_setf(error, SD_BUS_ERROR_ACCESS_DENIED, "Client is not permitted to alter cgroup."); + return sd_bus_error_set(error, SD_BUS_ERROR_ACCESS_DENIED, "Client is not permitted to alter cgroup."); r = unit_remove_subcgroup(u, path); if (r < 0) diff --git a/src/core/unit.c b/src/core/unit.c index ff6bac576de..4aad597fb0e 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -6078,7 +6078,7 @@ int unit_pid_attachable(Unit *u, PidRef *pid, sd_bus_error *error) { /* First, a simple range check */ if (!pidref_is_set(pid)) - return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Process identifier is not valid."); + return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Process identifier is not valid."); /* Some extra safety check */ if (pid->pid == 1 || pidref_is_self(pid)) diff --git a/src/home/homed-home-bus.c b/src/home/homed-home-bus.c index bec95aea6d3..f16756b32ef 100644 --- a/src/home/homed-home-bus.c +++ b/src/home/homed-home-bus.c @@ -442,7 +442,7 @@ int bus_home_update_record( return r; if ((flags & ~SD_HOMED_UPDATE_FLAGS_ALL) != 0) - return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid flags provided."); + return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid flags provided."); if (blobs) { const char *failed = NULL; diff --git a/src/home/homed-manager-bus.c b/src/home/homed-manager-bus.c index 9ffa758ee51..920153827a1 100644 --- a/src/home/homed-manager-bus.c +++ b/src/home/homed-manager-bus.c @@ -549,7 +549,7 @@ static int method_adopt_home( if (!path_is_absolute(image_path) || !path_is_safe(image_path)) return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Specified path is not absolute or not valid: %s", image_path); if (flags != 0) - return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Flags field must be zero."); + return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Flags field must be zero."); r = bus_verify_polkit_async( message, @@ -598,7 +598,7 @@ static int method_create_home(sd_bus_message *message, void *userdata, sd_bus_er if (r < 0) return r; if ((flags & ~SD_HOMED_CREATE_FLAGS_ALL) != 0) - return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid flags provided."); + return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid flags provided."); } r = bus_verify_polkit_async( @@ -963,11 +963,11 @@ static int method_add_signing_key(sd_bus_message *message, void *userdata, sd_bu return r; if (flags != 0) - return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Flags parameter must be zero."); + return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Flags parameter must be zero."); if (!valid_public_key_name(fn)) return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Public key name not valid: %s", fn); if (streq(fn, "local.public")) - return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Refusing to write local public key."); + return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Refusing to write local public key."); _cleanup_(EVP_PKEY_freep) EVP_PKEY *pkey = NULL; r = openssl_pubkey_from_pem(pem, /* pem_size= */ SIZE_MAX, &pkey); @@ -1040,13 +1040,13 @@ static int method_remove_signing_key(sd_bus_message *message, void *userdata, sd return r; if (flags != 0) - return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Flags parameter must be zero."); + return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Flags parameter must be zero."); if (!valid_public_key_name(fn)) return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Public key name not valid: %s", fn); if (streq(fn, "local.public")) - return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Refusing to remove local key."); + return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Refusing to remove local key."); if (!hashmap_contains(m->public_keys, fn)) return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Public key name does not exist: %s", fn); diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index eefd7b0f0d0..4e4ed92b204 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -128,10 +128,10 @@ static int get_sender_session( session = hashmap_get(m->sessions, name); if (!session) - return sd_bus_error_setf(error, BUS_ERROR_NO_SESSION_FOR_PID, - consult_display ? - "Caller does not belong to any known session and doesn't own any suitable session." : - "Caller does not belong to any known session."); + return sd_bus_error_set(error, BUS_ERROR_NO_SESSION_FOR_PID, + consult_display ? + "Caller does not belong to any known session and doesn't own any suitable session." : + "Caller does not belong to any known session."); *ret = session; return 0; @@ -183,8 +183,8 @@ static int get_sender_user(Manager *m, sd_bus_message *message, sd_bus_error *er user = hashmap_get(m->users, UID_TO_PTR(uid)); if (!user) - return sd_bus_error_setf(error, BUS_ERROR_NO_USER_FOR_PID, - "Caller does not belong to any logged in or lingering user"); + return sd_bus_error_set(error, BUS_ERROR_NO_USER_FOR_PID, + "Caller does not belong to any logged in or lingering user"); *ret = user; return 0; @@ -1183,31 +1183,31 @@ static int manager_create_session_by_bus( if (vtnr == 0) vtnr = (uint32_t) v; else if (vtnr != (uint32_t) v) - return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, - "Specified TTY and VT number do not match"); + return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, + "Specified TTY and VT number do not match"); } else if (tty_is_console(tty)) { if (!seat) seat = m->seat0; else if (seat != m->seat0) - return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, - "Console TTY specified but seat is not seat0"); + return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, + "Console TTY specified but seat is not seat0"); if (vtnr != 0) - return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, - "Console TTY specified but VT number is not 0"); + return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, + "Console TTY specified but VT number is not 0"); } if (seat) { if (seat_has_vts(seat)) { if (!vtnr_is_valid(vtnr)) - return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, - "VT number out of range"); + return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, + "VT number out of range"); } else { if (vtnr != 0) - return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, - "Seat has no VTs but VT number not 0"); + return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, + "Seat has no VTs but VT number not 0"); } } @@ -1229,7 +1229,7 @@ static int manager_create_session_by_bus( remote_host, &session); if (r == -EBUSY) - return sd_bus_error_setf(error, BUS_ERROR_SESSION_BUSY, "Already running in a session or user slice"); + return sd_bus_error_set(error, BUS_ERROR_SESSION_BUSY, "Already running in a session or user slice"); if (r == -EADDRNOTAVAIL) return sd_bus_error_set(error, BUS_ERROR_SESSION_BUSY, "Virtual terminal already occupied by a session"); if (r == -EUSERS) @@ -2240,8 +2240,8 @@ static int verify_shutdown_creds( if (!FLAGS_SET(flags, SD_LOGIND_SKIP_INHIBITORS) && (offending->mode != INHIBIT_BLOCK_WEAK || (uid == 0 && FLAGS_SET(flags, SD_LOGIND_ROOT_CHECK_INHIBITORS)))) - return sd_bus_error_setf(error, BUS_ERROR_BLOCKED_BY_INHIBITOR_LOCK, - "Operation denied due to active block inhibitor"); + return sd_bus_error_set(error, BUS_ERROR_BLOCKED_BY_INHIBITOR_LOCK, + "Operation denied due to active block inhibitor"); /* We want to always ask here, even for root, to only allow bypassing if explicitly allowed * by polkit, unless a weak blocker is used, in which case it will be authorized. */ @@ -3136,8 +3136,8 @@ static int method_set_reboot_parameter( if (r < 0) return r; if (r > 0) - return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, - "Reboot parameter not supported in containers, refusing."); + return sd_bus_error_set(error, SD_BUS_ERROR_NOT_SUPPORTED, + "Reboot parameter not supported in containers, refusing."); r = bus_verify_polkit_async( message, @@ -3801,16 +3801,16 @@ static int method_inhibit(sd_bus_message *message, void *userdata, sd_bus_error /* Delay is only supported for shutdown/sleep */ if (mm == INHIBIT_DELAY && (w & ~(INHIBIT_SHUTDOWN|INHIBIT_SLEEP))) - return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, - "Delay inhibitors only supported for shutdown and sleep"); + return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, + "Delay inhibitors only supported for shutdown and sleep"); /* Don't allow taking delay locks while we are already * executing the operation. We shouldn't create the impression * that the lock was successful if the machine is about to go * down/suspend any moment. */ if (m->delayed_action && m->delayed_action->inhibit_what & w) - return sd_bus_error_setf(error, BUS_ERROR_OPERATION_IN_PROGRESS, - "The operation inhibition has been requested for is already running"); + return sd_bus_error_set(error, BUS_ERROR_OPERATION_IN_PROGRESS, + "The operation inhibition has been requested for is already running"); BIT_FOREACH(i, w) { const InhibitWhat v = 1U << i; diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c index 70e7fa63c42..d7212ddecde 100644 --- a/src/login/logind-session-dbus.c +++ b/src/login/logind-session-dbus.c @@ -470,18 +470,18 @@ static int method_set_class(sd_bus_message *message, void *userdata, sd_bus_erro /* For now, we'll allow only upgrades user-incomplete → user */ if (class != SESSION_USER) - return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, - "Class may only be set to 'user'"); + return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, + "Class may only be set to 'user'"); if (s->class == SESSION_USER) /* No change, shortcut */ return sd_bus_reply_method_return(message, NULL); if (s->class != SESSION_USER_INCOMPLETE) - return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, - "Only sessions with class 'user-incomplete' may change class"); + return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, + "Only sessions with class 'user-incomplete' may change class"); if (s->upgrade_message) - return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, - "Set session class operation already in progress"); + return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, + "Set session class operation already in progress"); r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_EUID, &creds); if (r < 0)