Browse code

- much cleaner and explanatory error messages

git-svn: trunk@343

Thomas Lamy authored on 2004/02/27 06:15:23
Showing 1 changed files
... ...
@@ -43,43 +43,45 @@ int notify(const char *cfgfile)
43 43
 	struct hostent *he;
44 44
 	struct cfgstruct *copt, *cpt;
45 45
 	int sockd, bread;
46
+	char *socktype;
46 47
 
47 48
 
48 49
     if((copt = parsecfg(cfgfile)) == NULL) {
49
-	mprintf("@Can't parse configuration file.\n");
50
+	mprintf("@Clamd was NOT notified: Can't find or parse configuration file %s\n", cfgfile);
50 51
 	return 1;
51 52
     }
52 53
 
53 54
     if(cfgopt(copt, "TCPSocket") && cfgopt(copt, "LocalSocket")) {
54
-	mprintf("@Clamd is not configured properly. It wasn't notified.\n");
55
+	mprintf("@Clamd was NOT notified: Both socket types (TCP and local) declared in %s\n", cfgfile);
55 56
 	return 1;
56 57
     } else if((cpt = cfgopt(copt, "LocalSocket"))) {
57
-
58
+	socktype = "UNIX";
58 59
 	server.sun_family = AF_UNIX;
59 60
 	strncpy(server.sun_path, cpt->strarg, sizeof(server.sun_path));
60 61
 
61 62
 	if((sockd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
63
+	    mprintf("@Clamd was NOT notified: Can't create socket endpoint for %s\n", cpt->strarg);
62 64
 	    perror("socket()");
63
-	    mprintf("@Can't create the socket.\n");
64 65
 	    return 1;
65 66
 	}
66 67
 
67 68
 	if(connect(sockd, (struct sockaddr *) &server, sizeof(struct sockaddr_un)) < 0) {
68 69
 	    close(sockd);
70
+	    mprintf("@Clamd was NOT notified: Can't connect to clamd through %s\n", cpt->strarg);
69 71
 	    perror("connect()");
70
-	    mprintf("@Can't connect to clamd.\n");
71 72
 	    return 1;
72 73
 	}
73 74
 
74 75
     } else if((cpt = cfgopt(copt, "TCPSocket"))) {
75 76
 
77
+	socktype = "TCP";
76 78
 #ifdef PF_INET
77 79
 	if((sockd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
78 80
 #else
79 81
 	if((sockd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
80 82
 #endif
83
+	    mprintf("@Clamd was NOT notified: Can't create TCP socket\n");
81 84
 	    perror("socket()");
82
-	    mprintf("@Can't create the socket.\n");
83 85
 	    return 1;
84 86
 	}
85 87
 
... ...
@@ -89,7 +91,7 @@ int notify(const char *cfgfile)
89 89
 	if ((cpt = cfgopt(copt, "TCPAddr"))) {
90 90
 	    if ((he = gethostbyname(cpt->strarg)) == 0) {
91 91
 		perror("gethostbyname()");
92
-		mprintf("@Can't lookup hostname.\n");
92
+		mprintf("@Clamd was NOT notified: Can't resolve hostname '%s'\n", cpt->strarg);
93 93
 		return 1;
94 94
 	    }
95 95
 	    server2.sin_addr = *(struct in_addr *) he->h_addr_list[0];
... ...
@@ -99,26 +101,29 @@ int notify(const char *cfgfile)
99 99
 
100 100
 	if(connect(sockd, (struct sockaddr *) &server2, sizeof(struct sockaddr_in)) < 0) {
101 101
 	    close(sockd);
102
+	    mprintf("@Clamd was NOT notified: Can't connect to clamd on %s:%d\n",
103
+		    inet_ntoa(server2.sin_addr), ntohs(server2.sin_port));
102 104
 	    perror("connect()");
103
-	    mprintf("@Can't connect to clamd.\n");
104 105
 	    return 1;
105 106
 	}
106 107
 
107 108
     } else {
108
-	mprintf("@Clamd is not configured properly. It wasn't notified.\n");
109
+	mprintf("@Clamd was NOT notified: No socket specified in %s\n", cfgfile);
109 110
 	return 1;
110 111
     }
111 112
 
112 113
     if(write(sockd, "RELOAD", 6) < 0) {
113
-	mprintf("@Can't write to the socket.\n");
114
+	mprintf("@Clamd was NOT notified: Could not write to %s socket\n", socktype);
115
+	perror("write()");
114 116
 	close(sockd);
115 117
 	return 1;
116 118
     }
117 119
 
120
+    /* TODO: Handle timeout */
118 121
     memset(buff, 0, sizeof(buff));
119 122
     if((bread = read(sockd, buff, sizeof(buff))) > 0)
120 123
 	if(!strstr(buff, "RELOADING")) {
121
-	    mprintf("@No answer from clamd.\n");
124
+	    mprintf("@Clamd was NOT notified: Unknown answer from clamd: '%s'\n", buff);
122 125
 	    close(sockd);
123 126
 	    return 1;
124 127
 	}