From 20bb22d61b986d2036c681fc33db60f2b2b3c1c7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 14 Mar 1998 12:57:58 +0000 Subject: added the ability to start/stop the server from SWAT. I needed to modify the way the pidfile is handled in nmbd and smbd to do this. Jeremy, you may wish to look at what I've done as it probably breaks the Whistle use of pidfiles. In particular I've removed the -f option and instead smbd and nmbd always create a pidfile in the lock directory. --- source/nmbd/nmbd.c | 39 +++------------------------------------ 1 file changed, 3 insertions(+), 36 deletions(-) (limited to 'source/nmbd') diff --git a/source/nmbd/nmbd.c b/source/nmbd/nmbd.c index f199a21ea8a..e757aa46c41 100644 --- a/source/nmbd/nmbd.c +++ b/source/nmbd/nmbd.c @@ -549,7 +549,6 @@ int main(int argc,char *argv[]) int opt; extern FILE *dbf; extern char *optarg; - char pidFile[100] = { 0 }; global_nmb_port = NMB_PORT; *host_file = 0; @@ -599,9 +598,6 @@ int main(int argc,char *argv[]) { switch (opt) { - case 'f': - strncpy(pidFile, optarg, sizeof(pidFile)); - break; case 's': pstrcpy(servicesf,optarg); break; @@ -695,40 +691,11 @@ int main(int argc,char *argv[]) become_daemon(); } - if (!directory_exist(lp_lockdir(), NULL)) - { - mkdir(lp_lockdir(), 0755); - } - - if (*pidFile) - { - int fd; - char buf[20]; - -#ifdef O_NONBLOCK - fd = open( pidFile, O_NONBLOCK | O_CREAT | O_WRONLY | O_TRUNC, 0644 ); -#else - fd = open( pidFile, O_CREAT | O_WRONLY | O_TRUNC, 0644 ); -#endif - if ( fd < 0 ) - { - DEBUG(0,("ERROR: can't open %s: %s\n", pidFile, strerror(errno))); - exit(1); - } - if (fcntl_lock(fd,F_SETLK,0,1,F_WRLCK)==False) - { - DEBUG(0,("ERROR: nmbd is already running\n")); - exit(1); - } - sprintf(buf, "%u\n", (unsigned int) getpid()); - if (write(fd, buf, strlen(buf)) < 0) - { - DEBUG(0,("ERROR: can't write to %s: %s\n", pidFile, strerror(errno))); - exit(1); - } - /* Leave pid file open & locked for the duration... */ + if (!directory_exist(lp_lockdir(), NULL)) { + mkdir(lp_lockdir(), 0755); } + pidfile_create("nmbd"); DEBUG( 3, ( "Opening sockets %d\n", global_nmb_port ) ); -- cgit