
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. When running with type=simple and not forking() itself, we got two lines of output - one to syslog, one to stdout. I have to look at maybe using isatty(stdout). For spamd, changing it to type=forking and letting it fork() also solved the problem. I've kind of wanted to standardize on using type=simple, but stuff like this has made me wonder. Anyway, of course type=forking works just as well. -- Per Jessen, Zürich (18.5°C) http://www.dns24.ch/ - your free DNS host, made in Switzerland. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org