/* cc -o t-journal-tail t-journal-tail.c -lsystemd-journal */ #include #include #include void check (int r) { if (r < 0) { fprintf (stderr, "%s\n", strerror(-r)); exit (1); } } void checkv (const char *label, int r) { if (r < 0) { fprintf (stderr, "%s: %s\n", label, strerror(-r)); exit (1); } fprintf (stderr, "%s: %d\n", label, r); } void dump (sd_journal *j, int count) { int i = 0; while (i < count) { const void *data; size_t size; uint64_t usec; int r; check (sd_journal_get_realtime_usec (j, &usec)); check (sd_journal_get_data (j, "MESSAGE", &data, &size)); printf ("%lld %.*s\n", usec, size, data); i++; if (i >= count) break; check (r = sd_journal_next (j)); if (r == 0) break; } } void main () { sd_journal *j; check (sd_journal_open (&j, 0)); check (sd_journal_seek_tail (j)); checkv ("next", sd_journal_next (j)); dump (j, 5); }