summaryrefslogtreecommitdiffstats
path: root/src/basic/syslog-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2019-11-25 15:00:38 +0100
committerLennart Poettering <lennart@poettering.net>2020-01-31 15:01:18 +0100
commitb1852c48c12754f7d0e7705150b7f9488f34f4a9 (patch)
treed670d7a30e6c5dbe1c56597523775b7c7ad6f676 /src/basic/syslog-util.c
parentjournald: when create journal directories use calculated paths (diff)
downloadsystemd-b1852c48c12754f7d0e7705150b7f9488f34f4a9.tar.xz
systemd-b1852c48c12754f7d0e7705150b7f9488f34f4a9.zip
journald: allow running multiple instances of journald
If we do, we operate on a separate set of logs and runtime objects The namespace is configured via argv[1]. Fixes: #12123 Fixes: #10230 #9519 (These latter two issues ask for slightly different stuff, but the usecases generally can be solved by running separate instances of journald now, hence also declaring that as "Fixes:")
Diffstat (limited to 'src/basic/syslog-util.c')
-rw-r--r--src/basic/syslog-util.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/basic/syslog-util.c b/src/basic/syslog-util.c
index 29c9ec9ac4..caeba46db4 100644
--- a/src/basic/syslog-util.c
+++ b/src/basic/syslog-util.c
@@ -2,10 +2,15 @@
#include <syslog.h>
+#include "sd-id128.h"
+
+#include "glob-util.h"
#include "hexdecoct.h"
#include "macro.h"
+#include "path-util.h"
#include "string-table.h"
#include "syslog-util.h"
+#include "unit-name.h"
int syslog_parse_priority(const char **p, int *priority, bool with_facility) {
int a = 0, b = 0, c = 0;
@@ -96,3 +101,31 @@ DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(log_level, int, LOG_DEBUG);
bool log_level_is_valid(int level) {
return level >= 0 && level <= LOG_DEBUG;
}
+
+/* The maximum size for a log namespace length. This is the file name size limit 255 minus the size of a
+ * formatted machine ID minus a separator char */
+#define LOG_NAMESPACE_MAX (NAME_MAX - (SD_ID128_STRING_MAX - 1) - 1)
+
+bool log_namespace_name_valid(const char *s) {
+ /* Let's make sure the namespace fits in a filename that is prefixed with the machine ID and a dot
+ * (so that /var/log/journal/<machine-id>.<namespace> can be created based on it). Also make sure it
+ * is suitable as unit instance name, and does not contain fishy characters. */
+
+ if (!filename_is_valid(s))
+ return false;
+
+ if (strlen(s) > LOG_NAMESPACE_MAX)
+ return false;
+
+ if (!unit_instance_is_valid(s))
+ return false;
+
+ if (!string_is_safe(s))
+ return false;
+
+ /* Let's avoid globbing for now */
+ if (string_is_glob(s))
+ return false;
+
+ return true;
+}