[systemd-devel] Something wrong with sd_journal_add_match

Dennis Semakin insane79 at yandex.ru
Wed Jun 22 09:10:14 UTC 2016


Hello.

I've got some strange results when played with sd_journal_* functions. The task is to obtain messages _only_ with
specified fields (e.g. MESSAGE_ID=bla-bla-bla) and I get it. Theoretically there is only one tool which send unique msg
and one service to whom these msg.

And problem is that I can see incoming messages even when sending tool is not running (no execution).
Looks like I got all messages from journal (kernel, other services, etc.)
In other words on terminal where service is running I may see that we got a record in journal with MESSAGE_ID=bla-bla-bla
and it prints me >MESSAGE=DDDDD<.
Also I may see the same incoming messages as a result on any reaction, e.g. plug USB drive.

Here is some code (errors checking is omitted):

-------------------------------- service that listens journal -----------------------------
sd_journal_open(&sdj, SD_JOURNAL_RUNTIME_ONLY|
                                       SD_JOURNAL_SYSTEM_ONLY|
                                       SD_JOURNAL_LOCAL_ONLY));

sd_journal_add_match(sdj, "MESSAGE_ID=bla-bla-bla", 0);

sd_journal_seek_tail(j);

sd_journal_previous(j);

sd_journal_add_match(sdj, "MESSAGE_ID=bla-bla-bla", 0); /* ??? */

for (;;) {

                const void *data;
                size_t length;

                ret = sd_journal_next(sdj);
                if (ret == 0) {
                        ret = sd_journal_wait(sdj, (uint64_t) -1);
                        printf("wait ret = %d \n", ret);
                }

                sd_journal_get_data(sdj, "MESSAGE", &data, &length);
                printf(">%.*s<\n", (int) length, data);
        }


---------------------------- tool that sends messages -----------------------------

int main(int argc, char *argv[])
{
        int i;
        int ret;
        sd_journal *sdj;

        i = 100;
        while (i--) {
                sd_journal_send("MESSAGE=DDDDD",
                                "COUNTER=%d", i,
                                "MESSAGE_ID=bla-bla-bla",
                                NULL);
                sleep(3);
        }

        return 0;
}

Could you please tell me where should I dig to get right results or point to errors.
Thanks.


More information about the systemd-devel mailing list