Merge pull request #2497 from jsynacek/bootoffset-runtime-v4
Expose additional booleans in sd_journal and improve error messages in journalctl
This commit is contained in:
commit
f3ade27e68
|
@ -79,6 +79,7 @@ MANPAGES += \
|
||||||
man/sd_journal_get_fd.3 \
|
man/sd_journal_get_fd.3 \
|
||||||
man/sd_journal_get_realtime_usec.3 \
|
man/sd_journal_get_realtime_usec.3 \
|
||||||
man/sd_journal_get_usage.3 \
|
man/sd_journal_get_usage.3 \
|
||||||
|
man/sd_journal_has_runtime_files.3 \
|
||||||
man/sd_journal_next.3 \
|
man/sd_journal_next.3 \
|
||||||
man/sd_journal_open.3 \
|
man/sd_journal_open.3 \
|
||||||
man/sd_journal_print.3 \
|
man/sd_journal_print.3 \
|
||||||
|
@ -384,6 +385,7 @@ MANPAGES_ALIAS += \
|
||||||
man/sd_journal_get_events.3 \
|
man/sd_journal_get_events.3 \
|
||||||
man/sd_journal_get_monotonic_usec.3 \
|
man/sd_journal_get_monotonic_usec.3 \
|
||||||
man/sd_journal_get_timeout.3 \
|
man/sd_journal_get_timeout.3 \
|
||||||
|
man/sd_journal_has_persistent_files.3 \
|
||||||
man/sd_journal_next_skip.3 \
|
man/sd_journal_next_skip.3 \
|
||||||
man/sd_journal_open_container.3 \
|
man/sd_journal_open_container.3 \
|
||||||
man/sd_journal_open_directory.3 \
|
man/sd_journal_open_directory.3 \
|
||||||
|
@ -711,6 +713,7 @@ man/sd_journal_get_data_threshold.3: man/sd_journal_get_data.3
|
||||||
man/sd_journal_get_events.3: man/sd_journal_get_fd.3
|
man/sd_journal_get_events.3: man/sd_journal_get_fd.3
|
||||||
man/sd_journal_get_monotonic_usec.3: man/sd_journal_get_realtime_usec.3
|
man/sd_journal_get_monotonic_usec.3: man/sd_journal_get_realtime_usec.3
|
||||||
man/sd_journal_get_timeout.3: man/sd_journal_get_fd.3
|
man/sd_journal_get_timeout.3: man/sd_journal_get_fd.3
|
||||||
|
man/sd_journal_has_persistent_files.3: man/sd_journal_has_runtime_files.3
|
||||||
man/sd_journal_next_skip.3: man/sd_journal_next.3
|
man/sd_journal_next_skip.3: man/sd_journal_next.3
|
||||||
man/sd_journal_open_container.3: man/sd_journal_open.3
|
man/sd_journal_open_container.3: man/sd_journal_open.3
|
||||||
man/sd_journal_open_directory.3: man/sd_journal_open.3
|
man/sd_journal_open_directory.3: man/sd_journal_open.3
|
||||||
|
@ -1458,6 +1461,9 @@ man/sd_journal_get_monotonic_usec.html: man/sd_journal_get_realtime_usec.html
|
||||||
man/sd_journal_get_timeout.html: man/sd_journal_get_fd.html
|
man/sd_journal_get_timeout.html: man/sd_journal_get_fd.html
|
||||||
$(html-alias)
|
$(html-alias)
|
||||||
|
|
||||||
|
man/sd_journal_has_persistent_files.html: man/sd_journal_has_runtime_files.html
|
||||||
|
$(html-alias)
|
||||||
|
|
||||||
man/sd_journal_next_skip.html: man/sd_journal_next.html
|
man/sd_journal_next_skip.html: man/sd_journal_next.html
|
||||||
$(html-alias)
|
$(html-alias)
|
||||||
|
|
||||||
|
@ -2535,6 +2541,7 @@ EXTRA_DIST += \
|
||||||
man/sd_journal_get_fd.xml \
|
man/sd_journal_get_fd.xml \
|
||||||
man/sd_journal_get_realtime_usec.xml \
|
man/sd_journal_get_realtime_usec.xml \
|
||||||
man/sd_journal_get_usage.xml \
|
man/sd_journal_get_usage.xml \
|
||||||
|
man/sd_journal_has_runtime_files.xml \
|
||||||
man/sd_journal_next.xml \
|
man/sd_journal_next.xml \
|
||||||
man/sd_journal_open.xml \
|
man/sd_journal_open.xml \
|
||||||
man/sd_journal_print.xml \
|
man/sd_journal_print.xml \
|
||||||
|
|
|
@ -81,9 +81,11 @@
|
||||||
<citerefentry><refentrytitle>sd_journal_get_cutoff_realtime_usec</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
<citerefentry><refentrytitle>sd_journal_get_cutoff_realtime_usec</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||||
<citerefentry><refentrytitle>sd_journal_get_cutoff_monotonic_usec</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
<citerefentry><refentrytitle>sd_journal_get_cutoff_monotonic_usec</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||||
<citerefentry><refentrytitle>sd_journal_get_usage</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
<citerefentry><refentrytitle>sd_journal_get_usage</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||||
<citerefentry><refentrytitle>sd_journal_get_catalog</refentrytitle><manvolnum>3</manvolnum></citerefentry>
|
<citerefentry><refentrytitle>sd_journal_get_catalog</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||||
|
<citerefentry><refentrytitle>sd_journal_get_fd</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||||
|
<citerefentry><refentrytitle>sd_journal_has_runtime_files</refentrytitle><manvolnum>3</manvolnum></citerefentry>
|
||||||
and
|
and
|
||||||
<citerefentry><refentrytitle>sd_journal_get_fd</refentrytitle><manvolnum>3</manvolnum></citerefentry>
|
<citerefentry><refentrytitle>sd_journal_has_persistent_files</refentrytitle><manvolnum>3</manvolnum></citerefentry>
|
||||||
for more information about the functions implemented.</para>
|
for more information about the functions implemented.</para>
|
||||||
|
|
||||||
<para>Command line access for submitting entries to the journal is
|
<para>Command line access for submitting entries to the journal is
|
||||||
|
@ -116,6 +118,8 @@
|
||||||
<citerefentry><refentrytitle>sd_journal_get_fd</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
<citerefentry><refentrytitle>sd_journal_get_fd</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||||
<citerefentry><refentrytitle>sd_journal_query_unique</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
<citerefentry><refentrytitle>sd_journal_query_unique</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||||
<citerefentry><refentrytitle>sd_journal_get_catalog</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
<citerefentry><refentrytitle>sd_journal_get_catalog</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||||
|
<citerefentry><refentrytitle>sd_journal_has_runtime_files</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||||
|
<citerefentry><refentrytitle>sd_journal_has_persistent_files</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||||
<citerefentry><refentrytitle>journalctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
|
<citerefentry><refentrytitle>journalctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
|
||||||
<citerefentry><refentrytitle>sd-id128</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
<citerefentry><refentrytitle>sd-id128</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
|
||||||
<citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
|
<citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
|
||||||
|
|
|
@ -0,0 +1,95 @@
|
||||||
|
<?xml version='1.0'?> <!--*-nxml-*-->
|
||||||
|
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
|
||||||
|
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
|
||||||
|
|
||||||
|
<!--
|
||||||
|
This file is part of systemd.
|
||||||
|
|
||||||
|
Copyright 2016 Jan Synáček
|
||||||
|
|
||||||
|
systemd is free software; you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2.1 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
systemd is distributed in the hope that it will be useful, but
|
||||||
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<refentry id="sd_journal_has_runtime_files">
|
||||||
|
|
||||||
|
<refentryinfo>
|
||||||
|
<title>sd_journal_has_runtime_files</title>
|
||||||
|
<productname>systemd</productname>
|
||||||
|
|
||||||
|
<authorgroup>
|
||||||
|
<author>
|
||||||
|
<contrib>Developer</contrib>
|
||||||
|
<firstname>Jan</firstname>
|
||||||
|
<surname>Synáček</surname>
|
||||||
|
<email>jan.synacek@gmail.com</email>
|
||||||
|
</author>
|
||||||
|
</authorgroup>
|
||||||
|
</refentryinfo>
|
||||||
|
|
||||||
|
<refmeta>
|
||||||
|
<refentrytitle>sd_journal_has_runtime_files</refentrytitle>
|
||||||
|
<manvolnum>3</manvolnum>
|
||||||
|
</refmeta>
|
||||||
|
|
||||||
|
<refnamediv>
|
||||||
|
<refname>sd_journal_has_runtime_files</refname>
|
||||||
|
<refname>sd_journal_has_persistent_files</refname>
|
||||||
|
<refpurpose>Query availability of runtime or persistent journal files.</refpurpose>
|
||||||
|
</refnamediv>
|
||||||
|
|
||||||
|
<refsynopsisdiv>
|
||||||
|
<funcsynopsis>
|
||||||
|
<funcsynopsisinfo>#include <systemd/sd-journal.h></funcsynopsisinfo>
|
||||||
|
|
||||||
|
<funcprototype>
|
||||||
|
<funcdef>int <function>sd_journal_has_runtime_files</function></funcdef>
|
||||||
|
<paramdef>sd_journal *<parameter>j</parameter></paramdef>
|
||||||
|
</funcprototype>
|
||||||
|
|
||||||
|
<funcprototype>
|
||||||
|
<funcdef>int <function>sd_journal_has_persistent_files</function></funcdef>
|
||||||
|
<paramdef>sd_journal *<parameter>j</parameter></paramdef>
|
||||||
|
</funcprototype>
|
||||||
|
|
||||||
|
</funcsynopsis>
|
||||||
|
</refsynopsisdiv>
|
||||||
|
|
||||||
|
<refsect1>
|
||||||
|
<title>Description</title>
|
||||||
|
|
||||||
|
<para><function>sd_journal_has_runtime_files()</function> returns a positive value
|
||||||
|
if runtime journal files (present in /run/systemd/journal/) have been found.
|
||||||
|
Otherwise returns 0.</para>
|
||||||
|
|
||||||
|
<para><function>sd_journal_has_persistent_files()</function> returns a positive value
|
||||||
|
if persistent journal files (present in /var/log/journal/) have been found.
|
||||||
|
Otherwise returns 0.</para>
|
||||||
|
</refsect1>
|
||||||
|
|
||||||
|
<refsect1>
|
||||||
|
<title>Return value</title>
|
||||||
|
<para>Both <function>sd_journal_has_runtime_files()</function>
|
||||||
|
and <function>sd_journal_has_persistent_files()</function> return -EINVAL
|
||||||
|
if their argument is NULL.
|
||||||
|
</para>
|
||||||
|
</refsect1>
|
||||||
|
|
||||||
|
<refsect1>
|
||||||
|
<title>See Also</title>
|
||||||
|
<para>
|
||||||
|
<citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry>
|
||||||
|
</para>
|
||||||
|
</refsect1>
|
||||||
|
|
||||||
|
</refentry>
|
|
@ -115,6 +115,8 @@ struct sd_journal {
|
||||||
removed, and there were no more
|
removed, and there were no more
|
||||||
files, so sd_j_enumerate_unique
|
files, so sd_j_enumerate_unique
|
||||||
will return a value equal to 0. */
|
will return a value equal to 0. */
|
||||||
|
bool has_runtime_files:1;
|
||||||
|
bool has_persistent_files:1;
|
||||||
|
|
||||||
size_t data_threshold;
|
size_t data_threshold;
|
||||||
|
|
||||||
|
|
|
@ -1136,10 +1136,11 @@ static int add_boot(sd_journal *j) {
|
||||||
const char *reason = (r == 0) ? "No such boot ID in journal" : strerror(-r);
|
const char *reason = (r == 0) ? "No such boot ID in journal" : strerror(-r);
|
||||||
|
|
||||||
if (sd_id128_is_null(arg_boot_id))
|
if (sd_id128_is_null(arg_boot_id))
|
||||||
log_error("Failed to look up boot %+i: %s", arg_boot_offset, reason);
|
log_error("Data from the specified boot (%+i) is not available: %s",
|
||||||
|
arg_boot_offset, reason);
|
||||||
else
|
else
|
||||||
log_error("Failed to look up boot ID "SD_ID128_FORMAT_STR"%+i: %s",
|
log_error("Data from the specified boot ("SD_ID128_FORMAT_STR") is not available: %s",
|
||||||
SD_ID128_FORMAT_VAL(arg_boot_id), arg_boot_offset, reason);
|
SD_ID128_FORMAT_VAL(arg_boot_id), reason);
|
||||||
|
|
||||||
return r == 0 ? -ENODATA : r;
|
return r == 0 ? -ENODATA : r;
|
||||||
}
|
}
|
||||||
|
@ -2091,6 +2092,13 @@ int main(int argc, char *argv[]) {
|
||||||
assert_not_reached("Unknown action");
|
assert_not_reached("Unknown action");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (arg_boot_offset != 0 &&
|
||||||
|
sd_journal_has_runtime_files(j) > 0 &&
|
||||||
|
sd_journal_has_persistent_files(j) == 0) {
|
||||||
|
log_info("Specifying boot ID has no effect, no persistent journal was found");
|
||||||
|
r = 0;
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
/* add_boot() must be called first!
|
/* add_boot() must be called first!
|
||||||
* It may need to seek the journal to find parent boot IDs. */
|
* It may need to seek the journal to find parent boot IDs. */
|
||||||
r = add_boot(j);
|
r = add_boot(j);
|
||||||
|
|
|
@ -1292,6 +1292,12 @@ static int add_file(sd_journal *j, const char *prefix, const char *filename) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
path = strjoina(prefix, "/", filename);
|
path = strjoina(prefix, "/", filename);
|
||||||
|
|
||||||
|
if (!j->has_runtime_files && path_startswith(path, "/run/log/journal"))
|
||||||
|
j->has_runtime_files = true;
|
||||||
|
else if (!j->has_persistent_files && path_startswith(path, "/var/log/journal"))
|
||||||
|
j->has_persistent_files = true;
|
||||||
|
|
||||||
return add_any_file(j, path);
|
return add_any_file(j, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2630,3 +2636,15 @@ _public_ int sd_journal_get_data_threshold(sd_journal *j, size_t *sz) {
|
||||||
*sz = j->data_threshold;
|
*sz = j->data_threshold;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_public_ int sd_journal_has_runtime_files(sd_journal *j) {
|
||||||
|
assert_return(j, -EINVAL);
|
||||||
|
|
||||||
|
return j->has_runtime_files;
|
||||||
|
}
|
||||||
|
|
||||||
|
_public_ int sd_journal_has_persistent_files(sd_journal *j) {
|
||||||
|
assert_return(j, -EINVAL);
|
||||||
|
|
||||||
|
return j->has_persistent_files;
|
||||||
|
}
|
||||||
|
|
|
@ -139,6 +139,9 @@ int sd_journal_reliable_fd(sd_journal *j);
|
||||||
int sd_journal_get_catalog(sd_journal *j, char **text);
|
int sd_journal_get_catalog(sd_journal *j, char **text);
|
||||||
int sd_journal_get_catalog_for_message_id(sd_id128_t id, char **text);
|
int sd_journal_get_catalog_for_message_id(sd_id128_t id, char **text);
|
||||||
|
|
||||||
|
int sd_journal_has_runtime_files(sd_journal *j);
|
||||||
|
int sd_journal_has_persistent_files(sd_journal *j);
|
||||||
|
|
||||||
/* the inverse condition avoids ambiguity of danling 'else' after the macro */
|
/* the inverse condition avoids ambiguity of danling 'else' after the macro */
|
||||||
#define SD_JOURNAL_FOREACH(j) \
|
#define SD_JOURNAL_FOREACH(j) \
|
||||||
if (sd_journal_seek_head(j) < 0) { } \
|
if (sd_journal_seek_head(j) < 0) { } \
|
||||||
|
|
Loading…
Reference in New Issue