mirror of
https://github.com/systemd/systemd.git
synced 2024-11-01 09:21:26 +03:00
core: Introduce build_managed_oom_cgroups_json()
Will be reused to build the varlink message contents sent by user instances of systemd to systemd-oomd's varlink server in a future commit.
This commit is contained in:
parent
71feeae4bf
commit
f2ed82d510
@ -123,26 +123,13 @@ int manager_varlink_send_managed_oom_update(Unit *u) {
|
|||||||
return varlink_notify(u->manager->managed_oom_varlink_request, v);
|
return varlink_notify(u->manager->managed_oom_varlink_request, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vl_method_subscribe_managed_oom_cgroups(
|
static int build_managed_oom_cgroups_json(Manager *m, JsonVariant **ret) {
|
||||||
Varlink *link,
|
|
||||||
JsonVariant *parameters,
|
|
||||||
VarlinkMethodFlags flags,
|
|
||||||
void *userdata) {
|
|
||||||
static const UnitType supported_unit_types[] = { UNIT_SLICE, UNIT_SERVICE, UNIT_SCOPE };
|
static const UnitType supported_unit_types[] = { UNIT_SLICE, UNIT_SERVICE, UNIT_SCOPE };
|
||||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL, *arr = NULL;
|
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL, *arr = NULL;
|
||||||
Manager *m = userdata;
|
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(link);
|
|
||||||
assert(m);
|
assert(m);
|
||||||
|
assert(ret);
|
||||||
if (json_variant_elements(parameters) > 0)
|
|
||||||
return varlink_error_invalid_parameter(link, parameters);
|
|
||||||
|
|
||||||
/* We only take one subscriber for this method so return an error if there's already an existing one.
|
|
||||||
* This shouldn't happen since systemd-oomd is the only client of this method. */
|
|
||||||
if (FLAGS_SET(flags, VARLINK_METHOD_MORE) && m->managed_oom_varlink_request)
|
|
||||||
return varlink_error(link, VARLINK_ERROR_SUBSCRIPTION_TAKEN, NULL);
|
|
||||||
|
|
||||||
r = json_build(&arr, JSON_BUILD_EMPTY_ARRAY);
|
r = json_build(&arr, JSON_BUILD_EMPTY_ARRAY);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
@ -185,6 +172,35 @@ static int vl_method_subscribe_managed_oom_cgroups(
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
*ret = TAKE_PTR(v);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int vl_method_subscribe_managed_oom_cgroups(
|
||||||
|
Varlink *link,
|
||||||
|
JsonVariant *parameters,
|
||||||
|
VarlinkMethodFlags flags,
|
||||||
|
void *userdata) {
|
||||||
|
|
||||||
|
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||||
|
Manager *m = userdata;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
assert(link);
|
||||||
|
assert(m);
|
||||||
|
|
||||||
|
if (json_variant_elements(parameters) > 0)
|
||||||
|
return varlink_error_invalid_parameter(link, parameters);
|
||||||
|
|
||||||
|
/* We only take one subscriber for this method so return an error if there's already an existing one.
|
||||||
|
* This shouldn't happen since systemd-oomd is the only client of this method. */
|
||||||
|
if (FLAGS_SET(flags, VARLINK_METHOD_MORE) && m->managed_oom_varlink_request)
|
||||||
|
return varlink_error(link, VARLINK_ERROR_SUBSCRIPTION_TAKEN, NULL);
|
||||||
|
|
||||||
|
r = build_managed_oom_cgroups_json(m, &v);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
if (!FLAGS_SET(flags, VARLINK_METHOD_MORE))
|
if (!FLAGS_SET(flags, VARLINK_METHOD_MORE))
|
||||||
return varlink_reply(link, v);
|
return varlink_reply(link, v);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user