Re: [systemd-devel] why log_set_prohibit_ipc() is set in journald
On Fri, Aug 27, 2021, 08:52 Nishant Nayan wrote: > I have just started to learn journald and in its main function (in > journald.c) I encountered a function call "log_set_prohibit_ipc(true);" > In systemd source, I can see the declaration in src/basic/log.h:/* > > If turned on, then we'll never use IPC-based logging, * i.e. never log to > syslog or the journal. We'll only * log to stderr, the console or kmsg > */void log_set_prohibit_ipc(bool b); > > I did not get this because Journald not writing to journal itself by > default is strange, isn't it? > What is the reason behind it? > My understanding is that the point isn't to prevent logging to journal, but to prevent logging *through IPC* specifically, i.e. make sure journald doesn't try to create loopback connections to its own sockets. The journald daemon is single-threaded, so if it tries to connect to itself, it'll deadlock. But also if journald wants to log a critical error (e.g. running out of space or something like that), then it can't really *rely* on journal still working... Afaik, messages written to kmsg will be imported back into the journal anyway, but that happens asynchronously so it's fine. >
Re: [systemd-devel] why log_set_prohibit_ipc() is set in journald
On Fr, 27.08.21 10:01, Mantas Mikulėnas (graw...@gmail.com) wrote: > On Fri, Aug 27, 2021, 08:52 Nishant Nayan > wrote: > > > I have just started to learn journald and in its main function (in > > journald.c) I encountered a function call "log_set_prohibit_ipc(true);" > > In systemd source, I can see the declaration in src/basic/log.h:/* > > > > If turned on, then we'll never use IPC-based logging, * i.e. never log to > > syslog or the journal. We'll only * log to stderr, the console or kmsg > > */void log_set_prohibit_ipc(bool b); > > > > I did not get this because Journald not writing to journal itself by > > default is strange, isn't it? > > What is the reason behind it? > > > > My understanding is that the point isn't to prevent logging to journal, but > to prevent logging *through IPC* specifically, i.e. make sure journald > doesn't try to create loopback connections to its own sockets. The journald > daemon is single-threaded, so if it tries to connect to itself, it'll > deadlock. > > But also if journald wants to log a critical error (e.g. running out of > space or something like that), then it can't really *rely* on journal still > working... > > Afaik, messages written to kmsg will be imported back into the journal > anyway, but that happens asynchronously so it's fine. The above describes exactly how it is, and why journald turns of logging via IPC. journald should not be a client to itself. Lennart -- Lennart Poettering, Berlin
Re: [systemd-devel] why log_set_prohibit_ipc() is set in journald
So then where does journald logs its own messages if he wants to? On Fri, 27 Aug 2021, 13:37 Lennart Poettering, wrote: > On Fr, 27.08.21 10:01, Mantas Mikulėnas (graw...@gmail.com) wrote: > > > On Fri, Aug 27, 2021, 08:52 Nishant Nayan > > wrote: > > > > > I have just started to learn journald and in its main function (in > > > journald.c) I encountered a function call "log_set_prohibit_ipc(true);" > > > In systemd source, I can see the declaration in src/basic/log.h:/* > > > > > > If turned on, then we'll never use IPC-based logging, * i.e. never log > to > > > syslog or the journal. We'll only * log to stderr, the console or kmsg > > > */void log_set_prohibit_ipc(bool b); > > > > > > I did not get this because Journald not writing to journal itself by > > > default is strange, isn't it? > > > What is the reason behind it? > > > > > > > My understanding is that the point isn't to prevent logging to journal, > but > > to prevent logging *through IPC* specifically, i.e. make sure journald > > doesn't try to create loopback connections to its own sockets. The > journald > > daemon is single-threaded, so if it tries to connect to itself, it'll > > deadlock. > > > > But also if journald wants to log a critical error (e.g. running out of > > space or something like that), then it can't really *rely* on journal > still > > working... > > > > Afaik, messages written to kmsg will be imported back into the journal > > anyway, but that happens asynchronously so it's fine. > > The above describes exactly how it is, and why journald turns of > logging via IPC. journald should not be a client to itself. > > Lennart > > -- > Lennart Poettering, Berlin >
Re: [systemd-devel] why log_set_prohibit_ipc() is set in journald
On Fr, 27.08.21 17:34, Nishant Nayan (nayan.nishant2...@gmail.com) wrote: > So then where does journald logs its own messages if he wants to? Depends, some of them it logs to the journal itself, via server_driver_message(). But unless explicitly written that way log messages of the journal go to kmsg. Things is, if you want to log an error message about your inability to write a log message you better don't write that as a log message that will then result in an error, and thus another log message, and thus another log message and so on, and thus a cycle. thus by default all our own log messages to go kmsg, except for a bunch where we know for sure they aren#t immediate effect of an attempt to write a log message, and thus won't result in a cycle. Lennart -- Lennart Poettering, Berlin