git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@1281 77e5149b-7576-45b1-b177-96237e5ba77b
Trog authored on 2005/01/27 02:28:36... | ... |
@@ -64,7 +64,7 @@ void scanner_thread(void *arg) |
64 | 64 |
{ |
65 | 65 |
client_conn_t *conn = (client_conn_t *) arg; |
66 | 66 |
sigset_t sigset; |
67 |
- int ret, timeout; |
|
67 |
+ int ret, timeout, session=FALSE; |
|
68 | 68 |
struct cfgstruct *cpt; |
69 | 69 |
|
70 | 70 |
|
... | ... |
@@ -81,23 +81,52 @@ void scanner_thread(void *arg) |
81 | 81 |
if(!timeout) |
82 | 82 |
timeout = -1; |
83 | 83 |
|
84 |
- ret = command(conn->sd, conn->root, conn->limits, conn->options, conn->copt, timeout); |
|
85 |
- |
|
86 |
- switch(ret) { |
|
87 |
- case COMMAND_SHUTDOWN: |
|
88 |
- pthread_mutex_lock(&exit_mutex); |
|
89 |
- progexit = 1; |
|
90 |
- kill(conn->mainpid, SIGTERM); |
|
91 |
- pthread_mutex_unlock(&exit_mutex); |
|
92 |
- break; |
|
93 |
- |
|
94 |
- case COMMAND_RELOAD: |
|
95 |
- pthread_mutex_lock(&reload_mutex); |
|
96 |
- reload = 1; |
|
97 |
- pthread_mutex_unlock(&reload_mutex); |
|
98 |
- break; |
|
84 |
+ do { |
|
85 |
+ ret = command(conn->sd, conn->root, conn->limits, conn->options, conn->copt, timeout); |
|
86 |
+ if (ret == -1) { |
|
87 |
+ break; |
|
99 | 88 |
} |
100 | 89 |
|
90 |
+ switch(ret) { |
|
91 |
+ case COMMAND_SHUTDOWN: |
|
92 |
+ pthread_mutex_lock(&exit_mutex); |
|
93 |
+ progexit = 1; |
|
94 |
+ kill(conn->mainpid, SIGTERM); |
|
95 |
+ pthread_mutex_unlock(&exit_mutex); |
|
96 |
+ break; |
|
97 |
+ |
|
98 |
+ case COMMAND_RELOAD: |
|
99 |
+ pthread_mutex_lock(&reload_mutex); |
|
100 |
+ reload = 1; |
|
101 |
+ pthread_mutex_unlock(&reload_mutex); |
|
102 |
+ break; |
|
103 |
+ |
|
104 |
+ case COMMAND_SESSION: |
|
105 |
+ session = TRUE; |
|
106 |
+ timeout = 5; |
|
107 |
+ break; |
|
108 |
+ |
|
109 |
+ case COMMAND_END: |
|
110 |
+ session = FALSE; |
|
111 |
+ break; |
|
112 |
+ |
|
113 |
+ case COMMAND_TIMEOUT: |
|
114 |
+ if (session) { |
|
115 |
+ pthread_mutex_lock(&exit_mutex); |
|
116 |
+ if(progexit) { |
|
117 |
+ session = FALSE; |
|
118 |
+ } |
|
119 |
+ pthread_mutex_unlock(&exit_mutex); |
|
120 |
+ pthread_mutex_lock(&reload_mutex); |
|
121 |
+ if(reload) { |
|
122 |
+ session = FALSE; |
|
123 |
+ } |
|
124 |
+ pthread_mutex_unlock(&reload_mutex); |
|
125 |
+ } |
|
126 |
+ break; |
|
127 |
+ } |
|
128 |
+ } while (session); |
|
129 |
+ |
|
101 | 130 |
close(conn->sd); |
102 | 131 |
free(conn); |
103 | 132 |
return; |
... | ... |
@@ -525,7 +554,6 @@ int acceptloop_th(int socketd, struct cl_node *root, const struct cfgstruct *cop |
525 | 525 |
|
526 | 526 |
pthread_mutex_lock(&reload_mutex); |
527 | 527 |
if(reload) { |
528 |
- reload = 0; |
|
529 | 528 |
pthread_mutex_unlock(&reload_mutex); |
530 | 529 |
/* Destroy the thread manager. |
531 | 530 |
* This waits for all current tasks to end |
... | ... |
@@ -537,6 +565,9 @@ int acceptloop_th(int socketd, struct cl_node *root, const struct cfgstruct *cop |
537 | 537 |
pthread_mutex_unlock(&reload_mutex); |
538 | 538 |
exit(-1); |
539 | 539 |
} |
540 |
+ pthread_mutex_lock(&reload_mutex); |
|
541 |
+ reload = 0; |
|
542 |
+ pthread_mutex_unlock(&reload_mutex); |
|
540 | 543 |
#ifdef CLAMUKO |
541 | 544 |
if(cfgopt(copt, "ClamukoScanOnLine") || cfgopt(copt, "ClamukoScanOnAccess")) { |
542 | 545 |
logg("Stopping and restarting Clamuko.\n"); |
... | ... |
@@ -56,9 +56,7 @@ int command(int desc, const struct cl_node *root, const struct cl_limits *limits |
56 | 56 |
retval = poll_fd(desc, timeout); |
57 | 57 |
switch (retval) { |
58 | 58 |
case 0: /* timeout */ |
59 |
- mdprintf(desc, "ERROR\n"); |
|
60 |
- logg("!Command: command timeout.\n"); |
|
61 |
- return -1; |
|
59 |
+ return COMMAND_TIMEOUT; |
|
62 | 60 |
case -1: |
63 | 61 |
mdprintf(desc, "ERROR\n"); |
64 | 62 |
logg("!Command: poll_fd failed.\n"); |
... | ... |
@@ -67,8 +65,10 @@ int command(int desc, const struct cl_node *root, const struct cl_limits *limits |
67 | 67 |
|
68 | 68 |
while((bread = readsock(desc, buff, 1024)) == -1 && errno == EINTR); |
69 | 69 |
|
70 |
- if(!bread) |
|
71 |
- return 0; |
|
70 |
+ if(bread == 0) { |
|
71 |
+ /* Connection closed */ |
|
72 |
+ return -1; |
|
73 |
+ } |
|
72 | 74 |
|
73 | 75 |
if(bread < 0) { |
74 | 76 |
logg("!Command parser: read() failed.\n"); |
... | ... |
@@ -142,33 +142,7 @@ int command(int desc, const struct cl_node *root, const struct cl_limits *limits |
142 | 142 |
return COMMAND_SHUTDOWN; |
143 | 143 |
|
144 | 144 |
} else if(!strncmp(buff, CMD9, strlen(CMD9))) { /* SESSION */ |
145 |
- do { |
|
146 |
- if(!is_fd_connected(desc)) { |
|
147 |
- logg("SESSION: Client disconnected without END\n"); |
|
148 |
- return 0; |
|
149 |
- } |
|
150 |
- ret = command(desc, root, limits, options, copt, -1); |
|
151 |
- } while(!ret); |
|
152 |
- |
|
153 |
- switch(ret) { |
|
154 |
- case COMMAND_SHUTDOWN: |
|
155 |
- mdprintf(desc, "SESSION TERMINATED (SHUTDOWN)\n"); |
|
156 |
- break; |
|
157 |
- |
|
158 |
- case COMMAND_RELOAD: |
|
159 |
- mdprintf(desc, "SESSION TERMINATED (DATABASE RELOADING)\n"); |
|
160 |
- break; |
|
161 |
- |
|
162 |
- case COMMAND_END: |
|
163 |
- mdprintf(desc, "BYE\n"); |
|
164 |
- break; |
|
165 |
- |
|
166 |
- default: |
|
167 |
- mdprintf(desc, "SESSION TERMINATED (INTERNAL ERROR)\n"); |
|
168 |
- break; |
|
169 |
- } |
|
170 |
- |
|
171 |
- return ret; |
|
145 |
+ return COMMAND_SESSION; |
|
172 | 146 |
|
173 | 147 |
} else if(!strncmp(buff, CMD10, strlen(CMD10))) { /* END */ |
174 | 148 |
return COMMAND_END; |