Process group ownership

Jos Backus josb at cncdsl.com
Thu Dec 27 19:51:03 GMT 2001


    Hi Jeremy,

Thanks for the quick reply.

On Thu, Dec 27, 2001 at 06:18:34PM -0800, Jeremy Allison wrote:
> We do create our own process group.

I must have missed that while scanning the source. My apologies :-/
 
> Check out the code in the function become_daemon().
> setsid() is the POSIX way of creating a session after a fork
> and becoming the process group leader.

Indeed, sorry. Would you please have a look at the patch below? It adds the -F
flag to {n,s}mbd telling it not to fork. This way one can run these daemons
under Dan Bernstein's daemontools and AIX's System Resource Controller. I can
supply the doc diffs as well.

Thank you!

diff -ru work/samba-3.0-alpha12/source/lib/util.c work.new/samba-3.0-alpha12/source/lib/util.c
--- work/samba-3.0-alpha12/source/lib/util.c	Sun Dec  9 23:06:06 2001
+++ work.new/samba-3.0-alpha12/source/lib/util.c	Thu Dec 27 19:31:22 2001
@@ -641,9 +641,9 @@
  Become a daemon, discarding the controlling terminal.
 ****************************************************************************/
 
-void become_daemon(void)
+void become_daemon(BOOL dont_fork)
 {
-	if (sys_fork()) {
+	if (!dont_fork && sys_fork()) {
 		_exit(0);
 	}
 
diff -ru work/samba-3.0-alpha12/source/nmbd/nmbd.c work.new/samba-3.0-alpha12/source/nmbd/nmbd.c
--- work/samba-3.0-alpha12/source/nmbd/nmbd.c	Thu Dec 20 15:43:39 2001
+++ work.new/samba-3.0-alpha12/source/nmbd/nmbd.c	Thu Dec 27 19:33:49 2001
@@ -39,6 +39,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;
 
@@ -634,9 +637,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" );
@@ -703,7 +707,7 @@
 #endif
 
   while( EOF != 
-         (opt = getopt( argc, argv, "Vaos:T:I:C:bAB:N:Rn:l:d:Dp:hSH:G:f:i" )) )
+         (opt = getopt( argc, argv, "Vaos:T:I:C:bAB:N:Rn:l:d:Dp:hSH:G:f:iF" )) )
     {
       switch (opt)
         {
@@ -740,6 +744,9 @@
         case 'D':
           is_daemon = True;
           break;
+        case 'F':
+          in_foreground = True;
+          break;
         case 'd':
           DEBUGLEVEL = atoi(optarg);
           break;
@@ -799,7 +806,7 @@
   if (is_daemon && !opt_interactive)
   {
     DEBUG( 2, ( "Becoming a daemon.\n" ) );
-    become_daemon();
+    become_daemon(in_foreground);
   }
 
 #ifndef SYNC_DNS
diff -ru work/samba-3.0-alpha12/source/nsswitch/winbindd.c work.new/samba-3.0-alpha12/source/nsswitch/winbindd.c
--- work/samba-3.0-alpha12/source/nsswitch/winbindd.c	Thu Dec 20 15:43:40 2001
+++ work.new/samba-3.0-alpha12/source/nsswitch/winbindd.c	Thu Dec 27 19:27:28 2001
@@ -813,7 +813,7 @@
 		DEBUGLEVEL = new_debuglevel;
 
 	if (!interactive)
-		become_daemon();
+		become_daemon(0);
 
 	load_interfaces();
 
diff -ru work/samba-3.0-alpha12/source/smbd/server.c work.new/samba-3.0-alpha12/source/smbd/server.c
--- work/samba-3.0-alpha12/source/smbd/server.c	Thu Dec 20 15:43:43 2001
+++ work.new/samba-3.0-alpha12/source/smbd/server.c	Thu Dec 27 19:35:38 2001
@@ -559,9 +559,10 @@
 static void usage(char *pname)
 {
 
-	d_printf("Usage: %s [-DaoPh?Vb] [-d debuglevel] [-l log basename] [-p port]\n", pname);
+	d_printf("Usage: %s [-DFaoPh?Vb] [-d debuglevel] [-l log basename] [-p port]\n", pname);
 	d_printf("       [-O socket options] [-s services file]\n");
 	d_printf("\t-D                    Become a daemon\n");
+	d_printf("\t-F                    Execute in foreground\n");
 	d_printf("\t-a                    Append to log file (default)\n");
 	d_printf("\t-o                    Overwrite log file, don't append\n");
 	d_printf("\t-h                    Print usage\n");
@@ -585,6 +586,7 @@
 	extern char *optarg;
 	/* shall I run as a daemon */
 	BOOL is_daemon = False;
+	BOOL in_foreground = False;
 	BOOL specified_logfile = False;
 	int port = SMB_PORT;
 	int opt;
@@ -600,7 +602,7 @@
 		argc--;
 	}
 
-	while ( EOF != (opt = getopt(argc, argv, "O:l:s:d:Dp:h?bVaof:")) )
+	while ( EOF != (opt = getopt(argc, argv, "O:l:s:d:Dp:h?bVaof:F")) )
 		switch (opt)  {
 		case 'O':
 			pstrcpy(user_socket_options,optarg);
@@ -628,6 +630,10 @@
 			is_daemon = True;
 			break;
 
+		case 'F':
+			in_foreground = True;
+			break;
+
 		case 'd':
 			if (*optarg == 'A')
 				DEBUGLEVEL = 10000;
@@ -776,7 +782,7 @@
 
 	if (is_daemon) {
 		DEBUG( 3, ( "Becoming a daemon.\n" ) );
-		become_daemon();
+		become_daemon(in_foreground);
 	}
 
 	if (!directory_exist(lp_lockdir(), NULL)) {
diff -ru work/samba-3.0-alpha12/source/web/startstop.c work.new/samba-3.0-alpha12/source/web/startstop.c
--- work/samba-3.0-alpha12/source/web/startstop.c	Sun Nov 18 18:49:31 2001
+++ work.new/samba-3.0-alpha12/source/web/startstop.c	Thu Dec 27 19:28:14 2001
@@ -40,7 +40,7 @@
 
 	slprintf(binfile, sizeof(pstring) - 1, "%s/smbd", dyn_SBINDIR);
 
-	become_daemon();
+	become_daemon(0);
 
 	execl(binfile, binfile, "-D", NULL);
 
@@ -61,7 +61,7 @@
 
 	slprintf(binfile, sizeof(pstring) - 1, "%s/nmbd", dyn_SBINDIR);
 	
-	become_daemon();
+	become_daemon(0);
 
 	execl(binfile, binfile, "-D", NULL);
 
-- 
Jos Backus                 _/  _/_/_/        Santa Clara, CA
                          _/  _/   _/
                         _/  _/_/_/             
                    _/  _/  _/    _/
josb at cncdsl.com     _/_/   _/_/_/            use Std::Disclaimer;




More information about the samba-technical mailing list