Re: update process not running

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Yesterday I said:
> believe that was because the UpdateDaemonPid didn't get cleared. The following
> patch appears to have fixed that.

I spoke too soon.  The patch was certainly a step on the way but didn't
completely fix the problem.  I now believe it is because of a race condition
between the parent and child processes, where the child terminates and is
reaped before the parent sets the UpdateDaemonPid variable.  The same race
potentially exists for the expire and nocem processes as well.
Following patch should fix.


--- list.c~	Sat Jan 31 11:20:26 1998
+++ list.c	Fri Mar 27 23:54:57 1998
@@ -643,6 +643,7 @@
 	int pid = 0;
 	time_t tim;
 	struct tms tms;
+	sigset_t myset;
 
 	if (Task->ti_state != nc_master)
 		return;
@@ -650,16 +651,24 @@
 	if (UpdateDaemonPid || (!force && tim - last_time < con->minUpdateDelay))
 		return;
 	last_time = tim;
+	sigemptyset(&myset);
+	sigaddset(&myset, SIGCHLD);
+	sigprocmask (SIG_BLOCK, &myset, NULL);
 	pid = make_vm_proc(nc_update, -1, "update");
 	if (pid < 0)
+	{
+		sigprocmask (SIG_UNBLOCK, &myset, NULL);
 		return;
+	}
 	if (pid > 0)
 	{
 	        UpdateDaemonPid = pid;
+		sigprocmask (SIG_UNBLOCK, &myset, NULL);
 		statsUpdateServer ();
 		saveStats (con->statsFile);
 		return;
 	}
+	sigprocmask (SIG_UNBLOCK, &myset, NULL);
 	while (HoldForksUpdate) {}
 	memset (&st, 0, sizeof st);
 	for (scfg = ServerList; scfg; scfg=scfg->next)
--- expire.c~	Wed Jan 21 23:13:00 1998
+++ expire.c	Fri Mar 27 23:59:46 1998
@@ -118,6 +118,7 @@
 EXPORT bool expire (bool force)
 {
     static last_expire;
+    sigset_t myset;
     long ffree = 0, bfree = 0;
     if (!force && time (NULL) < last_expire + con->expireCheckPeriod)
 	return TRUE;
@@ -132,9 +133,15 @@
 	{
 	    if (!ExpireDaemonPid)
 		{
-		    int pid = make_vm_proc (nc_expire, -1, "expire");
+		    int pid;
+		    
+		    sigemptyset(&myset);
+		    sigaddset(&myset, SIGCHLD);
+		    sigprocmask (SIG_BLOCK, &myset, NULL);
+		    pid = make_vm_proc (nc_expire, -1, "expire");
 		    if (pid == 0)
 			{
+			    sigprocmask (SIG_UNBLOCK, &myset, NULL);
 			    if (chdir (con->cacheDir)==0)
 				expire_arts ();
 			    else
@@ -143,7 +150,10 @@
 			    NOTREACHED;
 			}
 		    if (pid > 0)
+		    {
 			ExpireDaemonPid = pid;
+			sigprocmask (SIG_UNBLOCK, &myset, NULL);
+		    }
 		}
 	}
     else
--- nocem.c~	Fri Jan 30 14:01:03 1998
+++ nocem.c	Sat Mar 28 00:04:05 1998
@@ -382,20 +382,29 @@
     static time_t last_time;
     time_t tim = time(NULL);
     struct tms tms;
+    sigset_t myset;
 
     if (Task->ti_state != nc_master)
 	return FALSE;
     if (!con->nocem || NocemDaemonPid || tim - last_time < con->nocemInterval)
 	return FALSE;
     last_time = tim;
+    sigemptyset(&myset);
+    sigaddset(&myset, SIGCHLD);
+    sigprocmask (SIG_BLOCK, &myset, NULL);
     pid = make_vm_proc(nc_nocem, -1, "nocem");
     if (pid == -1)
+    {
+	sigprocmask (SIG_UNBLOCK, &myset, NULL);
 	return FALSE;
+    }
     if (pid > 1)
 	{
 	    NocemDaemonPid = pid;
+	    sigprocmask (SIG_UNBLOCK, &myset, NULL);
 	    return TRUE;
 	}
+    sigprocmask (SIG_UNBLOCK, &myset, NULL);
     while (HoldForksNocem) {}
     /* set internal credentials */
     strcpy (ClientHost, "<nocem@nntpcache>");

cheers
mark


[Index of Archives]     [Yosemite]     [Yosemite Campsites]     [Bugtraq]     [Linux]     [Trn]

Powered by Linux