[systemd-devel] removing daemon(0,0)
Colin Guthrie
gmane at colin.guthr.ie
Sat Nov 5 05:53:06 PDT 2011
'Twas brillig, and Michael D. Berger at 05/11/11 00:19 did gyre and gimble:
>
>> -----Original Message-----
>> From: Michal Schmidt [mailto:mschmidt at redhat.com]
>> Sent: Friday, November 04, 2011 17:45
>> To: Michael D. Berger
>> Cc: systemd-devel at lists.freedesktop.org
>> Subject: Re: [systemd-devel] FW: pthread_create() fails SysV
>> in myDaemon on boot
>>
>> On Fri, 04 Nov 2011 14:36:05 -0400 Michael D. Berger wrote:
>>> Your assumption is correct. In the code I have:
>>> if (argc == 2)
>>> {
>>> string arg = argv[1];
>>> if (arg != "--daemon")
>>> throw ...
>>> ::daemon(0,0);
>>> isDaemon = true;
>>> }
>>
>> Not related to your problem with the cpu cgroup controller, but ...
>> daemon(3) is not the best way to daemonize a process. I
>> suggest you to take a look at
>> http://0pointer.de/public/systemd-man/daemon.html
>>
>> Michal
>
> As you see, I made a new thread of this.
>
> Looking at the recommended document, I concluded, perhaps
> incorrectly, that I should remove my
> daemon(0,0);
> and add:
> const char* const state = "OK";
> sd_notify(1/*unset_environment*/,state);
>
> "man sd_notify" says the include file is
> #include "sd-daemon.h"
> but the only one like this is:
> #include </usr/share/doc/systemd/sd-daemon.h>
> I suuppose that I should have expected that ld can't find
> "sd-daemon", but I see:
> /usr/share/doc/systemd/sd-daemon.c
>
> Should I get it and compile it, or am I up the wrong tree?
> This is looking a little odd.
See man sd-notify:
These APIs are implemented in the reference implementation's
sd-daemon.c and sd-daemon.h files. These interfaces are available as
shared library, which can be compiled and linked to with the
libsystemd-daemon pkg-config(1) file. Alternatively, applications
consuming these APIs may copy the implementation into their source
tree, either verbatim or in excerpts.
> I tried just removing "daemon(0,0)", but
> systemctl start myDaemon.service
> does not return, so it looked like sd_notify() might be
> a good thing.
If you're app doesn't daemonise itself, then you can use a different
Type= in the unit file so systemd does this for you. In this case
Type=simple will do the job (or just leave Type out completely as this
is the default value).
Col
--
Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/
Day Job:
Tribalogic Limited http://www.tribalogic.net/
Open Source:
Mageia Contributor http://www.mageia.org/
PulseAudio Hacker http://www.pulseaudio.org/
Trac Hacker http://trac.edgewall.org/
More information about the systemd-devel
mailing list