smbd as a daemon

Alexander Bokovoy ab at samba.org
Wed Mar 26 07:47:45 MDT 2014


On Wed, Mar 26, 2014 at 2:43 PM, Alexander Bokovoy <ab at samba.org> wrote:
> On Wed, Mar 26, 2014 at 2:03 PM, Alexander Bokovoy <ab at samba.org> wrote:
>> On Wed, Mar 26, 2014 at 9:47 AM, Andreas Schneider <asn at samba.org> wrote:
>>> On Tuesday 25 March 2014 21:52:34 Alexander Bokovoy wrote:
>>>> On Tue, Mar 25, 2014 at 9:38 PM, Jeremy Allison <jra at samba.org> wrote:
>>>> > On Tue, Mar 25, 2014 at 09:28:34PM +0200, Alexander Bokovoy wrote:
>>>> >> > Ok, attached patch compiles for me and links libsystem-daemon
>>>> >> > properly. I'm going to run some package tests tomorrow.
>>>> >>
>>>> >> Updated patch -- I forgot one define for non-systemd case and also
>>>> >> added changes to systemd services.
>>>> >
>>>> > Few comments inline.
>>>> >
>>>> >>   Become a daemon, discarding the controlling terminal.
>>>> >>
>>>> >>  ************************************************************************
>>>> >>  ****/>>
>>>> >> -_PUBLIC_ void become_daemon(bool do_fork, bool no_process_group, bool
>>>> >> log_stdout) +_PUBLIC_ void become_daemon(bool do_fork, bool
>>>> >> no_process_group, bool log_stdout, bool wait_for_child_init)>
>>>> > What is the extra parameter 'bool wait_for_child_init' for ?
>>>> > In the calling code you're always passing it as 'true' so
>>>> > what does it achieve ?
>>>>
>>>> I somehow thought I saw more become_daemon() uses. Looked again, I
>>>> don't see any more.
>>>> This should explain why I added it.
>>>>
>>>> >> -             become_daemon(Fork, no_process_group, log_stdout);
>>>> >> +             become_daemon(Fork, no_process_group, log_stdout, True);
>>>> >
>>>> > Bah. We don't use 'True' anymore. If you do end up
>>>> > keeping the parameter please use 'true/false' in all
>>>> > new code.
>>>>
>>>> Yes, changed it several times and missed here.
>>>>
>>>> > Otherwise looks ok to me.
>>>>
>>>> Updated patch attached, removed changes to become_daemon() prototype.
>>>
>>> The manpage states:
>>>
>>> A daemon could send the following shortly before exiting, on failure
>>>
>>> sd_notifyf(0, "STATUS=Failed to start up: %s\n"
>>>               "ERRNO=%i",
>>>               strerror(errno),
>>>               errno);
>>>
>>>
>>> So I would like to see
>>>
>>> static void exit_smbd(const char *msg, int error)
>>> {
>>> #ifdef HAVE_SYSTEMD
>>>         if (msg == NULL) {
>>>                 msg = strerror(error);
>>>         }
>>>
>>>         sd_notifyf(0, "STATUS=smbd failed to start: %s\n"
>>>                       "ERRNO=%i",
>>>                       msg,
>>>                       errno);
>>> #endif
>>>         DEBUG(0, "STATUS=smbd failed to start: %s\n", msg);
>>>         exit(1);
>>> }
>>>
>>>
>>> and then call this function if init fails in main().
>>
>> Ok, I've now have a version that works. The only issue I see is when
>> systemd stops the service, it unconditionally removes pid file and
>> then our pid removal code complaints that pid file is not there.
> Addtionally, here is what happens on error. If I remove
> /var/lib/samba, smbd startup fails due to missing secrets.tdb and we
> see that in the status:
> [root at masteripa lib]# mv samba samba.l
> [root at masteripa lib]# systemctl start smb
> Job for smb.service failed. See 'systemctl status smb.service' and
> 'journalctl -xn' for details.
> [root at masteripa lib]# systemctl status smb
> smb.service - Samba SMB Daemon
>    Loaded: loaded (/usr/lib/systemd/system/smb.service; disabled)
>    Active: failed (Result: exit-code) since Ср 2014-03-26 14:38:16 EET; 4s ago
>   Process: 11723 ExecStart=/usr/sbin/smbd $SMBDOPTIONS (code=exited,
> status=1/FAILURE)
>  Main PID: 11723 (code=exited, status=1/FAILURE)
>    Status: "daemon failed to start: smbd can not open secrets.tdb"
>
> мар 26 14:38:16 masteripa.ipa.weald.vda.li smbd[11722]: [2014/03/26
> 14:38:16.676499,  0] ../source3/smbd/server.c:1278(main)
> мар 26 14:38:16 masteripa.ipa.weald.vda.li smbd[11722]: standard input
> is not a socket, assuming -D option
> мар 26 14:38:16 masteripa.ipa.weald.vda.li systemd[1]: smb.service:
> Supervising process 11723 which is not our child. We'll most likely
> not notice when it exits.
> мар 26 14:38:16 masteripa.ipa.weald.vda.li smbd[11723]: [2014/03/26
> 14:38:16.684517,  0] ../source3/passdb/secrets.c:85(secrets_init_path)
> мар 26 14:38:16 masteripa.ipa.weald.vda.li smbd[11723]: Failed to open
> /var/lib/samba/private/secrets.tdb
> мар 26 14:38:16 masteripa.ipa.weald.vda.li smbd[11723]: [2014/03/26
> 14:38:16.685992,  0] ../lib/util/become_daemon.c:121(exit_daemon)
> мар 26 14:38:16 masteripa.ipa.weald.vda.li smbd[11723]: STATUS=daemon
> failed to start: smbd can not open secrets.tdb, error code 13
> мар 26 14:38:16 masteripa.ipa.weald.vda.li systemd[1]: smb.service:
> main process exited, code=exited, status=1/FAILURE
> мар 26 14:38:16 masteripa.ipa.weald.vda.li systemd[1]: Failed to start
> Samba SMB Daemon.
> мар 26 14:38:16 masteripa.ipa.weald.vda.li systemd[1]: Unit
> smb.service entered failed state.

I've created bug 10517. The bug now has all patches for master and 4.1.

https://bugzilla.samba.org/show_bug.cgi?id=10517



-- 
/ Alexander Bokovoy


More information about the samba-technical mailing list