1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-06 17:18:12 +03:00
This commit is contained in:
Yu Watanabe 2024-12-30 14:27:00 +00:00 committed by GitHub
commit 8e104f2257
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 29 additions and 16 deletions

View File

@ -192,9 +192,9 @@ shared_sources = files(
'varlink-io.systemd.PCRLock.c', 'varlink-io.systemd.PCRLock.c',
'varlink-io.systemd.Resolve.c', 'varlink-io.systemd.Resolve.c',
'varlink-io.systemd.Resolve.Monitor.c', 'varlink-io.systemd.Resolve.Monitor.c',
'varlink-io.systemd.Service.c',
'varlink-io.systemd.UserDatabase.c', 'varlink-io.systemd.UserDatabase.c',
'varlink-io.systemd.oom.c', 'varlink-io.systemd.oom.c',
'varlink-io.systemd.service.c',
'varlink-io.systemd.sysext.c', 'varlink-io.systemd.sysext.c',
'varlink-serialize.c', 'varlink-serialize.c',
'verb-log-control.c', 'verb-log-control.c',

View File

@ -3,7 +3,7 @@
#include <unistd.h> #include <unistd.h>
#include "macro.h" #include "macro.h"
#include "varlink-io.systemd.service.h" #include "varlink-io.systemd.Service.h"
static SD_VARLINK_DEFINE_METHOD(Ping); static SD_VARLINK_DEFINE_METHOD(Ping);
@ -14,8 +14,8 @@ static SD_VARLINK_DEFINE_METHOD(
SD_VARLINK_DEFINE_INPUT(level, SD_VARLINK_INT, 0)); SD_VARLINK_DEFINE_INPUT(level, SD_VARLINK_INT, 0));
SD_VARLINK_DEFINE_INTERFACE( SD_VARLINK_DEFINE_INTERFACE(
io_systemd_service, io_systemd_Service,
"io.systemd.service", "io.systemd.Service",
&vl_method_Ping, &vl_method_Ping,
&vl_method_Reload, &vl_method_Reload,
&vl_method_SetLogLevel); &vl_method_SetLogLevel);
@ -26,23 +26,21 @@ int varlink_method_ping(sd_varlink *link, sd_json_variant *parameters, sd_varlin
if (sd_json_variant_elements(parameters) > 0) if (sd_json_variant_elements(parameters) > 0)
return sd_varlink_error_invalid_parameter(link, parameters); return sd_varlink_error_invalid_parameter(link, parameters);
log_debug("Received io.systemd.service.Ping"); log_debug("Received io.systemd.Service.Ping");
return sd_varlink_reply(link, NULL); 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[] = { 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; int r, level;
uid_t uid;
int r;
assert(link); assert(link);
assert(parameters); assert(ret_log_level);
/* NOTE: The method does have 1 parameter, but we must compare to 2 here, because /* 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. */ * sd_json_variant_elements() breaks abstraction and exposes internal structure of JsonObject. */
@ -56,14 +54,28 @@ int varlink_method_set_log_level(sd_varlink *link, sd_json_variant *parameters,
if (LOG_PRI(level) != level) if (LOG_PRI(level) != level)
return sd_varlink_error_invalid_parameter(link, parameters); 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); r = sd_varlink_get_peer_uid(link, &uid);
if (r < 0) if (r < 0)
return r; return r;
if (uid != getuid() && uid != 0) if (uid != 0 && uid != getuid())
return sd_varlink_error(link, SD_VARLINK_ERROR_PERMISSION_DENIED, parameters); 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); log_set_max_level(level);

View File

@ -4,7 +4,8 @@
#include "sd-varlink.h" #include "sd-varlink.h"
#include "sd-varlink-idl.h" #include "sd-varlink-idl.h"
extern const sd_varlink_interface vl_interface_io_systemd_service; 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_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); int varlink_method_set_log_level(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata);

View File

@ -24,9 +24,9 @@
#include "varlink-io.systemd.PCRLock.h" #include "varlink-io.systemd.PCRLock.h"
#include "varlink-io.systemd.Resolve.h" #include "varlink-io.systemd.Resolve.h"
#include "varlink-io.systemd.Resolve.Monitor.h" #include "varlink-io.systemd.Resolve.Monitor.h"
#include "varlink-io.systemd.Service.h"
#include "varlink-io.systemd.UserDatabase.h" #include "varlink-io.systemd.UserDatabase.h"
#include "varlink-io.systemd.oom.h" #include "varlink-io.systemd.oom.h"
#include "varlink-io.systemd.service.h"
#include "varlink-io.systemd.sysext.h" #include "varlink-io.systemd.sysext.h"
#include "varlink-org.varlink.service.h" #include "varlink-org.varlink.service.h"
#include "varlink-util.h" #include "varlink-util.h"
@ -180,7 +180,7 @@ TEST(parse_format) {
print_separator(); print_separator();
test_parse_format_one(&vl_interface_io_systemd_PCRLock); test_parse_format_one(&vl_interface_io_systemd_PCRLock);
print_separator(); print_separator();
test_parse_format_one(&vl_interface_io_systemd_service); test_parse_format_one(&vl_interface_io_systemd_Service);
print_separator(); print_separator();
test_parse_format_one(&vl_interface_io_systemd_sysext); test_parse_format_one(&vl_interface_io_systemd_sysext);
print_separator(); print_separator();