Bug 1446140

Summary: sd_journal_process() reports invalidation of journal files even when no invalidating event (unlink, rotation) took place
Product: Red Hat Enterprise Linux 7 Reporter: Michal Sekletar <msekleta>
Component: systemdAssignee: systemd-maint
Status: CLOSED ERRATA QA Contact: Frantisek Sumsal <fsumsal>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 7.3CC: fsumsal, systemd-maint-list
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: systemd-219-39.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-08-01 09:14:52 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---
Bug Depends On:    
Bug Blocks: 1419228    

Description Michal Sekletar 2017-04-27 10:20:53 UTC
Description of problem:
$subject

Version-Release number of selected component (if applicable):
systemd-219-30.el7_3.8

How reproducible:
deterministic

Steps to Reproduce:
1. Compile following C program
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <systemd/sd-journal.h>

/* gcc journal-process-test.c -l systemd */

int main(void) {
        int r;
        sd_journal *j;

        r = sd_journal_open(&j, SD_JOURNAL_CURRENT_USER|SD_JOURNAL_LOCAL_ONLY);
        if (r < 0) {
                fprintf(stderr, "Failed to open system journal: %m");
                return EXIT_FAILURE;
        }

	/* seek to last message in journal */
        sd_journal_get_fd(j);
        sd_journal_seek_tail(j);
        sd_journal_previous(j);

	/* write to syslog and wait a bit for journal to append the message */
	openlog("sd-journal-process-test", LOG_NDELAY|LOG_PID, LOG_USER);
	syslog(LOG_DAEMON|LOG_ERR, "test message");

	sleep(1);
	
        r = sd_journal_process(j);
        switch (r) {
        case SD_JOURNAL_NOP:
                puts("nop");
                break;
        case SD_JOURNAL_APPEND:
                puts("append");
                break;
        case SD_JOURNAL_INVALIDATE:
                puts("invalidate");
                break;
        default:
                fprintf(stderr, "Failed to process journal events: %m");
                return EXIT_FAILURE;
        }

        return 0;
}   
2. Login as root user
3. Run ./a.out

Actual results:
Program output is "invalidate"


Expected results:
Program should be "append"

Additional info:
Note that on otherwise idle system it is very unlikely for actual journal invalidation to take place right after we append to journal via syslog(). Hence in 99.99999999% of cases program should really print "append" once the bug is fixed. Ideally we would detect possible invalidation and retry the test case instead of producing false-negative, but possibility of that happening so low that I don't bother.

Upstream fix,

https://github.com/systemd/systemd/pull/5580

Comment 3 Lukáš Nykrýn 2017-05-02 09:46:55 UTC
fix merged to upstream staging branch ->
https://github.com/lnykryn/systemd-rhel/commit/ca55fb67bc81313edf0aa6523b6f9ffce50ecdda
-> post

Comment 6 errata-xmlrpc 2017-08-01 09:14:52 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2017:2297