Browse code

Fixed QUIT/SHUTDOWN command.

git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@379 77e5149b-7576-45b1-b177-96237e5ba77b

Tomasz Kojm authored on 2004/03/08 08:34:29
Showing 2 changed files
... ...
@@ -1,3 +1,8 @@
1
+Mon Mar  8 00:33:17 CET 2004 (tk)
2
+---------------------------------
3
+  * clamd: fixed QUIT/SHUTDOWN command - break blocking accept() to allow
4
+	   immediate termination
5
+
1 6
 Sun Mar  7 23:29:25 CET 2004 (tk)
2 7
 ---------------------------------
3 8
   * Makefiles: allow building outside of the source tree (thanks to Philippe
... ...
@@ -54,6 +54,7 @@ typedef struct client_conn_tag {
54 54
     const struct cfgstruct *copt;
55 55
     const struct cl_node *root;
56 56
     const struct cl_limits *limits;
57
+    pid_t mainpid;
57 58
 } client_conn_t;
58 59
 
59 60
 void scanner_thread(void *arg)
... ...
@@ -73,6 +74,7 @@ void scanner_thread(void *arg)
73 73
 	case COMMAND_QUIT:
74 74
 	    pthread_mutex_lock(&exit_mutex);
75 75
 	    progexit = 1;
76
+	    kill(conn->mainpid, SIGTERM);
76 77
 	    pthread_mutex_unlock(&exit_mutex);
77 78
 	    break;
78 79
 
... ...
@@ -188,7 +190,8 @@ int acceptloop_th(int socketd, struct cl_node *root, const struct cfgstruct *cop
188 188
 	/* char *buff[BUFFSIZE+1]; */
189 189
 	unsigned int selfchk;
190 190
 	time_t start_time, current_time;
191
-	
191
+	pid_t mainpid;
192
+
192 193
 #if defined(C_BIGSTACK) || defined(C_BSD)
193 194
         size_t stacksize;
194 195
 #endif
... ...
@@ -201,13 +204,14 @@ int acceptloop_th(int socketd, struct cl_node *root, const struct cfgstruct *cop
201 201
 	memset(&sigact, 0, sizeof(struct sigaction));
202 202
 
203 203
     /* save the PID */
204
+    mainpid = getpid();
204 205
     if((cpt = cfgopt(copt, "PidFile"))) {
205 206
 	    FILE *fd;
206 207
 	old_umask = umask(0006);
207 208
 	if((fd = fopen(cpt->strarg, "w")) == NULL) {
208 209
 	    logg("!Can't save PID in file %s\n", cpt->strarg);
209 210
 	} else {
210
-	    fprintf(fd, "%d", getpid());
211
+	    fprintf(fd, "%d", (int) mainpid);
211 212
 	    fclose(fd);
212 213
 	}
213 214
 	umask(old_umask);
... ...
@@ -413,6 +417,7 @@ int acceptloop_th(int socketd, struct cl_node *root, const struct cfgstruct *cop
413 413
 		client_conn->copt = copt;
414 414
 		client_conn->root = root;
415 415
 		client_conn->limits = &limits;
416
+		client_conn->mainpid = mainpid;
416 417
 		thrmgr_dispatch(thr_pool, client_conn);
417 418
 	}
418 419