[systemd-devel] Journal log rotation notification

Lennart Poettering lennart at poettering.net
Fri Aug 14 10:10:41 PDT 2015


On Fri, 14.08.15 13:20, giulix (giulio.martinat at gmail.com) wrote:

> Hello,
> 
> I have a process that reads from the journald log file. It gets a
> notification from inotify that something's changed, opens the journal, skims
> through it for messages it's interested in, does its stuff and closes the
> journal file (http://www.giulix.it/content/extracting-data-systemd-journal-programmatically).
> When the journal log file is rotated, the process stops to do its job. It
> is, of course, because it never realizes the file it's waiting on for
> notifications via inotify has changed.
> I have uselessly tried to implement some mechanism to have my process
> restarted when the journal file changes, but it seems that nothing is
> available from systemd or journald to notify a process that journald is
> switching to a new output file.
> 
> Is there anything that I have missed?

As Mantas already mentioned: sd-journal.h already provides you with a
way to get notifications about journal changes, and it does handle
rotation properly. It internally uses inotify on the directories to
ensure it can track this all nicely. I'd always recommend using the
sd-journal.h API for watching the journal rather than watching things
on your own, since then it's our upstream duty to fix things if the
watching should be buggy...

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list