git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@825 77e5149b-7576-45b1-b177-96237e5ba77b
Tomasz Kojm authored on 2004/09/05 00:48:30... | ... |
@@ -1,3 +1,7 @@ |
1 |
+Sat Sep 4 17:46:39 CEST 2004 (tk) |
|
2 |
+---------------------------------- |
|
3 |
+ * clamd: make output of VERSION compatible with clamd --version |
|
4 |
+ |
|
1 | 5 |
Sat Sep 4 15:12:32 CEST 2004 (tk) |
2 | 6 |
---------------------------------- |
3 | 7 |
* freshclam: retry if mirrors are not fully synchronised |
... | ... |
@@ -74,7 +74,7 @@ void scanner_thread(void *arg) |
74 | 74 |
ret = command(conn->sd, conn->root, conn->limits, conn->options, conn->copt); |
75 | 75 |
|
76 | 76 |
switch(ret) { |
77 |
- case COMMAND_QUIT: |
|
77 |
+ case COMMAND_SHUTDOWN: |
|
78 | 78 |
pthread_mutex_lock(&exit_mutex); |
79 | 79 |
progexit = 1; |
80 | 80 |
kill(conn->mainpid, SIGTERM); |
... | ... |
@@ -41,7 +41,9 @@ |
41 | 41 |
#include "tests.h" |
42 | 42 |
#include "session.h" |
43 | 43 |
#include "str.h" /* libclamav */ |
44 |
+#include "clamav.h" |
|
44 | 45 |
#include "output.h" |
46 |
+#include "memory.h" |
|
45 | 47 |
|
46 | 48 |
#define CMD1 "SCAN" |
47 | 49 |
#define CMD2 "RAWSCAN" |
... | ... |
@@ -55,6 +57,7 @@ |
55 | 55 |
#define CMD10 "END" |
56 | 56 |
#define CMD11 "SHUTDOWN" |
57 | 57 |
|
58 |
+pthread_mutex_t ctime_mutex = PTHREAD_MUTEX_INITIALIZER; |
|
58 | 59 |
|
59 | 60 |
int command(int desc, const struct cl_node *root, const struct cl_limits *limits, int options, const struct cfgstruct *copt) |
60 | 61 |
{ |
... | ... |
@@ -106,7 +109,7 @@ int command(int desc, const struct cl_node *root, const struct cl_limits *limits |
106 | 106 |
scan(buff + strlen(CMD2) + 1, NULL, root, NULL, opt, copt, desc, 0); |
107 | 107 |
|
108 | 108 |
} else if(!strncmp(buff, CMD3, strlen(CMD3))) { /* QUIT */ |
109 |
- return COMMAND_QUIT; |
|
109 |
+ return COMMAND_SHUTDOWN; |
|
110 | 110 |
|
111 | 111 |
} else if(!strncmp(buff, CMD4, strlen(CMD4))) { /* RELOAD */ |
112 | 112 |
mdprintf(desc, "RELOADING\n"); |
... | ... |
@@ -119,7 +122,34 @@ int command(int desc, const struct cl_node *root, const struct cl_limits *limits |
119 | 119 |
scan(buff + strlen(CMD6) + 1, NULL, root, limits, options, copt, desc, 1); |
120 | 120 |
|
121 | 121 |
} else if(!strncmp(buff, CMD7, strlen(CMD7))) { /* VERSION */ |
122 |
- mdprintf(desc, "clamd / ClamAV version "VERSION"\n"); |
|
122 |
+ const char *dbdir; |
|
123 |
+ char *path; |
|
124 |
+ struct cl_cvd *daily; |
|
125 |
+ |
|
126 |
+ if((cpt = cfgopt(copt, "DatabaseDirectory")) || (cpt = cfgopt(copt, "DataDirectory"))) |
|
127 |
+ dbdir = cpt->strarg; |
|
128 |
+ else |
|
129 |
+ dbdir = cl_retdbdir(); |
|
130 |
+ |
|
131 |
+ if(!(path = mmalloc(strlen(dbdir) + 11))) { |
|
132 |
+ mdprintf(desc, "Memory allocation error - SHUTDOWN forced\n"); |
|
133 |
+ return COMMAND_SHUTDOWN; |
|
134 |
+ } |
|
135 |
+ |
|
136 |
+ sprintf(path, "%s/daily.cvd", dbdir); |
|
137 |
+ |
|
138 |
+ if((daily = cl_cvdhead(path))) { |
|
139 |
+ time_t t = (time_t) daily->stime; |
|
140 |
+ |
|
141 |
+ pthread_mutex_lock(&ctime_mutex); |
|
142 |
+ mdprintf(desc, "ClamAV "VERSION"/%d/%s", daily->version, ctime(&t)); |
|
143 |
+ pthread_mutex_unlock(&ctime_mutex); |
|
144 |
+ cl_cvdfree(daily); |
|
145 |
+ } else { |
|
146 |
+ mdprintf(desc, "ClamAV "VERSION"\n"); |
|
147 |
+ } |
|
148 |
+ |
|
149 |
+ free(path); |
|
123 | 150 |
|
124 | 151 |
} else if(!strncmp(buff, CMD8, strlen(CMD8))) { /* STREAM */ |
125 | 152 |
scanstream(desc, NULL, root, limits, options, copt); |
... | ... |
@@ -130,7 +160,7 @@ int command(int desc, const struct cl_node *root, const struct cl_limits *limits |
130 | 130 |
} while(!ret); |
131 | 131 |
|
132 | 132 |
switch(ret) { |
133 |
- case COMMAND_QUIT: |
|
133 |
+ case COMMAND_SHUTDOWN: |
|
134 | 134 |
mdprintf(desc, "SESSION TERMINATED (SHUTDOWN)\n"); |
135 | 135 |
break; |
136 | 136 |
|
... | ... |
@@ -153,7 +183,7 @@ int command(int desc, const struct cl_node *root, const struct cl_limits *limits |
153 | 153 |
return COMMAND_END; |
154 | 154 |
|
155 | 155 |
} else if(!strncmp(buff, CMD11, strlen(CMD11))) { /* SHUTDOWN */ |
156 |
- return COMMAND_QUIT; |
|
156 |
+ return COMMAND_SHUTDOWN; |
|
157 | 157 |
|
158 | 158 |
} else { |
159 | 159 |
mdprintf(desc, "UNKNOWN COMMAND\n"); |
... | ... |
@@ -22,6 +22,7 @@ |
22 | 22 |
|
23 | 23 |
#include <stdio.h> |
24 | 24 |
#include <string.h> |
25 |
+#include <time.h> |
|
25 | 26 |
|
26 | 27 |
#include "clamav.h" |
27 | 28 |
#include "cfgparser.h" |
... | ... |
@@ -80,10 +81,9 @@ void print_version(void) |
80 | 80 |
sprintf(path, "%s/daily.cvd", dbdir); |
81 | 81 |
|
82 | 82 |
if((daily = cl_cvdhead(path))) { |
83 |
- timecpy = strdup(daily->time); |
|
84 |
- timecpy[14] = ':'; |
|
85 |
- mprintf("ClamAV "VERSION"/%d/%s\n", daily->version, timecpy); |
|
86 |
- free(timecpy); |
|
83 |
+ time_t t = (time_t) daily->stime; |
|
84 |
+ mprintf("ClamAV "VERSION"/%d/%s", daily->version, ctime(&t)); |
|
85 |
+ cl_cvdfree(daily); |
|
87 | 86 |
} else { |
88 | 87 |
mprintf("ClamAV "VERSION"\n"); |
89 | 88 |
} |