mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-22 13:33:56 +03:00
Merge pull request #13600 from keszybz/ratelimit
Clean up ratelimit functions and disable /dev/kmsg ratelimit
This commit is contained in:
commit
68c2b5ddb1
@ -29,6 +29,7 @@
|
||||
#include "parse-util.h"
|
||||
#include "proc-cmdline.h"
|
||||
#include "process-util.h"
|
||||
#include "ratelimit.h"
|
||||
#include "signal-util.h"
|
||||
#include "socket-util.h"
|
||||
#include "stdio-util.h"
|
||||
@ -459,6 +460,15 @@ static int write_to_kmsg(
|
||||
const char *func,
|
||||
const char *buffer) {
|
||||
|
||||
/* Set a ratelimit on the amount of messages logged to /dev/kmsg. This is mostly supposed to be a
|
||||
* safety catch for the case where start indiscriminately logging in a loop. It will not catch cases
|
||||
* where we log excessively, but not in a tight loop.
|
||||
*
|
||||
* Note that this ratelimit is per-emitter, so we might still overwhelm /dev/kmsg with multiple
|
||||
* loggers.
|
||||
*/
|
||||
static thread_local RateLimit ratelimit = { 5 * USEC_PER_SEC, 200 };
|
||||
|
||||
char header_priority[2 + DECIMAL_STR_MAX(int) + 1],
|
||||
header_pid[4 + DECIMAL_STR_MAX(pid_t) + 1];
|
||||
struct iovec iovec[5] = {};
|
||||
@ -466,6 +476,9 @@ static int write_to_kmsg(
|
||||
if (kmsg_fd < 0)
|
||||
return 0;
|
||||
|
||||
if (!ratelimit_below(&ratelimit))
|
||||
return 0;
|
||||
|
||||
xsprintf(header_priority, "<%i>", level);
|
||||
xsprintf(header_pid, "["PID_FMT"]: ", getpid_cached());
|
||||
|
||||
|
@ -7,34 +7,14 @@
|
||||
#include "util.h"
|
||||
|
||||
typedef struct RateLimit {
|
||||
usec_t interval;
|
||||
usec_t begin;
|
||||
unsigned burst;
|
||||
usec_t interval; /* Keep those two fields first so they can be initialized easily: */
|
||||
unsigned burst; /* RateLimit rl = { INTERVAL, BURST }; */
|
||||
unsigned num;
|
||||
usec_t begin;
|
||||
} RateLimit;
|
||||
|
||||
#define RATELIMIT_DEFINE(_name, _interval, _burst) \
|
||||
RateLimit _name = { \
|
||||
.interval = (_interval), \
|
||||
.burst = (_burst), \
|
||||
.num = 0, \
|
||||
.begin = 0 \
|
||||
}
|
||||
|
||||
#define RATELIMIT_INIT(v, _interval, _burst) \
|
||||
do { \
|
||||
RateLimit *_r = &(v); \
|
||||
_r->interval = (_interval); \
|
||||
_r->burst = (_burst); \
|
||||
_r->num = 0; \
|
||||
_r->begin = 0; \
|
||||
} while (false)
|
||||
|
||||
#define RATELIMIT_RESET(v) \
|
||||
do { \
|
||||
RateLimit *_r = &(v); \
|
||||
_r->num = 0; \
|
||||
_r->begin = 0; \
|
||||
} while (false)
|
||||
static inline void ratelimit_reset(RateLimit *rl) {
|
||||
rl->num = rl->begin = 0;
|
||||
}
|
||||
|
||||
bool ratelimit_below(RateLimit *r);
|
||||
|
@ -764,8 +764,8 @@ const sd_bus_vtable bus_exec_vtable[] = {
|
||||
SD_BUS_PROPERTY("SyslogLevel", "i", property_get_syslog_level, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("SyslogFacility", "i", property_get_syslog_facility, offsetof(ExecContext, syslog_priority), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("LogLevelMax", "i", bus_property_get_int, offsetof(ExecContext, log_level_max), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("LogRateLimitIntervalUSec", "t", bus_property_get_usec, offsetof(ExecContext, log_rate_limit_interval_usec), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("LogRateLimitBurst", "u", bus_property_get_unsigned, offsetof(ExecContext, log_rate_limit_burst), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("LogRateLimitIntervalUSec", "t", bus_property_get_usec, offsetof(ExecContext, log_ratelimit_interval_usec), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("LogRateLimitBurst", "u", bus_property_get_unsigned, offsetof(ExecContext, log_ratelimit_burst), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("LogExtraFields", "aay", property_get_log_extra_fields, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("SecureBits", "i", bus_property_get_int, offsetof(ExecContext, secure_bits), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("CapabilityBoundingSet", "t", NULL, offsetof(ExecContext, capability_bounding_set), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
@ -1204,10 +1204,10 @@ int bus_exec_context_set_transient_property(
|
||||
return bus_set_transient_log_level(u, name, &c->log_level_max, message, flags, error);
|
||||
|
||||
if (streq(name, "LogRateLimitIntervalUSec"))
|
||||
return bus_set_transient_usec(u, name, &c->log_rate_limit_interval_usec, message, flags, error);
|
||||
return bus_set_transient_usec(u, name, &c->log_ratelimit_interval_usec, message, flags, error);
|
||||
|
||||
if (streq(name, "LogRateLimitBurst"))
|
||||
return bus_set_transient_unsigned(u, name, &c->log_rate_limit_burst, message, flags, error);
|
||||
return bus_set_transient_unsigned(u, name, &c->log_ratelimit_burst, message, flags, error);
|
||||
|
||||
if (streq(name, "Personality"))
|
||||
return bus_set_transient_personality(u, name, &c->personality, message, flags, error);
|
||||
|
@ -145,8 +145,8 @@ const sd_bus_vtable bus_service_vtable[] = {
|
||||
BUS_EXEC_EX_COMMAND_LIST_VTABLE("ExecStopPostEx", offsetof(Service, exec_command[SERVICE_EXEC_STOP_POST]), SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION),
|
||||
|
||||
/* The following four are obsolete, and thus marked hidden here. They moved into the Unit interface */
|
||||
SD_BUS_PROPERTY("StartLimitInterval", "t", bus_property_get_usec, offsetof(Unit, start_limit.interval), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
|
||||
SD_BUS_PROPERTY("StartLimitBurst", "u", bus_property_get_unsigned, offsetof(Unit, start_limit.burst), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
|
||||
SD_BUS_PROPERTY("StartLimitInterval", "t", bus_property_get_usec, offsetof(Unit, start_ratelimit.interval), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
|
||||
SD_BUS_PROPERTY("StartLimitBurst", "u", bus_property_get_unsigned, offsetof(Unit, start_ratelimit.burst), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
|
||||
SD_BUS_PROPERTY("StartLimitAction", "s", property_get_emergency_action, offsetof(Unit, start_limit_action), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
|
||||
SD_BUS_PROPERTY("FailureAction", "s", property_get_emergency_action, offsetof(Unit, failure_action), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
|
||||
SD_BUS_PROPERTY("RebootArgument", "s", NULL, offsetof(Unit, reboot_arg), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
|
||||
|
@ -829,8 +829,8 @@ const sd_bus_vtable bus_unit_vtable[] = {
|
||||
SD_BUS_PROPERTY("LoadError", "(ss)", property_get_load_error, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("Transient", "b", bus_property_get_bool, offsetof(Unit, transient), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("Perpetual", "b", bus_property_get_bool, offsetof(Unit, perpetual), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("StartLimitIntervalUSec", "t", bus_property_get_usec, offsetof(Unit, start_limit.interval), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("StartLimitBurst", "u", bus_property_get_unsigned, offsetof(Unit, start_limit.burst), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("StartLimitIntervalUSec", "t", bus_property_get_usec, offsetof(Unit, start_ratelimit.interval), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("StartLimitBurst", "u", bus_property_get_unsigned, offsetof(Unit, start_ratelimit.burst), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("StartLimitAction", "s", property_get_emergency_action, offsetof(Unit, start_limit_action), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("FailureAction", "s", property_get_emergency_action, offsetof(Unit, failure_action), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("FailureActionExitStatus", "i", bus_property_get_int, offsetof(Unit, failure_action_exit_status), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
@ -862,8 +862,8 @@ const sd_bus_vtable bus_unit_vtable[] = {
|
||||
SD_BUS_PROPERTY("RequiredByOverridable", "as", property_get_empty_strv, 0, SD_BUS_VTABLE_HIDDEN),
|
||||
SD_BUS_PROPERTY("RequisiteOfOverridable", "as", property_get_empty_strv, 0, SD_BUS_VTABLE_HIDDEN),
|
||||
/* Obsolete alias names */
|
||||
SD_BUS_PROPERTY("StartLimitInterval", "t", bus_property_get_usec, offsetof(Unit, start_limit.interval), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
|
||||
SD_BUS_PROPERTY("StartLimitIntervalSec", "t", bus_property_get_usec, offsetof(Unit, start_limit.interval), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
|
||||
SD_BUS_PROPERTY("StartLimitInterval", "t", bus_property_get_usec, offsetof(Unit, start_ratelimit.interval), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
|
||||
SD_BUS_PROPERTY("StartLimitIntervalSec", "t", bus_property_get_usec, offsetof(Unit, start_ratelimit.interval), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
|
||||
SD_BUS_VTABLE_END
|
||||
};
|
||||
|
||||
@ -1825,10 +1825,10 @@ static int bus_unit_set_transient_property(
|
||||
return bus_set_transient_string(u, name, &u->job_timeout_reboot_arg, message, flags, error);
|
||||
|
||||
if (streq(name, "StartLimitIntervalUSec"))
|
||||
return bus_set_transient_usec(u, name, &u->start_limit.interval, message, flags, error);
|
||||
return bus_set_transient_usec(u, name, &u->start_ratelimit.interval, message, flags, error);
|
||||
|
||||
if (streq(name, "StartLimitBurst"))
|
||||
return bus_set_transient_unsigned(u, name, &u->start_limit.burst, message, flags, error);
|
||||
return bus_set_transient_unsigned(u, name, &u->start_ratelimit.burst, message, flags, error);
|
||||
|
||||
if (streq(name, "StartLimitAction"))
|
||||
return bus_set_transient_emergency_action(u, name, &u->start_limit_action, message, flags, error);
|
||||
|
@ -4000,8 +4000,8 @@ void exec_context_done(ExecContext *c) {
|
||||
|
||||
exec_context_free_log_extra_fields(c);
|
||||
|
||||
c->log_rate_limit_interval_usec = 0;
|
||||
c->log_rate_limit_burst = 0;
|
||||
c->log_ratelimit_interval_usec = 0;
|
||||
c->log_ratelimit_burst = 0;
|
||||
|
||||
c->stdin_data = mfree(c->stdin_data);
|
||||
c->stdin_data_size = 0;
|
||||
@ -4515,16 +4515,16 @@ void exec_context_dump(const ExecContext *c, FILE* f, const char *prefix) {
|
||||
fprintf(f, "%sLogLevelMax: %s\n", prefix, strna(t));
|
||||
}
|
||||
|
||||
if (c->log_rate_limit_interval_usec > 0) {
|
||||
if (c->log_ratelimit_interval_usec > 0) {
|
||||
char buf_timespan[FORMAT_TIMESPAN_MAX];
|
||||
|
||||
fprintf(f,
|
||||
"%sLogRateLimitIntervalSec: %s\n",
|
||||
prefix, format_timespan(buf_timespan, sizeof(buf_timespan), c->log_rate_limit_interval_usec, USEC_PER_SEC));
|
||||
prefix, format_timespan(buf_timespan, sizeof(buf_timespan), c->log_ratelimit_interval_usec, USEC_PER_SEC));
|
||||
}
|
||||
|
||||
if (c->log_rate_limit_burst > 0)
|
||||
fprintf(f, "%sLogRateLimitBurst: %u\n", prefix, c->log_rate_limit_burst);
|
||||
if (c->log_ratelimit_burst > 0)
|
||||
fprintf(f, "%sLogRateLimitBurst: %u\n", prefix, c->log_ratelimit_burst);
|
||||
|
||||
if (c->n_log_extra_fields > 0) {
|
||||
size_t j;
|
||||
|
@ -245,8 +245,8 @@ struct ExecContext {
|
||||
struct iovec* log_extra_fields;
|
||||
size_t n_log_extra_fields;
|
||||
|
||||
usec_t log_rate_limit_interval_usec;
|
||||
unsigned log_rate_limit_burst;
|
||||
usec_t log_ratelimit_interval_usec;
|
||||
unsigned log_ratelimit_burst;
|
||||
|
||||
int log_level_max;
|
||||
|
||||
|
@ -59,8 +59,8 @@ $1.SyslogFacility, config_parse_log_facility, 0,
|
||||
$1.SyslogLevel, config_parse_log_level, 0, offsetof($1, exec_context.syslog_priority)
|
||||
$1.SyslogLevelPrefix, config_parse_bool, 0, offsetof($1, exec_context.syslog_level_prefix)
|
||||
$1.LogLevelMax, config_parse_log_level, 0, offsetof($1, exec_context.log_level_max)
|
||||
$1.LogRateLimitIntervalSec, config_parse_sec, 0, offsetof($1, exec_context.log_rate_limit_interval_usec)
|
||||
$1.LogRateLimitBurst, config_parse_unsigned, 0, offsetof($1, exec_context.log_rate_limit_burst)
|
||||
$1.LogRateLimitIntervalSec, config_parse_sec, 0, offsetof($1, exec_context.log_ratelimit_interval_usec)
|
||||
$1.LogRateLimitBurst, config_parse_unsigned, 0, offsetof($1, exec_context.log_ratelimit_burst)
|
||||
$1.LogExtraFields, config_parse_log_extra_fields, 0, offsetof($1, exec_context)
|
||||
$1.Capabilities, config_parse_warn_compat, DISABLED_LEGACY, offsetof($1, exec_context)
|
||||
$1.SecureBits, config_parse_exec_secure_bits, 0, offsetof($1, exec_context.secure_bits)
|
||||
@ -245,10 +245,10 @@ Unit.JobTimeoutSec, config_parse_job_timeout_sec, 0,
|
||||
Unit.JobRunningTimeoutSec, config_parse_job_running_timeout_sec, 0, 0
|
||||
Unit.JobTimeoutAction, config_parse_emergency_action, 0, offsetof(Unit, job_timeout_action)
|
||||
Unit.JobTimeoutRebootArgument, config_parse_unit_string_printf, 0, offsetof(Unit, job_timeout_reboot_arg)
|
||||
Unit.StartLimitIntervalSec, config_parse_sec, 0, offsetof(Unit, start_limit.interval)
|
||||
Unit.StartLimitIntervalSec, config_parse_sec, 0, offsetof(Unit, start_ratelimit.interval)
|
||||
m4_dnl The following is a legacy alias name for compatibility
|
||||
Unit.StartLimitInterval, config_parse_sec, 0, offsetof(Unit, start_limit.interval)
|
||||
Unit.StartLimitBurst, config_parse_unsigned, 0, offsetof(Unit, start_limit.burst)
|
||||
Unit.StartLimitInterval, config_parse_sec, 0, offsetof(Unit, start_ratelimit.interval)
|
||||
Unit.StartLimitBurst, config_parse_unsigned, 0, offsetof(Unit, start_ratelimit.burst)
|
||||
Unit.StartLimitAction, config_parse_emergency_action, 0, offsetof(Unit, start_limit_action)
|
||||
Unit.FailureAction, config_parse_emergency_action, 0, offsetof(Unit, failure_action)
|
||||
Unit.SuccessAction, config_parse_emergency_action, 0, offsetof(Unit, success_action)
|
||||
@ -320,8 +320,8 @@ Service.TimeoutAbortSec, config_parse_service_timeout_abort, 0,
|
||||
Service.RuntimeMaxSec, config_parse_sec, 0, offsetof(Service, runtime_max_usec)
|
||||
Service.WatchdogSec, config_parse_sec, 0, offsetof(Service, watchdog_usec)
|
||||
m4_dnl The following five only exist for compatibility, they moved into Unit, see above
|
||||
Service.StartLimitInterval, config_parse_sec, 0, offsetof(Unit, start_limit.interval)
|
||||
Service.StartLimitBurst, config_parse_unsigned, 0, offsetof(Unit, start_limit.burst)
|
||||
Service.StartLimitInterval, config_parse_sec, 0, offsetof(Unit, start_ratelimit.interval)
|
||||
Service.StartLimitBurst, config_parse_unsigned, 0, offsetof(Unit, start_ratelimit.burst)
|
||||
Service.StartLimitAction, config_parse_emergency_action, 0, offsetof(Unit, start_limit_action)
|
||||
Service.FailureAction, config_parse_emergency_action, 0, offsetof(Unit, failure_action)
|
||||
Service.RebootArgument, config_parse_unit_string_printf, 0, offsetof(Unit, reboot_arg)
|
||||
|
@ -2435,6 +2435,8 @@ int main(int argc, char *argv[]) {
|
||||
* available, and it previously wasn't. */
|
||||
log_open();
|
||||
|
||||
disable_printk_ratelimit();
|
||||
|
||||
r = initialize_security(
|
||||
&loaded_policy,
|
||||
&security_start_timestamp,
|
||||
|
@ -72,6 +72,7 @@
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "strxcpyx.h"
|
||||
#include "sysctl-util.h"
|
||||
#include "syslog-util.h"
|
||||
#include "terminal-util.h"
|
||||
#include "time-util.h"
|
||||
@ -815,7 +816,7 @@ int manager_new(UnitFileScope scope, ManagerTestRunFlags test_run_flags, Manager
|
||||
}
|
||||
|
||||
/* Reboot immediately if the user hits C-A-D more often than 7x per 2s */
|
||||
RATELIMIT_INIT(m->ctrl_alt_del_ratelimit, 2 * USEC_PER_SEC, 7);
|
||||
m->ctrl_alt_del_ratelimit = (RateLimit) { .interval = 2 * USEC_PER_SEC, .burst = 7 };
|
||||
|
||||
r = manager_default_environment(m);
|
||||
if (r < 0)
|
||||
@ -2855,10 +2856,9 @@ static int manager_dispatch_jobs_in_progress(sd_event_source *source, usec_t use
|
||||
}
|
||||
|
||||
int manager_loop(Manager *m) {
|
||||
RateLimit rl = { .interval = 1*USEC_PER_SEC, .burst = 50000 };
|
||||
int r;
|
||||
|
||||
RATELIMIT_DEFINE(rl, 1*USEC_PER_SEC, 50000);
|
||||
|
||||
assert(m);
|
||||
assert(m->objective == MANAGER_OK); /* Ensure manager_startup() has been called */
|
||||
|
||||
@ -4025,6 +4025,19 @@ static bool manager_journal_is_running(Manager *m) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void disable_printk_ratelimit(void) {
|
||||
/* Disable kernel's printk ratelimit.
|
||||
*
|
||||
* Logging to /dev/kmsg is most useful during early boot and shutdown, where normal logging
|
||||
* mechanisms are not available. The semantics of this sysctl are such that any kernel command-line
|
||||
* setting takes precedence. */
|
||||
int r;
|
||||
|
||||
r = sysctl_write("kernel/printk_devkmsg", "on");
|
||||
if (r < 0)
|
||||
log_debug_errno(r, "Failed to set sysctl kernel.printk_devkmsg=on: %m");
|
||||
}
|
||||
|
||||
void manager_recheck_journal(Manager *m) {
|
||||
|
||||
assert(m);
|
||||
|
@ -499,6 +499,7 @@ bool manager_unit_inactive_or_pending(Manager *m, const char *name);
|
||||
|
||||
void manager_check_finished(Manager *m);
|
||||
|
||||
void disable_printk_ratelimit(void);
|
||||
void manager_recheck_dbus(Manager *m);
|
||||
void manager_recheck_journal(Manager *m);
|
||||
|
||||
|
@ -469,7 +469,8 @@ static int relabel_extra(void) {
|
||||
}
|
||||
|
||||
/* Remove when we complete things. */
|
||||
if (rmdir("/run/systemd/relabel-extra.d") < 0)
|
||||
if (rmdir("/run/systemd/relabel-extra.d") < 0 &&
|
||||
errno != ENOENT)
|
||||
log_warning_errno(errno, "Failed to remove /run/systemd/relabel-extra.d/ directory: %m");
|
||||
|
||||
return c;
|
||||
|
@ -123,8 +123,8 @@ Unit *unit_new(Manager *m, size_t size) {
|
||||
|
||||
u->last_section_private = -1;
|
||||
|
||||
RATELIMIT_INIT(u->start_limit, m->default_start_limit_interval, m->default_start_limit_burst);
|
||||
RATELIMIT_INIT(u->auto_stop_ratelimit, 10 * USEC_PER_SEC, 16);
|
||||
u->start_ratelimit = (RateLimit) { m->default_start_limit_interval, m->default_start_limit_burst };
|
||||
u->auto_stop_ratelimit = (RateLimit) { 10 * USEC_PER_SEC, 16 };
|
||||
|
||||
for (CGroupIOAccountingMetric i = 0; i < _CGROUP_IO_ACCOUNTING_METRIC_MAX; i++)
|
||||
u->io_accounting_last[i] = UINT64_MAX;
|
||||
@ -1679,7 +1679,7 @@ int unit_test_start_limit(Unit *u) {
|
||||
|
||||
assert(u);
|
||||
|
||||
if (ratelimit_below(&u->start_limit)) {
|
||||
if (ratelimit_below(&u->start_ratelimit)) {
|
||||
u->start_limit_hit = false;
|
||||
return 0;
|
||||
}
|
||||
@ -3416,8 +3416,8 @@ int unit_serialize(Unit *u, FILE *f, FDSet *fds, bool serialize_jobs) {
|
||||
(void) serialize_bool(f, "exported-invocation-id", u->exported_invocation_id);
|
||||
(void) serialize_bool(f, "exported-log-level-max", u->exported_log_level_max);
|
||||
(void) serialize_bool(f, "exported-log-extra-fields", u->exported_log_extra_fields);
|
||||
(void) serialize_bool(f, "exported-log-rate-limit-interval", u->exported_log_rate_limit_interval);
|
||||
(void) serialize_bool(f, "exported-log-rate-limit-burst", u->exported_log_rate_limit_burst);
|
||||
(void) serialize_bool(f, "exported-log-rate-limit-interval", u->exported_log_ratelimit_interval);
|
||||
(void) serialize_bool(f, "exported-log-rate-limit-burst", u->exported_log_ratelimit_burst);
|
||||
|
||||
(void) serialize_item_format(f, "cpu-usage-base", "%" PRIu64, u->cpu_usage_base);
|
||||
if (u->cpu_usage_last != NSEC_INFINITY)
|
||||
@ -3636,7 +3636,7 @@ int unit_deserialize(Unit *u, FILE *f, FDSet *fds) {
|
||||
if (r < 0)
|
||||
log_unit_debug(u, "Failed to parse exported log rate limit interval %s, ignoring.", v);
|
||||
else
|
||||
u->exported_log_rate_limit_interval = r;
|
||||
u->exported_log_ratelimit_interval = r;
|
||||
|
||||
continue;
|
||||
|
||||
@ -3646,7 +3646,7 @@ int unit_deserialize(Unit *u, FILE *f, FDSet *fds) {
|
||||
if (r < 0)
|
||||
log_unit_debug(u, "Failed to parse exported log rate limit burst %s, ignoring.", v);
|
||||
else
|
||||
u->exported_log_rate_limit_burst = r;
|
||||
u->exported_log_ratelimit_burst = r;
|
||||
|
||||
continue;
|
||||
|
||||
@ -4000,7 +4000,7 @@ void unit_reset_failed(Unit *u) {
|
||||
if (UNIT_VTABLE(u)->reset_failed)
|
||||
UNIT_VTABLE(u)->reset_failed(u);
|
||||
|
||||
RATELIMIT_RESET(u->start_limit);
|
||||
ratelimit_reset(&u->start_ratelimit);
|
||||
u->start_limit_hit = false;
|
||||
}
|
||||
|
||||
@ -5504,7 +5504,7 @@ fail:
|
||||
return r;
|
||||
}
|
||||
|
||||
static int unit_export_log_rate_limit_interval(Unit *u, const ExecContext *c) {
|
||||
static int unit_export_log_ratelimit_interval(Unit *u, const ExecContext *c) {
|
||||
_cleanup_free_ char *buf = NULL;
|
||||
const char *p;
|
||||
int r;
|
||||
@ -5512,26 +5512,26 @@ static int unit_export_log_rate_limit_interval(Unit *u, const ExecContext *c) {
|
||||
assert(u);
|
||||
assert(c);
|
||||
|
||||
if (u->exported_log_rate_limit_interval)
|
||||
if (u->exported_log_ratelimit_interval)
|
||||
return 0;
|
||||
|
||||
if (c->log_rate_limit_interval_usec == 0)
|
||||
if (c->log_ratelimit_interval_usec == 0)
|
||||
return 0;
|
||||
|
||||
p = strjoina("/run/systemd/units/log-rate-limit-interval:", u->id);
|
||||
|
||||
if (asprintf(&buf, "%" PRIu64, c->log_rate_limit_interval_usec) < 0)
|
||||
if (asprintf(&buf, "%" PRIu64, c->log_ratelimit_interval_usec) < 0)
|
||||
return log_oom();
|
||||
|
||||
r = symlink_atomic(buf, p);
|
||||
if (r < 0)
|
||||
return log_unit_debug_errno(u, r, "Failed to create log rate limit interval symlink %s: %m", p);
|
||||
|
||||
u->exported_log_rate_limit_interval = true;
|
||||
u->exported_log_ratelimit_interval = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int unit_export_log_rate_limit_burst(Unit *u, const ExecContext *c) {
|
||||
static int unit_export_log_ratelimit_burst(Unit *u, const ExecContext *c) {
|
||||
_cleanup_free_ char *buf = NULL;
|
||||
const char *p;
|
||||
int r;
|
||||
@ -5539,22 +5539,22 @@ static int unit_export_log_rate_limit_burst(Unit *u, const ExecContext *c) {
|
||||
assert(u);
|
||||
assert(c);
|
||||
|
||||
if (u->exported_log_rate_limit_burst)
|
||||
if (u->exported_log_ratelimit_burst)
|
||||
return 0;
|
||||
|
||||
if (c->log_rate_limit_burst == 0)
|
||||
if (c->log_ratelimit_burst == 0)
|
||||
return 0;
|
||||
|
||||
p = strjoina("/run/systemd/units/log-rate-limit-burst:", u->id);
|
||||
|
||||
if (asprintf(&buf, "%u", c->log_rate_limit_burst) < 0)
|
||||
if (asprintf(&buf, "%u", c->log_ratelimit_burst) < 0)
|
||||
return log_oom();
|
||||
|
||||
r = symlink_atomic(buf, p);
|
||||
if (r < 0)
|
||||
return log_unit_debug_errno(u, r, "Failed to create log rate limit burst symlink %s: %m", p);
|
||||
|
||||
u->exported_log_rate_limit_burst = true;
|
||||
u->exported_log_ratelimit_burst = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -5591,8 +5591,8 @@ void unit_export_state_files(Unit *u) {
|
||||
if (c) {
|
||||
(void) unit_export_log_level_max(u, c);
|
||||
(void) unit_export_log_extra_fields(u, c);
|
||||
(void) unit_export_log_rate_limit_interval(u, c);
|
||||
(void) unit_export_log_rate_limit_burst(u, c);
|
||||
(void) unit_export_log_ratelimit_interval(u, c);
|
||||
(void) unit_export_log_ratelimit_burst(u, c);
|
||||
}
|
||||
}
|
||||
|
||||
@ -5630,18 +5630,18 @@ void unit_unlink_state_files(Unit *u) {
|
||||
u->exported_log_extra_fields = false;
|
||||
}
|
||||
|
||||
if (u->exported_log_rate_limit_interval) {
|
||||
if (u->exported_log_ratelimit_interval) {
|
||||
p = strjoina("/run/systemd/units/log-rate-limit-interval:", u->id);
|
||||
(void) unlink(p);
|
||||
|
||||
u->exported_log_rate_limit_interval = false;
|
||||
u->exported_log_ratelimit_interval = false;
|
||||
}
|
||||
|
||||
if (u->exported_log_rate_limit_burst) {
|
||||
if (u->exported_log_ratelimit_burst) {
|
||||
p = strjoina("/run/systemd/units/log-rate-limit-burst:", u->id);
|
||||
(void) unlink(p);
|
||||
|
||||
u->exported_log_rate_limit_burst = false;
|
||||
u->exported_log_ratelimit_burst = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -227,7 +227,7 @@ typedef struct Unit {
|
||||
int load_error;
|
||||
|
||||
/* Put a ratelimit on unit starting */
|
||||
RateLimit start_limit;
|
||||
RateLimit start_ratelimit;
|
||||
EmergencyAction start_limit_action;
|
||||
|
||||
/* What to do on failure or success */
|
||||
@ -365,8 +365,8 @@ typedef struct Unit {
|
||||
bool exported_invocation_id:1;
|
||||
bool exported_log_level_max:1;
|
||||
bool exported_log_extra_fields:1;
|
||||
bool exported_log_rate_limit_interval:1;
|
||||
bool exported_log_rate_limit_burst:1;
|
||||
bool exported_log_ratelimit_interval:1;
|
||||
bool exported_log_ratelimit_burst:1;
|
||||
|
||||
/* Whether we warned about clamping the CPU quota period */
|
||||
bool warned_clamping_cpu_quota_period:1;
|
||||
|
@ -49,7 +49,7 @@ struct RawExport {
|
||||
uint64_t written_uncompressed;
|
||||
|
||||
unsigned last_percent;
|
||||
RateLimit progress_rate_limit;
|
||||
RateLimit progress_ratelimit;
|
||||
|
||||
struct stat st;
|
||||
|
||||
@ -96,10 +96,9 @@ int raw_export_new(
|
||||
.on_finished = on_finished,
|
||||
.userdata = userdata,
|
||||
.last_percent = (unsigned) -1,
|
||||
.progress_ratelimit = { 100 * USEC_PER_MSEC, 1 },
|
||||
};
|
||||
|
||||
RATELIMIT_INIT(e->progress_rate_limit, 100 * USEC_PER_MSEC, 1);
|
||||
|
||||
if (event)
|
||||
e->event = sd_event_ref(event);
|
||||
else {
|
||||
@ -125,7 +124,7 @@ static void raw_export_report_progress(RawExport *e) {
|
||||
if (percent == e->last_percent)
|
||||
return;
|
||||
|
||||
if (!ratelimit_below(&e->progress_rate_limit))
|
||||
if (!ratelimit_below(&e->progress_ratelimit))
|
||||
return;
|
||||
|
||||
sd_notifyf(false, "X_IMPORT_PROGRESS=%u", percent);
|
||||
|
@ -44,7 +44,7 @@ struct TarExport {
|
||||
uint64_t quota_referenced;
|
||||
|
||||
unsigned last_percent;
|
||||
RateLimit progress_rate_limit;
|
||||
RateLimit progress_ratelimit;
|
||||
|
||||
bool eof;
|
||||
bool tried_splice;
|
||||
@ -99,10 +99,9 @@ int tar_export_new(
|
||||
.userdata = userdata,
|
||||
.quota_referenced = (uint64_t) -1,
|
||||
.last_percent = (unsigned) -1,
|
||||
.progress_ratelimit = { 100 * USEC_PER_MSEC, 1 },
|
||||
};
|
||||
|
||||
RATELIMIT_INIT(e->progress_rate_limit, 100 * USEC_PER_MSEC, 1);
|
||||
|
||||
if (event)
|
||||
e->event = sd_event_ref(event);
|
||||
else {
|
||||
@ -132,7 +131,7 @@ static void tar_export_report_progress(TarExport *e) {
|
||||
if (percent == e->last_percent)
|
||||
return;
|
||||
|
||||
if (!ratelimit_below(&e->progress_rate_limit))
|
||||
if (!ratelimit_below(&e->progress_ratelimit))
|
||||
return;
|
||||
|
||||
sd_notifyf(false, "X_IMPORT_PROGRESS=%u", percent);
|
||||
|
@ -169,7 +169,7 @@ static int import_fs(int argc, char *argv[], void *userdata) {
|
||||
|
||||
(void) mkdir_parents_label(temp_path, 0700);
|
||||
|
||||
RATELIMIT_INIT(progress.limit, 200*USEC_PER_MSEC, 1);
|
||||
progress.limit = (RateLimit) { 200*USEC_PER_MSEC, 1 };
|
||||
|
||||
/* Hook into SIGINT/SIGTERM, so that we can cancel things then */
|
||||
assert(sigaction(SIGINT, &sa, &old_sigint_sa) >= 0);
|
||||
|
@ -57,7 +57,7 @@ struct RawImport {
|
||||
struct stat st;
|
||||
|
||||
unsigned last_percent;
|
||||
RateLimit progress_rate_limit;
|
||||
RateLimit progress_ratelimit;
|
||||
};
|
||||
|
||||
RawImport* raw_import_unref(RawImport *i) {
|
||||
@ -111,10 +111,9 @@ int raw_import_new(
|
||||
.userdata = userdata,
|
||||
.last_percent = (unsigned) -1,
|
||||
.image_root = TAKE_PTR(root),
|
||||
.progress_ratelimit = { 100 * USEC_PER_MSEC, 1 },
|
||||
};
|
||||
|
||||
RATELIMIT_INIT(i->progress_rate_limit, 100 * USEC_PER_MSEC, 1);
|
||||
|
||||
if (event)
|
||||
i->event = sd_event_ref(event);
|
||||
else {
|
||||
@ -144,7 +143,7 @@ static void raw_import_report_progress(RawImport *i) {
|
||||
if (percent == i->last_percent)
|
||||
return;
|
||||
|
||||
if (!ratelimit_below(&i->progress_rate_limit))
|
||||
if (!ratelimit_below(&i->progress_ratelimit))
|
||||
return;
|
||||
|
||||
sd_notifyf(false, "X_IMPORT_PROGRESS=%u", percent);
|
||||
|
@ -60,7 +60,7 @@ struct TarImport {
|
||||
pid_t tar_pid;
|
||||
|
||||
unsigned last_percent;
|
||||
RateLimit progress_rate_limit;
|
||||
RateLimit progress_ratelimit;
|
||||
};
|
||||
|
||||
TarImport* tar_import_unref(TarImport *i) {
|
||||
@ -119,10 +119,9 @@ int tar_import_new(
|
||||
.userdata = userdata,
|
||||
.last_percent = (unsigned) -1,
|
||||
.image_root = TAKE_PTR(root),
|
||||
.progress_ratelimit = { 100 * USEC_PER_MSEC, 1 },
|
||||
};
|
||||
|
||||
RATELIMIT_INIT(i->progress_rate_limit, 100 * USEC_PER_MSEC, 1);
|
||||
|
||||
if (event)
|
||||
i->event = sd_event_ref(event);
|
||||
else {
|
||||
@ -152,7 +151,7 @@ static void tar_import_report_progress(TarImport *i) {
|
||||
if (percent == i->last_percent)
|
||||
return;
|
||||
|
||||
if (!ratelimit_below(&i->progress_rate_limit))
|
||||
if (!ratelimit_below(&i->progress_ratelimit))
|
||||
return;
|
||||
|
||||
sd_notifyf(false, "X_IMPORT_PROGRESS=%u", percent);
|
||||
|
@ -132,8 +132,8 @@ static int client_context_new(Server *s, pid_t pid, ClientContext **ret) {
|
||||
c->timestamp = USEC_INFINITY;
|
||||
c->extra_fields_mtime = NSEC_INFINITY;
|
||||
c->log_level_max = -1;
|
||||
c->log_rate_limit_interval = s->rate_limit_interval;
|
||||
c->log_rate_limit_burst = s->rate_limit_burst;
|
||||
c->log_ratelimit_interval = s->ratelimit_interval;
|
||||
c->log_ratelimit_burst = s->ratelimit_burst;
|
||||
|
||||
r = hashmap_put(s->client_contexts, PID_TO_PTR(pid), c);
|
||||
if (r < 0) {
|
||||
@ -182,8 +182,8 @@ static void client_context_reset(Server *s, ClientContext *c) {
|
||||
|
||||
c->log_level_max = -1;
|
||||
|
||||
c->log_rate_limit_interval = s->rate_limit_interval;
|
||||
c->log_rate_limit_burst = s->rate_limit_burst;
|
||||
c->log_ratelimit_interval = s->ratelimit_interval;
|
||||
c->log_ratelimit_burst = s->ratelimit_burst;
|
||||
}
|
||||
|
||||
static ClientContext* client_context_free(Server *s, ClientContext *c) {
|
||||
@ -459,7 +459,7 @@ static int client_context_read_extra_fields(
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int client_context_read_log_rate_limit_interval(ClientContext *c) {
|
||||
static int client_context_read_log_ratelimit_interval(ClientContext *c) {
|
||||
_cleanup_free_ char *value = NULL;
|
||||
const char *p;
|
||||
int r;
|
||||
@ -474,10 +474,10 @@ static int client_context_read_log_rate_limit_interval(ClientContext *c) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return safe_atou64(value, &c->log_rate_limit_interval);
|
||||
return safe_atou64(value, &c->log_ratelimit_interval);
|
||||
}
|
||||
|
||||
static int client_context_read_log_rate_limit_burst(ClientContext *c) {
|
||||
static int client_context_read_log_ratelimit_burst(ClientContext *c) {
|
||||
_cleanup_free_ char *value = NULL;
|
||||
const char *p;
|
||||
int r;
|
||||
@ -492,7 +492,7 @@ static int client_context_read_log_rate_limit_burst(ClientContext *c) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return safe_atou(value, &c->log_rate_limit_burst);
|
||||
return safe_atou(value, &c->log_ratelimit_burst);
|
||||
}
|
||||
|
||||
static void client_context_really_refresh(
|
||||
@ -521,8 +521,8 @@ static void client_context_really_refresh(
|
||||
(void) client_context_read_invocation_id(s, c);
|
||||
(void) client_context_read_log_level_max(s, c);
|
||||
(void) client_context_read_extra_fields(s, c);
|
||||
(void) client_context_read_log_rate_limit_interval(c);
|
||||
(void) client_context_read_log_rate_limit_burst(c);
|
||||
(void) client_context_read_log_ratelimit_interval(c);
|
||||
(void) client_context_read_log_ratelimit_burst(c);
|
||||
|
||||
c->timestamp = timestamp;
|
||||
|
||||
|
@ -53,8 +53,8 @@ struct ClientContext {
|
||||
void *extra_fields_data;
|
||||
nsec_t extra_fields_mtime;
|
||||
|
||||
usec_t log_rate_limit_interval;
|
||||
unsigned log_rate_limit_burst;
|
||||
usec_t log_ratelimit_interval;
|
||||
unsigned log_ratelimit_burst;
|
||||
};
|
||||
|
||||
int client_context_get(
|
||||
|
@ -24,9 +24,9 @@ Journal.Seal, config_parse_bool, 0, offsetof(Server, seal)
|
||||
Journal.ReadKMsg, config_parse_bool, 0, offsetof(Server, read_kmsg)
|
||||
Journal.SyncIntervalSec, config_parse_sec, 0, offsetof(Server, sync_interval_usec)
|
||||
# The following is a legacy name for compatibility
|
||||
Journal.RateLimitInterval, config_parse_sec, 0, offsetof(Server, rate_limit_interval)
|
||||
Journal.RateLimitIntervalSec,config_parse_sec, 0, offsetof(Server, rate_limit_interval)
|
||||
Journal.RateLimitBurst, config_parse_unsigned, 0, offsetof(Server, rate_limit_burst)
|
||||
Journal.RateLimitInterval, config_parse_sec, 0, offsetof(Server, ratelimit_interval)
|
||||
Journal.RateLimitIntervalSec,config_parse_sec, 0, offsetof(Server, ratelimit_interval)
|
||||
Journal.RateLimitBurst, config_parse_unsigned, 0, offsetof(Server, ratelimit_burst)
|
||||
Journal.SystemMaxUse, config_parse_iec_uint64, 0, offsetof(Server, system_storage.metrics.max_use)
|
||||
Journal.SystemMaxFileSize, config_parse_iec_uint64, 0, offsetof(Server, system_storage.metrics.max_size)
|
||||
Journal.SystemKeepFree, config_parse_iec_uint64, 0, offsetof(Server, system_storage.metrics.keep_free)
|
||||
|
@ -60,7 +60,7 @@ struct JournalRateLimit {
|
||||
uint8_t hash_key[16];
|
||||
};
|
||||
|
||||
JournalRateLimit *journal_rate_limit_new(void) {
|
||||
JournalRateLimit *journal_ratelimit_new(void) {
|
||||
JournalRateLimit *r;
|
||||
|
||||
r = new0(JournalRateLimit, 1);
|
||||
@ -72,7 +72,7 @@ JournalRateLimit *journal_rate_limit_new(void) {
|
||||
return r;
|
||||
}
|
||||
|
||||
static void journal_rate_limit_group_free(JournalRateLimitGroup *g) {
|
||||
static void journal_ratelimit_group_free(JournalRateLimitGroup *g) {
|
||||
assert(g);
|
||||
|
||||
if (g->parent) {
|
||||
@ -91,16 +91,16 @@ static void journal_rate_limit_group_free(JournalRateLimitGroup *g) {
|
||||
free(g);
|
||||
}
|
||||
|
||||
void journal_rate_limit_free(JournalRateLimit *r) {
|
||||
void journal_ratelimit_free(JournalRateLimit *r) {
|
||||
assert(r);
|
||||
|
||||
while (r->lru)
|
||||
journal_rate_limit_group_free(r->lru);
|
||||
journal_ratelimit_group_free(r->lru);
|
||||
|
||||
free(r);
|
||||
}
|
||||
|
||||
_pure_ static bool journal_rate_limit_group_expired(JournalRateLimitGroup *g, usec_t ts) {
|
||||
_pure_ static bool journal_ratelimit_group_expired(JournalRateLimitGroup *g, usec_t ts) {
|
||||
unsigned i;
|
||||
|
||||
assert(g);
|
||||
@ -112,18 +112,18 @@ _pure_ static bool journal_rate_limit_group_expired(JournalRateLimitGroup *g, us
|
||||
return true;
|
||||
}
|
||||
|
||||
static void journal_rate_limit_vacuum(JournalRateLimit *r, usec_t ts) {
|
||||
static void journal_ratelimit_vacuum(JournalRateLimit *r, usec_t ts) {
|
||||
assert(r);
|
||||
|
||||
/* Makes room for at least one new item, but drop all
|
||||
* expored items too. */
|
||||
|
||||
while (r->n_groups >= GROUPS_MAX ||
|
||||
(r->lru_tail && journal_rate_limit_group_expired(r->lru_tail, ts)))
|
||||
journal_rate_limit_group_free(r->lru_tail);
|
||||
(r->lru_tail && journal_ratelimit_group_expired(r->lru_tail, ts)))
|
||||
journal_ratelimit_group_free(r->lru_tail);
|
||||
}
|
||||
|
||||
static JournalRateLimitGroup* journal_rate_limit_group_new(JournalRateLimit *r, const char *id, usec_t interval, usec_t ts) {
|
||||
static JournalRateLimitGroup* journal_ratelimit_group_new(JournalRateLimit *r, const char *id, usec_t interval, usec_t ts) {
|
||||
JournalRateLimitGroup *g;
|
||||
|
||||
assert(r);
|
||||
@ -141,7 +141,7 @@ static JournalRateLimitGroup* journal_rate_limit_group_new(JournalRateLimit *r,
|
||||
|
||||
g->interval = interval;
|
||||
|
||||
journal_rate_limit_vacuum(r, ts);
|
||||
journal_ratelimit_vacuum(r, ts);
|
||||
|
||||
LIST_PREPEND(bucket, r->buckets[g->hash % BUCKETS_MAX], g);
|
||||
LIST_PREPEND(lru, r->lru, g);
|
||||
@ -153,7 +153,7 @@ static JournalRateLimitGroup* journal_rate_limit_group_new(JournalRateLimit *r,
|
||||
return g;
|
||||
|
||||
fail:
|
||||
journal_rate_limit_group_free(g);
|
||||
journal_ratelimit_group_free(g);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -185,7 +185,7 @@ static unsigned burst_modulate(unsigned burst, uint64_t available) {
|
||||
return burst;
|
||||
}
|
||||
|
||||
int journal_rate_limit_test(JournalRateLimit *r, const char *id, usec_t rl_interval, unsigned rl_burst, int priority, uint64_t available) {
|
||||
int journal_ratelimit_test(JournalRateLimit *r, const char *id, usec_t rl_interval, unsigned rl_burst, int priority, uint64_t available) {
|
||||
uint64_t h;
|
||||
JournalRateLimitGroup *g;
|
||||
JournalRateLimitPool *p;
|
||||
@ -214,7 +214,7 @@ int journal_rate_limit_test(JournalRateLimit *r, const char *id, usec_t rl_inter
|
||||
break;
|
||||
|
||||
if (!g) {
|
||||
g = journal_rate_limit_group_new(r, id, rl_interval, ts);
|
||||
g = journal_ratelimit_group_new(r, id, rl_interval, ts);
|
||||
if (!g)
|
||||
return -ENOMEM;
|
||||
} else
|
||||
|
@ -5,6 +5,6 @@
|
||||
|
||||
typedef struct JournalRateLimit JournalRateLimit;
|
||||
|
||||
JournalRateLimit *journal_rate_limit_new(void);
|
||||
void journal_rate_limit_free(JournalRateLimit *r);
|
||||
int journal_rate_limit_test(JournalRateLimit *r, const char *id, usec_t rl_interval, unsigned rl_burst, int priority, uint64_t available);
|
||||
JournalRateLimit *journal_ratelimit_new(void);
|
||||
void journal_ratelimit_free(JournalRateLimit *r);
|
||||
int journal_ratelimit_test(JournalRateLimit *r, const char *id, usec_t rl_interval, unsigned rl_burst, int priority, uint64_t available);
|
||||
|
@ -1098,7 +1098,7 @@ void server_dispatch_message(
|
||||
if (c && c->unit) {
|
||||
(void) determine_space(s, &available, NULL);
|
||||
|
||||
rl = journal_rate_limit_test(s->rate_limit, c->unit, c->log_rate_limit_interval, c->log_rate_limit_burst, priority & LOG_PRIMASK, available);
|
||||
rl = journal_ratelimit_test(s->ratelimit, c->unit, c->log_ratelimit_interval, c->log_ratelimit_burst, priority & LOG_PRIMASK, available);
|
||||
if (rl == 0)
|
||||
return;
|
||||
|
||||
@ -2020,8 +2020,8 @@ int server_init(Server *s) {
|
||||
.sync_interval_usec = DEFAULT_SYNC_INTERVAL_USEC,
|
||||
.sync_scheduled = false,
|
||||
|
||||
.rate_limit_interval = DEFAULT_RATE_LIMIT_INTERVAL,
|
||||
.rate_limit_burst = DEFAULT_RATE_LIMIT_BURST,
|
||||
.ratelimit_interval = DEFAULT_RATE_LIMIT_INTERVAL,
|
||||
.ratelimit_burst = DEFAULT_RATE_LIMIT_BURST,
|
||||
|
||||
.forward_to_wall = true,
|
||||
|
||||
@ -2048,10 +2048,10 @@ int server_init(Server *s) {
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m");
|
||||
|
||||
if (!!s->rate_limit_interval ^ !!s->rate_limit_burst) {
|
||||
if (!!s->ratelimit_interval ^ !!s->ratelimit_burst) {
|
||||
log_debug("Setting both rate limit interval and burst from "USEC_FMT",%u to 0,0",
|
||||
s->rate_limit_interval, s->rate_limit_burst);
|
||||
s->rate_limit_interval = s->rate_limit_burst = 0;
|
||||
s->ratelimit_interval, s->ratelimit_burst);
|
||||
s->ratelimit_interval = s->ratelimit_burst = 0;
|
||||
}
|
||||
|
||||
(void) mkdir_p("/run/systemd/journal", 0755);
|
||||
@ -2180,8 +2180,8 @@ int server_init(Server *s) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
s->rate_limit = journal_rate_limit_new();
|
||||
if (!s->rate_limit)
|
||||
s->ratelimit = journal_ratelimit_new();
|
||||
if (!s->ratelimit)
|
||||
return -ENOMEM;
|
||||
|
||||
r = cg_get_root_path(&s->cgroup_root);
|
||||
@ -2261,8 +2261,8 @@ void server_done(Server *s) {
|
||||
safe_close(s->hostname_fd);
|
||||
safe_close(s->notify_fd);
|
||||
|
||||
if (s->rate_limit)
|
||||
journal_rate_limit_free(s->rate_limit);
|
||||
if (s->ratelimit)
|
||||
journal_ratelimit_free(s->ratelimit);
|
||||
|
||||
if (s->kernel_seqnum)
|
||||
munmap(s->kernel_seqnum, sizeof(uint64_t));
|
||||
|
@ -94,10 +94,10 @@ struct Server {
|
||||
char *buffer;
|
||||
size_t buffer_size;
|
||||
|
||||
JournalRateLimit *rate_limit;
|
||||
JournalRateLimit *ratelimit;
|
||||
usec_t sync_interval_usec;
|
||||
usec_t rate_limit_interval;
|
||||
unsigned rate_limit_burst;
|
||||
usec_t ratelimit_interval;
|
||||
unsigned ratelimit_burst;
|
||||
|
||||
JournalStorage runtime_storage;
|
||||
JournalStorage system_storage;
|
||||
|
@ -70,7 +70,7 @@ int dns_scope_new(Manager *m, DnsScope **ret, Link *l, DnsProtocol protocol, int
|
||||
log_debug("New scope on link %s, protocol %s, family %s", l ? l->ifname : "*", dns_protocol_to_string(protocol), family == AF_UNSPEC ? "*" : af_to_name(family));
|
||||
|
||||
/* Enforce ratelimiting for the multicast protocols */
|
||||
RATELIMIT_INIT(s->ratelimit, MULTICAST_RATELIMIT_INTERVAL_USEC, MULTICAST_RATELIMIT_BURST);
|
||||
s->ratelimit = (RateLimit) { MULTICAST_RATELIMIT_INTERVAL_USEC, MULTICAST_RATELIMIT_BURST };
|
||||
|
||||
*ret = s;
|
||||
return 0;
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
static void test_ratelimit_below(void) {
|
||||
int i;
|
||||
RATELIMIT_DEFINE(ratelimit, 1 * USEC_PER_SEC, 10);
|
||||
RateLimit ratelimit = { 1 * USEC_PER_SEC, 10 };
|
||||
|
||||
for (i = 0; i < 10; i++)
|
||||
assert_se(ratelimit_below(&ratelimit));
|
||||
@ -17,7 +17,7 @@ static void test_ratelimit_below(void) {
|
||||
for (i = 0; i < 10; i++)
|
||||
assert_se(ratelimit_below(&ratelimit));
|
||||
|
||||
RATELIMIT_INIT(ratelimit, 0, 10);
|
||||
ratelimit = (RateLimit) { 0, 10 };
|
||||
for (i = 0; i < 10000; i++)
|
||||
assert_se(ratelimit_below(&ratelimit));
|
||||
}
|
||||
|
@ -1094,7 +1094,7 @@ int manager_new(Manager **ret) {
|
||||
|
||||
m->server_socket = m->clock_watch_fd = -1;
|
||||
|
||||
RATELIMIT_INIT(m->ratelimit, RATELIMIT_INTERVAL_USEC, RATELIMIT_BURST);
|
||||
m->ratelimit = (RateLimit) { RATELIMIT_INTERVAL_USEC, RATELIMIT_BURST };
|
||||
|
||||
r = sd_event_default(&m->event);
|
||||
if (r < 0)
|
||||
|
Loading…
Reference in New Issue
Block a user