... | ... |
@@ -23,31 +23,31 @@ |
23 | 23 |
/* Possible states during update */ |
24 | 24 |
typedef enum _AV_UPD_STATE |
25 | 25 |
{ |
26 |
- UPD_CHECK, |
|
27 |
- UPD_NEWER_FOUND, |
|
28 |
- UPD_NONE, |
|
29 |
- UPD_DOWNLOAD_BEGIN, |
|
30 |
- UPD_DOWNLOAD_COMPLETE, |
|
31 |
- UPD_PAUSE, |
|
32 |
- UPD_ABORT, |
|
33 |
- UPD_DONE, |
|
34 |
- UPD_INSTALL_BEGIN, |
|
35 |
- UPD_INSTALL_COMPLETE, |
|
36 |
- UPD_FILE_BEGIN, |
|
37 |
- UPD_FILE_COMPLETE, |
|
38 |
- UPD_FILE_PROGRESS, |
|
39 |
- UPD_STOP, /* Used by external module to stop the update */ |
|
40 |
-}AV_UPD_STATE; |
|
26 |
+ UPD_CHECK, |
|
27 |
+ UPD_NEWER_FOUND, |
|
28 |
+ UPD_NONE, |
|
29 |
+ UPD_DOWNLOAD_BEGIN, |
|
30 |
+ UPD_DOWNLOAD_COMPLETE, |
|
31 |
+ UPD_PAUSE, |
|
32 |
+ UPD_ABORT, |
|
33 |
+ UPD_DONE, |
|
34 |
+ UPD_INSTALL_BEGIN, |
|
35 |
+ UPD_INSTALL_COMPLETE, |
|
36 |
+ UPD_FILE_BEGIN, |
|
37 |
+ UPD_FILE_COMPLETE, |
|
38 |
+ UPD_FILE_PROGRESS, |
|
39 |
+ UPD_STOP, /* Used by external module to stop the update */ |
|
40 |
+} AV_UPD_STATE; |
|
41 | 41 |
|
42 | 42 |
#define AV_UPD_FILE_NAME_MAX 16 |
43 | 43 |
|
44 | 44 |
typedef struct _AV_UPD_STATUS |
45 | 45 |
{ |
46 |
- int state; /* AV_UPD_STATE */ |
|
47 |
- int status; /* 0 -> Success, anything else failure */ |
|
48 |
- int totalFiles; /* incase there update happens with multiple files */ |
|
49 |
- int percentDownloaded; /* file downloaded in % */ |
|
50 |
- WCHAR fileName[AV_UPD_FILE_NAME_MAX]; /* the current filename */ |
|
51 |
-}AV_UPD_STATUS, *PAV_UPD_STATUS; |
|
46 |
+ int state; /* AV_UPD_STATE */ |
|
47 |
+ int status; /* 0 -> Success, anything else failure */ |
|
48 |
+ int totalFiles; /* incase there update happens with multiple files */ |
|
49 |
+ int percentDownloaded; /* file downloaded in % */ |
|
50 |
+ WCHAR fileName[AV_UPD_FILE_NAME_MAX]; /* the current filename */ |
|
51 |
+} AV_UPD_STATUS, *PAV_UPD_STATUS; |
|
52 | 52 |
|
53 | 53 |
#endif /* _CLUPDATE_H */ |
... | ... |
@@ -26,82 +26,93 @@ |
26 | 26 |
static HANDLE logh = INVALID_HANDLE_VALUE; |
27 | 27 |
static int log_dbg = 0; |
28 | 28 |
|
29 |
-void flog_open(const char *path) { |
|
29 |
+void |
|
30 |
+flog_open (const char *path) |
|
31 |
+{ |
|
30 | 32 |
char logfile[4096]; |
31 | 33 |
DWORD sz; |
32 | 34 |
|
33 |
- _snprintf(logfile, sizeof(logfile), "%s\\update.log", path); |
|
34 |
- logfile[sizeof(logfile)-1] = '\0'; |
|
35 |
- logh = CreateFile(logfile, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); |
|
36 |
- if(logh == INVALID_HANDLE_VALUE) |
|
37 |
- return; |
|
38 |
- sz = GetFileSize(logh, NULL); |
|
39 |
- if(sz >= 10*1024*1024) |
|
40 |
- SetEndOfFile(logh); |
|
35 |
+ _snprintf (logfile, sizeof (logfile), "%s\\update.log", path); |
|
36 |
+ logfile[sizeof (logfile) - 1] = '\0'; |
|
37 |
+ logh = |
|
38 |
+ CreateFile (logfile, GENERIC_WRITE, FILE_SHARE_READ, NULL, |
|
39 |
+ OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); |
|
40 |
+ if (logh == INVALID_HANDLE_VALUE) |
|
41 |
+ return; |
|
42 |
+ sz = GetFileSize (logh, NULL); |
|
43 |
+ if (sz >= 10 * 1024 * 1024) |
|
44 |
+ SetEndOfFile (logh); |
|
41 | 45 |
else |
42 |
- SetFilePointer(logh, 0, NULL, FILE_END); |
|
46 |
+ SetFilePointer (logh, 0, NULL, FILE_END); |
|
43 | 47 |
|
44 |
- _snprintf(logfile, sizeof(logfile), "%s\\update_log_verbose", path); |
|
45 |
- logfile[sizeof(logfile)-1] = '\0'; |
|
46 |
- if(access(logfile, 0) != -1) |
|
47 |
- log_dbg = 1; |
|
48 |
- flog("Log file initialized"); |
|
48 |
+ _snprintf (logfile, sizeof (logfile), "%s\\update_log_verbose", path); |
|
49 |
+ logfile[sizeof (logfile) - 1] = '\0'; |
|
50 |
+ if (access (logfile, 0) != -1) |
|
51 |
+ log_dbg = 1; |
|
52 |
+ flog ("Log file initialized"); |
|
49 | 53 |
} |
50 | 54 |
|
51 |
-void flog(const char *fmt, ...) { |
|
55 |
+void |
|
56 |
+flog (const char *fmt, ...) |
|
57 |
+{ |
|
52 | 58 |
char buf[4096]; |
53 | 59 |
SYSTEMTIME t; |
54 | 60 |
DWORD x; |
55 | 61 |
va_list ap; |
56 | 62 |
int len; |
57 | 63 |
|
58 |
- if(logh == INVALID_HANDLE_VALUE) |
|
59 |
- return; |
|
64 |
+ if (logh == INVALID_HANDLE_VALUE) |
|
65 |
+ return; |
|
60 | 66 |
|
61 |
- GetLocalTime(&t); |
|
62 |
- _snprintf(buf, sizeof(buf), "%04u-%02u-%02u %02u:%02u:%02u - ", t.wYear, t.wMonth, t.wDay, t.wHour, t.wMinute, t.wSecond); |
|
63 |
- buf[sizeof(buf)-1] = '\0'; |
|
64 |
- len = strlen(buf); |
|
65 |
- va_start(ap, fmt); |
|
66 |
- vsnprintf(buf + len, sizeof(buf) - len, fmt, ap); |
|
67 |
- va_end(ap); |
|
68 |
- buf[sizeof(buf)-1] = '\0'; |
|
69 |
- len = strlen(buf); |
|
70 |
- len = len < sizeof(buf) - 2 ? len : sizeof(buf) - 2; |
|
71 |
- memcpy(buf + len, "\r\n", 2); |
|
67 |
+ GetLocalTime (&t); |
|
68 |
+ _snprintf (buf, sizeof (buf), "%04u-%02u-%02u %02u:%02u:%02u - ", t.wYear, |
|
69 |
+ t.wMonth, t.wDay, t.wHour, t.wMinute, t.wSecond); |
|
70 |
+ buf[sizeof (buf) - 1] = '\0'; |
|
71 |
+ len = strlen (buf); |
|
72 |
+ va_start (ap, fmt); |
|
73 |
+ vsnprintf (buf + len, sizeof (buf) - len, fmt, ap); |
|
74 |
+ va_end (ap); |
|
75 |
+ buf[sizeof (buf) - 1] = '\0'; |
|
76 |
+ len = strlen (buf); |
|
77 |
+ len = len < sizeof (buf) - 2 ? len : sizeof (buf) - 2; |
|
78 |
+ memcpy (buf + len, "\r\n", 2); |
|
72 | 79 |
len += 2; |
73 |
- WriteFile(logh, buf, len, &x, NULL); |
|
80 |
+ WriteFile (logh, buf, len, &x, NULL); |
|
74 | 81 |
} |
75 | 82 |
|
76 |
-void flog_dbg(const char *fmt, ...) { |
|
83 |
+void |
|
84 |
+flog_dbg (const char *fmt, ...) |
|
85 |
+{ |
|
77 | 86 |
char buf[4096]; |
78 | 87 |
SYSTEMTIME t; |
79 | 88 |
DWORD x; |
80 | 89 |
va_list ap; |
81 | 90 |
int len; |
82 | 91 |
|
83 |
- if(!log_dbg) |
|
84 |
- return; |
|
92 |
+ if (!log_dbg) |
|
93 |
+ return; |
|
85 | 94 |
|
86 |
- GetLocalTime(&t); |
|
87 |
- _snprintf(buf, sizeof(buf), "%04u-%02u-%02u %02u:%02u:%02u - [", t.wYear, t.wMonth, t.wDay, t.wHour, t.wMinute, t.wSecond); |
|
88 |
- buf[sizeof(buf)-1] = '\0'; |
|
89 |
- len = strlen(buf); |
|
90 |
- va_start(ap, fmt); |
|
91 |
- vsnprintf(buf + len, sizeof(buf) - len, fmt, ap); |
|
92 |
- va_end(ap); |
|
93 |
- buf[sizeof(buf)-1] = '\0'; |
|
94 |
- len = strlen(buf); |
|
95 |
- len = len < sizeof(buf) - 3 ? len : sizeof(buf) - 3; |
|
96 |
- memcpy(buf + len, "]\r\n", 3); |
|
95 |
+ GetLocalTime (&t); |
|
96 |
+ _snprintf (buf, sizeof (buf), "%04u-%02u-%02u %02u:%02u:%02u - [", |
|
97 |
+ t.wYear, t.wMonth, t.wDay, t.wHour, t.wMinute, t.wSecond); |
|
98 |
+ buf[sizeof (buf) - 1] = '\0'; |
|
99 |
+ len = strlen (buf); |
|
100 |
+ va_start (ap, fmt); |
|
101 |
+ vsnprintf (buf + len, sizeof (buf) - len, fmt, ap); |
|
102 |
+ va_end (ap); |
|
103 |
+ buf[sizeof (buf) - 1] = '\0'; |
|
104 |
+ len = strlen (buf); |
|
105 |
+ len = len < sizeof (buf) - 3 ? len : sizeof (buf) - 3; |
|
106 |
+ memcpy (buf + len, "]\r\n", 3); |
|
97 | 107 |
len += 3; |
98 |
- WriteFile(logh, buf, len, &x, NULL); |
|
108 |
+ WriteFile (logh, buf, len, &x, NULL); |
|
99 | 109 |
} |
100 | 110 |
|
101 |
-void flog_close(void) { |
|
102 |
- if(logh == INVALID_HANDLE_VALUE) |
|
103 |
- return; |
|
104 |
- flog("Log file closed"); |
|
105 |
- CloseHandle(logh); |
|
111 |
+void |
|
112 |
+flog_close (void) |
|
113 |
+{ |
|
114 |
+ if (logh == INVALID_HANDLE_VALUE) |
|
115 |
+ return; |
|
116 |
+ flog ("Log file closed"); |
|
117 |
+ CloseHandle (logh); |
|
106 | 118 |
} |
107 |
- |
... | ... |
@@ -20,9 +20,9 @@ |
20 | 20 |
#ifndef __FLOG_H |
21 | 21 |
#define __FLOG_H |
22 | 22 |
|
23 |
-void flog_open(const char *path); |
|
24 |
-void flog(const char *fmt, ...); |
|
25 |
-void flog_dbg(const char *fmt, ...); |
|
26 |
-void flog_close(void); |
|
23 |
+void flog_open (const char *path); |
|
24 |
+void flog (const char *fmt, ...); |
|
25 |
+void flog_dbg (const char *fmt, ...); |
|
26 |
+void flog_close (void); |
|
27 | 27 |
|
28 | 28 |
#endif |
... | ... |
@@ -25,55 +25,71 @@ |
25 | 25 |
#include "clupdate.h" |
26 | 26 |
#include "flog.h" |
27 | 27 |
|
28 |
-struct my_f { |
|
28 |
+struct my_f |
|
29 |
+{ |
|
29 | 30 |
HANDLE h; |
30 | 31 |
char buf[1024]; |
31 | 32 |
char *next; |
32 | 33 |
unsigned int len; |
33 | 34 |
}; |
34 | 35 |
|
35 |
-static void init_myf(struct my_f *f, HANDLE h) { |
|
36 |
+static void |
|
37 |
+init_myf (struct my_f *f, HANDLE h) |
|
38 |
+{ |
|
36 | 39 |
f->next = f->buf; |
37 | 40 |
f->len = 0; |
38 | 41 |
f->h = h; |
39 | 42 |
} |
40 | 43 |
|
41 |
-static char *my_fgets(struct my_f *f) { |
|
44 |
+static char * |
|
45 |
+my_fgets (struct my_f *f) |
|
46 |
+{ |
|
42 | 47 |
int stripping = 0; |
43 | 48 |
char *cur = f->next; |
44 |
- while(1) { |
|
45 |
- if(!f->len) { |
|
46 |
- if(f->next == &f->buf[sizeof(f->buf)-1]) { |
|
47 |
- if(cur == f->buf) { |
|
48 |
- *f->next = '\0'; |
|
49 |
- f->next = f->buf; |
|
50 |
- return f->buf; |
|
51 |
- } |
|
52 |
- memmove(f->buf, cur, f->next - cur); |
|
53 |
- f->next -= cur - f->buf; |
|
54 |
- cur = f->buf; |
|
55 |
- } |
|
56 |
- if(!ReadFile(f->h, f->next, sizeof(f->buf) - 1 - (f->next - f->buf), &f->len, NULL)) { |
|
57 |
- DWORD er = GetLastError(); |
|
58 |
- if(er != ERROR_BROKEN_PIPE) { |
|
59 |
- flog("ERROR: Cannot read from pipe: ReadFile failed (%u)", er); |
|
60 |
- return NULL; |
|
61 |
- } |
|
62 |
- f->len = 0; |
|
63 |
- } |
|
64 |
- if(!f->len) { |
|
65 |
- *f->next = '\0'; |
|
66 |
- return cur != f->next ? cur : NULL; |
|
67 |
- } |
|
68 |
- continue; |
|
69 |
- } |
|
70 |
- if(*f->next == '\n' || *f->next == '\r') { |
|
71 |
- *f->next = '\0'; |
|
72 |
- stripping = 1; |
|
73 |
- } else if(stripping) |
|
74 |
- return cur; |
|
75 |
- f->len--; |
|
76 |
- f->next++; |
|
49 |
+ while (1) |
|
50 |
+ { |
|
51 |
+ if (!f->len) |
|
52 |
+ { |
|
53 |
+ if (f->next == &f->buf[sizeof (f->buf) - 1]) |
|
54 |
+ { |
|
55 |
+ if (cur == f->buf) |
|
56 |
+ { |
|
57 |
+ *f->next = '\0'; |
|
58 |
+ f->next = f->buf; |
|
59 |
+ return f->buf; |
|
60 |
+ } |
|
61 |
+ memmove (f->buf, cur, f->next - cur); |
|
62 |
+ f->next -= cur - f->buf; |
|
63 |
+ cur = f->buf; |
|
64 |
+ } |
|
65 |
+ if (!ReadFile |
|
66 |
+ (f->h, f->next, sizeof (f->buf) - 1 - (f->next - f->buf), |
|
67 |
+ &f->len, NULL)) |
|
68 |
+ { |
|
69 |
+ DWORD er = GetLastError (); |
|
70 |
+ if (er != ERROR_BROKEN_PIPE) |
|
71 |
+ { |
|
72 |
+ flog ("ERROR: Cannot read from pipe: ReadFile failed (%u)", er); |
|
73 |
+ return NULL; |
|
74 |
+ } |
|
75 |
+ f->len = 0; |
|
76 |
+ } |
|
77 |
+ if (!f->len) |
|
78 |
+ { |
|
79 |
+ *f->next = '\0'; |
|
80 |
+ return cur != f->next ? cur : NULL; |
|
81 |
+ } |
|
82 |
+ continue; |
|
83 |
+ } |
|
84 |
+ if (*f->next == '\n' || *f->next == '\r') |
|
85 |
+ { |
|
86 |
+ *f->next = '\0'; |
|
87 |
+ stripping = 1; |
|
88 |
+ } |
|
89 |
+ else if (stripping) |
|
90 |
+ return cur; |
|
91 |
+ f->len--; |
|
92 |
+ f->next++; |
|
77 | 93 |
} |
78 | 94 |
} |
79 | 95 |
|
... | ... |
@@ -81,78 +97,97 @@ PROCESS_INFORMATION pinfo; |
81 | 81 |
HANDLE updpipe, write_event; |
82 | 82 |
char datadir[4096]; |
83 | 83 |
|
84 |
-static void cleanup(char *path) { |
|
84 |
+static void |
|
85 |
+cleanup (char *path) |
|
86 |
+{ |
|
85 | 87 |
WIN32_FIND_DATA wfd; |
86 | 88 |
char delme[4096]; |
87 | 89 |
HANDLE findh; |
88 | 90 |
|
89 |
- if(!path) |
|
90 |
- _snprintf(delme, sizeof(delme), "%s\\clamav-????????????????????????????????", datadir); |
|
91 |
+ if (!path) |
|
92 |
+ _snprintf (delme, sizeof (delme), |
|
93 |
+ "%s\\clamav-????????????????????????????????", datadir); |
|
91 | 94 |
else |
92 |
- _snprintf(delme, sizeof(delme), "%s\\*.*", path); |
|
93 |
- delme[sizeof(delme) - 1] = '\0'; |
|
94 |
- findh = FindFirstFile(delme, &wfd); |
|
95 |
- if(findh == INVALID_HANDLE_VALUE) |
|
96 |
- return; |
|
97 |
- do { |
|
98 |
- if(wfd.cFileName[0] == '.' && (!wfd.cFileName[1] || (wfd.cFileName[1] == '.' && !wfd.cFileName[2]))) |
|
99 |
- continue; |
|
100 |
- if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { |
|
101 |
- if(!path) |
|
102 |
- _snprintf(delme, sizeof(delme), "%s\\%s", datadir, wfd.cFileName); |
|
103 |
- else |
|
104 |
- _snprintf(delme, sizeof(delme), "%s\\%s", path, wfd.cFileName); |
|
105 |
- flog_dbg("recursing %s", delme); |
|
106 |
- cleanup(delme); |
|
107 |
- RemoveDirectory(delme); |
|
108 |
- } else if(path) { |
|
109 |
- _snprintf(delme, sizeof(delme), "%s\\%s", path, wfd.cFileName); |
|
110 |
- flog_dbg("deleting %s", delme); |
|
111 |
- SetFileAttributes(delme, FILE_ATTRIBUTE_NORMAL); |
|
112 |
- DeleteFile(delme); |
|
113 |
- } |
|
114 |
- } while(FindNextFile(findh, &wfd)); |
|
115 |
- FindClose(findh); |
|
95 |
+ _snprintf (delme, sizeof (delme), "%s\\*.*", path); |
|
96 |
+ delme[sizeof (delme) - 1] = '\0'; |
|
97 |
+ findh = FindFirstFile (delme, &wfd); |
|
98 |
+ if (findh == INVALID_HANDLE_VALUE) |
|
99 |
+ return; |
|
100 |
+ do |
|
101 |
+ { |
|
102 |
+ if (wfd.cFileName[0] == '.' |
|
103 |
+ && (!wfd.cFileName[1] |
|
104 |
+ || (wfd.cFileName[1] == '.' && !wfd.cFileName[2]))) |
|
105 |
+ continue; |
|
106 |
+ if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) |
|
107 |
+ { |
|
108 |
+ if (!path) |
|
109 |
+ _snprintf (delme, sizeof (delme), "%s\\%s", datadir, |
|
110 |
+ wfd.cFileName); |
|
111 |
+ else |
|
112 |
+ _snprintf (delme, sizeof (delme), "%s\\%s", path, |
|
113 |
+ wfd.cFileName); |
|
114 |
+ flog_dbg ("recursing %s", delme); |
|
115 |
+ cleanup (delme); |
|
116 |
+ RemoveDirectory (delme); |
|
117 |
+ } |
|
118 |
+ else if (path) |
|
119 |
+ { |
|
120 |
+ _snprintf (delme, sizeof (delme), "%s\\%s", path, wfd.cFileName); |
|
121 |
+ flog_dbg ("deleting %s", delme); |
|
122 |
+ SetFileAttributes (delme, FILE_ATTRIBUTE_NORMAL); |
|
123 |
+ DeleteFile (delme); |
|
124 |
+ } |
|
125 |
+ } |
|
126 |
+ while (FindNextFile (findh, &wfd)); |
|
127 |
+ FindClose (findh); |
|
116 | 128 |
} |
117 | 129 |
|
118 | 130 |
|
119 |
-static void kill_freshclam(void) { |
|
120 |
- TerminateProcess(pinfo.hProcess, 1337); |
|
121 |
- WaitForSingleObject(pinfo.hProcess, 30*1000); |
|
131 |
+static void |
|
132 |
+kill_freshclam (void) |
|
133 |
+{ |
|
134 |
+ TerminateProcess (pinfo.hProcess, 1337); |
|
135 |
+ WaitForSingleObject (pinfo.hProcess, 30 * 1000); |
|
122 | 136 |
} |
123 | 137 |
|
124 |
-static void send_pipe(AV_UPD_STATUS *updstatus, int state, int fail) { |
|
138 |
+static void |
|
139 |
+send_pipe (AV_UPD_STATUS * updstatus, int state, int fail) |
|
140 |
+{ |
|
125 | 141 |
DWORD got; |
126 | 142 |
const char *phases[] = { |
127 |
- "UPD_CHECK", |
|
128 |
- "UPD_NEWER_FOUND", |
|
129 |
- "UPD_NONE", |
|
130 |
- "UPD_DOWNLOAD_BEGIN", |
|
131 |
- "UPD_DOWNLOAD_COMPLETE", |
|
132 |
- "UPD_PAUSE", |
|
133 |
- "UPD_ABORT", |
|
134 |
- "UPD_DONE", |
|
135 |
- "UPD_INSTALL_BEGIN", |
|
136 |
- "UPD_INSTALL_COMPLETE", |
|
137 |
- "UPD_FILE_BEGIN", |
|
138 |
- "UPD_FILE_COMPLETE", |
|
139 |
- "UPD_FILE_PROGRESS", |
|
143 |
+ "UPD_CHECK", |
|
144 |
+ "UPD_NEWER_FOUND", |
|
145 |
+ "UPD_NONE", |
|
146 |
+ "UPD_DOWNLOAD_BEGIN", |
|
147 |
+ "UPD_DOWNLOAD_COMPLETE", |
|
148 |
+ "UPD_PAUSE", |
|
149 |
+ "UPD_ABORT", |
|
150 |
+ "UPD_DONE", |
|
151 |
+ "UPD_INSTALL_BEGIN", |
|
152 |
+ "UPD_INSTALL_COMPLETE", |
|
153 |
+ "UPD_FILE_BEGIN", |
|
154 |
+ "UPD_FILE_COMPLETE", |
|
155 |
+ "UPD_FILE_PROGRESS", |
|
140 | 156 |
}; |
141 | 157 |
OVERLAPPED o; |
142 | 158 |
|
143 |
- memset(&o, 0, sizeof(o)); /* kb110148 */ |
|
159 |
+ memset (&o, 0, sizeof (o)); /* kb110148 */ |
|
144 | 160 |
o.hEvent = write_event; |
145 |
- flog_dbg("SEND: state: %s - status: %s - file: %S - pct: %u%%", |
|
146 |
- (unsigned int)state < sizeof(phases) / sizeof(*phases) ? phases[state] : "INVALID", |
|
147 |
- fail ? "fail" : "success", updstatus->fileName, updstatus->percentDownloaded); |
|
161 |
+ flog_dbg ("SEND: state: %s - status: %s - file: %S - pct: %u%%", |
|
162 |
+ (unsigned int) state < |
|
163 |
+ sizeof (phases) / sizeof (*phases) ? phases[state] : "INVALID", |
|
164 |
+ fail ? "fail" : "success", updstatus->fileName, |
|
165 |
+ updstatus->percentDownloaded); |
|
148 | 166 |
updstatus->state = state; |
149 | 167 |
updstatus->status = fail; |
150 |
- if(!WriteFile(updpipe, updstatus, sizeof(*updstatus), NULL, &o)) { |
|
151 |
- DWORD er = GetLastError(); |
|
152 |
- if(er != ERROR_IO_PENDING) |
|
153 |
- flog("WARNING: cannot write to pipe (%u)", er); |
|
154 |
- else if(!GetOverlappedResult(updpipe, &o, &got, TRUE)) |
|
155 |
- flog("WARNING: cannot write to pipe (overlapped failure)"); |
|
168 |
+ if (!WriteFile (updpipe, updstatus, sizeof (*updstatus), NULL, &o)) |
|
169 |
+ { |
|
170 |
+ DWORD er = GetLastError (); |
|
171 |
+ if (er != ERROR_IO_PENDING) |
|
172 |
+ flog ("WARNING: cannot write to pipe (%u)", er); |
|
173 |
+ else if (!GetOverlappedResult (updpipe, &o, &got, TRUE)) |
|
174 |
+ flog ("WARNING: cannot write to pipe (overlapped failure)"); |
|
156 | 175 |
} |
157 | 176 |
} |
158 | 177 |
|
... | ... |
@@ -171,7 +206,8 @@ static void send_pipe(AV_UPD_STATUS *updstatus, int state, int fail) { |
171 | 171 |
send_pipe(&st, (phase), 0);\ |
172 | 172 |
} while(0) |
173 | 173 |
|
174 |
-enum fresh_states { |
|
174 |
+enum fresh_states |
|
175 |
+{ |
|
175 | 176 |
FRESH_PRE, |
176 | 177 |
FRESH_IDLE, |
177 | 178 |
FRESH_DOWN, |
... | ... |
@@ -185,38 +221,48 @@ const char *fstates[] = { |
185 | 185 |
"FRESH_RELOAD" |
186 | 186 |
}; |
187 | 187 |
|
188 |
-static void log_state(enum fresh_states s) { |
|
189 |
- flog_dbg("state is now: %s", (s < FRESH_PRE || s > FRESH_RELOAD) ? "INVALID" : fstates[s]); |
|
188 |
+static void |
|
189 |
+log_state (enum fresh_states s) |
|
190 |
+{ |
|
191 |
+ flog_dbg ("state is now: %s", |
|
192 |
+ (s < FRESH_PRE || s > FRESH_RELOAD) ? "INVALID" : fstates[s]); |
|
190 | 193 |
} |
191 | 194 |
|
192 | 195 |
|
193 |
-DWORD WINAPI watch_stop(LPVOID x) { |
|
196 |
+DWORD WINAPI |
|
197 |
+watch_stop (LPVOID x) |
|
198 |
+{ |
|
194 | 199 |
AV_UPD_STATUS st; |
195 | 200 |
DWORD got; |
196 | 201 |
OVERLAPPED o; |
197 |
- HANDLE read_event = CreateEvent(NULL, TRUE, FALSE, NULL); |
|
202 |
+ HANDLE read_event = CreateEvent (NULL, TRUE, FALSE, NULL); |
|
198 | 203 |
|
199 |
- if(!read_event) { |
|
200 |
- flog("ERROR: failed to create pipe read event"); |
|
201 |
- return 0; |
|
204 |
+ if (!read_event) |
|
205 |
+ { |
|
206 |
+ flog ("ERROR: failed to create pipe read event"); |
|
207 |
+ return 0; |
|
202 | 208 |
} |
203 | 209 |
|
204 |
- memset(&o, 0, sizeof(o)); |
|
210 |
+ memset (&o, 0, sizeof (o)); |
|
205 | 211 |
o.hEvent = read_event; |
206 |
- while(1) { |
|
207 |
- if(!ReadFile(updpipe, &st, sizeof(st), NULL, NULL)) { |
|
208 |
- if(GetLastError() != ERROR_IO_PENDING || !GetOverlappedResult(updpipe, &o, &got, TRUE)) { |
|
209 |
- flog("ERROR: failed to read stop event from pipe"); |
|
210 |
- return 0; |
|
211 |
- } |
|
212 |
- } |
|
213 |
- if(st.state == UPD_STOP) |
|
214 |
- break; |
|
215 |
- flog("WARNING: received bogus message (%d)", st.state); |
|
212 |
+ while (1) |
|
213 |
+ { |
|
214 |
+ if (!ReadFile (updpipe, &st, sizeof (st), NULL, NULL)) |
|
215 |
+ { |
|
216 |
+ if (GetLastError () != ERROR_IO_PENDING |
|
217 |
+ || !GetOverlappedResult (updpipe, &o, &got, TRUE)) |
|
218 |
+ { |
|
219 |
+ flog ("ERROR: failed to read stop event from pipe"); |
|
220 |
+ return 0; |
|
221 |
+ } |
|
222 |
+ } |
|
223 |
+ if (st.state == UPD_STOP) |
|
224 |
+ break; |
|
225 |
+ flog ("WARNING: received bogus message (%d)", st.state); |
|
216 | 226 |
} |
217 |
- flog("STOP event received, killing freshclam"); |
|
218 |
- kill_freshclam(); |
|
219 |
- cleanup(NULL); |
|
227 |
+ flog ("STOP event received, killing freshclam"); |
|
228 |
+ kill_freshclam (); |
|
229 |
+ cleanup (NULL); |
|
220 | 230 |
return 0; |
221 | 231 |
} |
222 | 232 |
|
... | ... |
@@ -228,224 +274,272 @@ DWORD WINAPI watch_stop(LPVOID x) { |
228 | 228 |
#define FRESH_UPTODATE_S " is up to date " |
229 | 229 |
#define FRESH_DONE_S "Database updated " |
230 | 230 |
|
231 |
-int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { |
|
231 |
+int WINAPI |
|
232 |
+WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, |
|
233 |
+ int nShowCmd) |
|
234 |
+{ |
|
232 | 235 |
HANDLE cld_r, cld_w2, cld_w; |
233 | 236 |
STARTUPINFO sinfo; |
234 | 237 |
enum fresh_states fstate = FRESH_PRE; |
235 |
- AV_UPD_STATUS st = {UPD_CHECK, 0, 0, 0, L""}; |
|
238 |
+ AV_UPD_STATUS st = { UPD_CHECK, 0, 0, 0, L"" }; |
|
236 | 239 |
DWORD dw; |
237 | 240 |
struct my_f spam; |
238 | 241 |
char command[8192], *ptr; |
239 | 242 |
int updated_files = 0; |
240 |
- wchar_t *cmdl = GetCommandLineW(); |
|
243 |
+ wchar_t *cmdl = GetCommandLineW (); |
|
241 | 244 |
|
242 | 245 |
//DebugBreak(); |
243 | 246 |
|
244 | 247 |
/* Locate myself */ |
245 |
- dw = GetModuleFileName(NULL, datadir, sizeof(datadir)); |
|
246 |
- if(!dw || dw >= sizeof(datadir)-2) |
|
247 |
- return 1; |
|
248 |
- ptr = strrchr(datadir, '\\'); |
|
249 |
- if(!ptr) |
|
250 |
- return 1; |
|
248 |
+ dw = GetModuleFileName (NULL, datadir, sizeof (datadir)); |
|
249 |
+ if (!dw || dw >= sizeof (datadir) - 2) |
|
250 |
+ return 1; |
|
251 |
+ ptr = strrchr (datadir, '\\'); |
|
252 |
+ if (!ptr) |
|
253 |
+ return 1; |
|
251 | 254 |
*ptr = '\0'; |
252 | 255 |
|
253 | 256 |
/* Log file */ |
254 |
- flog_open(datadir); |
|
257 |
+ flog_open (datadir); |
|
255 | 258 |
|
256 |
- _snprintf(command, sizeof(command)-1, "freshclam.exe --stdout --config-file=\"%s\\freshclam.conf\" --datadir=\"%s\"", datadir, datadir); |
|
257 |
- command[sizeof(command)-1] = '\0'; |
|
259 |
+ _snprintf (command, sizeof (command) - 1, |
|
260 |
+ "freshclam.exe --stdout --config-file=\"%s\\freshclam.conf\" --datadir=\"%s\"", |
|
261 |
+ datadir, datadir); |
|
262 |
+ command[sizeof (command) - 1] = '\0'; |
|
258 | 263 |
|
259 | 264 |
/* Connect to master */ |
260 |
- updpipe = CreateFile("\\\\.\\pipe\\IMMUNET_AVUPDATE", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); |
|
261 |
- if(updpipe == INVALID_HANDLE_VALUE) { |
|
262 |
- flog("ERROR: failed to connect pipe"); |
|
263 |
- flog_close(); |
|
264 |
- return 1; |
|
265 |
+ updpipe = |
|
266 |
+ CreateFile ("\\\\.\\pipe\\IMMUNET_AVUPDATE", |
|
267 |
+ GENERIC_READ | GENERIC_WRITE, |
|
268 |
+ FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, |
|
269 |
+ FILE_FLAG_OVERLAPPED, NULL); |
|
270 |
+ if (updpipe == INVALID_HANDLE_VALUE) |
|
271 |
+ { |
|
272 |
+ flog ("ERROR: failed to connect pipe"); |
|
273 |
+ flog_close (); |
|
274 |
+ return 1; |
|
265 | 275 |
} |
266 | 276 |
dw = PIPE_READMODE_MESSAGE; |
267 |
- if(!SetNamedPipeHandleState(updpipe, &dw, NULL, NULL)) { |
|
268 |
- CloseHandle(updpipe); |
|
269 |
- flog("ERROR: failed to set pipe to message mode"); |
|
270 |
- flog_close(); |
|
271 |
- return 1; |
|
277 |
+ if (!SetNamedPipeHandleState (updpipe, &dw, NULL, NULL)) |
|
278 |
+ { |
|
279 |
+ CloseHandle (updpipe); |
|
280 |
+ flog ("ERROR: failed to set pipe to message mode"); |
|
281 |
+ flog_close (); |
|
282 |
+ return 1; |
|
272 | 283 |
} |
273 |
- if(!(write_event = CreateEvent(NULL, TRUE, FALSE, NULL))) { |
|
274 |
- CloseHandle(updpipe); |
|
275 |
- flog("ERROR: failed to create write event"); |
|
276 |
- flog_close(); |
|
277 |
- return 1; |
|
284 |
+ if (!(write_event = CreateEvent (NULL, TRUE, FALSE, NULL))) |
|
285 |
+ { |
|
286 |
+ CloseHandle (updpipe); |
|
287 |
+ flog ("ERROR: failed to create write event"); |
|
288 |
+ flog_close (); |
|
289 |
+ return 1; |
|
278 | 290 |
} |
279 | 291 |
|
280 | 292 |
/* Make pipe for freshclam stdio */ |
281 |
- if(!CreatePipe(&cld_r, &cld_w, NULL, 0)) { |
|
282 |
- flog("ERROR: failed to create pipe"); |
|
283 |
- SENDFAIL_AND_QUIT(UPD_CHECK); |
|
293 |
+ if (!CreatePipe (&cld_r, &cld_w, NULL, 0)) |
|
294 |
+ { |
|
295 |
+ flog ("ERROR: failed to create pipe"); |
|
296 |
+ SENDFAIL_AND_QUIT (UPD_CHECK); |
|
284 | 297 |
} |
285 | 298 |
|
286 |
- if(!DuplicateHandle(GetCurrentProcess(), cld_w, GetCurrentProcess(), &cld_w2, 0, TRUE, DUPLICATE_SAME_ACCESS)) { |
|
287 |
- CloseHandle(cld_r); |
|
288 |
- CloseHandle(cld_w); |
|
289 |
- flog("ERROR: failed to duplicate pipe"); |
|
290 |
- SENDFAIL_AND_QUIT(UPD_CHECK); |
|
299 |
+ if (!DuplicateHandle |
|
300 |
+ (GetCurrentProcess (), cld_w, GetCurrentProcess (), &cld_w2, 0, TRUE, |
|
301 |
+ DUPLICATE_SAME_ACCESS)) |
|
302 |
+ { |
|
303 |
+ CloseHandle (cld_r); |
|
304 |
+ CloseHandle (cld_w); |
|
305 |
+ flog ("ERROR: failed to duplicate pipe"); |
|
306 |
+ SENDFAIL_AND_QUIT (UPD_CHECK); |
|
291 | 307 |
} |
292 |
- CloseHandle(cld_w); |
|
308 |
+ CloseHandle (cld_w); |
|
293 | 309 |
|
294 | 310 |
/* init my_fgets */ |
295 |
- init_myf(&spam, cld_r); |
|
311 |
+ init_myf (&spam, cld_r); |
|
296 | 312 |
|
297 | 313 |
/* Redir freshclam stdio */ |
298 |
- memset(&sinfo, 0, sizeof(sinfo)); |
|
299 |
- sinfo.cb = sizeof(sinfo); |
|
300 |
- sinfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE); |
|
314 |
+ memset (&sinfo, 0, sizeof (sinfo)); |
|
315 |
+ sinfo.cb = sizeof (sinfo); |
|
316 |
+ sinfo.hStdInput = GetStdHandle (STD_INPUT_HANDLE); |
|
301 | 317 |
sinfo.hStdOutput = cld_w2; |
302 | 318 |
sinfo.hStdError = cld_w2; |
303 |
- sinfo.dwFlags = STARTF_FORCEOFFFEEDBACK|STARTF_USESTDHANDLES; |
|
304 |
- if(!CreateProcess(NULL, command, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, datadir, &sinfo, &pinfo)) { |
|
305 |
- CloseHandle(cld_w2); |
|
306 |
- CloseHandle(cld_r); |
|
307 |
- flog("ERROR: failed to execute '%s'", command); |
|
308 |
- SENDFAIL_AND_QUIT(UPD_CHECK); |
|
319 |
+ sinfo.dwFlags = STARTF_FORCEOFFFEEDBACK | STARTF_USESTDHANDLES; |
|
320 |
+ if (!CreateProcess |
|
321 |
+ (NULL, command, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, datadir, |
|
322 |
+ &sinfo, &pinfo)) |
|
323 |
+ { |
|
324 |
+ CloseHandle (cld_w2); |
|
325 |
+ CloseHandle (cld_r); |
|
326 |
+ flog ("ERROR: failed to execute '%s'", command); |
|
327 |
+ SENDFAIL_AND_QUIT (UPD_CHECK); |
|
309 | 328 |
} |
310 |
- CloseHandle(pinfo.hThread); |
|
311 |
- CloseHandle(cld_w2); |
|
329 |
+ CloseHandle (pinfo.hThread); |
|
330 |
+ CloseHandle (cld_w2); |
|
312 | 331 |
|
313 |
- flog_dbg("Executing '%s'", command); |
|
332 |
+ flog_dbg ("Executing '%s'", command); |
|
314 | 333 |
|
315 | 334 |
/* Create STOP watcher */ |
316 |
- if(!CreateThread(NULL, 0, watch_stop, NULL, 0, &dw)) { |
|
317 |
- flog("ERROR: failed to create watch_stop thread"); |
|
318 |
- CloseHandle(cld_r); |
|
319 |
- CloseHandle(pinfo.hProcess); |
|
320 |
- SENDFAIL_AND_QUIT(UPD_CHECK); |
|
335 |
+ if (!CreateThread (NULL, 0, watch_stop, NULL, 0, &dw)) |
|
336 |
+ { |
|
337 |
+ flog ("ERROR: failed to create watch_stop thread"); |
|
338 |
+ CloseHandle (cld_r); |
|
339 |
+ CloseHandle (pinfo.hProcess); |
|
340 |
+ SENDFAIL_AND_QUIT (UPD_CHECK); |
|
321 | 341 |
} |
322 | 342 |
|
323 |
- log_state(fstate); |
|
343 |
+ log_state (fstate); |
|
324 | 344 |
/* Spam parsing */ |
325 |
- while(1) { |
|
326 |
- char *buf; |
|
327 |
- buf = my_fgets(&spam); |
|
328 |
- flog_dbg("GOT: %s", buf); |
|
329 |
- if(!buf) |
|
330 |
- break; |
|
331 |
- |
|
332 |
- if(fstate == FRESH_PRE && !strncmp(buf, FRESH_PRE_START_S, sizeof(FRESH_PRE_START_S)-1)) { |
|
333 |
- SENDOK(UPD_CHECK); |
|
334 |
- fstate = FRESH_IDLE; |
|
335 |
- log_state(fstate); |
|
336 |
- continue; |
|
337 |
- } |
|
338 |
- |
|
339 |
- if((fstate == FRESH_IDLE || fstate == FRESH_DOWN) && !strncmp(buf, FRESH_DOWN_S, sizeof(FRESH_DOWN_S)-1)) { |
|
340 |
- unsigned int pct, fnamelen; |
|
341 |
- unsigned char *partname = buf + 12, *partend, *pctend; |
|
342 |
- wchar_t nuname[AV_UPD_FILE_NAME_MAX]; |
|
343 |
- |
|
344 |
- if(!updated_files) { |
|
345 |
- SENDOK(UPD_NEWER_FOUND); |
|
346 |
- SENDOK(UPD_DOWNLOAD_BEGIN); |
|
347 |
- } |
|
348 |
- updated_files++; |
|
349 |
- partend = strchr(partname, ' '); |
|
350 |
- if(!partend) |
|
351 |
- break; |
|
352 |
- *partend = '\0'; |
|
353 |
- fnamelen = partend - partname; |
|
354 |
- partend = strchr(partend + 1, '['); |
|
355 |
- if(!partend) |
|
356 |
- break; |
|
357 |
- partend++; |
|
358 |
- pct = strtol(partend, &pctend, 10); |
|
359 |
- if(pctend == partend || *pctend != '%') |
|
360 |
- break; |
|
361 |
- fnamelen = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, partname, (fnamelen < AV_UPD_FILE_NAME_MAX-1) ? fnamelen : AV_UPD_FILE_NAME_MAX-1, nuname, sizeof(nuname)); |
|
362 |
- if(!fnamelen) |
|
363 |
- break; |
|
364 |
- nuname[fnamelen] = L'\0'; |
|
365 |
- if(fstate == FRESH_DOWN && wcscmp(nuname, st.fileName)) { |
|
366 |
- st.percentDownloaded = 100; |
|
367 |
- SENDOK(UPD_FILE_COMPLETE); |
|
368 |
- fstate = FRESH_IDLE; |
|
369 |
- log_state(fstate); |
|
370 |
- } |
|
371 |
- if(fstate == FRESH_IDLE) { |
|
372 |
- wcscpy(st.fileName, nuname); |
|
373 |
- st.percentDownloaded = 0; |
|
374 |
- SENDOK(UPD_FILE_BEGIN); |
|
375 |
- fstate = FRESH_DOWN; |
|
376 |
- log_state(fstate); |
|
377 |
- } |
|
378 |
- st.percentDownloaded = pct; |
|
379 |
- SENDOK(UPD_FILE_PROGRESS); |
|
380 |
- continue; |
|
381 |
- } |
|
382 |
- |
|
383 |
- if(fstate == FRESH_IDLE) { |
|
384 |
- if(strstr(buf, FRESH_UPTODATE_S)) |
|
385 |
- continue; |
|
386 |
- if(!strncmp(buf, FRESH_DONE_S, sizeof(FRESH_DONE_S) - 1)) { |
|
387 |
- fstate = FRESH_RELOAD; |
|
388 |
- log_state(fstate); |
|
389 |
- continue; |
|
390 |
- } |
|
391 |
- } |
|
392 |
- if(fstate == FRESH_DOWN) { |
|
393 |
- if(!strcmp(buf, FRESH_DOWN_FAIL_S)) { |
|
394 |
- flog("ERROR: sigcheck verification failed"); |
|
345 |
+ while (1) |
|
346 |
+ { |
|
347 |
+ char *buf; |
|
348 |
+ buf = my_fgets (&spam); |
|
349 |
+ flog_dbg ("GOT: %s", buf); |
|
350 |
+ if (!buf) |
|
351 |
+ break; |
|
352 |
+ |
|
353 |
+ if (fstate == FRESH_PRE |
|
354 |
+ && !strncmp (buf, FRESH_PRE_START_S, |
|
355 |
+ sizeof (FRESH_PRE_START_S) - 1)) |
|
356 |
+ { |
|
357 |
+ SENDOK (UPD_CHECK); |
|
358 |
+ fstate = FRESH_IDLE; |
|
359 |
+ log_state (fstate); |
|
360 |
+ continue; |
|
361 |
+ } |
|
362 |
+ |
|
363 |
+ if ((fstate == FRESH_IDLE || fstate == FRESH_DOWN) |
|
364 |
+ && !strncmp (buf, FRESH_DOWN_S, sizeof (FRESH_DOWN_S) - 1)) |
|
365 |
+ { |
|
366 |
+ unsigned int pct, fnamelen; |
|
367 |
+ unsigned char *partname = buf + 12, *partend, *pctend; |
|
368 |
+ wchar_t nuname[AV_UPD_FILE_NAME_MAX]; |
|
369 |
+ |
|
370 |
+ if (!updated_files) |
|
371 |
+ { |
|
372 |
+ SENDOK (UPD_NEWER_FOUND); |
|
373 |
+ SENDOK (UPD_DOWNLOAD_BEGIN); |
|
374 |
+ } |
|
375 |
+ updated_files++; |
|
376 |
+ partend = strchr (partname, ' '); |
|
377 |
+ if (!partend) |
|
378 |
+ break; |
|
379 |
+ *partend = '\0'; |
|
380 |
+ fnamelen = partend - partname; |
|
381 |
+ partend = strchr (partend + 1, '['); |
|
382 |
+ if (!partend) |
|
383 |
+ break; |
|
384 |
+ partend++; |
|
385 |
+ pct = strtol (partend, &pctend, 10); |
|
386 |
+ if (pctend == partend || *pctend != '%') |
|
387 |
+ break; |
|
388 |
+ fnamelen = |
|
389 |
+ MultiByteToWideChar (CP_ACP, MB_PRECOMPOSED, partname, |
|
390 |
+ (fnamelen < |
|
391 |
+ AV_UPD_FILE_NAME_MAX - |
|
392 |
+ 1) ? fnamelen : AV_UPD_FILE_NAME_MAX - |
|
393 |
+ 1, nuname, sizeof (nuname)); |
|
394 |
+ if (!fnamelen) |
|
395 |
+ break; |
|
396 |
+ nuname[fnamelen] = L'\0'; |
|
397 |
+ if (fstate == FRESH_DOWN && wcscmp (nuname, st.fileName)) |
|
398 |
+ { |
|
399 |
+ st.percentDownloaded = 100; |
|
400 |
+ SENDOK (UPD_FILE_COMPLETE); |
|
401 |
+ fstate = FRESH_IDLE; |
|
402 |
+ log_state (fstate); |
|
403 |
+ } |
|
404 |
+ if (fstate == FRESH_IDLE) |
|
405 |
+ { |
|
406 |
+ wcscpy (st.fileName, nuname); |
|
407 |
+ st.percentDownloaded = 0; |
|
408 |
+ SENDOK (UPD_FILE_BEGIN); |
|
409 |
+ fstate = FRESH_DOWN; |
|
410 |
+ log_state (fstate); |
|
411 |
+ } |
|
412 |
+ st.percentDownloaded = pct; |
|
413 |
+ SENDOK (UPD_FILE_PROGRESS); |
|
414 |
+ continue; |
|
415 |
+ } |
|
416 |
+ |
|
417 |
+ if (fstate == FRESH_IDLE) |
|
418 |
+ { |
|
419 |
+ if (strstr (buf, FRESH_UPTODATE_S)) |
|
420 |
+ continue; |
|
421 |
+ if (!strncmp (buf, FRESH_DONE_S, sizeof (FRESH_DONE_S) - 1)) |
|
422 |
+ { |
|
423 |
+ fstate = FRESH_RELOAD; |
|
424 |
+ log_state (fstate); |
|
425 |
+ continue; |
|
426 |
+ } |
|
427 |
+ } |
|
428 |
+ if (fstate == FRESH_DOWN) |
|
429 |
+ { |
|
430 |
+ if (!strcmp (buf, FRESH_DOWN_FAIL_S)) |
|
431 |
+ { |
|
432 |
+ flog ("ERROR: sigcheck verification failed"); |
|
395 | 433 |
#if 0 |
396 |
- // FIXME: ask prashant |
|
397 |
- send_pipe(&st, UPD_FILE_COMPLETE, 1); |
|
434 |
+ // FIXME: ask prashant |
|
435 |
+ send_pipe (&st, UPD_FILE_COMPLETE, 1); |
|
398 | 436 |
#else |
399 |
- SENDOK(UPD_FILE_COMPLETE); |
|
437 |
+ SENDOK (UPD_FILE_COMPLETE); |
|
400 | 438 |
#endif |
401 |
- fstate = FRESH_IDLE; |
|
402 |
- log_state(fstate); |
|
403 |
- continue; |
|
404 |
- } |
|
405 |
- if(strstr(buf, FRESH_UPDATED_S)) { |
|
406 |
- SENDOK(UPD_FILE_COMPLETE); |
|
407 |
- fstate = FRESH_IDLE; |
|
408 |
- log_state(fstate); |
|
409 |
- continue; |
|
410 |
- } |
|
411 |
- if(strlen(buf) > sizeof(FRESH_DOWN_S)-1 && strstr(buf, FRESH_DOWN_S)) |
|
412 |
- continue; |
|
413 |
- } |
|
439 |
+ fstate = FRESH_IDLE; |
|
440 |
+ log_state (fstate); |
|
441 |
+ continue; |
|
442 |
+ } |
|
443 |
+ if (strstr (buf, FRESH_UPDATED_S)) |
|
444 |
+ { |
|
445 |
+ SENDOK (UPD_FILE_COMPLETE); |
|
446 |
+ fstate = FRESH_IDLE; |
|
447 |
+ log_state (fstate); |
|
448 |
+ continue; |
|
449 |
+ } |
|
450 |
+ if (strlen (buf) > sizeof (FRESH_DOWN_S) - 1 |
|
451 |
+ && strstr (buf, FRESH_DOWN_S)) |
|
452 |
+ continue; |
|
453 |
+ } |
|
414 | 454 |
} |
415 |
- CloseHandle(cld_r); |
|
416 |
- WaitForSingleObject(pinfo.hProcess, 30*1000); |
|
417 |
- if(!GetExitCodeProcess(pinfo.hProcess, &dw)) { |
|
418 |
- CloseHandle(pinfo.hProcess); |
|
419 |
- flog("ERROR: failed to retrieve freshclam return code"); |
|
420 |
- SENDFAIL_AND_QUIT(UPD_ABORT); |
|
455 |
+ CloseHandle (cld_r); |
|
456 |
+ WaitForSingleObject (pinfo.hProcess, 30 * 1000); |
|
457 |
+ if (!GetExitCodeProcess (pinfo.hProcess, &dw)) |
|
458 |
+ { |
|
459 |
+ CloseHandle (pinfo.hProcess); |
|
460 |
+ flog ("ERROR: failed to retrieve freshclam return code"); |
|
461 |
+ SENDFAIL_AND_QUIT (UPD_ABORT); |
|
421 | 462 |
} |
422 |
- CloseHandle(pinfo.hProcess); |
|
423 |
- if(dw) { |
|
424 |
- if(dw == STILL_ACTIVE) { |
|
425 |
- flog("WARNING: freshclam didn't exit, killing it..."); |
|
426 |
- kill_freshclam(); |
|
427 |
- } else |
|
428 |
- flog("ERROR: freshclam exit code %u", dw); |
|
429 |
- if(st.state == UPD_CHECK) |
|
430 |
- st.state = UPD_ABORT; |
|
431 |
- SENDFAIL_AND_QUIT(st.state); |
|
463 |
+ CloseHandle (pinfo.hProcess); |
|
464 |
+ if (dw) |
|
465 |
+ { |
|
466 |
+ if (dw == STILL_ACTIVE) |
|
467 |
+ { |
|
468 |
+ flog ("WARNING: freshclam didn't exit, killing it..."); |
|
469 |
+ kill_freshclam (); |
|
470 |
+ } |
|
471 |
+ else |
|
472 |
+ flog ("ERROR: freshclam exit code %u", dw); |
|
473 |
+ if (st.state == UPD_CHECK) |
|
474 |
+ st.state = UPD_ABORT; |
|
475 |
+ SENDFAIL_AND_QUIT (st.state); |
|
432 | 476 |
} |
433 |
- if((updated_files && fstate != FRESH_RELOAD) || (!updated_files && fstate != FRESH_IDLE)) { |
|
434 |
- flog("ERROR: log parse failure. Freshclam exit value: %u", dw); |
|
435 |
- SENDFAIL_AND_QUIT(st.state); |
|
477 |
+ if ((updated_files && fstate != FRESH_RELOAD) |
|
478 |
+ || (!updated_files && fstate != FRESH_IDLE)) |
|
479 |
+ { |
|
480 |
+ flog ("ERROR: log parse failure. Freshclam exit value: %u", dw); |
|
481 |
+ SENDFAIL_AND_QUIT (st.state); |
|
436 | 482 |
} |
437 | 483 |
|
438 | 484 |
/* Send complete fin seq */ |
439 |
- if(updated_files) { |
|
440 |
- SENDOK(UPD_DOWNLOAD_COMPLETE); |
|
441 |
- SENDOK(UPD_INSTALL_BEGIN); |
|
442 |
- SENDOK(UPD_INSTALL_COMPLETE); |
|
443 |
- SENDOK(UPD_DONE); |
|
444 |
- } else |
|
445 |
- SENDOK(UPD_NONE); |
|
446 |
- |
|
447 |
- CloseHandle(updpipe); |
|
448 |
- CloseHandle(write_event); |
|
449 |
- flog_close(); |
|
485 |
+ if (updated_files) |
|
486 |
+ { |
|
487 |
+ SENDOK (UPD_DOWNLOAD_COMPLETE); |
|
488 |
+ SENDOK (UPD_INSTALL_BEGIN); |
|
489 |
+ SENDOK (UPD_INSTALL_COMPLETE); |
|
490 |
+ SENDOK (UPD_DONE); |
|
491 |
+ } |
|
492 |
+ else |
|
493 |
+ SENDOK (UPD_NONE); |
|
494 |
+ |
|
495 |
+ CloseHandle (updpipe); |
|
496 |
+ CloseHandle (write_event); |
|
497 |
+ flog_close (); |
|
450 | 498 |
return 0; |
451 | 499 |
} |