fixed a potential problem with wins_write_database() child processes.
authorAndrew Tridgell <tridge@samba.org>
Thu, 17 Sep 1998 06:36:08 +0000 (06:36 +0000)
committerAndrew Tridgell <tridge@samba.org>
Thu, 17 Sep 1998 06:36:08 +0000 (06:36 +0000)
In sig_term() we were calling wins_write_database(0) which would fork a
child. This child might then get killed by the same process killing
off the parent. That process would then fork another child etc.

The solution is to pass a "background" flag to wins_write_database(0)
and only fork if this is set.

source/include/proto.h
source/nmbd/nmbd.c
source/nmbd/nmbd_serverlistdb.c
source/nmbd/nmbd_winsserver.c

index a864cd7033dc085a5508eb0bf620b9d9a8b1a1a0..f2b74b40763db174aeb43eb5809ba59da0d60673 100644 (file)
@@ -825,7 +825,7 @@ void wins_process_name_query_request(struct subnet_record *subrec,
 void wins_process_name_release_request(struct subnet_record *subrec,
                                        struct packet_struct *p);
 void initiate_wins_processing(time_t t);
-void wins_write_database(void);
+void wins_write_database(BOOL background);
 
 /*The following definitions come from  nmbd/nmbd_workgroupdb.c  */
 
@@ -1744,11 +1744,6 @@ void file_chain_reset(void);
 void file_chain_save(void);
 void file_chain_restore(void);
 
-/*The following definitions come from  smbd/groupname.c  */
-
-void load_groupname_map(void);
-void map_gid_to_sid( gid_t gid, DOM_SID *psid);
-
 /*The following definitions come from  smbd/ipc.c  */
 
 int reply_trans(connection_struct *conn, char *inbuf,char *outbuf, int size, int bufsize);
index 482e136ba4ebdd3f0cb768f77c7097f28fe64621..d7383fb7368049369c7bed27c02e6b722b224af9 100644 (file)
@@ -68,7 +68,7 @@ static void sig_term(int sig)
   DEBUG(0,("Got SIGTERM: going down...\n"));
   
   /* Write out wins.dat file if samba is a WINS server */
-  wins_write_database();
+  wins_write_database(False);
   
   /* Remove all SELF registered names. */
   release_my_names();
index a4dab6f419db67e01dd72fdacc00be6df5156f41..458fbd00855dfda28460b93a4510065f9097812e 100644 (file)
@@ -321,6 +321,8 @@ void write_browse_list(time_t t, BOOL force_write)
       return;
   }
 
+  lasttime = t;
+
   dump_workgroups(force_write);
  
   for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec))
@@ -335,7 +337,6 @@ void write_browse_list(time_t t, BOOL force_write)
   if(!list_changed)
     return;
 
-  lasttime = t;
   updatecount++;
     
   pstrcpy(fname,lp_lockdir());
index 1502dd8155d7912d250eb32c9aa2f5e9a7f9f18b..3c831ee1ea087a9e3c6ca38a1475fa059707b018 100644 (file)
@@ -1535,7 +1535,7 @@ void initiate_wins_processing(time_t t)
   expire_names_on_subnet(wins_server_subnet, t);
 
   if(wins_server_subnet->namelist_changed)
-    wins_write_database();
+    wins_write_database(True);
 
   wins_server_subnet->namelist_changed = False;
 }
@@ -1543,7 +1543,7 @@ void initiate_wins_processing(time_t t)
 /*******************************************************************
  Write out the current WINS database.
 ******************************************************************/
-void wins_write_database(void)
+void wins_write_database(BOOL background)
 {
   struct name_record *namerec;
   pstring fname, fnamenew;
@@ -1556,16 +1556,15 @@ void wins_write_database(void)
 
   /* we will do the writing in a child process to ensure that the parent
      doesn't block while this is done */
-  if ((child_pid=fork())) {
-         return;
+  if (background) {
+         CatchChild();
+         if ((child_pid=fork())) {
+                 return;
+         }
   }
 
-  pstrcpy(fname,lp_lockdir());
-  trim_string(fname,NULL,"/");
-  pstrcat(fname,"/");
-  pstrcat(fname,WINS_LIST);
-  pstrcpy(fnamenew,fname);
-  pstrcat(fnamenew,".");
+  slprintf(fname,sizeof(fname),"%s/%s.%d", lp_lockdir(), WINS_LIST, getpid());
+  string_sub(s->fname,"//", "/");
 
   if((fp = fopen(fnamenew,"w")) == NULL)
   {
@@ -1612,7 +1611,7 @@ void wins_write_database(void)
   }
   
   fclose(fp);
-  unlink(fname);
   chmod(fnamenew,0644);
+  unlink(fname);
   rename(fnamenew,fname);
 }