projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Refactor collectd binary to separate Unix-specific code.
[collectd.git]
/
src
/
hddtemp.c
diff --git
a/src/hddtemp.c
b/src/hddtemp.c
index
321c165
..
80daf15
100644
(file)
--- a/
src/hddtemp.c
+++ b/
src/hddtemp.c
@@
-53,7
+53,7
@@
static const char *config_keys[] = {"Host", "Port"};
static int config_keys_num = STATIC_ARRAY_SIZE(config_keys);
static const char *config_keys[] = {"Host", "Port"};
static int config_keys_num = STATIC_ARRAY_SIZE(config_keys);
-static char *hddtemp_host
= NULL
;
+static char *hddtemp_host;
static char hddtemp_port[16];
/*
static char hddtemp_port[16];
/*
@@
-108,11
+108,9
@@
static char *hddtemp_query_daemon(void) {
.ai_socktype = SOCK_STREAM};
if ((ai_return = getaddrinfo(host, port, &ai_hints, &ai_list)) != 0) {
.ai_socktype = SOCK_STREAM};
if ((ai_return = getaddrinfo(host, port, &ai_hints, &ai_list)) != 0) {
- char errbuf[1024];
ERROR("hddtemp plugin: getaddrinfo (%s, %s): %s", host, port,
ERROR("hddtemp plugin: getaddrinfo (%s, %s): %s", host, port,
- (ai_return == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
- : gai_strerror(ai_return));
- return (NULL);
+ (ai_return == EAI_SYSTEM) ? STRERRNO : gai_strerror(ai_return));
+ return NULL;
}
fd = -1;
}
fd = -1;
@@
-121,17
+119,13
@@
static char *hddtemp_query_daemon(void) {
/* create our socket descriptor */
fd = socket(ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
if (fd < 0) {
/* create our socket descriptor */
fd = socket(ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
if (fd < 0) {
- char errbuf[1024];
- ERROR("hddtemp plugin: socket: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("hddtemp plugin: socket: %s", STRERRNO);
continue;
}
/* connect to the hddtemp daemon */
if (connect(fd, (struct sockaddr *)ai_ptr->ai_addr, ai_ptr->ai_addrlen)) {
continue;
}
/* connect to the hddtemp daemon */
if (connect(fd, (struct sockaddr *)ai_ptr->ai_addr, ai_ptr->ai_addrlen)) {
- char errbuf[1024];
- INFO("hddtemp plugin: connect (%s, %s) failed: %s", host, port,
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ INFO("hddtemp plugin: connect (%s, %s) failed: %s", host, port, STRERRNO);
close(fd);
fd = -1;
continue;
close(fd);
fd = -1;
continue;
@@
-146,7
+140,7
@@
static char *hddtemp_query_daemon(void) {
if (fd < 0) {
ERROR("hddtemp plugin: Could not connect to daemon.");
if (fd < 0) {
ERROR("hddtemp plugin: Could not connect to daemon.");
- return
(NULL)
;
+ return
NULL
;
}
/* receive data from the hddtemp daemon */
}
/* receive data from the hddtemp daemon */
@@
-169,7
+163,7
@@
static char *hddtemp_query_daemon(void) {
close(fd);
free(buffer);
ERROR("hddtemp plugin: Allocation failed.");
close(fd);
free(buffer);
ERROR("hddtemp plugin: Allocation failed.");
- return
(NULL)
;
+ return
NULL
;
}
buffer = new_buffer;
}
}
buffer = new_buffer;
}
@@
-177,16
+171,14
@@
static char *hddtemp_query_daemon(void) {
if (status == 0) {
break;
} else if (status == -1) {
if (status == 0) {
break;
} else if (status == -1) {
- char errbuf[1024];
if ((errno == EAGAIN) || (errno == EINTR))
continue;
if ((errno == EAGAIN) || (errno == EINTR))
continue;
- ERROR("hddtemp plugin: Error reading from socket: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("hddtemp plugin: Error reading from socket: %s", STRERRNO);
close(fd);
free(buffer);
close(fd);
free(buffer);
- return
(NULL)
;
+ return
NULL
;
}
buffer_fill += status;
}
}
buffer_fill += status;
}
@@
-197,13
+189,13
@@
static char *hddtemp_query_daemon(void) {
buffer);
close(fd);
free(buffer);
buffer);
close(fd);
free(buffer);
- return
(NULL)
;
+ return
NULL
;
}
assert(buffer_fill < buffer_size);
buffer[buffer_fill] = '\0';
close(fd);
}
assert(buffer_fill < buffer_size);
buffer[buffer_fill] = '\0';
close(fd);
- return
(buffer)
;
+ return
buffer
;
}
static int hddtemp_config(const char *key, const char *value) {
}
static int hddtemp_config(const char *key, const char *value) {
@@
-214,14
+206,14
@@
static int hddtemp_config(const char *key, const char *value) {
} else if (strcasecmp(key, "Port") == 0) {
int port = (int)(atof(value));
if ((port > 0) && (port <= 65535))
} else if (strcasecmp(key, "Port") == 0) {
int port = (int)(atof(value));
if ((port > 0) && (port <= 65535))
- s
s
nprintf(hddtemp_port, sizeof(hddtemp_port), "%i", port);
+ snprintf(hddtemp_port, sizeof(hddtemp_port), "%i", port);
else
sstrncpy(hddtemp_port, value, sizeof(hddtemp_port));
} else {
else
sstrncpy(hddtemp_port, value, sizeof(hddtemp_port));
} else {
- return
(-1)
;
+ return
-1
;
}
}
- return
(0)
;
+ return
0
;
}
static void hddtemp_submit(char *type_instance, double value) {
}
static void hddtemp_submit(char *type_instance, double value) {
@@
-248,7
+240,7
@@
static int hddtemp_read(void) {
/* get data from daemon */
buf = hddtemp_query_daemon();
if (buf == NULL)
/* get data from daemon */
buf = hddtemp_query_daemon();
if (buf == NULL)
- return
(-1)
;
+ return
-1
;
/* NB: strtok_r will eat up "||" and leading "|"'s */
ptr = buf;
/* NB: strtok_r will eat up "||" and leading "|"'s */
ptr = buf;
@@
-276,7
+268,7
@@
static int hddtemp_read(void) {
}
free(buf);
}
free(buf);
- return
(0)
;
+ return
0
;
} /* int hddtemp_read */
/* module_register
} /* int hddtemp_read */
/* module_register