Andrei Borzenkov wrote:
On Tue, Jul 9, 2019 at 10:01 PM Per Jessen <per@computer.org> wrote:
Andrei Borzenkov wrote:
09.07.2019 20:12, Per Jessen пишет:
Andrei Borzenkov wrote:
09.07.2019 17:50, Per Jessen пишет:
Per Jessen wrote:
> As part of migrating a mail cluster til leap15.1, I noticed > that log messages from a custom-written daemon were being > written to both /var/log/mail and to /var/log/messages - only > intended for > facility=LOG_MAIL. I noticed the same for spamd.
I have to take a closer look at spamd, but for our own stuff, it was some old code making assumptions (about running under sysvinit) that no longer hold true.
for testing whether a process is running under systemd - is getppid()==1 a good idea?
Do you mean "if /sbin/init is systemd" or "if program is running as system service as opposed to being launched by user"?
The latter - "if program is running as system service as opposed to being launched by user".
I do not think there is any reliable way to check it. Any double forked program will be reparented to init:
[1] 2072 [1]+ Done ( sleep 100000000000 & exit ) bor@leap15:~> ps -ef | grep sleep bor 2074 1 0 20:47 pts/0 00:00:00 sleep 100000000000 bor 2079 1957 0 20:47 pts/0 00:00:00 grep --color=auto sleep bor@leap15:~>
although Linux also has notion of process subreaper so depending on how exactly it has been started it may be reparented to something else. Any environment variable may be faked as well. I am not aware of any mutual handshake protocol with systemd - sd_booted() just checks whether systemd runtime diretory is present, sd_notify() returns success if no notification socket is set, etc.
What caused us the problem was that the code (dating back to 2006) assumed "not daemonized" -> write log output to stdout, and "daemonized" -> write to syslog.
So your program already does some checks; how does it detect "daemonized' state?
Heh, by argument setting. Which is what causes the problem when using type=simple.
When running with type=simple and not forking() itself, we got two lines of output - one to syslog, one to stdout.
According to previous paragraph your program only logs to one destination at a time. How comes you get logs twice?
The idea was to have output written to syslog and stdout, when running in the foreground. In the background, only to syslog.
Both syslog and stdout end up in exactly the same journal, so I honestly think you over engineer it.
Entirely possible :-) What I noticed with the stdout output - when logged, it had a timestamp prepended, that's not very pretty. spamd example: 2019-07-09T00:00:02+02:00 tattoo16 spamd[29337]: Jul 9 00:00:02.651 [8970] info: spamd: got connection over /var/lib/bulwark/spamd I'm beginning to think isatty(stdout) might be the easiest. -- Per Jessen, Zürich (15.8°C) http://www.dns24.ch/ - free dynamic DNS, made in Switzerland. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org