|
Line
Link Here
|
|
Revert apcupsd-related code to Conky 1.8.0 in order to fix broken apcupsd |
|
Revert apcupsd-related code to Conky 1.8.0 in order to fix broken apcupsd |
| 1 |
support. This is a workaround until upstream properly addresses this issue. |
1 |
support. This is a workaround until upstream properly addresses this issue. |
| 2 |
-- a/src/apcupsd.c |
2 |
++ b/src/apcupsd.c |
|
Lines 154-160
Link Here
|
| 154 |
// |
154 |
// |
| 155 |
// Conky update function for apcupsd data |
155 |
// Conky update function for apcupsd data |
| 156 |
// |
156 |
// |
| 157 |
int update_apcupsd(void) { |
157 |
void update_apcupsd(void) { |
| 158 |
|
158 |
|
| 159 |
int i; |
159 |
int i; |
| 160 |
APCUPSD_S apc; |
160 |
APCUPSD_S apc; |
|
Lines 164-204
Link Here
|
| 164 |
memcpy(apc.items[i], "N/A", 4); // including \0 |
164 |
memcpy(apc.items[i], "N/A", 4); // including \0 |
| 165 |
|
165 |
|
| 166 |
do { |
166 |
do { |
| 167 |
struct addrinfo hints; |
167 |
struct hostent* he = 0; |
| 168 |
struct addrinfo *ai, *rp; |
168 |
struct sockaddr_in addr; |
| 169 |
int res; |
|
|
| 170 |
short sz = 0; |
169 |
short sz = 0; |
| 171 |
char portbuf[8]; |
170 |
#ifdef HAVE_GETHOSTBYNAME_R |
|
|
171 |
struct hostent he_mem; |
| 172 |
int he_errno; |
| 173 |
char hostbuff[2048]; |
| 174 |
#endif |
| 172 |
// |
175 |
// |
| 173 |
// connect to apcupsd daemon |
176 |
// connect to apcupsd daemon |
| 174 |
// |
177 |
// |
| 175 |
memset(&hints, 0, sizeof(struct addrinfo)); |
178 |
sock = socket(AF_INET, SOCK_STREAM, 0); |
| 176 |
hints.ai_family = AF_UNSPEC; |
179 |
if (sock < 0) { |
| 177 |
hints.ai_socktype = SOCK_STREAM; |
180 |
perror("socket"); |
| 178 |
hints.ai_flags = 0; |
|
|
| 179 |
hints.ai_protocol = 0; |
| 180 |
snprintf(portbuf, 8, "%d", info.apcupsd.port); |
| 181 |
res = getaddrinfo(info.apcupsd.host, portbuf, &hints, &ai); |
| 182 |
if (res != 0) { |
| 183 |
NORM_ERR("APCUPSD getaddrinfo: %s", gai_strerror(res)); |
| 184 |
break; |
181 |
break; |
| 185 |
} |
182 |
} |
| 186 |
for (rp = ai; rp != NULL; rp = rp->ai_next) { |
183 |
#ifdef HAVE_GETHOSTBYNAME_R |
| 187 |
sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); |
184 |
if (gethostbyname_r(info.apcupsd.host, &he_mem, hostbuff, sizeof(hostbuff), &he, &he_errno) || !he ) { |
| 188 |
if (sock == -1) { |
185 |
NORM_ERR("APCUPSD gethostbyname_r: %s", hstrerror(h_errno)); |
| 189 |
continue; |
186 |
break; |
| 190 |
} |
187 |
} |
| 191 |
if (connect(sock, rp->ai_addr, rp->ai_addrlen) != -1) { |
188 |
#else /* HAVE_GETHOSTBYNAME_R */ |
| 192 |
break; |
189 |
he = gethostbyname(info.apcupsd.host); |
| 193 |
} |
190 |
if (!he) { |
| 194 |
close(sock); |
191 |
herror("gethostbyname"); |
|
|
192 |
break; |
| 195 |
} |
193 |
} |
| 196 |
freeaddrinfo(ai); |
194 |
#endif /* HAVE_GETHOSTBYNAME_R */ |
| 197 |
if (rp == NULL) { |
195 |
|
|
|
196 |
memset(&addr, 0, sizeof(addr)); |
| 197 |
addr.sin_family = AF_INET; |
| 198 |
addr.sin_port = info.apcupsd.port; |
| 199 |
memcpy(&addr.sin_addr, he->h_addr, he->h_length); |
| 200 |
if (connect(sock, (struct sockaddr*)&addr, sizeof(struct sockaddr)) < 0) { |
| 198 |
// no error reporting, the daemon is probably not running |
201 |
// no error reporting, the daemon is probably not running |
| 199 |
break; |
202 |
break; |
| 200 |
} |
203 |
} |
| 201 |
|
204 |
|
| 202 |
// |
205 |
// |
| 203 |
// send status request - "status" - 6B |
206 |
// send status request - "status" - 6B |
| 204 |
// |
207 |
// |
|
Lines 222-226
Link Here
|
| 222 |
// "atomically" copy the data into working set |
225 |
// "atomically" copy the data into working set |
| 223 |
// |
226 |
// |
| 224 |
memcpy(info.apcupsd.items, apc.items, sizeof(info.apcupsd.items)); |
227 |
memcpy(info.apcupsd.items, apc.items, sizeof(info.apcupsd.items)); |
| 225 |
return 0; |
228 |
return; |
| 226 |
} |
229 |
} |
| 227 |
-- a/src/apcupsd.h |
230 |
++ b/src/apcupsd.h |
|
Lines 49-54
Link Here
|
| 49 |
} APCUPSD_S, *PAPCUPSD_S; |
49 |
} APCUPSD_S, *PAPCUPSD_S; |
| 50 |
|
50 |
|
| 51 |
/* Service routine for the conky main thread */ |
51 |
/* Service routine for the conky main thread */ |
| 52 |
int update_apcupsd(void); |
52 |
void update_apcupsd(void); |
| 53 |
|
53 |
|
| 54 |
#endif /*APCUPSD_H_*/ |
54 |
#endif /*APCUPSD_H_*/ |