On Fri, Aug 20, 2021 at 12:31 PM Nishant Nayan <nayan.nishant2...@gmail.com>
wrote:

> Hi,
>     My query is how does systemd-journald talk to other services so that
> it stores their logs/output in journal files, which could be displayed
> using journalctl utlity.
>

Journald doesn't talk to services, services talk to journald:

a) The service uses the standard syslog(3) call to send basic messages
through the /dev/log socket, where journald (or a traditional syslogd) is
listening.

b) The service uses sd_journal_print(3) from libsystemd to send structured
messages through /run/systemd/journal/socket (systemd-journald.socket).
Some frameworks, such as GLib, have their own implementations of this
protocol without needing libsystemd.

c) The service prints to stdout/stderr, but systemd attaches the service's
stdout/stderr to a pipe which is read by journald (using
sd_journal_stream_fd(3) from libsystemd). See [Service] StandardOutput= in
systemd.service(5).

d) Journald also reads kernel messages (dmesg) from the /dev/kmsg device.
Programs can actually write to /dev/kmsg to generate dmesg messages and
journald will capture them.

-- 
Mantas Mikulėnas

Reply via email to