mirror of
https://github.com/systemd/systemd.git
synced 2024-12-26 03:22:00 +03:00
varlink: add generic impl. of io.systemd.service.SetLogLevel()
This commit is contained in:
parent
ca46756cd8
commit
1263055121
@ -1,5 +1,7 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "varlink-io.systemd.service.h"
|
||||
|
||||
static VARLINK_DEFINE_METHOD(Ping);
|
||||
@ -27,3 +29,42 @@ int varlink_method_ping(Varlink *link, JsonVariant *parameters, VarlinkMethodFla
|
||||
|
||||
return varlink_reply(link, NULL);
|
||||
}
|
||||
|
||||
int varlink_method_set_log_level(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) {
|
||||
static const JsonDispatch dispatch_table[] = {
|
||||
{"level", JSON_VARIANT_INTEGER, json_dispatch_int64, 0, JSON_MANDATORY},
|
||||
{}
|
||||
};
|
||||
|
||||
int64_t level;
|
||||
uid_t uid;
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
assert(parameters);
|
||||
|
||||
/* NOTE: The method does have 1 parameter, but we must compare to 2 here, because
|
||||
* json_variant_elements() breaks abstraction and exposes internal structure of JsonObject. */
|
||||
if (json_variant_elements(parameters) != 2)
|
||||
return varlink_error_invalid_parameter(link, parameters);
|
||||
|
||||
r = json_dispatch(parameters, dispatch_table, NULL, 0, &level);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (LOG_PRI(level) != level)
|
||||
return varlink_error_invalid_parameter(link, parameters);
|
||||
|
||||
r = varlink_get_peer_uid(link, &uid);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (uid != getuid() && uid != 0)
|
||||
return varlink_error(link, VARLINK_ERROR_PERMISSION_DENIED, parameters);
|
||||
|
||||
log_debug("Received io.systemd.service.SetLogLevel(%" PRIi64 ")", level);
|
||||
|
||||
log_set_max_level(level);
|
||||
|
||||
return varlink_reply(link, NULL);
|
||||
}
|
||||
|
@ -7,3 +7,4 @@
|
||||
extern const VarlinkInterface vl_interface_io_systemd_service;
|
||||
|
||||
int varlink_method_ping(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata);
|
||||
int varlink_method_set_log_level(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata);
|
||||
|
Loading…
Reference in New Issue
Block a user