1 |
|
/* |
2 |
|
* i-scream central monitoring system |
3 |
+ |
* http://www.i-scream.org.uk |
4 |
|
* Copyright (C) 2000-2002 i-scream |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or |
18 |
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 |
|
*/ |
20 |
|
|
21 |
+ |
#ifdef HAVE_CONFIG_H |
22 |
+ |
#include "config.h" |
23 |
+ |
#endif |
24 |
+ |
|
25 |
|
#include <stdio.h> |
26 |
|
#include <stdlib.h> |
22 |
– |
#include <sys/types.h> |
27 |
|
#include <unistd.h> |
24 |
– |
#include <syslog.h> |
25 |
– |
#include <netinet/in.h> |
26 |
– |
#include "ukcprog.h" |
27 |
– |
#include <netdb.h> |
28 |
|
#include <string.h> |
29 |
< |
#include "statgrab.h" |
30 |
< |
#include <time.h> |
29 |
> |
#include <sys/types.h> |
30 |
|
#include <sys/socket.h> |
31 |
+ |
#include <stdarg.h> |
32 |
+ |
#include <errno.h> |
33 |
+ |
#include <netdb.h> |
34 |
|
#include <netinet/in.h> |
33 |
– |
#include <arpa/inet.h> |
34 |
– |
#include <syslog.h> |
35 |
|
|
36 |
< |
#define versionNo 0.8 |
37 |
< |
#define RECONFIGURE_RETURN_CODE 2 |
38 |
< |
#define UDP_MAX_PACKET_SIZE 8192 |
36 |
> |
#include <ukcprog.h> |
37 |
> |
#include <statgrab.h> |
38 |
|
|
39 |
< |
#define logmessage(level, ...) do { cur_level = level; errf(__VA_ARGS__); } while (0) |
39 |
> |
#define LOG_CRIT 0 |
40 |
> |
#define LOG_ERR 1 |
41 |
> |
#define LOG_INFO 2 |
42 |
> |
#define LOG_DEBUG 3 |
43 |
|
|
44 |
|
typedef struct{ |
45 |
< |
int fm_port; |
46 |
< |
char *fm_host; |
45 |
> |
int filtermanager_port; |
46 |
> |
char *filtermanager_host; |
47 |
|
|
48 |
< |
char *my_ip; |
49 |
< |
char *my_fqdn; |
48 |
> |
char *host_ip; |
49 |
> |
char *host_fqdn; |
50 |
> |
int preset_fqdn; |
51 |
> |
int preset_ip; |
52 |
> |
|
53 |
|
char *server_fqdn; |
54 |
|
int server_udp_port; |
55 |
< |
int server_tcp_port; |
55 |
> |
|
56 |
> |
/* Weird stuff iscream wants sent to it */ |
57 |
|
char *last_modified; |
58 |
< |
char *files_list; |
59 |
< |
char *key; |
58 |
> |
char *file_list; |
59 |
> |
|
60 |
|
int udp_update_time; |
61 |
< |
int tcp_update_time; |
61 |
> |
// int config_ttl; |
62 |
|
|
63 |
+ |
time_t config_ttl; |
64 |
+ |
|
65 |
|
}ihost_state_t; |
66 |
|
|
67 |
< |
static int log_level; |
68 |
< |
static int cur_level; |
69 |
< |
static int syslog_logging; |
67 |
> |
typedef struct{ |
68 |
> |
int verbose; |
69 |
> |
int daemon; |
70 |
|
|
71 |
< |
void log_errors(const char *message){ |
72 |
< |
if(log_level>=cur_level){ |
73 |
< |
if (syslog_logging==1){ |
74 |
< |
syslog(cur_level, "%s\n", message); |
71 |
> |
FILE *log; |
72 |
> |
}ihost_config_t; |
73 |
> |
|
74 |
> |
typedef struct{ |
75 |
> |
struct sockaddr_in addr; |
76 |
> |
int sock; |
77 |
> |
}udp_sockinfo_t; |
78 |
> |
|
79 |
> |
ihost_config_t ihost_config; |
80 |
> |
|
81 |
> |
extern int errno; |
82 |
> |
|
83 |
> |
/* Taken from the OpenSSH code. Its licence included in function.*/ |
84 |
> |
#ifndef HAVE_STRLCAT |
85 |
> |
|
86 |
> |
/* |
87 |
> |
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> |
88 |
> |
* All rights reserved. |
89 |
> |
* |
90 |
> |
* Redistribution and use in source and binary forms, with or without |
91 |
> |
* modification, are permitted provided that the following conditions |
92 |
> |
* are met: |
93 |
> |
* 1. Redistributions of source code must retain the above copyright |
94 |
> |
* notice, this list of conditions and the following disclaimer. |
95 |
> |
* 2. Redistributions in binary form must reproduce the above copyright |
96 |
> |
* notice, this list of conditions and the following disclaimer in the |
97 |
> |
* documentation and/or other materials provided with the distribution. |
98 |
> |
* 3. The name of the author may not be used to endorse or promote products |
99 |
> |
* derived from this software without specific prior written permission. |
100 |
> |
* |
101 |
> |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, |
102 |
> |
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
103 |
> |
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
104 |
> |
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
105 |
> |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
106 |
> |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
107 |
> |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
108 |
> |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
109 |
> |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
110 |
> |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
111 |
> |
*/ |
112 |
> |
|
113 |
> |
/* |
114 |
> |
* Appends src to string dst of size siz (unlike strncat, siz is the |
115 |
> |
* full size of dst, not space left). At most siz-1 characters |
116 |
> |
* will be copied. Always NUL terminates (unless siz <= strlen(dst)). |
117 |
> |
* Returns strlen(src) + MIN(siz, strlen(initial dst)). |
118 |
> |
* If retval >= siz, truncation occurred. |
119 |
> |
*/ |
120 |
> |
size_t |
121 |
> |
strlcat(dst, src, siz) |
122 |
> |
char *dst; |
123 |
> |
const char *src; |
124 |
> |
size_t siz; |
125 |
> |
{ |
126 |
> |
register char *d = dst; |
127 |
> |
register const char *s = src; |
128 |
> |
register size_t n = siz; |
129 |
> |
size_t dlen; |
130 |
> |
|
131 |
> |
/* Find the end of dst and adjust bytes left but don't go past end */ |
132 |
> |
while (n-- != 0 && *d != '\0') |
133 |
> |
d++; |
134 |
> |
dlen = d - dst; |
135 |
> |
n = siz - dlen; |
136 |
> |
|
137 |
> |
if (n == 0) |
138 |
> |
return(dlen + strlen(s)); |
139 |
> |
while (*s != '\0') { |
140 |
> |
if (n != 1) { |
141 |
> |
*d++ = *s; |
142 |
> |
n--; |
143 |
> |
} |
144 |
> |
s++; |
145 |
> |
} |
146 |
> |
*d = '\0'; |
147 |
> |
|
148 |
> |
return(dlen + (s - src)); /* count does not include NUL */ |
149 |
> |
} |
150 |
> |
|
151 |
> |
#endif |
152 |
> |
/* End strlcat function taken from OpenSSH */ |
153 |
> |
|
154 |
> |
void log_msg(int level, char *format, ...){ |
155 |
> |
int cur_errno; |
156 |
> |
va_list ap; |
157 |
> |
|
158 |
> |
cur_errno=errno; |
159 |
> |
|
160 |
> |
if(level<=ihost_config.verbose){ |
161 |
> |
va_start(ap, format); |
162 |
> |
vfprintf(ihost_config.log, format, ap); |
163 |
> |
va_end(ap); |
164 |
> |
if(level==LOG_CRIT){ |
165 |
> |
fprintf(ihost_config.log, " (%s)\n", strerror(cur_errno)); |
166 |
|
}else{ |
167 |
< |
fprintf(stderr, "%s\n", message); |
167 |
> |
fprintf(ihost_config.log, "\n"); |
168 |
|
} |
169 |
< |
} |
169 |
> |
fflush(ihost_config.log); |
170 |
> |
} |
171 |
|
} |
172 |
|
|
173 |
< |
char* sock_comm(FILE *f_r, FILE *f_w, char *sendString){ |
174 |
< |
char *reply; |
175 |
< |
fprintf(f_w, "%s\n", sendString); |
176 |
< |
fflush(f_w); |
177 |
< |
reply=fpgetline(f_r); |
178 |
< |
/* Returns pointer to static buffer */ |
79 |
< |
return reply; |
80 |
< |
} |
173 |
> |
/* Takes many pointers, checks if they are NULL or not, and then free's them */ |
174 |
> |
/* Deprciated - and i only wrote it today! :) |
175 |
> |
void m_free(int num_pointers, ...){ |
176 |
> |
int x=0; |
177 |
> |
va_list ap; |
178 |
> |
void *p; |
179 |
|
|
180 |
< |
int ihost_configure(ihost_state_t *ihost_state){ |
181 |
< |
struct sockaddr_in addr; |
182 |
< |
struct in_addr haddr; |
183 |
< |
struct sockaddr ip; |
184 |
< |
int ip_len; |
185 |
< |
int sd; |
186 |
< |
FILE *fm_fd_r, *fm_fd_w; |
187 |
< |
char *reply; |
188 |
< |
char *reply_ptr; |
180 |
> |
va_start(ap, num_pointers); |
181 |
> |
for(;x<num_pointers;x++){ |
182 |
> |
p=va_arg(ap, void*); |
183 |
> |
if(p!=NULL){ |
184 |
> |
free(p); |
185 |
> |
} |
186 |
> |
} |
187 |
> |
va_end(ap); |
188 |
> |
} |
189 |
> |
*/ |
190 |
|
|
191 |
< |
/* Check to see if anything needs to be free'd */ |
93 |
< |
if (ihost_state->my_fqdn!=NULL) free(ihost_state->my_fqdn); |
94 |
< |
if (ihost_state->server_fqdn!=NULL) free(ihost_state->server_fqdn); |
95 |
< |
if (ihost_state->last_modified!=NULL) free(ihost_state->last_modified); |
96 |
< |
if (ihost_state->files_list!=NULL) free(ihost_state->files_list); |
191 |
> |
int create_udp_sockinfo(udp_sockinfo_t *udp_sockinfo, char *hostname, int port){ |
192 |
|
|
193 |
< |
logmessage(LOG_DEBUG, "Setting up configure socket to %s on port %d", ihost_state->fm_host, ihost_state->fm_port); |
99 |
< |
if ((sd = socket(AF_INET, SOCK_STREAM, PF_UNSPEC)) < 0) { |
100 |
< |
logmessage(LOG_ERR, "Can't create AF_INET socket (%m)"); |
101 |
< |
return -1; |
102 |
< |
} |
193 |
> |
struct in_addr haddr; |
194 |
|
|
195 |
< |
if (get_host_addr(ihost_state->fm_host, &haddr) != 0){ |
196 |
< |
logmessage(LOG_ERR, "Failed to resolve address %s (%m)", ihost_state->fm_host); |
197 |
< |
return -1; |
195 |
> |
log_msg(LOG_DEBUG, "Resolving name for udp connection"); |
196 |
> |
if(get_host_addr(hostname, &haddr) != 0){ |
197 |
> |
log_msg(LOG_CRIT, "Failed to lookup name"); |
198 |
> |
return 1; |
199 |
|
} |
200 |
|
|
201 |
< |
memset(&addr, 0, sizeof addr); |
202 |
< |
addr.sin_family = AF_INET; |
203 |
< |
memcpy(&addr.sin_addr, &haddr, sizeof haddr); |
204 |
< |
addr.sin_port = htons(ihost_state->fm_port); |
201 |
> |
if((udp_sockinfo->sock=socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0){ |
202 |
> |
log_msg(LOG_CRIT, "Failed to create UDP socket"); |
203 |
> |
return 1; |
204 |
> |
} |
205 |
|
|
206 |
< |
if (connect(sd, (struct sockaddr *)&addr, sizeof addr) != 0) { |
207 |
< |
logmessage(LOG_ERR, "Failed to connect to %s on port %d (%m)", ihost_state->fm_host, ihost_state->fm_port); |
208 |
< |
return -1; |
206 |
> |
memset(&(udp_sockinfo->addr), 0, sizeof(struct sockaddr_in)); |
207 |
> |
udp_sockinfo->addr.sin_family=AF_INET; |
208 |
> |
memcpy((char *)&(udp_sockinfo->addr.sin_addr), &haddr, sizeof(haddr)); |
209 |
> |
udp_sockinfo->addr.sin_port = htons(port); |
210 |
> |
|
211 |
> |
log_msg(LOG_DEBUG, "Socket created"); |
212 |
> |
return 0; |
213 |
> |
} |
214 |
> |
|
215 |
> |
FILE *create_tcp_connection(char *hostname, int port){ |
216 |
> |
int sock; |
217 |
> |
struct sockaddr_in addr; |
218 |
> |
struct in_addr haddr; |
219 |
> |
FILE *f; |
220 |
> |
|
221 |
> |
log_msg(LOG_DEBUG, "Creating tcp socket"); |
222 |
> |
if((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP))<0){ |
223 |
> |
log_msg(LOG_CRIT, "Failed to make TCP Socket"); |
224 |
> |
return NULL; |
225 |
|
} |
226 |
|
|
227 |
< |
/* Need to open 2 files, one for reading one for writing, as it gets confused if we only use 1 :) */ |
228 |
< |
if ((fm_fd_r=fdopen(sd,"r")) == NULL){ |
229 |
< |
logmessage(LOG_ERR, "Failed to open read stream (%m)"); |
230 |
< |
return -1; |
227 |
> |
if((get_host_addr(hostname, &haddr))!=0){ |
228 |
> |
log_msg(LOG_CRIT, "Failed to lookup name for %s", hostname); |
229 |
> |
close(sock); |
230 |
> |
return NULL; |
231 |
|
} |
232 |
|
|
233 |
< |
if ((fm_fd_w=fdopen(dup(sd),"w")) == NULL){ |
234 |
< |
logmessage(LOG_ERR, "Failed to open write stream (%m)"); |
235 |
< |
return -1; |
233 |
> |
memset(&addr, 0, sizeof(addr)); |
234 |
> |
addr.sin_family = AF_INET; |
235 |
> |
memcpy(&addr.sin_addr, &haddr, sizeof(haddr)); |
236 |
> |
addr.sin_port = htons(port); |
237 |
> |
|
238 |
> |
log_msg(LOG_DEBUG, "Creating a tcp connection"); |
239 |
> |
if(connect(sock, (struct sockaddr *)&addr, sizeof(addr)) !=0){ |
240 |
> |
log_msg(LOG_CRIT, "Failed to connect to hostname %s on port %d", hostname, port); |
241 |
> |
close(sock); |
242 |
> |
return NULL; |
243 |
|
} |
244 |
< |
ip_len=sizeof ip; |
245 |
< |
memset(&ip, 0, ip_len); |
246 |
< |
if((getsockname(sd, &ip, &ip_len)) != 0){ |
247 |
< |
logmessage(LOG_ERR, "Failed to get IP address (%m)"); |
248 |
< |
return -1; |
244 |
> |
|
245 |
> |
if((f=fdopen(sock, "r+"))==NULL){ |
246 |
> |
log_msg(LOG_CRIT, "Failed to connect to open filedescriptor on tcp connection"); |
247 |
> |
close(sock); |
248 |
> |
return NULL; |
249 |
|
} |
250 |
< |
if (ip.sa_family!=AF_INET){ |
251 |
< |
logmessage(LOG_ERR, "sa family is wrong type"); |
250 |
> |
|
251 |
> |
return f; |
252 |
> |
} |
253 |
> |
|
254 |
> |
int tcp_comm(FILE *f, char *send, char **response, char *expected){ |
255 |
> |
|
256 |
> |
log_msg(LOG_DEBUG, "Sending %s", send); |
257 |
> |
fprintf(f, "%s\n", send); |
258 |
> |
fflush(f); |
259 |
> |
*response=fpgetline(f); |
260 |
> |
fseek(f, 0, SEEK_CUR); |
261 |
> |
|
262 |
> |
if(*response!=NULL) log_msg(LOG_DEBUG, "Recieved %s", *response); |
263 |
> |
|
264 |
> |
if( (*response==NULL) || (strcmp(*response, "ERROR")==0) ) return -1; |
265 |
> |
|
266 |
> |
if(expected==NULL) return 0; |
267 |
> |
|
268 |
> |
if((strcmp(expected, *response))==0) return 0; |
269 |
> |
|
270 |
> |
log_msg(LOG_DEBUG, "Did not get expected response"); |
271 |
> |
return -1; |
272 |
> |
} |
273 |
> |
|
274 |
> |
int tcp_comm_strdup(FILE *f, char *send, char **response, char *expected){ |
275 |
> |
if((tcp_comm(f, send, response, expected))!=0){ |
276 |
|
return -1; |
277 |
|
} |
278 |
+ |
|
279 |
+ |
*response=strdup(*response); |
280 |
+ |
if (response==NULL) return -1; |
281 |
+ |
|
282 |
+ |
return 0; |
283 |
+ |
} |
284 |
|
|
285 |
< |
if((ihost_state->my_ip=inet_ntoa(((struct sockaddr_in *)&ip)->sin_addr))==NULL){ |
286 |
< |
logmessage(LOG_ERR, "Failed to get IP (%m)"); |
285 |
> |
int ihost_getconfig(ihost_state_t *ihost_state){ |
286 |
> |
|
287 |
> |
FILE *tcp_con; |
288 |
> |
char *response; |
289 |
> |
char *response_ptr; |
290 |
> |
|
291 |
> |
/* Keep these in case of a failure and so it can keep running on the old config */ |
292 |
> |
char *file_list=NULL; |
293 |
> |
char *last_modified=NULL; |
294 |
> |
char *host_fqdn=NULL; |
295 |
> |
char *host_ip=NULL; |
296 |
> |
int udp_update_time=0; |
297 |
> |
char *server_fqdn=NULL; |
298 |
> |
int server_udp_port=0; |
299 |
> |
time_t config_ttl=0; |
300 |
> |
|
301 |
> |
if((tcp_con=create_tcp_connection(ihost_state->filtermanager_host, ihost_state->filtermanager_port))==NULL){ |
302 |
|
return -1; |
143 |
– |
} |
144 |
– |
|
145 |
– |
logmessage(LOG_DEBUG, "Sending STARTCONIG"); |
146 |
– |
reply=sock_comm(fm_fd_r, fm_fd_w, "STARTCONFIG"); |
147 |
– |
if ((reply==NULL) || (strncasecmp(reply, "OK", 2) != 0) ) { |
148 |
– |
logmessage(LOG_ERR, "Server error on STARTCONFIG"); |
149 |
– |
return -1; |
303 |
|
} |
304 |
|
|
305 |
< |
logmessage(LOG_DEBUG, "Sending LASTMODIFIED"); |
306 |
< |
reply=sock_comm(fm_fd_r, fm_fd_w, "LASTMODIFIED"); |
307 |
< |
if((reply== NULL) || (strncasecmp(reply, "ERROR", 5) ==0)){ |
308 |
< |
logmessage(LOG_ERR, "Server error on LASTMODIFIED (%m)"); |
309 |
< |
return -1; |
305 |
> |
if(ihost_state->file_list!=NULL || ihost_state->last_modified!=NULL){ |
306 |
> |
if(tcp_con==NULL){ |
307 |
> |
goto error; |
308 |
> |
} |
309 |
> |
|
310 |
> |
if((tcp_comm(tcp_con, "CHECKCONFIG", &response, "OK"))!=0){ |
311 |
> |
goto error; |
312 |
> |
} |
313 |
> |
|
314 |
> |
if((tcp_comm(tcp_con, ihost_state->file_list, &response, "OK"))!=0){ |
315 |
> |
goto error; |
316 |
> |
} |
317 |
> |
|
318 |
> |
if((tcp_comm(tcp_con, ihost_state->last_modified, &response, "OK"))==0){ |
319 |
> |
if((tcp_comm(tcp_con, "END", &response, "OK"))!=0){ |
320 |
> |
goto error; |
321 |
> |
} |
322 |
> |
fclose(tcp_con); |
323 |
> |
return 0; |
324 |
> |
}else{ |
325 |
> |
if((strcmp(response, "EXPIRED"))!=0){ |
326 |
> |
goto error; |
327 |
> |
} |
328 |
> |
} |
329 |
|
} |
158 |
– |
if((ihost_state->last_modified=strdup(reply)) == NULL){ |
159 |
– |
logmessage(LOG_ERR, "strdup failed (%m)"); |
160 |
– |
return -1; |
161 |
– |
} |
330 |
|
|
331 |
< |
logmessage(LOG_DEBUG, "Sending FILELIST"); |
332 |
< |
reply=sock_comm(fm_fd_r, fm_fd_w, "FILELIST"); |
333 |
< |
if((reply== NULL) || (strncasecmp(reply, "ERROR", 5) ==0)){ |
334 |
< |
logmessage(LOG_ERR, "Server error on FILELIST (%m)"); |
167 |
< |
return -1; |
331 |
> |
/* If we got to here, the config must of expired */ |
332 |
> |
|
333 |
> |
if((tcp_comm(tcp_con, "STARTCONFIG", &response, "OK"))!=0){ |
334 |
> |
goto error; |
335 |
|
} |
169 |
– |
if((ihost_state->files_list=strdup(reply)) == NULL){ |
170 |
– |
logmessage(LOG_ERR, "strdup failed (%m)"); |
171 |
– |
return -1; |
172 |
– |
} |
336 |
|
|
337 |
< |
logmessage(LOG_DEBUG, "Sending FQDN"); |
338 |
< |
reply=sock_comm(fm_fd_r, fm_fd_w, "FQDN"); |
176 |
< |
if((reply== NULL) || (strncasecmp(reply, "ERROR", 5)==0)){ |
177 |
< |
logmessage(LOG_ERR, "Server error on FQDN (%m)"); |
178 |
< |
return -1; |
337 |
> |
if((tcp_comm_strdup(tcp_con, "LASTMODIFIED", &response, NULL))!=0){ |
338 |
> |
goto error; |
339 |
|
} |
340 |
< |
if((ihost_state->my_fqdn=strdup(reply)) == NULL){ |
341 |
< |
logmessage(LOG_ERR, "strdup failed (%m)"); |
342 |
< |
return -1; |
340 |
> |
last_modified=response; |
341 |
> |
|
342 |
> |
if((tcp_comm_strdup(tcp_con, "FILELIST", &response, NULL))!=0){ |
343 |
> |
goto error; |
344 |
|
} |
345 |
+ |
file_list=response; |
346 |
|
|
347 |
< |
logmessage(LOG_DEBUG, "Sending FQDN"); |
348 |
< |
reply=sock_comm(fm_fd_r, fm_fd_w, "UDPUpdateTime"); |
187 |
< |
if(reply== NULL){ |
188 |
< |
logmessage(LOG_ERR, "Server error (%m)"); |
189 |
< |
return -1; |
347 |
> |
if((tcp_comm_strdup(tcp_con, "FQDN", &response, NULL))!=0){ |
348 |
> |
goto error; |
349 |
|
} |
350 |
< |
if (strncasecmp(reply, "ERROR", 5) != 0){ |
351 |
< |
ihost_state->udp_update_time=atoi(reply); |
350 |
> |
host_fqdn=response; |
351 |
> |
|
352 |
> |
if((tcp_comm_strdup(tcp_con, "IP", &response, NULL))!=0){ |
353 |
> |
goto error; |
354 |
|
} |
355 |
< |
|
356 |
< |
logmessage(LOG_DEBUG, "Sending TCPUpdateTime"); |
357 |
< |
reply=sock_comm(fm_fd_r, fm_fd_w, "TCPUpdateTime"); |
358 |
< |
if(reply== NULL){ |
198 |
< |
logmessage(LOG_ERR, "Server error on TCPUpdateTime (%m)"); |
199 |
< |
return -1; |
355 |
> |
host_ip=response; |
356 |
> |
|
357 |
> |
if((tcp_comm(tcp_con, "UDPUpdateTime", &response, NULL))!=0){ |
358 |
> |
goto error; |
359 |
|
} |
360 |
< |
if (strncasecmp(reply, "ERROR", 5) != 0){ |
361 |
< |
ihost_state->tcp_update_time=atoi(reply); |
360 |
> |
udp_update_time=atoi(response); |
361 |
> |
|
362 |
> |
if((tcp_comm(tcp_con, "ConfigTTL", &response, NULL))!=0){ |
363 |
> |
goto error; |
364 |
|
} |
365 |
+ |
config_ttl=atoi(response); |
366 |
|
|
367 |
< |
logmessage(LOG_DEBUG, "Sending ENDCONFIG"); |
368 |
< |
reply=sock_comm(fm_fd_r, fm_fd_w, "ENDCONFIG"); |
207 |
< |
if(reply== NULL){ |
208 |
< |
logmessage(LOG_ERR, "Server error on ENDCONFIG (%m)"); |
209 |
< |
return -1; |
367 |
> |
if((tcp_comm(tcp_con, "ENDCONFIG", &response, NULL))!=0){ |
368 |
> |
goto error; |
369 |
|
} |
370 |
|
|
371 |
< |
logmessage(LOG_DEBUG, "Sending FILTER"); |
372 |
< |
reply=sock_comm(fm_fd_r, fm_fd_w, "FILTER"); |
373 |
< |
if((reply== NULL) || (strncasecmp(reply, "ERROR", 5)==0)){ |
374 |
< |
logmessage(LOG_ERR, "Server error FILTER failed (%m)"); |
375 |
< |
return -1; |
371 |
> |
if((tcp_comm(tcp_con, "FILTER", &response, NULL))!=0){ |
372 |
> |
goto error; |
373 |
> |
}else{ |
374 |
> |
response_ptr=strchr(response,';'); |
375 |
> |
if(response_ptr==NULL){ |
376 |
> |
log_msg(LOG_ERR, "Incorrect data sent by server"); |
377 |
> |
goto error; |
378 |
> |
} |
379 |
> |
*response_ptr='\0'; |
380 |
> |
server_fqdn=strdup(response); |
381 |
> |
if(server_fqdn==NULL){ |
382 |
> |
goto error; |
383 |
> |
} |
384 |
> |
response_ptr++; |
385 |
> |
if(response_ptr==NULL){ |
386 |
> |
log_msg(LOG_ERR, "Incorrect data sent by server"); |
387 |
> |
goto error; |
388 |
> |
} |
389 |
> |
|
390 |
> |
printf("string : %s\n", response_ptr); |
391 |
> |
server_udp_port=atoi(response_ptr); |
392 |
> |
|
393 |
> |
if (server_udp_port==0){ |
394 |
> |
log_msg(LOG_ERR, "Incorrect data sent by server"); |
395 |
> |
goto error; |
396 |
> |
} |
397 |
|
} |
398 |
< |
reply_ptr=strchr(reply,';'); |
399 |
< |
if (reply_ptr==NULL){ |
400 |
< |
logmessage(LOG_ERR, "Incorrect data returned"); |
221 |
< |
return -1; |
398 |
> |
|
399 |
> |
if((tcp_comm(tcp_con, "END", &response, "OK"))!=0){ |
400 |
> |
goto error; |
401 |
|
} |
223 |
– |
*reply_ptr='\0'; |
224 |
– |
if((ihost_state->server_fqdn=strdup(reply)) == NULL){ |
225 |
– |
logmessage(LOG_ERR, "strdup failed (%m)"); |
226 |
– |
return -1; |
227 |
– |
} |
228 |
– |
reply=reply_ptr + 1; |
229 |
– |
reply_ptr=strchr(reply,';'); |
230 |
– |
if (reply_ptr==NULL){ |
231 |
– |
logmessage(LOG_ERR, "Incorrect data returned 2"); |
232 |
– |
return -1; |
233 |
– |
} |
234 |
– |
*reply_ptr='\0'; |
235 |
– |
ihost_state->server_udp_port=atoi(reply); |
236 |
– |
reply=reply_ptr+1; |
237 |
– |
ihost_state->server_tcp_port=atoi(reply); |
238 |
– |
if ((ihost_state->server_tcp_port==0) || (ihost_state->server_udp_port==0)){ |
239 |
– |
logmessage(LOG_ERR, "Incorrect data returned 3 "); |
240 |
– |
return -1; |
241 |
– |
} |
402 |
|
|
403 |
< |
logmessage(LOG_DEBUG, "Sending END"); |
404 |
< |
reply=sock_comm(fm_fd_r, fm_fd_w, "END"); |
405 |
< |
if((reply== NULL) || (strncasecmp(reply, "ERROR", 5) ==0 )){ |
406 |
< |
logmessage(LOG_ERR, "Server error on END (%m)"); |
407 |
< |
return -1; |
403 |
> |
fclose(tcp_con); |
404 |
> |
|
405 |
> |
/* We have the data we need, and its all been read correctly */ |
406 |
> |
|
407 |
> |
/* Free the old data before pointing them to the new data. m_free copes should |
408 |
> |
* this already be NULL */ |
409 |
> |
if(ihost_state->file_list!=NULL) free(ihost_state->file_list); |
410 |
> |
if(ihost_state->last_modified!=NULL) free(ihost_state->last_modified); |
411 |
> |
if(ihost_state->server_fqdn!=NULL) free(ihost_state->server_fqdn); |
412 |
> |
|
413 |
> |
if(ihost_state->preset_fqdn){ |
414 |
> |
if(host_fqdn != NULL) free(host_fqdn); |
415 |
> |
}else{ |
416 |
> |
if(ihost_state->host_fqdn!=NULL) free(ihost_state->host_fqdn); |
417 |
> |
ihost_state->host_fqdn=host_fqdn; |
418 |
|
} |
419 |
|
|
420 |
< |
if(fclose(fm_fd_r) !=0){ |
421 |
< |
logmessage(LOG_ERR, "Failed to close read FD (%m)"); |
422 |
< |
return -1; |
420 |
> |
if(ihost_state->preset_ip){ |
421 |
> |
if(host_ip != NULL) free(host_ip); |
422 |
> |
}else{ |
423 |
> |
if(ihost_state->host_ip!=NULL) free(ihost_state->host_ip); |
424 |
> |
ihost_state->host_ip=host_ip; |
425 |
|
} |
254 |
– |
if(fclose(fm_fd_w) !=0){ |
255 |
– |
logmessage(LOG_ERR, "Failed to close write FD (%m)"); |
256 |
– |
return -1; |
257 |
– |
} |
426 |
|
|
427 |
+ |
|
428 |
+ |
ihost_state->file_list=file_list; |
429 |
+ |
ihost_state->last_modified=last_modified; |
430 |
+ |
ihost_state->server_fqdn=server_fqdn; |
431 |
+ |
ihost_state->server_udp_port=server_udp_port; |
432 |
+ |
ihost_state->udp_update_time=udp_update_time; |
433 |
+ |
ihost_state->config_ttl=config_ttl; |
434 |
+ |
|
435 |
+ |
log_msg(LOG_DEBUG, "UDP Update time %d", udp_update_time); |
436 |
+ |
log_msg(LOG_DEBUG, "Configure ttl %d", config_ttl); |
437 |
+ |
|
438 |
|
return 0; |
439 |
+ |
|
440 |
+ |
error: |
441 |
+ |
|
442 |
+ |
if(file_list!=NULL) free(file_list); |
443 |
+ |
if(last_modified!=NULL) free(last_modified); |
444 |
+ |
if(host_fqdn!=NULL) free(host_fqdn); |
445 |
+ |
if(server_fqdn!=NULL) free(server_fqdn); |
446 |
+ |
if(host_ip!=NULL) free(host_ip); |
447 |
+ |
fclose(tcp_con); |
448 |
+ |
|
449 |
+ |
return -1; |
450 |
|
} |
451 |
|
|
452 |
< |
int heartbeat(ihost_state_t *ihost_state){ |
453 |
< |
struct sockaddr_in addr; |
454 |
< |
struct in_addr haddr; |
455 |
< |
int sd; |
456 |
< |
FILE *fm_fd_r, *fm_fd_w; |
457 |
< |
char *reply; |
458 |
< |
int exitcode=0; |
452 |
> |
int get_system_stats(int seq_no, ihost_state_t *ihost_state, char *xml, int size){ |
453 |
> |
char tmp[size]; |
454 |
> |
cpu_percent_t *cpu_percent; |
455 |
> |
mem_stat_t *mem_stats; |
456 |
> |
load_stat_t *load_stats; |
457 |
> |
user_stat_t *user_stats; |
458 |
> |
swap_stat_t *swap_stats; |
459 |
> |
general_stat_t *general_stats; |
460 |
> |
disk_stat_t *disk_stats; |
461 |
> |
diskio_stat_t *diskio_stats; |
462 |
> |
process_stat_t *process_stats; |
463 |
> |
network_stat_t *network_stats; |
464 |
> |
page_stat_t *page_stats; |
465 |
> |
int disk_entries=0; |
466 |
> |
int diskio_entries=0; |
467 |
> |
int network_entries=0; |
468 |
|
|
469 |
< |
logmessage(LOG_DEBUG, "Setting up configure socket to %s on port %d", ihost_state->server_fqdn, ihost_state->server_tcp_port); |
470 |
< |
if ((sd = socket(AF_INET, SOCK_STREAM, PF_UNSPEC)) < 0) { |
471 |
< |
logmessage(LOG_ERR, "Can't create AF_INET socket (%m)"); |
273 |
< |
return -1; |
274 |
< |
} |
469 |
> |
int counter; |
470 |
> |
long long x; |
471 |
> |
long long y; |
472 |
|
|
473 |
< |
if (get_host_addr(ihost_state->server_fqdn, &haddr) != 0){ |
474 |
< |
logmessage(LOG_ERR, "Failed to resolve address %s (%m)", ihost_state->server_fqdn); |
475 |
< |
return -1; |
279 |
< |
} |
473 |
> |
/* Print start of the packet we want */ |
474 |
> |
snprintf(xml, size, "<packet seq_no=\"%d\" machine_name=\"%s\" date=\"%ld\" type=\"data\" ip=\"%s\">", \ |
475 |
> |
seq_no, ihost_state->host_fqdn, time(NULL), ihost_state->host_ip); |
476 |
|
|
477 |
< |
memset(&addr, 0, sizeof addr); |
478 |
< |
addr.sin_family = AF_INET; |
479 |
< |
memcpy(&addr.sin_addr, &haddr, sizeof haddr); |
480 |
< |
addr.sin_port = htons(ihost_state->server_tcp_port); |
477 |
> |
/* Get cpu stats, check it is correct, then fill in its entry for the xml */ |
478 |
> |
if((cpu_percent=cpu_percent_usage())==NULL){ |
479 |
> |
log_msg(LOG_CRIT, "Failed to get cpu statistics"); |
480 |
> |
}else{ |
481 |
> |
snprintf(tmp, size, \ |
482 |
> |
"<cpu><user>%3.2f</user><kernel>%3.2f</kernel><idle>%3.2f</idle><iowait>%3.2f</iowait><swap>%3.2f</swap></cpu>", \ |
483 |
> |
cpu_percent->user, \ |
484 |
> |
cpu_percent->kernel, \ |
485 |
> |
cpu_percent->idle, \ |
486 |
> |
cpu_percent->iowait, \ |
487 |
> |
cpu_percent->swap); |
488 |
|
|
489 |
< |
if (connect(sd, (struct sockaddr *)&addr, sizeof addr) != 0) { |
490 |
< |
logmessage(LOG_ERR, "Failed to connect to %s on port %d (%m)", ihost_state->server_fqdn, ihost_state->server_tcp_port); |
288 |
< |
return -1; |
289 |
< |
} |
489 |
> |
if(strlcat(xml, tmp, size) >= size) goto too_big_error; |
490 |
> |
} |
491 |
|
|
492 |
< |
/* Need to open 2 files, one for reading one for writing, as it gets confused if we only use 1 :) */ |
493 |
< |
if ((fm_fd_r=fdopen(sd,"r")) == NULL){ |
494 |
< |
logmessage(LOG_ERR, "Failed to open stream (%m)"); |
495 |
< |
return -1; |
496 |
< |
} |
492 |
> |
|
493 |
> |
/*Get mem stats, and fill in xml */ |
494 |
> |
if((mem_stats=get_memory_stats())==NULL){ |
495 |
> |
log_msg(LOG_CRIT, "Failed to get memory statistics"); |
496 |
> |
}else{ |
497 |
> |
snprintf(tmp, size, \ |
498 |
> |
"<memory><total>%lld</total><free>%lld</free><used>%lld</used><cache>%lld</cache></memory>", \ |
499 |
> |
mem_stats->total, \ |
500 |
> |
mem_stats->free, \ |
501 |
> |
mem_stats->used, \ |
502 |
> |
mem_stats->cache); |
503 |
> |
|
504 |
> |
if(strlcat(xml, tmp, size) >= size) goto too_big_error; |
505 |
> |
} |
506 |
|
|
297 |
– |
if ((fm_fd_w=fdopen(dup(sd),"w")) == NULL){ |
298 |
– |
logmessage(LOG_ERR, "Failed to open stream (%m)"); |
299 |
– |
return -1; |
300 |
– |
} |
507 |
|
|
508 |
< |
logmessage(LOG_DEBUG, "Sending HEARTBEAT"); |
509 |
< |
reply=sock_comm(fm_fd_r, fm_fd_w, "HEARTBEAT"); |
510 |
< |
if ((reply==NULL) || (strncasecmp(reply, "ERROR", 5) == 0) ) { |
511 |
< |
logmessage(LOG_ERR, "Server error on HEARTBEAT"); |
512 |
< |
return -1; |
513 |
< |
} |
508 |
> |
/* Get load stats */ |
509 |
> |
if((load_stats=get_load_stats())==NULL){ |
510 |
> |
log_msg(LOG_CRIT, "Failed to get load statistics"); |
511 |
> |
}else{ |
512 |
> |
snprintf(tmp, size, \ |
513 |
> |
"<load><load1>%.2lf</load1><load5>%.2lf</load5><load15>%.2lf</load15></load>", \ |
514 |
> |
load_stats->min1, \ |
515 |
> |
load_stats->min5, \ |
516 |
> |
load_stats->min15); |
517 |
> |
if(strlcat(xml, tmp, size) >= size) goto too_big_error; |
518 |
> |
} |
519 |
|
|
309 |
– |
logmessage(LOG_DEBUG, "Sending CONFIG"); |
310 |
– |
reply=sock_comm(fm_fd_r, fm_fd_w, "CONFIG"); |
311 |
– |
if ((reply==NULL) || (strncasecmp(reply, "ERROR", 5) == 0) ) { |
312 |
– |
logmessage(LOG_ERR, "Server error on CONFIG"); |
313 |
– |
return -1; |
314 |
– |
} |
520 |
|
|
521 |
< |
logmessage(LOG_DEBUG, "Sending %s", ihost_state->files_list); |
522 |
< |
reply=sock_comm(fm_fd_r, fm_fd_w, ihost_state->files_list); |
523 |
< |
if ((reply==NULL) || (strncasecmp(reply, "OK", 2) != 0) ) { |
524 |
< |
logmessage(LOG_ERR, "Server error on fileslist"); |
525 |
< |
return -1; |
321 |
< |
} |
521 |
> |
/* get user stats */ |
522 |
> |
|
523 |
> |
if((user_stats=get_user_stats())==NULL){ |
524 |
> |
log_msg(LOG_CRIT, "Failed to get user statistics"); |
525 |
> |
}else{ |
526 |
|
|
527 |
< |
logmessage(LOG_DEBUG, "Sending %s", ihost_state->last_modified); |
528 |
< |
reply=sock_comm(fm_fd_r, fm_fd_w, ihost_state->last_modified); |
529 |
< |
if (reply==NULL) { |
530 |
< |
logmessage(LOG_ERR, "Server error NULL recieved on lastmodified"); |
531 |
< |
return -1; |
532 |
< |
} |
329 |
< |
if (strncasecmp(reply, "ERROR", 5) == 0){ |
330 |
< |
/* Means the config has changed */ |
331 |
< |
logmessage(LOG_INFO, "Recieved ERROR from server for a reconfigure required"); |
332 |
< |
exitcode=RECONFIGURE_RETURN_CODE; |
527 |
> |
snprintf(tmp, size, \ |
528 |
> |
"<users><list>%s</list><count>%d</count></users>", \ |
529 |
> |
user_stats->name_list, \ |
530 |
> |
user_stats->num_entries); |
531 |
> |
|
532 |
> |
if(strlcat(xml, tmp, size) >= size) goto too_big_error; |
533 |
|
} |
534 |
|
|
335 |
– |
logmessage(LOG_DEBUG,"Sending KEY"); |
336 |
– |
reply=sock_comm(fm_fd_r, fm_fd_w, "KEY"); |
337 |
– |
if ((reply==NULL) || (strncasecmp(reply, "ERROR", 5) == 0) ) { |
338 |
– |
logmessage(LOG_ERR, "Server error on KEY"); |
339 |
– |
return -1; |
340 |
– |
} |
341 |
– |
if (ihost_state->key!=NULL) free(ihost_state->key); |
342 |
– |
|
343 |
– |
if((ihost_state->key=strdup(reply)) == NULL){ |
344 |
– |
logmessage(LOG_ERR, "strdup failed (%m)"); |
345 |
– |
return -1; |
346 |
– |
} |
535 |
|
|
536 |
< |
logmessage(LOG_DEBUG,"Sending ENDHEARTBEAT"); |
537 |
< |
reply=sock_comm(fm_fd_r, fm_fd_w, "ENDHEARTBEAT"); |
538 |
< |
if((reply== NULL) || (strncasecmp(reply, "ERROR", 5) ==0 )){ |
539 |
< |
logmessage(LOG_ERR, "Server error on ENDHEARTBEAT (%m)"); |
540 |
< |
return -1; |
541 |
< |
} |
536 |
> |
/* swap stats */ |
537 |
> |
if((swap_stats=get_swap_stats())==NULL){ |
538 |
> |
log_msg(LOG_CRIT, "Failed to get swap statistics"); |
539 |
> |
}else{ |
540 |
> |
snprintf(tmp, size, \ |
541 |
> |
"<swap><total>%lld</total><used>%lld</used><free>%lld</free></swap>",\ |
542 |
> |
swap_stats->total, \ |
543 |
> |
swap_stats->used, \ |
544 |
> |
swap_stats->free); |
545 |
> |
|
546 |
> |
if(strlcat(xml, tmp, size) >= size) goto too_big_error; |
547 |
> |
} |
548 |
|
|
355 |
– |
fflush(fm_fd_r); |
356 |
– |
fflush(fm_fd_w); |
549 |
|
|
550 |
< |
if(fclose(fm_fd_r) !=0){ |
551 |
< |
logmessage(LOG_ERR, "Failed to close read FD (%m)"); |
552 |
< |
return -1; |
553 |
< |
} |
554 |
< |
if(fclose(fm_fd_w) !=0){ |
555 |
< |
logmessage(LOG_ERR, "Failed to close write FD (%m)"); |
556 |
< |
return -1; |
557 |
< |
} |
550 |
> |
/* general stats */ |
551 |
> |
|
552 |
> |
if((general_stats=get_general_stats())==NULL){ |
553 |
> |
log_msg(LOG_CRIT, "Failed to get general statistics"); |
554 |
> |
}else{ |
555 |
> |
snprintf(tmp, size, \ |
556 |
> |
"<os><name>%s</name><release>%s</release><version>%s</version><sysname>%s</sysname><platform>%s</platform><uptime>%ld</uptime></os>", \ |
557 |
> |
general_stats->os_name, \ |
558 |
> |
general_stats->os_release, \ |
559 |
> |
general_stats->os_version, \ |
560 |
> |
general_stats->hostname, \ |
561 |
> |
general_stats->platform, \ |
562 |
> |
(long)general_stats->uptime); |
563 |
> |
|
564 |
> |
if(strlcat(xml, tmp, size) >= size) goto too_big_error; |
565 |
> |
|
566 |
> |
} |
567 |
|
|
568 |
< |
return exitcode; |
569 |
< |
} |
568 |
> |
|
569 |
> |
/* process stats */ |
570 |
> |
if((process_stats=get_process_stats())==NULL){ |
571 |
> |
log_msg(LOG_CRIT, "Failed to get general statistics"); |
572 |
> |
}else{ |
573 |
> |
snprintf(tmp, size, \ |
574 |
> |
"<processes><sleeping>%d</sleeping><cpu>%d</cpu><zombie>%d</zombie><stopped>%d</stopped><total>%d</total></processes>",\ |
575 |
> |
process_stats->sleeping, \ |
576 |
> |
process_stats->running, \ |
577 |
> |
process_stats->zombie, \ |
578 |
> |
process_stats->stopped, \ |
579 |
> |
process_stats->total); |
580 |
|
|
581 |
< |
char *stat_grab(ihost_state_t *ihost_state, int counter){ |
371 |
< |
#define NUM_STATS 9 |
372 |
< |
char *stats[NUM_STATS]; |
373 |
< |
char *xml_data=NULL; |
374 |
< |
char *xml_data_p; |
375 |
< |
int x=0; |
581 |
> |
if(strlcat(xml, tmp, size) >= size) goto too_big_error; |
582 |
|
|
583 |
< |
logmessage(LOG_DEBUG,"get_cpu_stats"); |
378 |
< |
stats[0]=get_cpu_stats(); |
379 |
< |
logmessage(LOG_DEBUG,"get_disk_stats"); |
380 |
< |
stats[1]=get_disk_stats(); |
381 |
< |
logmessage(LOG_DEBUG,"get_load_stats"); |
382 |
< |
stats[2]=get_load_stats(); |
383 |
< |
logmessage(LOG_DEBUG,"get_memory_stats"); |
384 |
< |
stats[3]=get_memory_stats(); |
385 |
< |
logmessage(LOG_DEBUG,"get_os_info"); |
386 |
< |
stats[4]=get_os_info(); |
387 |
< |
logmessage(LOG_DEBUG,"get_page_stats"); |
388 |
< |
stats[5]=get_page_stats(); |
389 |
< |
logmessage(LOG_DEBUG,"get_process_stats"); |
390 |
< |
stats[6]=get_process_stats(); |
391 |
< |
logmessage(LOG_DEBUG,"get_swap_stats"); |
392 |
< |
stats[7]=get_swap_stats(); |
393 |
< |
logmessage(LOG_DEBUG,"get_user_stats"); |
394 |
< |
stats[8]=get_user_stats(); |
583 |
> |
} |
584 |
|
|
585 |
< |
for(;x<NUM_STATS;x++){ |
586 |
< |
if(stats[x]==NULL){ |
587 |
< |
logmessage(LOG_ERR,"Function returned NULL"); |
588 |
< |
return NULL; |
585 |
> |
|
586 |
> |
/* Get paging stats */ |
587 |
> |
if((page_stats=get_page_stats_diff())==NULL){ |
588 |
> |
log_msg(LOG_CRIT, "Failed to get paging statistics"); |
589 |
> |
}else{ |
590 |
> |
if(page_stats->systime!=0){ |
591 |
> |
x=page_stats->pages_pagein / page_stats->systime; |
592 |
> |
y=page_stats->pages_pageout / page_stats->systime; |
593 |
> |
}else{ |
594 |
> |
x=page_stats->pages_pagein; |
595 |
> |
y=page_stats->pages_pageout; |
596 |
|
} |
597 |
< |
if(xml_data==NULL){ |
598 |
< |
if((xml_data=strf("%s", stats[x])) == NULL){ |
599 |
< |
logmessage(LOG_ERR, "str failed (%m)"); |
600 |
< |
return NULL; |
597 |
> |
snprintf(tmp, size, \ |
598 |
> |
"<pages><pageins>%lld</pageins><pageouts>%lld</pageouts></pages>", \ |
599 |
> |
x, \ |
600 |
> |
y); |
601 |
> |
|
602 |
> |
if(strlcat(xml, tmp, size) >= size) goto too_big_error; |
603 |
> |
} |
604 |
> |
|
605 |
> |
|
606 |
> |
/* get diskio stats */ |
607 |
> |
|
608 |
> |
if((diskio_stats=get_diskio_stats_diff(&diskio_entries))==NULL){ |
609 |
> |
log_msg(LOG_CRIT, "Failed to get diskio statistics"); |
610 |
> |
}else{ |
611 |
> |
strlcat(xml, "<diskio>", size); |
612 |
> |
for(counter=0;counter<diskio_entries;counter++){ |
613 |
> |
|
614 |
> |
if(diskio_stats->systime!=0){ |
615 |
> |
x=diskio_stats->read_bytes / diskio_stats->systime; |
616 |
> |
y=diskio_stats->write_bytes / diskio_stats->systime; |
617 |
> |
}else{ |
618 |
> |
x=diskio_stats->read_bytes; |
619 |
> |
y=diskio_stats->write_bytes; |
620 |
|
} |
621 |
< |
}else{ |
622 |
< |
xml_data_p=xml_data; |
623 |
< |
if((xml_data=strf("%s%s", xml_data, stats[x])) == NULL){ |
624 |
< |
logmessage(LOG_ERR, "str failed (%m)"); |
625 |
< |
return NULL; |
626 |
< |
} |
627 |
< |
free(xml_data_p); |
621 |
> |
|
622 |
> |
snprintf(tmp, size, \ |
623 |
> |
"<p%d name=\"%s\" rbytes=\"%lld\" wbytes=\"%lld\"></p%d>", \ |
624 |
> |
counter, \ |
625 |
> |
diskio_stats->disk_name, \ |
626 |
> |
x, \ |
627 |
> |
y, \ |
628 |
> |
counter); |
629 |
> |
|
630 |
> |
strlcat(xml, tmp, size); |
631 |
> |
diskio_stats++; |
632 |
|
} |
633 |
< |
free(stats[x]); |
633 |
> |
|
634 |
> |
if(strlcat(xml, "</diskio>", size) >= size) goto too_big_error; |
635 |
> |
|
636 |
|
} |
416 |
– |
xml_data_p=xml_data; |
417 |
– |
xml_data=strf("<packet seq_no=\"%d\" machine_name=\"%s\" date=\"%ld\" type=\"data\" ip=\"%s\" key=\"%s\">%s</packet>", counter, ihost_state->my_fqdn, time(NULL), ihost_state->my_ip, ihost_state->key, xml_data); |
418 |
– |
free(xml_data_p); |
637 |
|
|
638 |
< |
logmessage(LOG_DEBUG,"Generated XML Data of : %s", xml_data); |
639 |
< |
return xml_data; |
640 |
< |
} |
638 |
> |
|
639 |
> |
/* get networks stats */ |
640 |
> |
|
641 |
> |
if((network_stats=get_network_stats_diff(&network_entries))==NULL){ |
642 |
> |
log_msg(LOG_CRIT, "Failed to get network statistics"); |
643 |
> |
}else{ |
644 |
> |
strlcat(xml, "<net>", size); |
645 |
> |
for(counter=0;counter<network_entries;counter++){ |
646 |
> |
if(network_stats->systime!=0){ |
647 |
> |
x=network_stats->rx / network_stats->systime; |
648 |
> |
y=network_stats->tx / network_stats->systime; |
649 |
> |
}else{ |
650 |
> |
x=network_stats->rx; |
651 |
> |
y=network_stats->tx; |
652 |
> |
} |
653 |
|
|
654 |
< |
int send_stats(ihost_state_t *ihost_state, char *data_stream){ |
655 |
< |
struct sockaddr_in addr; |
656 |
< |
struct in_addr haddr; |
654 |
> |
snprintf(tmp, size, \ |
655 |
> |
"<p%d name=\"%s\" rx=\"%lld\" tx=\"%lld\"></p%d>", \ |
656 |
> |
counter, \ |
657 |
> |
network_stats->interface_name, \ |
658 |
> |
x, \ |
659 |
> |
y, \ |
660 |
> |
counter); |
661 |
|
|
662 |
< |
int sd; |
663 |
< |
size_t len; |
662 |
> |
strlcat(xml, tmp, size); |
663 |
> |
network_stats++; |
664 |
> |
} |
665 |
|
|
666 |
< |
len=strlen(data_stream); |
667 |
< |
if(len>UDP_MAX_PACKET_SIZE){ |
433 |
< |
logmessage(LOG_ERR, "Too big to send to server. Please reconfigure client and server and recompile"); |
434 |
< |
exit(1); |
666 |
> |
if(strlcat(xml, "</net>", size) >= size) goto too_big_error; |
667 |
> |
|
668 |
|
} |
436 |
– |
logmessage(LOG_DEBUG,"Resolving IP of server"); |
437 |
– |
if (get_host_addr(ihost_state->server_fqdn, &haddr) != 0){ |
438 |
– |
logmessage(LOG_ERR, "Failed to resolve address %s (%m)", ihost_state->server_fqdn); |
439 |
– |
return -1; |
440 |
– |
} |
441 |
– |
logmessage(LOG_DEBUG,"Creating UDP connection to %s on %d",ihost_state->server_fqdn, ihost_state->server_udp_port); |
442 |
– |
if((sd=socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0){ |
443 |
– |
logmessage(LOG_ERR, "failed to create UDP socket (%m)"); |
444 |
– |
return -1; |
445 |
– |
} |
669 |
|
|
447 |
– |
memset(&addr, 0, sizeof(addr)); |
448 |
– |
addr.sin_family=AF_INET; |
449 |
– |
memcpy((char *)&addr.sin_addr, &haddr, sizeof haddr); |
450 |
– |
addr.sin_port = htons(ihost_state->server_udp_port); |
670 |
|
|
671 |
< |
logmessage(LOG_INFO,"Sending packet : %s", data_stream); |
672 |
< |
if((sendto(sd, data_stream, len, 0, (struct sockaddr *) &addr, sizeof(addr))) != len){ |
673 |
< |
logmessage(LOG_ERR, "Send the wrong number of bytes (%m)"); |
674 |
< |
return -1; |
671 |
> |
/* get disk stats */ |
672 |
> |
|
673 |
> |
if((disk_stats=get_disk_stats(&disk_entries))==NULL){ |
674 |
> |
log_msg(LOG_CRIT, "Failed to get disk statistics"); |
675 |
> |
}else{ |
676 |
> |
strlcat(xml, "<disk>", size); |
677 |
> |
for(counter=0;counter<disk_entries;counter++){ |
678 |
> |
snprintf(tmp, size, \ |
679 |
> |
"<p%d name=\"%s\" mount=\"%s\" fstype=\"%s\" total=\"%lld\" used=\"%lld\" avail=\"%lld\" totalinodes=\"%lld\" usedinodes=\"%lld\" freeinodes=\"%lld\"></p%d>", \ |
680 |
> |
counter, \ |
681 |
> |
disk_stats->device_name, \ |
682 |
> |
disk_stats->mnt_point, \ |
683 |
> |
disk_stats->fs_type, \ |
684 |
> |
disk_stats->size, \ |
685 |
> |
disk_stats->used, \ |
686 |
> |
disk_stats->avail, \ |
687 |
> |
disk_stats->total_inodes, \ |
688 |
> |
disk_stats->used_inodes, \ |
689 |
> |
disk_stats->free_inodes, \ |
690 |
> |
counter); |
691 |
> |
|
692 |
> |
strlcat(xml, tmp, size); |
693 |
> |
|
694 |
> |
disk_stats++; |
695 |
> |
} |
696 |
> |
|
697 |
> |
if(strlcat(xml, "</disk>", size) >= size) goto too_big_error; |
698 |
> |
|
699 |
|
} |
700 |
+ |
|
701 |
|
|
702 |
< |
close(sd); |
702 |
> |
if(strlcat(xml, "</packet>", size) >= size) goto too_big_error; |
703 |
|
|
704 |
< |
return 0; |
704 |
> |
/*If we got to here, it should of all been filled in nicely now */ |
705 |
> |
return 0; |
706 |
> |
|
707 |
> |
too_big_error: |
708 |
> |
log_msg(LOG_ERR, "UDP Packet is too large. Throwing away the packet"); |
709 |
> |
return -1; |
710 |
|
} |
711 |
|
|
712 |
+ |
|
713 |
+ |
|
714 |
|
void usage(char *progname){ |
715 |
< |
fprintf(stderr, "Usage %s [options] server port\n", progname); |
716 |
< |
fprintf(stderr, "Options\n"); |
717 |
< |
fprintf(stderr, " -v Verbose, the more v flags the more verbose, eg -vv\n"); |
718 |
< |
fprintf(stderr, " -d Daemon mode, self backgrounding\n"); |
719 |
< |
fprintf(stderr, " -s Send errors to syslog\n"); |
720 |
< |
fprintf(stderr, " -V Print version number\n"); |
721 |
< |
fprintf(stderr, " -h Prints this help page\n"); |
722 |
< |
exit(1); |
715 |
> |
fprintf(stderr, "Usage %s [options] server port\n", progname); |
716 |
> |
fprintf(stderr, "Options\n"); |
717 |
> |
fprintf(stderr, " -v Verbose mode,-vv would make even more verbose\n"); |
718 |
> |
fprintf(stderr, " -f Foreground mode, print errors to stderr\n"); |
719 |
> |
fprintf(stderr, " -s Set the machine name to be reported as\n"); |
720 |
> |
fprintf(stderr, " -i Set the IP to be reported as\n"); |
721 |
> |
fprintf(stderr, " -V Print version number\n"); |
722 |
> |
fprintf(stderr, " -h Prints this help page\n"); |
723 |
> |
exit(1); |
724 |
|
} |
725 |
|
|
726 |
|
int main(int argc, char **argv){ |
727 |
+ |
|
728 |
|
ihost_state_t ihost_state; |
729 |
< |
int heartbeat_exit; |
730 |
< |
int counter=0; |
478 |
< |
long udp_time=0, tcp_time=0, stat_grab_time=0, cur_time=0; |
479 |
< |
int sleep_delay=0; |
480 |
< |
char *xml_stats; |
481 |
< |
pid_t pid; |
729 |
> |
udp_sockinfo_t udp_sockinfo; |
730 |
> |
|
731 |
|
int cmdopt; |
732 |
|
extern int optind; |
733 |
< |
int verbose=0, daemon=0; |
734 |
< |
extern int syslog_logging; |
735 |
< |
extern int log_level; |
736 |
< |
extern int cur_level; |
733 |
> |
pid_t pid; |
734 |
> |
FILE *f; |
735 |
> |
int packet_num=0; |
736 |
> |
int len; |
737 |
|
|
738 |
< |
log_level=1; |
490 |
< |
cur_level=1; |
491 |
< |
syslog_logging=0; |
738 |
> |
char packet[MAX_UDP_PACKET_SIZE]; |
739 |
|
|
740 |
< |
errf_set_ofunc(log_errors); |
494 |
< |
/* NULL'ify so i can tell if i need to free it or not */ |
495 |
< |
ihost_state.fm_host=NULL; |
496 |
< |
ihost_state.my_fqdn=NULL; |
497 |
< |
ihost_state.server_fqdn=NULL; |
498 |
< |
ihost_state.last_modified=NULL; |
499 |
< |
ihost_state.files_list=NULL; |
500 |
< |
ihost_state.key=NULL; |
740 |
> |
time_t cur_time, sleep_delay, udp_time=0, config_time=0; |
741 |
|
|
742 |
< |
errf_set_progname(argv[0]); |
743 |
< |
|
742 |
> |
/* Set default settings */ |
743 |
> |
ihost_config.verbose=1; |
744 |
> |
ihost_config.daemon=1; |
745 |
> |
/* Set all errors to go down stderr until told otherwise */ |
746 |
> |
ihost_config.log=stderr; |
747 |
|
|
748 |
< |
while((cmdopt=getopt(argc, argv, "vdshV")) != -1){ |
749 |
< |
switch(cmdopt){ |
750 |
< |
case 'v': |
751 |
< |
verbose++; |
752 |
< |
break; |
753 |
< |
|
754 |
< |
case 'd': |
755 |
< |
/* Force syslog logging since stderr will be closed in this case */ |
756 |
< |
syslog_logging=1; |
757 |
< |
daemon=1; |
758 |
< |
break; |
759 |
< |
|
748 |
> |
/* Blank ihost_state to default settings */ |
749 |
> |
ihost_state.filtermanager_host=NULL; |
750 |
> |
ihost_state.host_fqdn=NULL; |
751 |
> |
ihost_state.host_ip=NULL; |
752 |
> |
ihost_state.preset_fqdn = 0; |
753 |
> |
ihost_state.preset_ip = 0; |
754 |
> |
ihost_state.server_fqdn=NULL; |
755 |
> |
ihost_state.file_list=NULL; |
756 |
> |
ihost_state.last_modified=NULL; |
757 |
> |
|
758 |
> |
while((cmdopt=getopt(argc, argv, "vfhVs:i:")) != -1){ |
759 |
> |
switch(cmdopt){ |
760 |
> |
case 'v': |
761 |
> |
ihost_config.verbose++; |
762 |
> |
break; |
763 |
> |
|
764 |
> |
case 'f': |
765 |
> |
/* Force syslog logging since stderr will be closed in this case */ |
766 |
> |
ihost_config.daemon=0; |
767 |
> |
break; |
768 |
> |
|
769 |
> |
case 'h': |
770 |
> |
usage(argv[0]); |
771 |
> |
break; |
772 |
> |
|
773 |
> |
case 'V': |
774 |
> |
fprintf(stderr, "%s version %s\n", argv[0], VERSION); |
775 |
> |
break; |
776 |
|
case 's': |
777 |
< |
syslog_logging=1; |
777 |
> |
ihost_state.preset_fqdn = 1; |
778 |
> |
ihost_state.host_fqdn = strdup(optarg); |
779 |
> |
if(ihost_state.host_fqdn == NULL){ |
780 |
> |
fprintf(stderr, "Missing hostname\n"); |
781 |
> |
usage(argv[0]); |
782 |
> |
} |
783 |
|
break; |
784 |
< |
|
785 |
< |
case 'h': |
786 |
< |
usage(argv[0]); |
784 |
> |
case 'i': |
785 |
> |
/* Hmm.. Someone could set any string to be the IP, and it will let it */ |
786 |
> |
ihost_state.preset_ip = 1; |
787 |
> |
ihost_state.host_ip = strdup(optarg); |
788 |
> |
if(ihost_state.host_ip == NULL){ |
789 |
> |
fprintf(stderr, "Missing ip\n"); |
790 |
> |
usage(argv[0]); |
791 |
> |
} |
792 |
|
break; |
793 |
|
|
794 |
< |
case 'V': |
795 |
< |
errf("%s version %f",argv[0], versionNo); |
796 |
< |
break; |
794 |
> |
default: |
795 |
> |
usage(argv[0]); |
796 |
> |
exit(1); |
797 |
> |
} |
798 |
> |
} |
799 |
|
|
800 |
< |
default: |
801 |
< |
usage(argv[0]); |
802 |
< |
exit(1); |
803 |
< |
} |
533 |
< |
} |
800 |
> |
if(argc!=optind+2){ |
801 |
> |
usage(argv[0]); |
802 |
> |
exit(1); |
803 |
> |
} |
804 |
|
|
805 |
< |
if(argc!=optind+2){ |
806 |
< |
usage(argv[0]); |
805 |
> |
ihost_state.filtermanager_host=strdup(argv[optind]); |
806 |
> |
ihost_state.filtermanager_port=atoi(argv[optind+1]); |
807 |
> |
|
808 |
> |
if(gethostbyname(ihost_state.filtermanager_host)==NULL){ |
809 |
> |
log_msg(LOG_CRIT, "Failed to lookup hostname. Please check settings"); |
810 |
|
exit(1); |
811 |
|
} |
812 |
< |
ihost_state.fm_host=argv[optind]; |
813 |
< |
ihost_state.fm_port=atoi(argv[optind+1]); |
814 |
< |
if(ihost_state.fm_port==0){ |
542 |
< |
errf("Invalid port number"); |
543 |
< |
usage(argv[0]); |
812 |
> |
if(ihost_state.filtermanager_port==0){ |
813 |
> |
log_msg(LOG_ERR, "Invalid port number"); |
814 |
> |
exit(1); |
815 |
|
} |
816 |
|
|
817 |
< |
if(daemon==1){ |
817 |
> |
if(ihost_config.daemon){ |
818 |
|
pid=fork(); |
819 |
|
if(pid==-1){ |
820 |
< |
errf("Fork failed, can't background. Exiting"); |
821 |
< |
exit(1); |
820 |
> |
log_msg(LOG_CRIT, "Failed to background exiting"); |
821 |
> |
exit(1); |
822 |
|
}else if(pid!=0){ |
823 |
< |
/* Parent process */ |
824 |
< |
return 0; |
825 |
< |
} |
826 |
< |
/* We should now be in the background*/ |
827 |
< |
if(setsid()==-1){ |
828 |
< |
errf("setsid failed (%m)"); |
823 |
> |
/* Parent process */ |
824 |
> |
return 0; |
825 |
> |
} |
826 |
> |
/* We should now be in the background*/ |
827 |
> |
if(setsid()==-1){ |
828 |
> |
log_msg(LOG_CRIT, "setsid failed"); |
829 |
> |
exit(1); |
830 |
> |
} |
831 |
> |
|
832 |
> |
if((ihost_config.log=fopen(LOG_FILE, "a"))==NULL){ |
833 |
> |
ihost_config.log=stderr; |
834 |
> |
log_msg(LOG_CRIT, "Failed to open Logfiles %s for writing", LOG_FILE); |
835 |
|
exit(1); |
836 |
|
} |
560 |
– |
fclose(stdin); |
561 |
– |
fclose(stdout); |
562 |
– |
fclose(stderr); |
563 |
– |
} |
837 |
|
|
838 |
< |
if(syslog_logging==1){ |
839 |
< |
openlog(errf_get_progname(),0,LOG_ERR); |
840 |
< |
setlogmask(LOG_UPTO(LOG_DEBUG)); |
838 |
> |
fclose(stdin); |
839 |
> |
fclose(stdout); |
840 |
> |
fclose(stderr); |
841 |
> |
|
842 |
> |
} |
843 |
> |
|
844 |
> |
log_msg(LOG_INFO, "Starting ihost"); |
845 |
> |
|
846 |
> |
log_msg(LOG_DEBUG,"Writing PID FILE"); |
847 |
> |
|
848 |
> |
pid=getpid(); |
849 |
> |
|
850 |
> |
if((f=fopen(PID_FILE,"w")) == NULL){ |
851 |
> |
log_msg(LOG_CRIT, "Failed to write PID file"); |
852 |
> |
}else{ |
853 |
> |
if((fprintf(f,"%d",(int)pid)) <= 0 ){ |
854 |
> |
log_msg(LOG_CRIT, "Failed to write PID file"); |
855 |
> |
} |
856 |
> |
if((fclose(f))!=0){ |
857 |
> |
log_msg(LOG_CRIT, "failed to close PID file"); |
858 |
> |
} |
859 |
> |
} |
860 |
> |
|
861 |
> |
/* Get the initial config from the filter manager. Should this fail, |
862 |
> |
* wait, and then try again. */ |
863 |
> |
|
864 |
> |
get_diskio_stats_diff(&packet_num); |
865 |
> |
packet_num=0; |
866 |
> |
|
867 |
> |
while(ihost_getconfig(&ihost_state)!=0){ |
868 |
> |
log_msg(LOG_ERR, "Failed to get ihost config"); |
869 |
> |
sleep(10); |
870 |
|
} |
569 |
– |
|
570 |
– |
switch(verbose){ |
571 |
– |
case 0: |
572 |
– |
/* Critical errors + */ |
573 |
– |
log_level=LOG_ERR; |
574 |
– |
break; |
575 |
– |
case 1: |
576 |
– |
/* Recoverable errors */ |
577 |
– |
log_level=LOG_WARNING; |
578 |
– |
break; |
579 |
– |
case 2: |
580 |
– |
/* Print stuff like the XML packets */ |
581 |
– |
log_level=LOG_INFO; |
582 |
– |
break; |
583 |
– |
default: |
584 |
– |
/* Must have lots of v's */ |
585 |
– |
/* Print out everything its doing */ |
586 |
– |
log_level=LOG_DEBUG; |
587 |
– |
break; |
588 |
– |
} |
871 |
|
|
872 |
< |
if(ihost_configure(&ihost_state)!=0){ |
873 |
< |
logmessage(LOG_ERR,"configure failed"); |
874 |
< |
/* Ok, ideally we prob should have 2 copies of the structure and carry on if this |
875 |
< |
happens.. But we dont :) (at the moment) */ |
594 |
< |
exit(1); |
872 |
> |
printf("%s\n%d\n", ihost_state.server_fqdn, ihost_state.server_udp_port); |
873 |
> |
while((create_udp_sockinfo(&udp_sockinfo, ihost_state.server_fqdn, ihost_state.server_udp_port))!=0){ |
874 |
> |
log_msg(LOG_ERR, "Failed to create udp socket"); |
875 |
> |
sleep(10); |
876 |
|
} |
877 |
|
|
878 |
+ |
config_time=time(NULL)+ihost_state.config_ttl; |
879 |
+ |
|
880 |
+ |
/* Now have config.. collect data and send as often as required */ |
881 |
|
for(;;){ |
882 |
|
cur_time=time(NULL); |
599 |
– |
if(cur_time>=tcp_time){ |
600 |
– |
logmessage(LOG_DEBUG,"Sending heartbeat"); |
601 |
– |
heartbeat_exit=heartbeat(&ihost_state); |
602 |
– |
if(heartbeat_exit==RECONFIGURE_RETURN_CODE){ |
603 |
– |
logmessage(LOG_INFO,"heartbeat needs to be reconfigured"); |
604 |
– |
ihost_configure(&ihost_state); |
605 |
– |
udp_time=0; |
606 |
– |
} |
607 |
– |
if(heartbeat_exit==-1){ |
608 |
– |
logmessage(LOG_ERR,"Heartbeat failed"); |
609 |
– |
exit(1); |
610 |
– |
} |
611 |
– |
tcp_time=time(NULL)+ihost_state.tcp_update_time; |
612 |
– |
logmessage(LOG_DEBUG,"next tcp time should be %d", tcp_time); |
613 |
– |
} |
883 |
|
|
884 |
|
if(cur_time>=udp_time){ |
885 |
< |
logmessage(LOG_DEBUG,"Sending udp data"); |
885 |
> |
if((get_system_stats(packet_num++, &ihost_state, packet, MAX_UDP_PACKET_SIZE))!=0){ |
886 |
> |
log_msg(LOG_ERR, "Failed to get system stats"); |
887 |
> |
} |
888 |
|
|
889 |
< |
stat_grab_time=time(NULL); |
890 |
< |
if((xml_stats=stat_grab(&ihost_state, counter++)) == NULL){ |
891 |
< |
logmessage(LOG_ERR,"Failed to get stats (%m)"); |
892 |
< |
exit(1); |
889 |
> |
len=strlen(packet); |
890 |
> |
log_msg(LOG_DEBUG, "Packet size: %d\nPacket: %s\n", len, packet); |
891 |
> |
|
892 |
> |
if((sendto(udp_sockinfo.sock, packet, len, 0, (struct sockaddr *) &udp_sockinfo.addr, sizeof(udp_sockinfo.addr)))!=len){ |
893 |
> |
log_msg(LOG_CRIT, "Failed to send packet"); |
894 |
|
} |
895 |
< |
stat_grab_time=time(NULL)-stat_grab_time; |
896 |
< |
send_stats(&ihost_state, xml_stats); |
625 |
< |
free(xml_stats); |
626 |
< |
udp_time=time(NULL)+ihost_state.udp_update_time-stat_grab_time; |
627 |
< |
logmessage(LOG_DEBUG,"next udp time should be %d", udp_time); |
895 |
> |
udp_time=cur_time+ihost_state.udp_update_time; |
896 |
> |
log_msg(LOG_DEBUG, "Next packet should be sent on %d", udp_time); |
897 |
|
} |
898 |
+ |
|
899 |
+ |
if(cur_time>=config_time){ |
900 |
+ |
if(ihost_getconfig(&ihost_state)!=0){ |
901 |
+ |
/* If we can't get the config, try again 5 minutes time */ |
902 |
+ |
log_msg(LOG_ERR, "Failed to get config, try again 5 minutes time"); |
903 |
+ |
config_time=time(NULL)+300; |
904 |
+ |
}else{ |
905 |
+ |
close(udp_sockinfo.sock); |
906 |
|
|
907 |
< |
if(tcp_time<udp_time){ |
908 |
< |
sleep_delay=tcp_time-time(NULL); |
909 |
< |
}else{ |
910 |
< |
sleep_delay=udp_time-time(NULL); |
907 |
> |
while((create_udp_sockinfo(&udp_sockinfo, ihost_state.server_fqdn, ihost_state.server_udp_port))!=0){ |
908 |
> |
log_msg(LOG_CRIT, "Failed to create udp socket"); |
909 |
> |
sleep(10); |
910 |
> |
} |
911 |
> |
|
912 |
> |
config_time=time(NULL)+ihost_state.config_ttl; |
913 |
> |
|
914 |
> |
log_msg(LOG_DEBUG, "Config expires on %d\n", ihost_state.config_ttl); |
915 |
> |
} |
916 |
|
} |
917 |
< |
logmessage(LOG_DEBUG,"Sleeping for %d", sleep_delay); |
917 |
> |
|
918 |
> |
sleep_delay=udp_time-time(NULL); |
919 |
> |
log_msg(LOG_DEBUG, "Sleeping for %d", sleep_delay); |
920 |
|
if(sleep_delay>0) sleep(sleep_delay); |
921 |
< |
} |
922 |
< |
return 0; |
921 |
> |
} |
922 |
> |
|
923 |
> |
return(0); |
924 |
|
} |
640 |
– |
|