smbd as a daemon

Andreas Schneider asn at samba.org
Wed Mar 26 01:47:47 MDT 2014


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().



	-- andreas

-- 
Andreas Schneider                   GPG-ID: CC014E3D
Samba Team                             asn at samba.org
www.samba.org



More information about the samba-technical mailing list