<html>
    <head>
      <base href="https://bugs.freedesktop.org/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Reading journal backwards misses entries"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=86855">86855</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Reading journal backwards misses entries
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>systemd
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Other
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>major
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>medium
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>general
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>systemd-bugs@lists.freedesktop.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>jjk@jjacky.com
          </td>
        </tr>

        <tr>
          <th>QA Contact</th>
          <td>systemd-bugs@lists.freedesktop.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Simple illustration of the problem:

% coredumpctl list COREDUMP_PID=8212   
TIME                            PID   UID   GID SIG PRESENT EXE
Sat 2014-11-29 13:17:03 CET    8212  1000   100   6 * /usr/bin/Xorg.bin

% coredumpctl list -1 COREDUMP_PID=8212
No match found.


The reason it fails to find a match with -1 is that then
sd_journal_seek_tail()/sd_journal_previous() are used, else it's be
seek_head()/next(); and apparently going backwards doen't work right.

As a test, I did a small program that uses similar matches (COREDUMP_PID=8212
AND MESSAGE_ID=fc2e22bc6ee647b6b90729ab34a250b1), if the loop with the call to
sd_journal_get_data() is done with SD_JOURNAL_FOREACH(j) it works, with
SD_JOURNAL_FOREACH_BACKWARDS(j) no matches are found.

Trying using another set of matches (on a COREDUMP_EXE this time), I get 13
matches going forward, only 12 going backwards.

No idea what's going on, but clearly going backwards in the journal doesn't
work properly.

This is on up-to-date Arch Linux x86_64:
% systemctl --version
systemd 217
+PAM -AUDIT -SELINUX -IMA -APPARMOR +SMACK -SYSVINIT +UTMP +LIBCRYPTSETUP
+GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID -ELFUTILS +KMOD +IDN</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the QA Contact for the bug.</li>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>