summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/journal/journal-gatewayd.c2
-rw-r--r--src/journal/sd-journal.c45
-rw-r--r--src/python-systemd/_reader.c1
-rw-r--r--src/shared/logs-show.c2
-rw-r--r--src/systemd/sd-journal.h4
5 files changed, 45 insertions, 9 deletions
diff --git a/src/journal/journal-gatewayd.c b/src/journal/journal-gatewayd.c
index 745f45f932..86338c66f3 100644
--- a/src/journal/journal-gatewayd.c
+++ b/src/journal/journal-gatewayd.c
@@ -109,7 +109,7 @@ static int open_journal(RequestMeta *m) {
if (m->journal)
return 0;
- return sd_journal_open(&m->journal, SD_JOURNAL_LOCAL_ONLY|SD_JOURNAL_SYSTEM_ONLY);
+ return sd_journal_open(&m->journal, SD_JOURNAL_LOCAL_ONLY|SD_JOURNAL_SYSTEM);
}
static int respond_oom_internal(struct MHD_Connection *connection) {
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index 2bad243ea1..46511df6be 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -1249,6 +1249,42 @@ static void check_network(sd_journal *j, int fd) {
F_TYPE_CMP(sfs.f_type, SMB_SUPER_MAGIC);
}
+static bool file_has_type_prefix(const char *prefix, const char *filename) {
+ const char *full, *tilded, *atted;
+
+ full = strappend(prefix, ".journal");
+ tilded = strappenda(full, "~");
+ atted = strappenda(prefix, "@");
+
+ return streq(filename, full) ||
+ streq(filename, tilded) ||
+ startswith(filename, atted);
+}
+
+static bool file_type_wanted(int flags, const char *filename) {
+ if (!endswith(filename, ".journal") && !endswith(filename, ".journal~"))
+ return false;
+
+ /* no flags set → every type is OK */
+ if (!(flags & (SD_JOURNAL_SYSTEM | SD_JOURNAL_CURRENT_USER)))
+ return true;
+
+ if (flags & SD_JOURNAL_SYSTEM && file_has_type_prefix("system", filename))
+ return true;
+
+ if (flags & SD_JOURNAL_CURRENT_USER) {
+ char prefix[5 + DECIMAL_STR_MAX(uid_t) + 1];
+
+ assert_se(snprintf(prefix, sizeof(prefix), "user-%lu", (unsigned long) getuid())
+ < (int) sizeof(prefix));
+
+ if (file_has_type_prefix(prefix, filename))
+ return true;
+ }
+
+ return false;
+}
+
static int add_file(sd_journal *j, const char *prefix, const char *filename) {
_cleanup_free_ char *path = NULL;
int r;
@@ -1258,11 +1294,7 @@ static int add_file(sd_journal *j, const char *prefix, const char *filename) {
assert(prefix);
assert(filename);
- if ((j->flags & SD_JOURNAL_SYSTEM_ONLY) &&
- !(streq(filename, "system.journal") ||
- streq(filename, "system.journal~") ||
- (startswith(filename, "system@") &&
- (endswith(filename, ".journal") || endswith(filename, ".journal~")))))
+ if (!file_type_wanted(j->flags, filename))
return 0;
path = strjoin(prefix, "/", filename, NULL);
@@ -1619,7 +1651,8 @@ _public_ int sd_journal_open(sd_journal **ret, int flags) {
if (flags & ~(SD_JOURNAL_LOCAL_ONLY|
SD_JOURNAL_RUNTIME_ONLY|
- SD_JOURNAL_SYSTEM_ONLY))
+ SD_JOURNAL_SYSTEM|
+ SD_JOURNAL_CURRENT_USER))
return -EINVAL;
j = journal_new(flags, NULL);
diff --git a/src/python-systemd/_reader.c b/src/python-systemd/_reader.c
index c4c4fdfe1d..2c699630c2 100644
--- a/src/python-systemd/_reader.c
+++ b/src/python-systemd/_reader.c
@@ -1097,6 +1097,7 @@ init_reader(void)
PyModule_AddIntConstant(m, "INVALIDATE", SD_JOURNAL_INVALIDATE) ||
PyModule_AddIntConstant(m, "LOCAL_ONLY", SD_JOURNAL_LOCAL_ONLY) ||
PyModule_AddIntConstant(m, "RUNTIME_ONLY", SD_JOURNAL_RUNTIME_ONLY) ||
+ PyModule_AddIntConstant(m, "SYSTEM", SD_JOURNAL_SYSTEM) ||
PyModule_AddIntConstant(m, "SYSTEM_ONLY", SD_JOURNAL_SYSTEM_ONLY) ||
PyModule_AddStringConstant(m, "__version__", PACKAGE_VERSION)) {
#if PY_MAJOR_VERSION >= 3
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
index 7947df3a89..013a281eac 100644
--- a/src/shared/logs-show.c
+++ b/src/shared/logs-show.c
@@ -1010,7 +1010,7 @@ int show_journal_by_unit(
_cleanup_journal_close_ sd_journal*j = NULL;
int r;
- int jflags = SD_JOURNAL_LOCAL_ONLY | system * SD_JOURNAL_SYSTEM_ONLY;
+ int jflags = SD_JOURNAL_LOCAL_ONLY | system * SD_JOURNAL_SYSTEM;
assert(mode >= 0);
assert(mode < _OUTPUT_MODE_MAX);
diff --git a/src/systemd/sd-journal.h b/src/systemd/sd-journal.h
index 5375d49963..cf105cde72 100644
--- a/src/systemd/sd-journal.h
+++ b/src/systemd/sd-journal.h
@@ -86,7 +86,9 @@ typedef struct sd_journal sd_journal;
enum {
SD_JOURNAL_LOCAL_ONLY = 1,
SD_JOURNAL_RUNTIME_ONLY = 2,
- SD_JOURNAL_SYSTEM_ONLY = 4
+ SD_JOURNAL_SYSTEM = 4,
+ SD_JOURNAL_SYSTEM_ONLY = SD_JOURNAL_SYSTEM, /* deprecated */
+ SD_JOURNAL_CURRENT_USER = 8,
};
/* Wakeup event types */