PATCH: Running the samba daemons under djb's daemontools

Jos Backus josb at cncdsl.com
Thu Apr 26 00:58:21 GMT 2001


This patch makes it possible to run {n,s}mbd under Dan Bernstein's daemontools
package (see http://cr.yp.to/daemontools.html for details). It adds a new flag
(-F) wich tells {n,s}mdb not to background themselves but still listen for
connections.

diff -ru samba-2.2.0.dist/docs/manpages/nmbd.8 samba-2.2.0/docs/manpages/nmbd.8
--- samba-2.2.0.dist/docs/manpages/nmbd.8	Tue Apr 17 13:50:56 2001
+++ samba-2.2.0/docs/manpages/nmbd.8	Wed Apr 25 17:52:59 2001
@@ -56,6 +56,11 @@
 nmbd can also be operated from the \fBinetd\fR 
 meta-daemon, although this is not recommended.
 .TP
+\fB-F\fR
+If specified, this parameter causes the server not 
+to background itself. This is needed when running
+the server under a service controller.
+.TP
 \fB-a\fR
 If this parameter is specified, each new 
 connection will append log messages to the log file. 
diff -ru samba-2.2.0.dist/docs/manpages/smbd.8 samba-2.2.0/docs/manpages/smbd.8
--- samba-2.2.0.dist/docs/manpages/smbd.8	Tue Apr 17 13:50:56 2001
+++ samba-2.2.0/docs/manpages/smbd.8	Wed Apr 25 17:53:39 2001
@@ -8,7 +8,7 @@
 smbd \- server to provide SMB/CIFS services to clients
 .SH SYNOPSIS
 .sp
-\fBsmbd\fR [ \fB-D\fR ]  [ \fB-a\fR ]  [ \fB-o\fR ]  [ \fB-P\fR ]  [ \fB-h\fR ]  [ \fB-V\fR ]  [ \fB-d <debug level>\fR ]  [ \fB-l <log file>\fR ]  [ \fB-p <port number>\fR ]  [ \fB-O <socket option>\fR ]  [ \fB-s <configuration file>\fR ] 
+\fBsmbd\fR [ \fB-D\fR ] [ \fB-F\fR ] [ \fB-a\fR ]  [ \fB-o\fR ]  [ \fB-P\fR ]  [ \fB-h\fR ]  [ \fB-V\fR ]  [ \fB-d <debug level>\fR ]  [ \fB-l <log file>\fR ]  [ \fB-p <port number>\fR ]  [ \fB-O <socket option>\fR ]  [ \fB-s <configuration file>\fR ] 
 .SH "DESCRIPTION"
 .PP
 This program is part of the Samba suite.
@@ -57,6 +57,11 @@
 servers that provide more than casual use file and 
 print services. This switch is assumed is \fBsmbd
 \fRis executed on the command line of a shell.
+.TP
+\fB-F\fR
+If specified, this parameter causes the server not
+to background itself. This is needed when running
+the server under a service controller.
 .TP
 \fB-a\fR
 If this parameter is specified, each new 
diff -ru samba-2.2.0.dist/source/nmbd/nmbd.c samba-2.2.0/source/nmbd/nmbd.c
--- samba-2.2.0.dist/source/nmbd/nmbd.c	Sun Apr  8 13:22:30 2001
+++ samba-2.2.0/source/nmbd/nmbd.c	Wed Apr 25 17:48:47 2001
@@ -46,6 +46,9 @@
 /* are we running as a daemon ? */
 static BOOL is_daemon = False;
 
+/* run in foreground */
+static BOOL in_foreground = False;
+
 /* have we found LanMan clients yet? */
 BOOL found_lm_clients = False;
 
@@ -629,9 +632,10 @@
 static void usage(char *pname)
 {
 
-  printf( "Usage: %s [-DaohV] [-H lmhosts file] [-d debuglevel] [-l log basename]\n", pname );
+  printf( "Usage: %s [-DFaohV] [-H lmhosts file] [-d debuglevel] [-l log basename]\n", pname );
   printf( "       [-n name] [-p port] [-s configuration file]\n" );
   printf( "\t-D                    Become a daemon\n" );
+  printf( "\t-F                    Execute in foreground\n" );
   printf( "\t-a                    Append to log file (default)\n" );
   printf( "\t-o                    Overwrite log file, don't append\n" );
   printf( "\t-h                    Print usage\n" );
@@ -706,7 +710,7 @@
 #endif
 
   while( EOF != 
-         (opt = getopt( argc, argv, "Vaos:T:I:C:bAB:N:Rn:l:d:Dp:hSH:G:f:" )) )
+         (opt = getopt( argc, argv, "Vaos:T:I:C:bAB:N:Rn:l:d:Dp:hSH:G:f:F" )) )
     {
       switch (opt)
         {
@@ -739,6 +743,9 @@
         case 'D':
           is_daemon = True;
           break;
+        case 'F':
+          in_foreground = True;
+          break;
         case 'd':
           DEBUGLEVEL = atoi(optarg);
           break;
@@ -795,7 +802,7 @@
     is_daemon = True;
   }
   
-  if (is_daemon)
+  if (!in_foreground && is_daemon)
   {
     DEBUG( 2, ( "Becoming a daemon.\n" ) );
     become_daemon();
diff -ru samba-2.2.0.dist/source/smbd/server.c samba-2.2.0/source/smbd/server.c
--- samba-2.2.0.dist/source/smbd/server.c	Sun Apr  8 23:35:52 2001
+++ samba-2.2.0/source/smbd/server.c	Wed Apr 25 17:49:15 2001
@@ -512,9 +512,10 @@
 static void usage(char *pname)
 {
 
-	printf("Usage: %s [-DaoPh?V] [-d debuglevel] [-l log basename] [-p port]\n", pname);
+	printf("Usage: %s [-DFaoPh?V] [-d debuglevel] [-l log basename] [-p port]\n", pname);
 	printf("       [-O socket options] [-s services file]\n");
 	printf("\t-D                    Become a daemon\n");
+	printf("\t-F                    Execute in foreground\n");
 	printf("\t-a                    Append to log file (default)\n");
 	printf("\t-o                    Overwrite log file, don't append\n");
 	printf("\t-h                    Print usage\n");
@@ -537,6 +538,7 @@
 	extern BOOL append_log;
 	/* shall I run as a daemon */
 	BOOL is_daemon = False;
+	BOOL in_foreground = False;
 	BOOL specified_logfile = False;
 	int port = SMB_PORT;
 	int opt;
@@ -552,7 +554,7 @@
 		argc--;
 	}
 
-	while ( EOF != (opt = getopt(argc, argv, "O:l:s:d:Dp:h?Vaof:")) )
+	while ( EOF != (opt = getopt(argc, argv, "O:l:s:d:Dp:h?Vaof:F")) )
 		switch (opt)  {
 		case 'O':
 			pstrcpy(user_socket_options,optarg);
@@ -579,6 +581,10 @@
 			is_daemon = True;
 			break;
 
+		case 'F':
+			in_foreground = True;
+			break;
+
 		case 'd':
 			if (*optarg == 'A')
 				DEBUGLEVEL = 10000;
@@ -723,7 +729,7 @@
 		is_daemon = True;
 	}
 
-	if (is_daemon) {
+	if (!in_foreground && is_daemon) {
 		DEBUG( 3, ( "Becoming a daemon.\n" ) );
 		become_daemon();
 	}

Thanks,
-- 
Jos Backus                 _/  _/_/_/        "Modularity is not a hack."
                          _/  _/   _/                -- D. J. Bernstein
                         _/  _/_/_/             
                    _/  _/  _/    _/
josb at cncdsl.com     _/_/   _/_/_/            use Std::Disclaimer;




More information about the samba-technical mailing list