From e959f2e2322cfac811946d418406267629a2c12b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 17 Sep 1998 06:36:08 +0000 Subject: fixed a potential problem with wins_write_database() child processes. 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. (This used to be commit 1e1a512e3ff59f962fb3de382f671618bed60839) --- source3/nmbd/nmbd_winsserver.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'source3/nmbd/nmbd_winsserver.c') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 1502dd8155..3c831ee1ea 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -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); } -- cgit