tree-wide: switch a bunch of sd_bus_error_setf() to sd_bus_error_set()

This commit is contained in:
Lennart Poettering
2025-07-08 06:00:33 +02:00
parent 3ef791876b
commit a5ddad2795
8 changed files with 64 additions and 64 deletions
+2 -2
View File
@@ -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)) {
+22 -22
View File
@@ -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;
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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))
+1 -1
View File
@@ -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;
+6 -6
View File
@@ -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);
+25 -25
View File
@@ -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;
+6 -6
View File
@@ -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)