[PATCH] smbcontrolify config updates

Alexander Bokovoy a.bokovoy at sam-solutions.net
Wed Jul 9 13:02:03 GMT 2003


On Tue, Jul 08, 2003 at 09:58:41PM +0300, Alexander Bokovoy wrote:
> On Tue, Jul 08, 2003 at 08:35:39PM +0200, Stefan (metze) Metzmacher wrote:
> > At 18:52 08.07.2003 +0300, Alexander Bokovoy wrote:
> > >Greetings!
> > >
> > >Following patch adds support to force daemons to reload smb.conf on
> > >'smbcontrol <dest> reload-config' command. This basically does the same as
> > >SIGHUP signal sent to winbindd and nmbd, and for smbd it uses already
> > >existing message handler.
> > >
> > >What do you think about it?
> > 
> > sounds good
> > 
> > but I don't see any changes for smbd to handle this in the patch,
> > only nmbd and winbind
> Because smbd already supports this.
> 
> I did some code consolidation for this patch, thanks to Volker on
> suggestions and discussion. New version is attached. I tested it with
> updated init scripts which are using smbcontrol for most of tasks. It
> works for all daemons.
Ok, next edition.

This changeset adds MSG_SHUTDOWN handling to winbindd which was missing
it. So, now all daemons respond to following common and useable for init
scripts messages:

	MSG_SMB_CONF_UPDATED -- trigger reload of smb.conf and related actions
	MSG_SHUTDOWN -- trigger termination of a daemon

These commands can be send using smbcontrol utility:

	smbcontrol <dest> reload-config -- for MSG_SMB_CONF_UPDATED
	smbcontrol <dest> shutdown      -- for MSG_SHUTDOWN

-- 
/ Alexander Bokovoy
-------------- next part --------------
Index: docs/docbook/manpages/smbcontrol.1.xml
===================================================================
RCS file: /home/cvs/samba/docs/docbook/manpages/smbcontrol.1.xml,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 smbcontrol.1.xml
--- docs/docbook/manpages/smbcontrol.1.xml	1 May 2003 14:00:10 -0000	1.1.2.1
+++ docs/docbook/manpages/smbcontrol.1.xml	8 Jul 2003 19:10:22 -0000
@@ -254,6 +254,13 @@
 	sent to smbd.</para></listitem>
 	</varlistentry>
 
+	<varlistentry>
+	<term>reload-config</term>
+	<listitem><para>Force daemon to reload smb.conf configuration file. Can be sent
+	to <constant>smbd</constant>, <constant>nmbd</constant>, or <constant>winbindd</constant>.
+	</para></listitem>
+	</varlistentry>
+
 </variablelist>
 </refsect1>
 
Index: source/nmbd/nmbd.c
===================================================================
RCS file: /home/cvs/samba/source/nmbd/nmbd.c,v
retrieving revision 1.134.2.15
diff -u -r1.134.2.15 nmbd.c
--- source/nmbd/nmbd.c	10 May 2003 11:49:50 -0000	1.134.2.15
+++ source/nmbd/nmbd.c	8 Jul 2003 19:10:24 -0000
@@ -299,12 +299,35 @@
 }
 
 /**************************************************************************** **
+ * React on 'smbcontrol nmbd reload-config' in the same way as to SIGHUP
+ * We use buf here to return BOOL result to process() when reload_interfaces()
+ * detects that there are no subnets.
+ **************************************************************************** */
+static void msg_reload_nmbd_services(int msg_type, pid_t src, void *buf, size_t len)
+{
+	write_browse_list( 0, True );
+	dump_all_namelists();
+	reload_nmbd_services( True );
+	reopen_logs();
+	
+	if(buf) {
+		/* We were called from process() */
+		/* If reload_interfaces() returned True */
+		/* we need to shutdown if there are no subnets... */
+		/* pass this info back to process() */
+		*((BOOL*)buf) = reload_interfaces(0);  
+	}
+}
+
+
+/**************************************************************************** **
  The main select loop.
  **************************************************************************** */
 
 static void process(void)
 {
 	BOOL run_election;
+	BOOL no_subnets;
 
 	while( True ) {
 		time_t t = time(NULL);
@@ -513,11 +536,8 @@
 
 		if(reload_after_sighup) {
 			DEBUG( 0, ( "Got SIGHUP dumping debug info.\n" ) );
-			write_browse_list( 0, True );
-			dump_all_namelists();
-			reload_nmbd_services( True );
-			reopen_logs();
-			if(reload_interfaces(0))
+			msg_reload_nmbd_services(MSG_SMB_CONF_UPDATED, (pid_t) 0, (void*) &no_subnets, 0);
+			if(no_subnets)
 				return;
 			reload_after_sighup = 0;
 		}
@@ -696,6 +716,7 @@
   message_register(MSG_FORCE_ELECTION, nmbd_message_election);
   message_register(MSG_WINS_NEW_ENTRY, nmbd_wins_new_entry);
   message_register(MSG_SHUTDOWN, nmbd_terminate);
+  message_register(MSG_SMB_CONF_UPDATED, msg_reload_nmbd_services);
 
   DEBUG( 3, ( "Opening sockets %d\n", global_nmb_port ) );
 
Index: source/nsswitch/winbindd.c
===================================================================
RCS file: /home/cvs/samba/source/nsswitch/winbindd.c,v
retrieving revision 1.55.2.31
diff -u -r1.55.2.31 winbindd.c
--- source/nsswitch/winbindd.c	27 Jun 2003 20:55:47 -0000	1.55.2.31
+++ source/nsswitch/winbindd.c	8 Jul 2003 19:10:25 -0000
@@ -52,6 +52,7 @@
 	return(ret);
 }
 
+
 #if DUMP_CORE
 
 /**************************************************************************** **
@@ -187,6 +188,20 @@
 	sys_select_signal();
 }
 
+/* React on 'smbcontrol winbindd reload-config' in the same way as on SIGHUP*/
+static void msg_reload_services(int msg_type, pid_t src, void *buf, size_t len)
+{
+        /* Flush various caches */
+	flush_caches();
+	reload_services_file(True);
+}
+
+/* React on 'smbcontrol winbindd shutdown' in the same way as on SIGTERM*/
+static void msg_shutdown(int msg_type, pid_t src, void *buf, size_t len)
+{
+	terminate();
+}
+
 struct dispatch_table {
 	enum winbindd_cmd cmd;
 	enum winbindd_result (*fn)(struct winbindd_cli_state *state);
@@ -723,11 +738,8 @@
 		if (do_sighup) {
 
 			DEBUG(3, ("got SIGHUP\n"));
- 
-                        /* Flush various caches */
 
-			flush_caches();
-			reload_services_file(True);
+			msg_reload_services(MSG_SMB_CONF_UPDATED, (pid_t) 0, NULL, 0);
 			do_sighup = False;
 		}
 
@@ -896,6 +908,12 @@
 		DEBUG(0, ("unable to initialise messaging system\n"));
 		exit(1);
 	}
+	
+	/* React on 'smbcontrol winbindd reload-config' in the same way
+	   as to SIGHUP signal */
+	message_register(MSG_SMB_CONF_UPDATED, msg_reload_services);
+	message_register(MSG_SHUTDOWN, msg_shutdown);
+	
 	poptFreeContext(pc);
 
 	netsamlogon_cache_init(); /* Non-critical */
Index: source/utils/smbcontrol.c
===================================================================
RCS file: /home/cvs/samba/source/utils/smbcontrol.c,v
retrieving revision 1.42.2.20
diff -u -r1.42.2.20 smbcontrol.c
--- source/utils/smbcontrol.c	27 Jun 2003 20:55:48 -0000	1.42.2.20
+++ source/utils/smbcontrol.c	8 Jul 2003 19:10:26 -0000
@@ -553,6 +553,16 @@
 		pid, MSG_DEBUG, argv[1], strlen(argv[1]) + 1, False);
 }
 
+static BOOL do_reload_config(const pid_t pid, const int argc, const char **argv)
+{
+	if (argc != 1) {
+		fprintf(stderr, "Usage: smbcontrol <dest> reload-config\n");
+		return False;
+	}
+
+	return send_message(pid, MSG_SMB_CONF_UPDATED, NULL, 0, False);
+}
+
 /* A list of message type supported */
 
 static const struct {
@@ -576,6 +586,7 @@
 	{ "dmalloc-log-changed", do_dmalloc_changed, "" },
 	{ "shutdown", do_shutdown, "Shut down daemon" },
 	{ "drvupgrade", do_drvupgrade, "Notify a printer driver has changed" },
+	{ "reload-config", do_reload_config, "Force smbd or winbindd to reload config file"},
 	{ "noop", do_noop, "Do nothing" },
 	{ NULL }
 };


More information about the samba-technical mailing list