/[packages]/cauldron/rrdcollect/current/SOURCES/rrdcollect-socket.diff
ViewVC logotype

Contents of /cauldron/rrdcollect/current/SOURCES/rrdcollect-socket.diff

Parent Directory Parent Directory | Revision Log Revision Log


Revision 209251 - (show annotations) (download)
Wed Feb 15 09:56:18 2012 UTC (12 years, 7 months ago) by bertl
File size: 4314 byte(s)
imported package rrdcollect
1 diff -NurpP --minimal --exclude '*.orig' rrdcollect-0.2.4/include/rrdcollect.h rrdcollect-0.2.4-socket/include/rrdcollect.h
2 --- rrdcollect-0.2.4/include/rrdcollect.h 2009-02-25 15:40:37.000000000 +0100
3 +++ rrdcollect-0.2.4-socket/include/rrdcollect.h 2009-05-18 19:13:33.000000000 +0200
4 @@ -148,6 +148,7 @@ struct uri_t {
5 RRDCOLLECT_SNMP
6 }
7 */
8 + unsigned port;
9 const char *host;
10 const char *path;
11 };
12 diff -NurpP --minimal --exclude '*.orig' rrdcollect-0.2.4/src/counters.c rrdcollect-0.2.4-socket/src/counters.c
13 --- rrdcollect-0.2.4/src/counters.c 2009-02-25 15:40:37.000000000 +0100
14 +++ rrdcollect-0.2.4-socket/src/counters.c 2009-05-18 19:17:23.000000000 +0200
15 @@ -20,6 +20,9 @@
16
17 #include "rrdcollect.h"
18
19 +#include <netinet/in.h>
20 +#include <netdb.h>
21 +
22 struct rrd_t **rrd = NULL;
23 int rrd_count = 0;
24
25 @@ -111,14 +114,29 @@ void perform_tests()
26 {
27 int i;
28 for (i = 0; i < test_count; i++) {
29 - FILE *input;
30 + FILE *input = NULL;
31 int n;
32 int line = 0;
33
34 #ifdef ENABLE_EXEC
35 /* Horribly ugly and shameful code... */
36 - if (*(test[i]->uri->domain) == 'e') { /* exec */
37 + if (strcmp(test[i]->uri->domain, "exec") == 0) {
38 input = popen(test[i]->uri->path, "r");
39 + } else if (strcmp(test[i]->uri->domain, "socket") == 0) {
40 + int sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
41 + struct sockaddr_in server;
42 + struct hostent *host;
43 +
44 + server.sin_family = AF_INET;
45 + server.sin_port = htons(test[i]->uri->port);
46 + server.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
47 +
48 + host = gethostbyname(test[i]->uri->host);
49 + if (host)
50 + server.sin_addr.s_addr = *(uint32_t *)host->h_addr_list[0];
51 +
52 + if (connect(sock, (struct sockaddr *)&server, sizeof(server)) >= 0)
53 + input = fdopen(sock, "r");
54 } else { /* file */
55 #endif /* ENABLE_EXEC */
56 input = fopen(test[i]->uri->path, "r");
57 @@ -127,7 +145,7 @@ void perform_tests()
58 #endif /* ENABLE_EXEC */
59
60 if (!input) {
61 - send_log(LOG_ERR, "Cannot open file %s: %s\n", test[i]->uri->path, strerror(errno));
62 + send_log(LOG_ERR, "Cannot open %s: %s\n", test[i]->uri->path, strerror(errno));
63 errno = 0;
64 continue; /* FIXME: more intelligent error handling! */
65 }
66 @@ -157,7 +175,7 @@ void perform_tests()
67 }
68
69 #ifdef ENABLE_EXEC
70 - if (*(test[i]->uri->domain) == 'e') { /* exec */
71 + if (strcmp(test[i]->uri->domain, "exec") == 0) {
72 pclose(input);
73 } else {
74 #endif /* ENABLE_EXEC */
75 diff -NurpP --minimal --exclude '*.orig' rrdcollect-0.2.4/src/parse.c rrdcollect-0.2.4-socket/src/parse.c
76 --- rrdcollect-0.2.4/src/parse.c 2009-02-25 15:41:24.000000000 +0100
77 +++ rrdcollect-0.2.4-socket/src/parse.c 2009-05-18 19:20:23.000000000 +0200
78 @@ -164,28 +164,39 @@ static char *find_host_end(char *line)
79 static int get_uri(char *domain, struct uri_t *uri)
80 {
81 char *dend, *host, *path;
82 + char *port;
83
84 if (!(dend = find_domain_end(domain)))
85 return 1;
86
87 - host = dend+2;
88 + host = dend + 3;
89
90 if (!(path = find_host_end(host)))
91 return 2;
92
93 - /* FIXME: smarted domain handling!!! */
94 + /* FIXME: smarter domain handling!!! */
95 if (strncmp(domain, "file", dend-domain)
96 #ifdef ENABLE_EXEC
97 - && strncmp(domain, "exec", dend-domain)
98 + && strncmp(domain, "exec", dend-domain)
99 #endif /* ENABLE_EXEC*/
100 + && strncmp(domain, "socket", dend-domain)
101 ) {
102 return 3;
103 }
104
105 + uri->path = strdup(path);
106 +
107 /* Now we can modify the line */
108 - *(path++) = '\0';
109 + *path = '\0';
110 *dend = '\0';
111
112 + /* check for port */
113 + if ((port = index(host, ':'))) {
114 + uri->port = atoi(port + 1);
115 + *port = '\0';
116 + } else
117 + uri->port = 0;
118 +
119 #ifdef ENABLE_EXEC
120 if(strcmp(domain,"exec")==0) {
121 if(path[0]!='/') {
122 @@ -199,7 +210,6 @@ static int get_uri(char *domain, struct
123
124 uri->domain = strdup(domain);
125 uri->host = strdup(host);
126 - uri->path = strdup(path);
127
128 return 0;
129 }
130 diff -NurpP --minimal --exclude '*.orig' rrdcollect-0.2.4/src/scan.c rrdcollect-0.2.4-socket/src/scan.c
131 --- rrdcollect-0.2.4/src/scan.c 2007-07-28 18:42:49.000000000 +0200
132 +++ rrdcollect-0.2.4-socket/src/scan.c 2009-05-18 19:24:15.000000000 +0200
133 @@ -185,8 +185,13 @@ int scan(const char *buf, const char *fm
134 fmt++;
135 break;
136
137 - case ' ':
138 case '\t':
139 + /* match zero spaces too */
140 + if(!isspace(*(buf))) {
141 + fmt++;
142 + break;
143 + }
144 + case ' ':
145 case '\n':
146 case '\r':
147 case '\f':

  ViewVC Help
Powered by ViewVC 1.1.30