projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add standard include early or _FILE_OFFSET_BITS will have definition mismatches on...
[collectd.git]
/
src
/
email.c
diff --git
a/src/email.c
b/src/email.c
index
e1ce218
..
deb6600
100644
(file)
--- a/
src/email.c
+++ b/
src/email.c
@@
-40,8
+40,8
@@
#include "collectd.h"
#include "collectd.h"
-#include "common.h"
#include "plugin.h"
#include "plugin.h"
+#include "utils/common/common.h"
#include <stddef.h>
#include <stddef.h>
@@
-111,13
+111,13
@@
static const char *config_keys[] = {"SocketFile", "SocketGroup", "SocketPerms",
static int config_keys_num = STATIC_ARRAY_SIZE(config_keys);
/* socket configuration */
static int config_keys_num = STATIC_ARRAY_SIZE(config_keys);
/* socket configuration */
-static char *sock_file
= NULL
;
-static char *sock_group
= NULL
;
+static char *sock_file;
+static char *sock_group;
static int sock_perms = S_IRWXU | S_IRWXG;
static int max_conns = MAX_CONNS;
/* state of the plugin */
static int sock_perms = S_IRWXU | S_IRWXG;
static int max_conns = MAX_CONNS;
/* state of the plugin */
-static int disabled
= 0
;
+static int disabled;
/* thread managing "client" connections */
static pthread_t connector = (pthread_t)0;
/* thread managing "client" connections */
static pthread_t connector = (pthread_t)0;
@@
-134,7
+134,7
@@
static conn_list_t conns;
static pthread_cond_t collector_available = PTHREAD_COND_INITIALIZER;
/* collector threads */
static pthread_cond_t collector_available = PTHREAD_COND_INITIALIZER;
/* collector threads */
-static collector_t **collectors
= NULL
;
+static collector_t **collectors;
static pthread_mutex_t available_mutex = PTHREAD_MUTEX_INITIALIZER;
static int available_collectors;
static pthread_mutex_t available_mutex = PTHREAD_MUTEX_INITIALIZER;
static int available_collectors;
@@
-260,23
+260,20
@@
static void *collect(void *arg) {
while (42) {
/* 256 bytes ought to be enough for anybody ;-) */
char line[256 + 1]; /* line + '\0' */
while (42) {
/* 256 bytes ought to be enough for anybody ;-) */
char line[256 + 1]; /* line + '\0' */
- int len = 0;
errno = 0;
if (fgets(line, sizeof(line), this->socket) == NULL) {
if (errno != 0) {
errno = 0;
if (fgets(line, sizeof(line), this->socket) == NULL) {
if (errno != 0) {
- char errbuf[1024];
log_err("collect: reading from socket (fd #%i) "
"failed: %s",
log_err("collect: reading from socket (fd #%i) "
"failed: %s",
- fileno(this->socket),
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ fileno(this->socket), STRERRNO);
}
break;
}
}
break;
}
- len = strlen(line);
+
size_t
len = strlen(line);
if ((line[len - 1] != '\n') && (line[len - 1] != '\r')) {
if ((line[len - 1] != '\n') && (line[len - 1] != '\r')) {
- log_warn("collect: line too long (> %
zu
characters): "
+ log_warn("collect: line too long (> %
" PRIsz "
characters): "
"'%s' (truncated)",
sizeof(line) - 1, line);
"'%s' (truncated)",
sizeof(line) - 1, line);
@@
-289,7
+286,7
@@
static void *collect(void *arg) {
continue;
}
continue;
}
- line[len - 1] =
0
;
+ line[len - 1] =
'\0'
;
log_debug("collect: line = '%s'", line);
log_debug("collect: line = '%s'", line);
@@
-366,9
+363,8
@@
static void *open_connection(void __attribute__((unused)) * arg) {
/* create UNIX socket */
errno = 0;
if ((connector_socket = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) {
/* create UNIX socket */
errno = 0;
if ((connector_socket = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) {
- char errbuf[1024];
disabled = 1;
disabled = 1;
- log_err("socket() failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf))
);
+ log_err("socket() failed: %s",
STRERRNO
);
pthread_exit((void *)1);
}
pthread_exit((void *)1);
}
@@
-381,21
+377,19
@@
static void *open_connection(void __attribute__((unused)) * arg) {
if (bind(connector_socket, (struct sockaddr *)&addr,
offsetof(struct sockaddr_un, sun_path) + strlen(addr.sun_path)) ==
-1) {
if (bind(connector_socket, (struct sockaddr *)&addr,
offsetof(struct sockaddr_un, sun_path) + strlen(addr.sun_path)) ==
-1) {
- char errbuf[1024];
disabled = 1;
close(connector_socket);
connector_socket = -1;
disabled = 1;
close(connector_socket);
connector_socket = -1;
- log_err("bind() failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf))
);
+ log_err("bind() failed: %s",
STRERRNO
);
pthread_exit((void *)1);
}
errno = 0;
if (listen(connector_socket, 5) == -1) {
pthread_exit((void *)1);
}
errno = 0;
if (listen(connector_socket, 5) == -1) {
- char errbuf[1024];
disabled = 1;
close(connector_socket);
connector_socket = -1;
disabled = 1;
close(connector_socket);
connector_socket = -1;
- log_err("listen() failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf))
);
+ log_err("listen() failed: %s",
STRERRNO
);
pthread_exit((void *)1);
}
pthread_exit((void *)1);
}
@@
-414,25
+408,21
@@
static void *open_connection(void __attribute__((unused)) * arg) {
grp = NULL;
status = getgrnam_r(group, &sg, grbuf, sizeof(grbuf), &grp);
if (status != 0) {
grp = NULL;
status = getgrnam_r(group, &sg, grbuf, sizeof(grbuf), &grp);
if (status != 0) {
- char errbuf[1024];
- log_warn("getgrnam_r (%s) failed: %s", group,
- sstrerror(status, errbuf, sizeof(errbuf)));
+ log_warn("getgrnam_r (%s) failed: %s", group, STRERROR(status));
} else if (grp == NULL) {
log_warn("No such group: `%s'", group);
} else {
status = chown(path, (uid_t)-1, grp->gr_gid);
if (status != 0) {
} else if (grp == NULL) {
log_warn("No such group: `%s'", group);
} else {
status = chown(path, (uid_t)-1, grp->gr_gid);
if (status != 0) {
- char errbuf[1024];
log_warn("chown (%s, -1, %i) failed: %s", path, (int)grp->gr_gid,
log_warn("chown (%s, -1, %i) failed: %s", path, (int)grp->gr_gid,
-
sstrerror(errno, errbuf, sizeof(errbuf))
);
+
STRERRNO
);
}
}
}
errno = 0;
if (chmod(path, sock_perms) != 0) {
}
}
}
errno = 0;
if (chmod(path, sock_perms) != 0) {
- char errbuf[1024];
- log_warn("chmod() failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_warn("chmod() failed: %s", STRERRNO);
}
{ /* initialize collector threads */
}
{ /* initialize collector threads */
@@
-454,9
+444,7
@@
static void *open_connection(void __attribute__((unused)) * arg) {
if (plugin_thread_create(&collectors[i]->thread, &ptattr, collect,
collectors[i], "email collector") != 0) {
if (plugin_thread_create(&collectors[i]->thread, &ptattr, collect,
collectors[i], "email collector") != 0) {
- char errbuf[1024];
- log_err("plugin_thread_create() failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_err("plugin_thread_create() failed: %s", STRERRNO);
collectors[i]->thread = (pthread_t)0;
}
}
collectors[i]->thread = (pthread_t)0;
}
}
@@
-484,16
+472,13
@@
static void *open_connection(void __attribute__((unused)) * arg) {
remote = accept(connector_socket, NULL, NULL);
if (remote == -1) {
remote = accept(connector_socket, NULL, NULL);
if (remote == -1) {
- char errbuf[1024];
-
if (errno == EINTR)
continue;
disabled = 1;
close(connector_socket);
connector_socket = -1;
if (errno == EINTR)
continue;
disabled = 1;
close(connector_socket);
connector_socket = -1;
- log_err("accept() failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_err("accept() failed: %s", STRERRNO);
pthread_exit((void *)1);
}
pthread_exit((void *)1);
}
@@
-538,10
+523,8
@@
static void *open_connection(void __attribute__((unused)) * arg) {
static int email_init(void) {
if (plugin_thread_create(&connector, NULL, open_connection, NULL,
"email listener") != 0) {
static int email_init(void) {
if (plugin_thread_create(&connector, NULL, open_connection, NULL,
"email listener") != 0) {
- char errbuf[1024];
disabled = 1;
disabled = 1;
- log_err("plugin_thread_create() failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ log_err("plugin_thread_create() failed: %s", STRERRNO);
return -1;
}
return -1;
}