git-svn: trunk@4325
Török Edvin authored on 2008/11/04 17:58:44... | ... |
@@ -1,3 +1,8 @@ |
1 |
+Tue Nov 4 11:28:09 EET 2008 (edwin) |
|
2 |
+------------------------------------ |
|
3 |
+ * clamd/thrmgr.c: use mdprintf instead of fdopen on socket (bb |
|
4 |
+ #1270) (thanks to Gianluigi Tiesi <sherpya*netfarm.it>) |
|
5 |
+ |
|
1 | 6 |
Mon Nov 3 21:05:54 EET 2008 (edwin) |
2 | 7 |
------------------------------------ |
3 | 8 |
* clamd/scanner.c, clamd/session.c, clamd/session.h, |
... | ... |
@@ -151,20 +151,13 @@ static void remove_frompools(threadpool_t *t) |
151 | 151 |
pthread_mutex_unlock(&pools_lock); |
152 | 152 |
} |
153 | 153 |
|
154 |
-int thrmgr_printstats(int outfd) |
|
154 |
+int thrmgr_printstats(int f) |
|
155 | 155 |
{ |
156 |
- FILE *f; |
|
157 | 156 |
struct threadpool_list *l; |
158 | 157 |
size_t cnt; |
159 |
- int fd = dup(outfd); |
|
160 |
- if(fd < 0) |
|
161 |
- return -1; |
|
162 |
- f = fdopen(fd, "w"); |
|
163 |
- if(!f) |
|
164 |
- return -1; |
|
165 | 158 |
pthread_mutex_lock(&pools_lock); |
166 | 159 |
for(cnt=0,l=pools;l;l=l->nxt) cnt++; |
167 |
- fprintf(f,"POOLS: %u\n\n", cnt); |
|
160 |
+ mdprintf(f,"POOLS: %u\n\n", cnt); |
|
168 | 161 |
for(l= pools;l;l = l->nxt) { |
169 | 162 |
threadpool_t *pool = l->pool; |
170 | 163 |
const char *state; |
... | ... |
@@ -175,7 +168,7 @@ int thrmgr_printstats(int outfd) |
175 | 175 |
struct task_desc *task; |
176 | 176 |
|
177 | 177 |
if(!pool) { |
178 |
- fprintf(f,"NULL\n\n"); |
|
178 |
+ mdprintf(f,"NULL\n\n"); |
|
179 | 179 |
continue; |
180 | 180 |
} |
181 | 181 |
pthread_mutex_lock(&pool->pool_mutex); |
... | ... |
@@ -190,11 +183,11 @@ int thrmgr_printstats(int outfd) |
190 | 190 |
state = "EXIT"; |
191 | 191 |
break; |
192 | 192 |
} |
193 |
- fprintf(f, "STATE: %s %s\n", state, l->nxt ? "" : "PRIMARY"); |
|
194 |
- fprintf(f, "THREADS: live %u idle %u max %u idle-timeout %u\n" |
|
193 |
+ mdprintf(f, "STATE: %s %s\n", state, l->nxt ? "" : "PRIMARY"); |
|
194 |
+ mdprintf(f, "THREADS: live %u idle %u max %u idle-timeout %u\n" |
|
195 | 195 |
,pool->thr_alive, pool->thr_idle, pool->thr_max, |
196 | 196 |
pool->idle_timeout); |
197 |
- fprintf(f,"QUEUE: %u items", pool->queue->item_count); |
|
197 |
+ mdprintf(f,"QUEUE: %u items", pool->queue->item_count); |
|
198 | 198 |
gettimeofday(&tv_now, NULL); |
199 | 199 |
if(pool->queue->head) { |
200 | 200 |
for(q=pool->queue->head;q;q=q->next) { |
... | ... |
@@ -212,39 +205,38 @@ int thrmgr_printstats(int outfd) |
212 | 212 |
usum += delta; |
213 | 213 |
++cnt; |
214 | 214 |
} |
215 |
- fprintf(f," min_wait: %.6f max_wait: %.6f avg_wait: %.6f", |
|
215 |
+ mdprintf(f," min_wait: %.6f max_wait: %.6f avg_wait: %.6f", |
|
216 | 216 |
umin/1e6, umax/1e6, usum /(1e6*cnt)); |
217 | 217 |
if(invalids) |
218 |
- fprintf(f," (INVALID timestamps: %u)", invalids); |
|
218 |
+ mdprintf(f," (INVALID timestamps: %u)", invalids); |
|
219 | 219 |
} |
220 | 220 |
if(cnt + invalids != pool->queue->item_count) |
221 |
- fprintf(f," (ERROR: %u != %u)", cnt + invalids, |
|
221 |
+ mdprintf(f," (ERROR: %u != %u)", cnt + invalids, |
|
222 | 222 |
pool->queue->item_count); |
223 |
- fputc('\n', f); |
|
223 |
+ mdprintf(f, "\n"); |
|
224 | 224 |
for(task = pool->tasks; task; task = task->nxt) { |
225 | 225 |
long delta; |
226 | 226 |
delta = tv_now.tv_usec - task->tv.tv_usec; |
227 | 227 |
delta += (tv_now.tv_sec - task->tv.tv_sec)*1000000; |
228 |
- fprintf(f,"\t%s %f %s\n", |
|
228 |
+ mdprintf(f,"\t%s %f %s\n", |
|
229 | 229 |
task->command ? task->command : "N/A", |
230 | 230 |
delta/1e6, |
231 | 231 |
task->filename ? task->filename:""); |
232 | 232 |
} |
233 |
- fputc('\n',f); |
|
233 |
+ mdprintf(f,"\n"); |
|
234 | 234 |
pthread_mutex_unlock(&pool->pool_mutex); |
235 | 235 |
} |
236 | 236 |
#if defined(C_LINUX) |
237 | 237 |
{ |
238 | 238 |
struct mallinfo inf = mallinfo(); |
239 |
- fprintf(f,"MEMSTATS: heap %.3fM mmap %.3fM used %.3fM free %.3fM releasable %.3fM\n", |
|
239 |
+ mdprintf(f,"MEMSTATS: heap %.3fM mmap %.3fM used %.3fM free %.3fM releasable %.3fM\n", |
|
240 | 240 |
inf.arena/(1024*1024.0), inf.hblkhd/(1024*1024.0), |
241 | 241 |
inf.uordblks/(1024*1024.0), inf.fordblks/(1024*1024.0), |
242 | 242 |
inf.keepcost/(1024*1024.0)); |
243 | 243 |
} |
244 | 244 |
#endif |
245 |
- fputs("END\n",f); |
|
245 |
+ mdprintf(f,"END\n"); |
|
246 | 246 |
pthread_mutex_unlock(&pools_lock); |
247 |
- fclose(f); |
|
248 | 247 |
return 0; |
249 | 248 |
} |
250 | 249 |
|