mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 00:14:32 +09:00
core: split out the helper to serialize/deserialize ratelimits
This commit is contained in:
@@ -152,13 +152,7 @@ int manager_serialize(
|
||||
(void) serialize_item_format(f, "user-lookup", "%i %i", copy0, copy1);
|
||||
}
|
||||
|
||||
(void) serialize_item_format(f,
|
||||
"dump-ratelimit",
|
||||
USEC_FMT " " USEC_FMT " %u %u",
|
||||
m->dump_ratelimit.begin,
|
||||
m->dump_ratelimit.interval,
|
||||
m->dump_ratelimit.num,
|
||||
m->dump_ratelimit.burst);
|
||||
(void) serialize_ratelimit(f, "dump-ratelimit", &m->dump_ratelimit);
|
||||
|
||||
bus_track_serialize(m->subscribed, f, "subscribed");
|
||||
|
||||
@@ -519,22 +513,9 @@ int manager_deserialize(Manager *m, FILE *f, FDSet *fds) {
|
||||
* remains set until all serialized contents are handled. */
|
||||
if (deserialize_varlink_sockets)
|
||||
(void) varlink_server_deserialize_one(m->varlink_server, val, fds);
|
||||
} else if ((val = startswith(l, "dump-ratelimit="))) {
|
||||
usec_t begin, interval;
|
||||
unsigned num, burst;
|
||||
|
||||
if (sscanf(val, USEC_FMT " " USEC_FMT " %u %u", &begin, &interval, &num, &burst) != 4)
|
||||
log_notice("Failed to parse dump ratelimit, ignoring: %s", val);
|
||||
else {
|
||||
/* If we changed the values across versions, flush the counter */
|
||||
if (interval != m->dump_ratelimit.interval || burst != m->dump_ratelimit.burst)
|
||||
m->dump_ratelimit.num = 0;
|
||||
else
|
||||
m->dump_ratelimit.num = num;
|
||||
m->dump_ratelimit.begin = begin;
|
||||
}
|
||||
|
||||
} else {
|
||||
} else if ((val = startswith(l, "dump-ratelimit=")))
|
||||
deserialize_ratelimit(&m->dump_ratelimit, "dump-ratelimit", val);
|
||||
else {
|
||||
ManagerTimestamp q;
|
||||
|
||||
for (q = 0; q < _MANAGER_TIMESTAMP_MAX; q++) {
|
||||
|
||||
@@ -201,6 +201,17 @@ int serialize_pidref(FILE *f, FDSet *fds, const char *key, PidRef *pidref) {
|
||||
return serialize_item_format(f, key, "@%i", copy);
|
||||
}
|
||||
|
||||
int serialize_ratelimit(FILE *f, const char *key, const RateLimit *rl) {
|
||||
assert(rl);
|
||||
|
||||
return serialize_item_format(f, key,
|
||||
USEC_FMT " " USEC_FMT " %u %u",
|
||||
rl->begin,
|
||||
rl->interval,
|
||||
rl->num,
|
||||
rl->burst);
|
||||
}
|
||||
|
||||
int serialize_item_hexmem(FILE *f, const char *key, const void *p, size_t l) {
|
||||
_cleanup_free_ char *encoded = NULL;
|
||||
int r;
|
||||
@@ -486,6 +497,22 @@ int deserialize_pidref(FDSet *fds, const char *value, PidRef *ret) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void deserialize_ratelimit(RateLimit *rl, const char *name, const char *value) {
|
||||
usec_t begin, interval;
|
||||
unsigned num, burst;
|
||||
|
||||
assert(rl);
|
||||
assert(name);
|
||||
assert(value);
|
||||
|
||||
if (sscanf(value, USEC_FMT " " USEC_FMT " %u %u", &begin, &interval, &num, &burst) != 4)
|
||||
return log_notice("Failed to parse %s, ignoring: %s", name, value);
|
||||
|
||||
/* Preserve the counter only if the configuration didn't change. */
|
||||
rl->num = (interval == rl->interval && burst == rl->burst) ? num : 0;
|
||||
rl->begin = begin;
|
||||
}
|
||||
|
||||
int open_serialization_fd(const char *ident) {
|
||||
int fd;
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "image-policy.h"
|
||||
#include "macro.h"
|
||||
#include "pidref.h"
|
||||
#include "ratelimit.h"
|
||||
#include "set.h"
|
||||
#include "string-util.h"
|
||||
#include "time-util.h"
|
||||
@@ -22,6 +23,7 @@ int serialize_usec(FILE *f, const char *key, usec_t usec);
|
||||
int serialize_dual_timestamp(FILE *f, const char *key, const dual_timestamp *t);
|
||||
int serialize_strv(FILE *f, const char *key, char **l);
|
||||
int serialize_pidref(FILE *f, FDSet *fds, const char *key, PidRef *pidref);
|
||||
int serialize_ratelimit(FILE *f, const char *key, const RateLimit *rl);
|
||||
int serialize_string_set(FILE *f, const char *key, Set *s);
|
||||
int serialize_image_policy(FILE *f, const char *key, const ImagePolicy *p);
|
||||
|
||||
@@ -45,6 +47,7 @@ int deserialize_dual_timestamp(const char *value, dual_timestamp *ret);
|
||||
int deserialize_environment(const char *value, char ***environment);
|
||||
int deserialize_strv(const char *value, char ***l);
|
||||
int deserialize_pidref(FDSet *fds, const char *value, PidRef *ret);
|
||||
void deserialize_ratelimit(RateLimit *rl, const char *name, const char *value);
|
||||
|
||||
int open_serialization_fd(const char *ident);
|
||||
int open_serialization_file(const char *ident, FILE **ret);
|
||||
|
||||
Reference in New Issue
Block a user