summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>1998-03-14 12:57:58 +0000
committerAndrew Tridgell <tridge@samba.org>1998-03-14 12:57:58 +0000
commitc063e9ec3e90508e846dd51e22a643c74c02f7c1 (patch)
treeacc4717e33dfdf1a6492e00b5737da1a3a708be0 /source3
parente2b50d04ad5eb5fa7c10b59cf5ba0cfe374ab240 (diff)
downloadsamba-c063e9ec3e90508e846dd51e22a643c74c02f7c1.tar.gz
samba-c063e9ec3e90508e846dd51e22a643c74c02f7c1.tar.bz2
samba-c063e9ec3e90508e846dd51e22a643c74c02f7c1.zip
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. (This used to be commit 20bb22d61b986d2036c681fc33db60f2b2b3c1c7)
Diffstat (limited to 'source3')
-rw-r--r--source3/include/proto.h17
-rw-r--r--source3/lib/util.c2
-rw-r--r--source3/nmbd/nmbd.c39
-rw-r--r--source3/smbd/server.c36
-rw-r--r--source3/web/swat.c49
5 files changed, 70 insertions, 73 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 9c7c37f1a6..88b340319e 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -1487,6 +1487,11 @@ BOOL server_validate(char *user, char *domain,
BOOL pcap_printername_ok(char *pszPrintername, char *pszPrintcapname);
void pcap_printer_fn(void (*fn)());
+/*The following definitions come from pidfile.c */
+
+void pidfile_create(char *name);
+int pidfile_pid(char *name);
+
/*The following definitions come from pipes.c */
int reply_open_pipe_and_X(char *inbuf,char *outbuf,int length,int bufsize);
@@ -1913,6 +1918,18 @@ char *cgi_baseurl(void);
char *cgi_rooturl(void);
char *cgi_pathinfo(void);
+/*The following definitions come from web/diagnose.c */
+
+BOOL nmbd_running(void);
+BOOL smbd_running(void);
+
+/*The following definitions come from web/startstop.c */
+
+void start_smbd(void);
+void start_nmbd(void);
+void stop_smbd(void);
+void stop_nmbd(void);
+
/*The following definitions come from web/swat.c */
int main(int argc, char *argv[]);
diff --git a/source3/lib/util.c b/source3/lib/util.c
index 19fa42592f..3bc96e1034 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -3106,7 +3106,7 @@ void become_daemon(void)
{
#ifndef NO_FORK_DEBUG
if (fork())
- exit(0);
+ _exit(0);
/* detach from the terminal */
#ifdef USE_SETSID
diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c
index f199a21ea8..e757aa46c4 100644
--- a/source3/nmbd/nmbd.c
+++ b/source3/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 ) );
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index b42ebd6c0f..ca4a95f59d 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -5144,9 +5144,6 @@ static void usage(char *pname)
int port = SMB_PORT;
int opt;
extern char *optarg;
- char pidFile[100];
-
- *pidFile = '\0';
#ifdef NEED_AUTH_PARAMETERS
set_auth_parameters(argc,argv);
@@ -5200,9 +5197,6 @@ static void usage(char *pname)
while ((opt = getopt(argc, argv, "O:i:l:s:d:Dp:hPaf:")) != EOF)
switch (opt)
{
- case 'f':
- strncpy(pidFile, optarg, sizeof(pidFile));
- break;
case 'O':
strcpy(user_socket_options,optarg);
break;
@@ -5328,33 +5322,9 @@ static void usage(char *pname)
mkdir(lp_lockdir(), 0755);
}
- if (*pidFile)
- {
- int fd;
- char buf[20];
-
- if ((fd = open(pidFile,
-#ifdef O_NONBLOCK
- O_NONBLOCK |
-#endif
- 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: smbd 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 (is_daemon) {
+ pidfile_create("smbd");
+ }
if (!open_sockets(is_daemon,port))
exit(1);
diff --git a/source3/web/swat.c b/source3/web/swat.c
index 650740428f..422259a05a 100644
--- a/source3/web/swat.c
+++ b/source3/web/swat.c
@@ -1,7 +1,7 @@
/*
Unix SMB/Netbios implementation.
Version 1.9.
- html smb.conf editing - prototype only
+ Samba Web Administration Tool
Copyright (C) Andrew Tridgell 1997-1998
This program is free software; you can redistribute it and/or modify
@@ -537,8 +537,26 @@ static void status_page(void)
pstring fname;
FILE *f;
+ if (cgi_variable("smbd_start")) {
+ start_smbd();
+ }
+
+ if (cgi_variable("smbd_stop")) {
+ stop_smbd();
+ }
+
+ if (cgi_variable("nmbd_start")) {
+ start_nmbd();
+ }
+
+ if (cgi_variable("nmbd_stop")) {
+ stop_nmbd();
+ }
+
printf("<H2>Server Status</H2>\n");
+ printf("<FORM method=post>\n");
+
pstrcpy(fname,lp_lockdir());
standard_sub_basic(fname);
trim_string(fname,"","/");
@@ -553,9 +571,32 @@ static void status_page(void)
}
- printf("\nSamba version %s\n<p>",VERSION);
+ printf("<table>\n");
+
+ printf("<tr><td>version:</td><td>%s</td></tr>",VERSION);
+
+ fflush(stdout);
+ if (smbd_running()) {
+ printf("<tr><td>smbd:</td><td>running</td><td><input type=submit name=\"smbd_stop\" value=\"Stop smbd\"></td></tr>\n");
+ } else {
+ printf("<tr><td>smbd:</td><td>not running</td><td><input type=submit name=\"smbd_start\" value=\"Start smbd\"></td></tr>\n");
+ }
+
+ fflush(stdout);
+ if (nmbd_running()) {
+ printf("<tr><td>nmbd:</td><td>running</td><td><input type=submit name=\"nmbd_stop\" value=\"Stop nmbd\"></td></tr>\n");
+ } else {
+ printf("<tr><td>nmbd:</td><td>not running</td><td><input type=submit name=\"nmbd_start\" value=\"Start nmbd\"></td></tr>\n");
+ }
+
+ printf("</table>\n");
+ fflush(stdout);
+
- printf("<h3>Active Connections</h3>\n");
+ if (geteuid() != 0)
+ printf("<b>NOTE: You are not logged in as root and won't be able to start/stop the server</b><p>\n");
+
+ printf("<p><h3>Active Connections</h3>\n");
printf("<table border=1>\n");
printf("<tr><th>Share</th><th>User</th><th>Group</th><th>PID</th><th>Client</th><th>Date</th></tr>\n\n");
@@ -583,6 +624,8 @@ static void status_page(void)
printf("</table>\n");
fclose(f);
+
+ printf("</FORM>\n");
}