Browse code

DO NOT logg() before libclamav is initialized - Partial revert of 74dfa7c89ff536a08fae1c3ed6ab21f1d8846865

aCaB authored on 2011/01/21 00:08:22
Showing 1 changed files
... ...
@@ -33,15 +33,32 @@ BOOL init() {
33 33
     int ret;
34 34
 
35 35
     ret = GetModuleFileName((HINSTANCE)&__ImageBase, whereami, sizeof(whereami) -1);
36
-    if(!ret || ret == sizeof(whereami) -1)
36
+    if(!ret || ret == sizeof(whereami) -1) {
37
+	printf("ERROR: GetModuleFileName failed\n");
37 38
 	return FALSE;
39
+    }
38 40
 
39 41
     whereami[sizeof(whereami)-1] = '\0';
40 42
     slash = strrchr(whereami, '\\');
41
-    if(!slash)
43
+    if(!slash) {
44
+	printf("ERROR: No slash found in path %s\n", whereami);
42 45
 	return FALSE;
46
+    }
43 47
 
44 48
     slash++;
49
+    *slash='\0';
50
+    SetDllDirectory(whereami);
51
+    __try {
52
+	cl_set_clcb_msg(msg_callback);
53
+	ret = cl_init(CL_INIT_DEFAULT);
54
+    }
55
+    __except(EXCEPTION_EXECUTE_HANDLER) { ret = -1; }
56
+
57
+    SetDllDirectory(NULL);
58
+    if(ret) {
59
+	printf("ERROR: Failed cl_init() returned %d\n", ret);
60
+	return FALSE;
61
+    }
45 62
 
46 63
     strncpy(slash, "clamav_log_verbose", sizeof(whereami) - (slash - whereami));
47 64
     whereami[sizeof(whereami)-1] = '\0';
... ...
@@ -54,31 +71,19 @@ BOOL init() {
54 54
     logg_time = 1;
55 55
     logg_size = -1;
56 56
     logg_file = strdup(whereami);
57
-    if(!logg_file)
57
+    if(!logg_file) {
58
+	printf("ERROR: failed to duplicate log filename\n");
58 59
 	return FALSE;
60
+    }
59 61
     strncpy(slash, "clamav.old.log", sizeof(whereami) - (slash - whereami));
60 62
     whereami[sizeof(whereami)-1] = '\0';
61
-
62 63
     if(!MoveFileEx(logg_file, whereami, MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH))
63 64
 	DeleteFile(logg_file);
64 65
     logg_noflush = 1;/* only flush on errors and warnings */
65
-    if(logg("ClamAV module initializing\n")<0)
66
-	return FALSE;
67
-
68
-    *slash='\0';
69
-    SetDllDirectory(whereami);
70
-    __try {
71
-	cl_set_clcb_msg(msg_callback);
72
-	ret = cl_init(CL_INIT_DEFAULT);
73
-    }
74
-    __except(EXCEPTION_EXECUTE_HANDLER) { ret = -1; }
75
-
76
-    SetDllDirectory(NULL);
77
-    if(ret) {
78
-	logg("!Failed to init ClamAV engine (%d)\n", ret);
66
+    if(logg("ClamAV core initialized (version %s, flevel %d)\n", cl_retver(), cl_retflevel())<0) {
67
+	printf("ERROR: logg failed\n");
79 68
 	return FALSE;
80 69
     }
81
-    logg("ClamAV core initialized (version %s, flevel %d)\n", cl_retver(), cl_retflevel());
82 70
 
83 71
     if(init_errors()) {
84 72
 	logg("!Failed to initialize errors\n");