]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-journal: introduce sd_journal_step_one()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 28 May 2023 05:20:27 +0000 (14:20 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 28 May 2023 14:53:18 +0000 (23:53 +0900)
After the commit 7a4ee861615101ddd2f95056cf30e69e41da86ce,
sd_journal_next() following sd_journal_seek_tail() takes no-op,
and we need to call sd_journal_previous(). This may be useful in
some cases, e.g. to fix the issue explained in the previous commit.

man/rules/meson.build
man/sd_journal_next.xml
src/libsystemd/libsystemd.sym
src/libsystemd/sd-journal/sd-journal.c
src/systemd/sd-journal.h

index d496ebc747fd37056586cc7af38be5efb59b9c4c..4658ef99f0460de28e2b5b11f2db5b7278948936 100644 (file)
@@ -742,7 +742,8 @@ manpages = [
    'SD_JOURNAL_FOREACH_BACKWARDS',
    'sd_journal_next_skip',
    'sd_journal_previous',
-   'sd_journal_previous_skip'],
+   'sd_journal_previous_skip',
+   'sd_journal_step_one'],
   ''],
  ['sd_journal_open',
   '3',
index 628abb296cb5044d782bb199f04369a7bbe2e88b..cc267fa1bd010d09d62d3c26d616ac2dbca51efb 100644 (file)
@@ -18,6 +18,7 @@
   <refnamediv>
     <refname>sd_journal_next</refname>
     <refname>sd_journal_previous</refname>
+    <refname>sd_journal_step_one</refname>
     <refname>sd_journal_next_skip</refname>
     <refname>sd_journal_previous_skip</refname>
     <refname>SD_JOURNAL_FOREACH</refname>
         <paramdef>sd_journal *<parameter>j</parameter></paramdef>
       </funcprototype>
 
+      <funcprototype>
+        <funcdef>int <function>sd_journal_step_one</function></funcdef>
+        <paramdef>sd_journal *<parameter>j</parameter></paramdef>
+        <paramdef>int <parameter>advanced</parameter></paramdef>
+      </funcprototype>
+
       <funcprototype>
         <funcdef>int <function>sd_journal_next_skip</function></funcdef>
         <paramdef>sd_journal *<parameter>j</parameter></paramdef>
     <para>Similarly, <function>sd_journal_previous()</function> sets
     the read pointer back one entry.</para>
 
+    <para><function>sd_journal_step_one()</function> also moves the read pointer. If the current location
+    is the head of the journal, e.g. when this is called following
+    <function>sd_journal_seek_head()</function>, then this is equivalent to
+    <function>sd_journal_next()</function>, and the argument <varname>advanced</varname> will be ignored.
+    Similary, if the current location is the tail of the journal, e.g. when this is called following
+    <function>sd_journal_seek_tail()</function>, then this is equivalent to
+    <function>sd_journal_previous()</function>, and <varname>advanced</varname> will be ignored. Otherwise,
+    this is equivalent to <function>sd_journal_next()</function> when <varname>advanced</varname> is
+    non-zero, and <function>sd_journal_previous()</function> when <varname>advanced</varname> is zero.</para>
+
     <para><function>sd_journal_next_skip()</function> and
     <function>sd_journal_previous_skip()</function> advance/set back the read pointer by multiple
     entries at once, as specified in the <varname>skip</varname> parameter. The <varname>skip</varname>
index 35352dc8326e685cf9c729312d12bd63e006b109..936a3577f546e29f5f099df474c0030d0ccd77de 100644 (file)
@@ -825,4 +825,5 @@ global:
         sd_event_trim_memory;
         sd_pid_notify_barrier;
         sd_event_source_leave_ratelimit;
+        sd_journal_step_one;
 } LIBSYSTEMD_253;
index 47532e2cbc28c41fa903c9f45c507c4836cd2d27..957817bfabc4e624a7fa8d43dad90cc949149cbe 100644 (file)
@@ -979,6 +979,16 @@ _public_ int sd_journal_previous(sd_journal *j) {
         return real_journal_next(j, DIRECTION_UP);
 }
 
+_public_ int sd_journal_step_one(sd_journal *j, int advanced) {
+        assert_return(j, -EINVAL);
+
+        if (j->current_location.type == LOCATION_HEAD)
+                return sd_journal_next(j);
+        if (j->current_location.type == LOCATION_TAIL)
+                return sd_journal_previous(j);
+        return real_journal_next(j, advanced ? DIRECTION_DOWN : DIRECTION_UP);
+}
+
 static int real_journal_next_skip(sd_journal *j, direction_t direction, uint64_t skip) {
         int c = 0, r;
 
index 24e67663b954296fda9e0cf9a7b8794c458bd02e..4af540400dc49f379b82ecab1e9fea829629944c 100644 (file)
@@ -93,6 +93,7 @@ void sd_journal_close(sd_journal *j);
 
 int sd_journal_previous(sd_journal *j);
 int sd_journal_next(sd_journal *j);
+int sd_journal_step_one(sd_journal *j, int advanced);
 
 int sd_journal_previous_skip(sd_journal *j, uint64_t skip);
 int sd_journal_next_skip(sd_journal *j, uint64_t skip);