_LOG_TARGET_INVALID = -EINVAL,
} LogTarget;
+/* This log level disables logging completely. It can only be passed to log_set_max_level() and cannot be
+ * used a regular log level. */
+#define LOG_NULL (LOG_EMERG - 1)
+
/* Note to readers: << and >> have lower precedence than & and | */
#define SYNTHETIC_ERRNO(num) (1 << 30 | (num))
#define IS_SYNTHETIC_ERRNO(val) ((val) >> 30 & 1)
#include "journald-kmsg.h"
#include "journald-server.h"
#include "journald-syslog.h"
+#include "log.h"
#include "parse-util.h"
#include "process-util.h"
#include "stdio-util.h"
char *e, *f, *k;
uint64_t serial;
size_t pl;
+ int saved_log_max_level = INT_MAX;
+ ClientContext *c = NULL;
assert(s);
assert(p);
else {
pl -= syslog_parse_identifier((const char**) &p, &identifier, &pid);
- /* Avoid any messages we generated ourselves via
- * log_info() and friends. */
- if (is_us(identifier, pid))
- goto finish;
+ /* Avoid logging any new messages when we're processing messages generated by ourselves via
+ * log_info() and friends to avoid infinite loops. */
+ if (is_us(identifier, pid)) {
+ if (!ratelimit_below(&s->kmsg_own_ratelimit))
+ return;
+
+ saved_log_max_level = log_get_max_level();
+ c = s->my_context;
+ log_set_max_level(LOG_NULL);
+ }
if (identifier) {
syslog_identifier = strjoin("SYSLOG_IDENTIFIER=", identifier);
if (cunescape_length_with_prefix(p, pl, "MESSAGE=", UNESCAPE_RELAX, &message) >= 0)
iovec[n++] = IOVEC_MAKE_STRING(message);
- server_dispatch_message(s, iovec, n, ELEMENTSOF(iovec), NULL, NULL, priority, 0);
+
+ server_dispatch_message(s, iovec, n, ELEMENTSOF(iovec), c, NULL, priority, 0);
+
+ if (saved_log_max_level != INT_MAX)
+ log_set_max_level(saved_log_max_level);
finish:
for (j = 0; j < z; j++)
#define DEFAULT_RATE_LIMIT_BURST 10000
#define DEFAULT_MAX_FILE_USEC USEC_PER_MONTH
+#define DEFAULT_KMSG_OWN_INTERVAL (5 * USEC_PER_SEC)
+#define DEFAULT_KMSG_OWN_BURST 50
+
#define RECHECK_SPACE_USEC (30*USEC_PER_SEC)
#define NOTIFY_SNDBUF_SIZE (8*1024*1024)
.runtime_storage.name = "Runtime Journal",
.system_storage.name = "System Journal",
+
+ .kmsg_own_ratelimit = {
+ .interval = DEFAULT_KMSG_OWN_INTERVAL,
+ .burst = DEFAULT_KMSG_OWN_BURST,
+ },
};
r = set_namespace(s, namespace);