1 #! /bin/sh /usr/share/dpatch/dpatch-run
2 ## bts557599_powerdns_fix.dpatch by Luke Heberling <collectd@c-ware.com>
3 ##
4 ## DP: powerdns plugin: Fixed communication when talking to pdns 2.9.22.
5 ## DP:
6 ## DP: powerdns version 2.9.22 (and above) require a newline at the end of
7 ## DP: commands sent to the server.
9 @DPATCH@
11 diff a/src/powerdns.c b/src/powerdns.c
12 --- a/src/powerdns.c
13 +++ b/src/powerdns.c
14 @@ -46,12 +46,12 @@
15 #define FUNC_ERROR(func) do { char errbuf[1024]; ERROR ("powerdns plugin: %s failed: %s", func, sstrerror (errno, errbuf, sizeof (errbuf))); } while (0)
17 #define SERVER_SOCKET LOCALSTATEDIR"/run/pdns.controlsocket"
18 -#define SERVER_COMMAND "SHOW *"
19 +#define SERVER_COMMAND "SHOW * \n"
21 #define RECURSOR_SOCKET LOCALSTATEDIR"/run/pdns_recursor.controlsocket"
22 #define RECURSOR_COMMAND "get noerror-answers nxdomain-answers " \
23 "servfail-answers sys-msec user-msec qa-latency cache-entries cache-hits " \
24 - "cache-misses questions"
25 + "cache-misses questions\n"
27 struct list_item_s;
28 typedef struct list_item_s list_item_t;
29 @@ -437,6 +437,11 @@ static int powerdns_get_data_stream (lis
30 return (-1);
31 }
33 + struct timeval timeout;
34 + timeout.tv_sec=5;
35 + timeout.tv_usec=0;
36 + status = setsockopt (sd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof (timeout));
37 +
38 status = connect (sd, (struct sockaddr *) &item->sockaddr,
39 sizeof (item->sockaddr));
40 if (status != 0)
41 @@ -529,7 +534,7 @@ static int powerdns_read_server (list_it
42 int fields_num;
44 if (item->command == NULL)
45 - item->command = strdup ("SHOW *");
46 + item->command = strdup (SERVER_COMMAND);
47 if (item->command == NULL)
48 {
49 ERROR ("powerdns plugin: strdup failed.");
50 @@ -610,7 +615,7 @@ static int powerdns_update_recursor_comm
51 else
52 {
53 sstrncpy (buffer, "get ", sizeof (buffer));
54 - status = strjoin (&buffer[4], sizeof (buffer) - strlen ("get "),
55 + status = strjoin (&buffer[strlen("get ")], sizeof (buffer) - strlen ("get "),
56 li->fields, li->fields_num,
57 /* seperator = */ " ");
58 if (status < 0)
59 @@ -618,6 +623,14 @@ static int powerdns_update_recursor_comm
60 ERROR ("powerdns plugin: strjoin failed.");
61 return (-1);
62 }
63 + buffer[sizeof (buffer) - 1] = 0;
64 + int i = strlen (buffer);
65 + if (i < sizeof (buffer) - 2)
66 + {
67 + buffer[i++] = ' ';
68 + buffer[i++] = '\n';
69 + buffer[i++] = '\0';
70 + }
71 }
73 buffer[sizeof (buffer) - 1] = 0;