pidfile and become_daemon
Michael Steffens
michael_steffens at hp.com
Fri Feb 15 08:57:02 GMT 2002
Hi Tim,
as 2.2.3 winbindd does not yet create a pid file preventing
it from being started multiple times, I started fiddling around
with that. And things became less and less clear to me :-)
HEAD winbindd does have a create_pidfile call(), which is before
become_daemon() gets called. Fine this way, because the caller
of winbindd can be notified about failure.
But the pid written to that file is meaningless, because
after that become_daemon() (lib/util.c) forks
if (sys_fork()) {
_exit(0);
}
/* detach from the terminal */
#ifdef HAVE_SETSID
setsid();
#elif defined(TIOCNOTTY)
{
int i = sys_open("/dev/tty", O_RDWR, 0);
if (i != -1) {
ioctl(i, (int) TIOCNOTTY, (char *)0);
close(i);
}
}
#endif /* HAVE_SETSID */
making the daemon pid a different one! What is this fork good
for? Detaching is performed right afterwards...
Another question is about the pidfile size, rather cosmetical
may be. But create_pidfile() always writes the entire buffer
of 20 bytes, regardless of content's size:
memset(buf, 0, sizeof(buf));
slprintf(buf, sizeof(buf) - 1, "%u\n", (unsigned int) sys_getpid());
if (write(fd, buf, sizeof(buf)) != sizeof(buf)) {
DEBUG(0,("ERROR: can't write to file %s: %s\n",
pidFile, strerror(errno)));
exit(1);
}
Wouldn't
if (write(fd, buf, strlen(buf) + 1) != strlen(buf) + 1) {
make more sense?
And the last question may also belong to the cosmetical ones:
Why don't the Samba daemons clean up their pid files on termination?
Cheers!
Michael
More information about the samba-technical
mailing list