32 |
|
#include <errno.h> |
33 |
|
#include <netdb.h> |
34 |
|
|
35 |
< |
#include <ukcprog.h> |
35 |
> |
#include "ukcprog.h" |
36 |
|
#include "statgrab.h" |
37 |
|
|
38 |
|
#define LOG_CRIT 0 |
40 |
|
#define LOG_INFO 2 |
41 |
|
#define LOG_DEBUG 3 |
42 |
|
|
43 |
– |
#define PID_FILE "/var/run/ihost.pid" |
44 |
– |
#define LOGFILE_PATH "/var/log/ihost.log" |
45 |
– |
#define VERSION ".03" |
46 |
– |
|
47 |
– |
#define MAX_UDP_PACKET_SIZE 8192 |
48 |
– |
|
43 |
|
typedef struct{ |
44 |
|
int filtermanager_port; |
45 |
|
char *filtermanager_host; |
75 |
|
|
76 |
|
ihost_config_t ihost_config; |
77 |
|
|
78 |
+ |
extern int errno; |
79 |
+ |
|
80 |
+ |
/* Taken from the OpenSSH code. Its licence included in function.*/ |
81 |
+ |
#ifndef HAVE_STRLCAT |
82 |
+ |
|
83 |
+ |
/* |
84 |
+ |
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> |
85 |
+ |
* All rights reserved. |
86 |
+ |
* |
87 |
+ |
* Redistribution and use in source and binary forms, with or without |
88 |
+ |
* modification, are permitted provided that the following conditions |
89 |
+ |
* are met: |
90 |
+ |
* 1. Redistributions of source code must retain the above copyright |
91 |
+ |
* notice, this list of conditions and the following disclaimer. |
92 |
+ |
* 2. Redistributions in binary form must reproduce the above copyright |
93 |
+ |
* notice, this list of conditions and the following disclaimer in the |
94 |
+ |
* documentation and/or other materials provided with the distribution. |
95 |
+ |
* 3. The name of the author may not be used to endorse or promote products |
96 |
+ |
* derived from this software without specific prior written permission. |
97 |
+ |
* |
98 |
+ |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, |
99 |
+ |
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
100 |
+ |
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
101 |
+ |
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
102 |
+ |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
103 |
+ |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
104 |
+ |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
105 |
+ |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
106 |
+ |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
107 |
+ |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
108 |
+ |
*/ |
109 |
+ |
|
110 |
+ |
/* |
111 |
+ |
* Appends src to string dst of size siz (unlike strncat, siz is the |
112 |
+ |
* full size of dst, not space left). At most siz-1 characters |
113 |
+ |
* will be copied. Always NUL terminates (unless siz <= strlen(dst)). |
114 |
+ |
* Returns strlen(src) + MIN(siz, strlen(initial dst)). |
115 |
+ |
* If retval >= siz, truncation occurred. |
116 |
+ |
*/ |
117 |
+ |
size_t |
118 |
+ |
strlcat(dst, src, siz) |
119 |
+ |
char *dst; |
120 |
+ |
const char *src; |
121 |
+ |
size_t siz; |
122 |
+ |
{ |
123 |
+ |
register char *d = dst; |
124 |
+ |
register const char *s = src; |
125 |
+ |
register size_t n = siz; |
126 |
+ |
size_t dlen; |
127 |
+ |
|
128 |
+ |
/* Find the end of dst and adjust bytes left but don't go past end */ |
129 |
+ |
while (n-- != 0 && *d != '\0') |
130 |
+ |
d++; |
131 |
+ |
dlen = d - dst; |
132 |
+ |
n = siz - dlen; |
133 |
+ |
|
134 |
+ |
if (n == 0) |
135 |
+ |
return(dlen + strlen(s)); |
136 |
+ |
while (*s != '\0') { |
137 |
+ |
if (n != 1) { |
138 |
+ |
*d++ = *s; |
139 |
+ |
n--; |
140 |
+ |
} |
141 |
+ |
s++; |
142 |
+ |
} |
143 |
+ |
*d = '\0'; |
144 |
+ |
|
145 |
+ |
return(dlen + (s - src)); /* count does not include NUL */ |
146 |
+ |
} |
147 |
+ |
|
148 |
+ |
#endif |
149 |
+ |
/* End strlcat function taken from OpenSSH */ |
150 |
+ |
|
151 |
|
void log_msg(int level, char *format, ...){ |
85 |
– |
extern int errno; |
152 |
|
int cur_errno; |
153 |
|
va_list ap; |
154 |
|
|
292 |
|
int server_udp_port=0; |
293 |
|
time_t config_ttl=0; |
294 |
|
|
295 |
< |
tcp_con=create_tcp_connection(ihost_state->filtermanager_host, ihost_state->filtermanager_port); |
295 |
> |
if((tcp_con=create_tcp_connection(ihost_state->filtermanager_host, ihost_state->filtermanager_port))==NULL){ |
296 |
> |
return -1; |
297 |
> |
} |
298 |
|
|
299 |
|
if(ihost_state->file_list!=NULL || ihost_state->last_modified!=NULL){ |
300 |
|
if(tcp_con==NULL){ |
310 |
|
} |
311 |
|
|
312 |
|
if((tcp_comm(tcp_con, ihost_state->last_modified, &response, "OK"))==0){ |
313 |
< |
if((tcp_comm(tcp_con, "END", &response, "OK"))==0){ |
313 |
> |
if((tcp_comm(tcp_con, "END", &response, "OK"))!=0){ |
314 |
|
goto error; |
315 |
|
} |
316 |
|
fclose(tcp_con); |
578 |
|
y=page_stats->pages_pageout; |
579 |
|
} |
580 |
|
snprintf(tmp, size, \ |
581 |
< |
"<pages><swapins>%lld</swapins><swapouts>%lld</swapouts></pages>", \ |
581 |
> |
"<pages><pageins>%lld</pageins><pageouts>%lld</pageouts></pages>", \ |
582 |
|
x, \ |
583 |
|
y); |
584 |
|
|
750 |
|
break; |
751 |
|
|
752 |
|
case 'V': |
753 |
< |
fprintf(stderr, "%s version %s", argv[0], VERSION); |
753 |
> |
fprintf(stderr, "%s version %s\n", argv[0], VERSION); |
754 |
|
break; |
755 |
|
|
756 |
|
default: |
791 |
|
exit(1); |
792 |
|
} |
793 |
|
|
794 |
< |
if((ihost_config.log=fopen(LOGFILE_PATH, "a"))==NULL){ |
794 |
> |
if((ihost_config.log=fopen(LOG_FILE, "a"))==NULL){ |
795 |
|
ihost_config.log=stderr; |
796 |
< |
log_msg(LOG_CRIT, "Failed to open Logfiles %s for writing", LOGFILE_PATH); |
796 |
> |
log_msg(LOG_CRIT, "Failed to open Logfiles %s for writing", LOG_FILE); |
797 |
|
exit(1); |
798 |
|
} |
799 |
|
|