diff options
author | Samba Release Account <samba-bugs@samba.org> | 1996-12-10 17:55:27 +0000 |
---|---|---|
committer | Samba Release Account <samba-bugs@samba.org> | 1996-12-10 17:55:27 +0000 |
commit | 61236274fe27ed0fd563f78853d70a55a16f2cd0 (patch) | |
tree | 868fc8323896500db8fc28a7f90337bea2c0c2ef | |
parent | c95ed5bbbd714214a4d0bed2f67cc6008c455223 (diff) | |
download | samba-61236274fe27ed0fd563f78853d70a55a16f2cd0.tar.gz samba-61236274fe27ed0fd563f78853d70a55a16f2cd0.tar.bz2 samba-61236274fe27ed0fd563f78853d70a55a16f2cd0.zip |
Added -f option for lock file.
jra@cygnus.com
(This used to be commit 0c8df4cef915ff1bead02e5dad8d761a614dfb62)
-rw-r--r-- | source3/nmbd/nmbd.c | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index d8865662c7..58953bcd9d 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -403,6 +403,7 @@ static void usage(char *pname) int opt; extern FILE *dbf; extern char *optarg; + char pidFile[100] = { 0 }; *host_file = 0; @@ -431,10 +432,13 @@ static void usage(char *pname) signal(SIGHUP ,SIGNAL_CAST sig_hup); signal(SIGTERM,SIGNAL_CAST sig_term); - while ((opt = getopt(argc, argv, "s:T:I:C:bAi:B:N:Rn:l:d:Dp:hSH:G:")) != EOF) + while ((opt = getopt(argc, argv, "s:T:I:C:bAi:B:N:Rn:l:d:Dp:hSH:G:f:")) != EOF) { switch (opt) { + case 'f': + strncpy(pidFile, optarg, sizeof(pidFile)); + break; case 's': strcpy(servicesf,optarg); break; @@ -504,6 +508,32 @@ static void usage(char *pname) become_daemon(); } + if (*pidFile) + { + int fd; + char buf[20]; + + if ((fd = open(pidFile, + O_NONBLOCK | O_CREAT | O_WRONLY | O_TRUNC, 0644)) < 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... */ + } + + DEBUG(3,("Opening sockets %d\n", port)); if (!open_sockets(is_daemon,port)) return 1; |