[opensuse] openlog() setting not being inherited by threads?
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. With our own custom-written daemon, on a hunch I fixed the problem by adding an openlog() in the threads that are being created, so it seems the openlog() is not being inherited across a thread create / fork() ? I haven't looked at spamd yet, but as it also forks .... -- Per Jessen, Zürich (20.0°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
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? -- Per Jessen, Zürich (22.2°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
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"? -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
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". -- Per Jessen, Zürich (22.0°C) http://www.hostsuisse.com/ - virtual servers, made in Switzerland. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
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. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
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
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?
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?
I have to look at maybe using isatty(stdout).
Both syslog and stdout end up in exactly the same journal, so I honestly think you over engineer it.
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.
-- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
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
On Tue, 9 Jul 2019 20:57:12 +0300 Andrei Borzenkov <arvidjaar@gmail.com> wrote:
09.07.2019 20:12, Per Jessen пишет:
Andrei Borzenkov wrote:
09.07.2019 17:50, Per Jessen пишет:
Per Jessen wrote: 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:
What about "ps -eo pid,comm,cgroup | grep firefox" or some similar mantra to check the cgroup as described at https://superuser.com/questions/915533/tell-if-a-process-is-under-systemd-in... -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
Dave Howorth wrote:
On Tue, 9 Jul 2019 20:57:12 +0300 Andrei Borzenkov <arvidjaar@gmail.com> wrote:
09.07.2019 20:12, Per Jessen пишет:
Andrei Borzenkov wrote:
09.07.2019 17:50, Per Jessen пишет:
Per Jessen wrote: 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:
What about "ps -eo pid,comm,cgroup | grep firefox" or some similar mantra to check the cgroup as described at
In C please :-) -- Per Jessen, Zürich (17.6°C) http://www.hostsuisse.com/ - virtual servers, made in Switzerland. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On Tue, 09 Jul 2019 21:34:14 +0200 Per Jessen <per@computer.org> wrote:
Dave Howorth wrote:
On Tue, 9 Jul 2019 20:57:12 +0300 Andrei Borzenkov <arvidjaar@gmail.com> wrote:
09.07.2019 20:12, Per Jessen пишет:
Andrei Borzenkov wrote:
09.07.2019 17:50, Per Jessen пишет:
Per Jessen wrote: 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:
What about "ps -eo pid,comm,cgroup | grep firefox" or some similar mantra to check the cgroup as described at
In C please :-)
Now you want me to do your coding for you as well, already? :) -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
Dave Howorth wrote:
On Tue, 09 Jul 2019 21:34:14 +0200 Per Jessen <per@computer.org> wrote:
Dave Howorth wrote:
On Tue, 9 Jul 2019 20:57:12 +0300 Andrei Borzenkov <arvidjaar@gmail.com> wrote:
09.07.2019 20:12, Per Jessen пишет:
Andrei Borzenkov wrote:
09.07.2019 17:50, Per Jessen пишет: > Per Jessen wrote: > 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:
What about "ps -eo pid,comm,cgroup | grep firefox" or some similar mantra to check the cgroup as described at
In C please :-)
Now you want me to do your coding for you as well, already? :)
I'm outsourcing .... Interesting thing with the cgroup, but does it hold up - a systemd unit could easily have its own cgroup? Mine don't though ps -eo pid,comm,cgroup | grep ibwd 27607 ibwd 11:devices:/system.slice/bwid.service,8:pids:/system.slice/bwid.service,1:name=systemd:/system.slice/bwid.service,0::/system.slice/bwid.service -- Per Jessen, Zürich (15.9°C) http://www.hostsuisse.com/ - dedicated server rental in Switzerland. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
participants (3)
-
Andrei Borzenkov
-
Dave Howorth
-
Per Jessen