1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-21 22:04:01 +03:00

varlink: split out varlink_dispatch_set_log_level()

No functional change, preparation for later commits.
This commit is contained in:
Yu Watanabe 2024-12-22 01:23:31 +09:00
parent 2069b8eeae
commit 7647b8b2c2
2 changed files with 20 additions and 7 deletions

View File

@ -31,18 +31,16 @@ int varlink_method_ping(sd_varlink *link, sd_json_variant *parameters, sd_varlin
return sd_varlink_reply(link, NULL);
}
int varlink_method_set_log_level(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) {
int varlink_dispatch_set_log_level(sd_varlink *link, sd_json_variant *parameters, int *ret_log_level) {
static const sd_json_dispatch_field dispatch_table[] = {
{ "level", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int64, 0, SD_JSON_MANDATORY },
{ "level", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int, 0, SD_JSON_MANDATORY },
{}
};
int64_t level;
uid_t uid;
int r;
int r, level;
assert(link);
assert(parameters);
assert(ret_log_level);
/* NOTE: The method does have 1 parameter, but we must compare to 2 here, because
* sd_json_variant_elements() breaks abstraction and exposes internal structure of JsonObject. */
@ -56,6 +54,20 @@ int varlink_method_set_log_level(sd_varlink *link, sd_json_variant *parameters,
if (LOG_PRI(level) != level)
return sd_varlink_error_invalid_parameter(link, parameters);
*ret_log_level = level;
return 0;
}
int varlink_method_set_log_level(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) {
int r, level;
uid_t uid;
assert(link);
r = varlink_dispatch_set_log_level(link, parameters, &level);
if (r < 0)
return r;
r = sd_varlink_get_peer_uid(link, &uid);
if (r < 0)
return r;
@ -63,7 +75,7 @@ int varlink_method_set_log_level(sd_varlink *link, sd_json_variant *parameters,
if (uid != getuid() && uid != 0)
return sd_varlink_error(link, SD_VARLINK_ERROR_PERMISSION_DENIED, parameters);
log_debug("Received io.systemd.Service.SetLogLevel(%" PRIi64 ")", level);
log_debug("Received io.systemd.Service.SetLogLevel(%i)", level);
log_set_max_level(level);

View File

@ -7,4 +7,5 @@
extern const sd_varlink_interface vl_interface_io_systemd_Service;
int varlink_method_ping(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata);
int varlink_dispatch_set_log_level(sd_varlink *link, sd_json_variant *parameters, int *ret_log_level);
int varlink_method_set_log_level(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata);