|
|
17b0f1 |
From 5ec508cc5c13d831c93ce98d84b1d9cedb0117a7 Mon Sep 17 00:00:00 2001
|
|
|
17b0f1 |
From: Jan Synacek <jsynacek@redhat.com>
|
|
|
17b0f1 |
Date: Mon, 1 Feb 2016 09:23:58 +0100
|
|
|
17b0f1 |
Subject: [PATCH] sd-journal: introduce has_runtime_files and
|
|
|
17b0f1 |
has_persistent_files
|
|
|
17b0f1 |
|
|
|
17b0f1 |
Also introduce sd_journal_has_runtime_files() and
|
|
|
17b0f1 |
sd_journal_has_persistent_files() to the public API. These functions
|
|
|
17b0f1 |
can be used to easily find out if the open journal files are runtime
|
|
|
17b0f1 |
and/or persistent.
|
|
|
17b0f1 |
|
|
|
17b0f1 |
Cherry-picked from: 39fd5b08a73f144a20202a665bd25cad51d8a90b
|
|
|
17b0f1 |
Resolves: #1082179
|
|
|
17b0f1 |
---
|
|
|
17b0f1 |
Makefile-man.am | 7 ++
|
|
|
17b0f1 |
man/sd-journal.xml | 8 ++-
|
|
|
17b0f1 |
man/sd_journal_has_runtime_files.xml | 95 ++++++++++++++++++++++++++++
|
|
|
17b0f1 |
src/journal/journal-internal.h | 2 +
|
|
|
17b0f1 |
src/journal/sd-journal.c | 29 ++++++---
|
|
|
17b0f1 |
src/systemd/sd-journal.h | 3 +
|
|
|
17b0f1 |
6 files changed, 133 insertions(+), 11 deletions(-)
|
|
|
17b0f1 |
create mode 100644 man/sd_journal_has_runtime_files.xml
|
|
|
17b0f1 |
|
|
|
17b0f1 |
diff --git a/Makefile-man.am b/Makefile-man.am
|
|
|
17b0f1 |
index 497be6612c..7ec709c8b8 100644
|
|
|
17b0f1 |
--- a/Makefile-man.am
|
|
|
17b0f1 |
+++ b/Makefile-man.am
|
|
|
17b0f1 |
@@ -40,6 +40,7 @@ MANPAGES += \
|
|
|
17b0f1 |
man/sd_journal_get_fd.3 \
|
|
|
17b0f1 |
man/sd_journal_get_realtime_usec.3 \
|
|
|
17b0f1 |
man/sd_journal_get_usage.3 \
|
|
|
17b0f1 |
+ man/sd_journal_has_runtime_files.3 \
|
|
|
17b0f1 |
man/sd_journal_next.3 \
|
|
|
17b0f1 |
man/sd_journal_open.3 \
|
|
|
17b0f1 |
man/sd_journal_print.3 \
|
|
|
17b0f1 |
@@ -176,6 +177,7 @@ MANPAGES_ALIAS += \
|
|
|
17b0f1 |
man/sd_journal_get_events.3 \
|
|
|
17b0f1 |
man/sd_journal_get_monotonic_usec.3 \
|
|
|
17b0f1 |
man/sd_journal_get_timeout.3 \
|
|
|
17b0f1 |
+ man/sd_journal_has_persistent_files.3 \
|
|
|
17b0f1 |
man/sd_journal_next_skip.3 \
|
|
|
17b0f1 |
man/sd_journal_open_container.3 \
|
|
|
17b0f1 |
man/sd_journal_open_directory.3 \
|
|
|
17b0f1 |
@@ -287,6 +289,7 @@ man/sd_journal_get_data_threshold.3: man/sd_journal_get_data.3
|
|
|
17b0f1 |
man/sd_journal_get_events.3: man/sd_journal_get_fd.3
|
|
|
17b0f1 |
man/sd_journal_get_monotonic_usec.3: man/sd_journal_get_realtime_usec.3
|
|
|
17b0f1 |
man/sd_journal_get_timeout.3: man/sd_journal_get_fd.3
|
|
|
17b0f1 |
+man/sd_journal_has_persistent_files.3: man/sd_journal_has_runtime_files.3
|
|
|
17b0f1 |
man/sd_journal_next_skip.3: man/sd_journal_next.3
|
|
|
17b0f1 |
man/sd_journal_open_container.3: man/sd_journal_open.3
|
|
|
17b0f1 |
man/sd_journal_open_directory.3: man/sd_journal_open.3
|
|
|
17b0f1 |
@@ -500,6 +503,9 @@ man/sd_journal_get_monotonic_usec.html: man/sd_journal_get_realtime_usec.html
|
|
|
17b0f1 |
man/sd_journal_get_timeout.html: man/sd_journal_get_fd.html
|
|
|
17b0f1 |
$(html-alias)
|
|
|
17b0f1 |
|
|
|
17b0f1 |
+man/sd_journal_has_persistent_files.html: man/sd_journal_has_runtime_files.html
|
|
|
17b0f1 |
+ $(html-alias)
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
man/sd_journal_next_skip.html: man/sd_journal_next.html
|
|
|
17b0f1 |
$(html-alias)
|
|
|
17b0f1 |
|
|
|
17b0f1 |
@@ -1727,6 +1733,7 @@ EXTRA_DIST += \
|
|
|
17b0f1 |
man/sd_journal_get_fd.xml \
|
|
|
17b0f1 |
man/sd_journal_get_realtime_usec.xml \
|
|
|
17b0f1 |
man/sd_journal_get_usage.xml \
|
|
|
17b0f1 |
+ man/sd_journal_has_runtime_files.xml \
|
|
|
17b0f1 |
man/sd_journal_next.xml \
|
|
|
17b0f1 |
man/sd_journal_open.xml \
|
|
|
17b0f1 |
man/sd_journal_print.xml \
|
|
|
17b0f1 |
diff --git a/man/sd-journal.xml b/man/sd-journal.xml
|
|
|
17b0f1 |
index 9b1a52207f..a1185d372b 100644
|
|
|
17b0f1 |
--- a/man/sd-journal.xml
|
|
|
17b0f1 |
+++ b/man/sd-journal.xml
|
|
|
17b0f1 |
@@ -81,9 +81,11 @@
|
|
|
17b0f1 |
<citerefentry><refentrytitle>sd_journal_get_cutoff_realtime_usec</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
|
|
17b0f1 |
<citerefentry><refentrytitle>sd_journal_get_cutoff_monotonic_usec</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
|
|
17b0f1 |
<citerefentry><refentrytitle>sd_journal_get_usage</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
|
|
17b0f1 |
- <citerefentry><refentrytitle>sd_journal_get_catalog</refentrytitle><manvolnum>3</manvolnum></citerefentry>
|
|
|
17b0f1 |
+ <citerefentry><refentrytitle>sd_journal_get_catalog</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
|
|
17b0f1 |
+ <citerefentry><refentrytitle>sd_journal_get_fd</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
|
|
17b0f1 |
+ <citerefentry><refentrytitle>sd_journal_has_runtime_files</refentrytitle><manvolnum>3</manvolnum></citerefentry>
|
|
|
17b0f1 |
and
|
|
|
17b0f1 |
- <citerefentry><refentrytitle>sd_journal_get_fd</refentrytitle><manvolnum>3</manvolnum></citerefentry>
|
|
|
17b0f1 |
+ <citerefentry><refentrytitle>sd_journal_has_persistent_files</refentrytitle><manvolnum>3</manvolnum></citerefentry>
|
|
|
17b0f1 |
for more information about the functions implemented.</para>
|
|
|
17b0f1 |
|
|
|
17b0f1 |
<para>Command line access for submitting entries to the journal is
|
|
|
17b0f1 |
@@ -116,6 +118,8 @@
|
|
|
17b0f1 |
<citerefentry><refentrytitle>sd_journal_get_fd</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
|
|
17b0f1 |
<citerefentry><refentrytitle>sd_journal_query_unique</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
|
|
17b0f1 |
<citerefentry><refentrytitle>sd_journal_get_catalog</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
|
|
17b0f1 |
+ <citerefentry><refentrytitle>sd_journal_has_runtime_files</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
|
|
17b0f1 |
+ <citerefentry><refentrytitle>sd_journal_has_persistent_files</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
|
|
17b0f1 |
<citerefentry><refentrytitle>journalctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
|
|
|
17b0f1 |
<citerefentry><refentrytitle>sd-id128</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
|
|
17b0f1 |
<citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
|
|
|
17b0f1 |
diff --git a/man/sd_journal_has_runtime_files.xml b/man/sd_journal_has_runtime_files.xml
|
|
|
17b0f1 |
new file mode 100644
|
|
|
17b0f1 |
index 0000000000..237e649206
|
|
|
17b0f1 |
--- /dev/null
|
|
|
17b0f1 |
+++ b/man/sd_journal_has_runtime_files.xml
|
|
|
17b0f1 |
@@ -0,0 +1,95 @@
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ This file is part of systemd.
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ Copyright 2016 Jan Synáček
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ systemd is free software; you can redistribute it and/or modify it
|
|
|
17b0f1 |
+ under the terms of the GNU Lesser General Public License as published by
|
|
|
17b0f1 |
+ the Free Software Foundation; either version 2.1 of the License, or
|
|
|
17b0f1 |
+ (at your option) any later version.
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ systemd is distributed in the hope that it will be useful, but
|
|
|
17b0f1 |
+ WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
17b0f1 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
17b0f1 |
+ Lesser General Public License for more details.
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ You should have received a copy of the GNU Lesser General Public License
|
|
|
17b0f1 |
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
|
17b0f1 |
+-->
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+<refentry id="sd_journal_has_runtime_files">
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ <refentryinfo>
|
|
|
17b0f1 |
+ <title>sd_journal_has_runtime_files</title>
|
|
|
17b0f1 |
+ <productname>systemd</productname>
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ <authorgroup>
|
|
|
17b0f1 |
+ <author>
|
|
|
17b0f1 |
+ <contrib>Developer</contrib>
|
|
|
17b0f1 |
+ <firstname>Jan</firstname>
|
|
|
17b0f1 |
+ <surname>Synáček</surname>
|
|
|
17b0f1 |
+ <email>jan.synacek@gmail.com</email>
|
|
|
17b0f1 |
+ </author>
|
|
|
17b0f1 |
+ </authorgroup>
|
|
|
17b0f1 |
+ </refentryinfo>
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ <refmeta>
|
|
|
17b0f1 |
+ <refentrytitle>sd_journal_has_runtime_files</refentrytitle>
|
|
|
17b0f1 |
+ <manvolnum>3</manvolnum>
|
|
|
17b0f1 |
+ </refmeta>
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ <refnamediv>
|
|
|
17b0f1 |
+ <refname>sd_journal_has_runtime_files</refname>
|
|
|
17b0f1 |
+ <refname>sd_journal_has_persistent_files</refname>
|
|
|
17b0f1 |
+ <refpurpose>Query availability of runtime or persistent journal files.</refpurpose>
|
|
|
17b0f1 |
+ </refnamediv>
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ <refsynopsisdiv>
|
|
|
17b0f1 |
+ <funcsynopsis>
|
|
|
17b0f1 |
+ <funcsynopsisinfo>#include <systemd/sd-journal.h></funcsynopsisinfo>
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ <funcprototype>
|
|
|
17b0f1 |
+ <funcdef>int <function>sd_journal_has_runtime_files</function></funcdef>
|
|
|
17b0f1 |
+ <paramdef>sd_journal *<parameter>j</parameter></paramdef>
|
|
|
17b0f1 |
+ </funcprototype>
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ <funcprototype>
|
|
|
17b0f1 |
+ <funcdef>int <function>sd_journal_has_persistent_files</function></funcdef>
|
|
|
17b0f1 |
+ <paramdef>sd_journal *<parameter>j</parameter></paramdef>
|
|
|
17b0f1 |
+ </funcprototype>
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ </funcsynopsis>
|
|
|
17b0f1 |
+ </refsynopsisdiv>
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ <refsect1>
|
|
|
17b0f1 |
+ <title>Description</title>
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ <para><function>sd_journal_has_runtime_files()</function> returns a positive value
|
|
|
17b0f1 |
+ if runtime journal files (present in /run/systemd/journal/) have been found.
|
|
|
17b0f1 |
+ Otherwise returns 0.</para>
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ <para><function>sd_journal_has_persistent_files()</function> returns a positive value
|
|
|
17b0f1 |
+ if persistent journal files (present in /var/log/journal/) have been found.
|
|
|
17b0f1 |
+ Otherwise returns 0.</para>
|
|
|
17b0f1 |
+ </refsect1>
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ <refsect1>
|
|
|
17b0f1 |
+ <title>Return value</title>
|
|
|
17b0f1 |
+ <para>Both <function>sd_journal_has_runtime_files()</function>
|
|
|
17b0f1 |
+ and <function>sd_journal_has_persistent_files()</function> return -EINVAL
|
|
|
17b0f1 |
+ if their argument is NULL.
|
|
|
17b0f1 |
+ </para>
|
|
|
17b0f1 |
+ </refsect1>
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ <refsect1>
|
|
|
17b0f1 |
+ <title>See Also</title>
|
|
|
17b0f1 |
+ <para>
|
|
|
17b0f1 |
+ <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry>
|
|
|
17b0f1 |
+ </para>
|
|
|
17b0f1 |
+ </refsect1>
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+</refentry>
|
|
|
17b0f1 |
diff --git a/src/journal/journal-internal.h b/src/journal/journal-internal.h
|
|
|
17b0f1 |
index b51ecdb600..115d7776da 100644
|
|
|
17b0f1 |
--- a/src/journal/journal-internal.h
|
|
|
17b0f1 |
+++ b/src/journal/journal-internal.h
|
|
|
17b0f1 |
@@ -115,6 +115,8 @@ struct sd_journal {
|
|
|
17b0f1 |
removed, and there were no more
|
|
|
17b0f1 |
files, so sd_j_enumerate_unique
|
|
|
17b0f1 |
will return a value equal to 0. */
|
|
|
17b0f1 |
+ bool has_runtime_files:1;
|
|
|
17b0f1 |
+ bool has_persistent_files:1;
|
|
|
17b0f1 |
|
|
|
17b0f1 |
size_t data_threshold;
|
|
|
17b0f1 |
|
|
|
17b0f1 |
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
|
|
|
17b0f1 |
index 9b9e8ac859..20456c3a12 100644
|
|
|
17b0f1 |
--- a/src/journal/sd-journal.c
|
|
|
17b0f1 |
+++ b/src/journal/sd-journal.c
|
|
|
17b0f1 |
@@ -1230,8 +1230,7 @@ static int add_any_file(sd_journal *j, const char *path) {
|
|
|
17b0f1 |
}
|
|
|
17b0f1 |
|
|
|
17b0f1 |
static int add_file(sd_journal *j, const char *prefix, const char *filename) {
|
|
|
17b0f1 |
- _cleanup_free_ char *path = NULL;
|
|
|
17b0f1 |
- int r;
|
|
|
17b0f1 |
+ char *path = NULL;
|
|
|
17b0f1 |
|
|
|
17b0f1 |
assert(j);
|
|
|
17b0f1 |
assert(prefix);
|
|
|
17b0f1 |
@@ -1241,14 +1240,14 @@ static int add_file(sd_journal *j, const char *prefix, const char *filename) {
|
|
|
17b0f1 |
!file_type_wanted(j->flags, filename))
|
|
|
17b0f1 |
return 0;
|
|
|
17b0f1 |
|
|
|
17b0f1 |
- path = strjoin(prefix, "/", filename, NULL);
|
|
|
17b0f1 |
- if (!path)
|
|
|
17b0f1 |
- return -ENOMEM;
|
|
|
17b0f1 |
+ path = strjoina(prefix, "/", filename);
|
|
|
17b0f1 |
|
|
|
17b0f1 |
- r = add_any_file(j, path);
|
|
|
17b0f1 |
- if (r == -ENOENT)
|
|
|
17b0f1 |
- return 0;
|
|
|
17b0f1 |
- return r;
|
|
|
17b0f1 |
+ if (!j->has_runtime_files && path_startswith(path, "/run/log/journal"))
|
|
|
17b0f1 |
+ j->has_runtime_files = true;
|
|
|
17b0f1 |
+ else if (!j->has_persistent_files && path_startswith(path, "/var/log/journal"))
|
|
|
17b0f1 |
+ j->has_persistent_files = true;
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ return add_any_file(j, path);
|
|
|
17b0f1 |
}
|
|
|
17b0f1 |
|
|
|
17b0f1 |
static int remove_file(sd_journal *j, const char *prefix, const char *filename) {
|
|
|
17b0f1 |
@@ -2616,3 +2615,15 @@ _public_ int sd_journal_get_data_threshold(sd_journal *j, size_t *sz) {
|
|
|
17b0f1 |
*sz = j->data_threshold;
|
|
|
17b0f1 |
return 0;
|
|
|
17b0f1 |
}
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+_public_ int sd_journal_has_runtime_files(sd_journal *j) {
|
|
|
17b0f1 |
+ assert_return(j, -EINVAL);
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ return j->has_runtime_files;
|
|
|
17b0f1 |
+}
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+_public_ int sd_journal_has_persistent_files(sd_journal *j) {
|
|
|
17b0f1 |
+ assert_return(j, -EINVAL);
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ return j->has_persistent_files;
|
|
|
17b0f1 |
+}
|
|
|
17b0f1 |
diff --git a/src/systemd/sd-journal.h b/src/systemd/sd-journal.h
|
|
|
17b0f1 |
index 00237a2158..d5fd46eea4 100644
|
|
|
17b0f1 |
--- a/src/systemd/sd-journal.h
|
|
|
17b0f1 |
+++ b/src/systemd/sd-journal.h
|
|
|
17b0f1 |
@@ -138,6 +138,9 @@ int sd_journal_reliable_fd(sd_journal *j);
|
|
|
17b0f1 |
int sd_journal_get_catalog(sd_journal *j, char **text);
|
|
|
17b0f1 |
int sd_journal_get_catalog_for_message_id(sd_id128_t id, char **text);
|
|
|
17b0f1 |
|
|
|
17b0f1 |
+int sd_journal_has_runtime_files(sd_journal *j);
|
|
|
17b0f1 |
+int sd_journal_has_persistent_files(sd_journal *j);
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
/* the inverse condition avoids ambiguity of danling 'else' after the macro */
|
|
|
17b0f1 |
#define SD_JOURNAL_FOREACH(j) \
|
|
|
17b0f1 |
if (sd_journal_seek_head(j) < 0) { } \
|