summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 117f27d)
raw | patch | inline | side by side (parent: 117f27d)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Mon, 26 Mar 2007 08:15:04 +0000 (10:15 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Mon, 26 Mar 2007 08:15:04 +0000 (10:15 +0200) |
.. which internally uses the thread-safe function `strerror_r'.
35 files changed:
diff --git a/src/apcups.c b/src/apcups.c
index b5b939a1ebe7ddb0be33703500185ed646696fcb..fc94e7d778b4b16e9689284afe62d5be0fec7ca1 100644 (file)
--- a/src/apcups.c
+++ b/src/apcups.c
status = getaddrinfo (host, port_str, &ai_hints, &ai_return);
if (status != 0)
{
- DEBUG ("getaddrinfo failed: %s", status == EAI_SYSTEM ? strerror (errno) : gai_strerror (status));
+ char errbuf[1024];
+ DEBUG ("getaddrinfo failed: %s",
+ (status == EAI_SYSTEM)
+ ? sstrerror (errno, errbuf, sizeof (errbuf))
+ : gai_strerror (status));
return (-1);
}
if (status != 0) /* `connect(2)' failed */
{
- DEBUG ("connect failed: %s", strerror (errno));
+ char errbuf[1024];
+ DEBUG ("connect failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
close (sd);
return (-1);
}
diff --git a/src/battery.c b/src/battery.c
index 85bfc00ac373cd644be8a6ca6249c60356056d3b..53442ce6dc049a2145cb53a81460c3e63e934361 100644 (file)
--- a/src/battery.c
+++ b/src/battery.c
if ((dh = opendir ("/proc/acpi/battery")) == NULL)
{
- ERROR ("Cannot open `/proc/acpi/battery': %s", strerror (errno));
+ char errbuf[1024];
+ ERROR ("Cannot open `/proc/acpi/battery': %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
if ((fh = fopen (filename, "r")) == NULL)
{
- ERROR ("Cannot open `%s': %s", filename, strerror (errno));
+ char errbuf[1024];
+ ERROR ("Cannot open `%s': %s", filename,
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
continue;
}
diff --git a/src/collectd.c b/src/collectd.c
index e873adc2d5f58890ae2590fd9993732b6efa3a3a..9f3c62b7e17cec657a94df111544892c137d39c3 100644 (file)
--- a/src/collectd.c
+++ b/src/collectd.c
if (dir == NULL)
{
- ERROR ("strdup failed: %s", strerror (errno));
+ char errbuf[1024];
+ ERROR ("strdup failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
{
if (mkdir (orig_dir, 0755) == -1)
{
+ char errbuf[1024];
ERROR ("mkdir (%s): %s", orig_dir,
- strerror (errno));
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
return (-1);
}
else if (chdir (orig_dir) == -1)
{
+ char errbuf[1024];
ERROR ("chdir (%s): %s", orig_dir,
- strerror (errno));
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
return (-1);
}
}
else
{
+ char errbuf[1024];
ERROR ("chdir (%s): %s", orig_dir,
- strerror (errno));
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
return (-1);
}
}
{
if (gettimeofday (&tv_next, NULL) < 0)
{
- ERROR ("gettimeofday failed: %s", strerror (errno));
+ char errbuf[1024];
+ ERROR ("gettimeofday failed: %s",
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
return (-1);
}
tv_next.tv_sec += interval_g;
if (gettimeofday (&tv_now, NULL) < 0)
{
+ char errbuf[1024];
ERROR ("gettimeofday failed: %s",
- strerror (errno));
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
return (-1);
}
{
if (errno != EINTR)
{
- ERROR ("nanosleep failed: %s", strerror (errno));
+ char errbuf[1024];
+ ERROR ("nanosleep failed: %s",
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
return (-1);
}
}
if ((fh = fopen (file, "w")) == NULL)
{
- ERROR ("fopen (%s): %s", file, strerror (errno));
+ char errbuf[1024];
+ ERROR ("fopen (%s): %s", file,
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (1);
}
if ((pid = fork ()) == -1)
{
/* error */
- fprintf (stderr, "fork: %s", strerror (errno));
+ char errbuf[1024];
+ fprintf (stderr, "fork: %s",
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
return (1);
}
else if (pid != 0)
diff --git a/src/common.c b/src/common.c
index ede2ea5c26aea81720b23c16555216d942aa99d2..967a82af42c930fa01992df78774bf45d0f7945c 100644 (file)
--- a/src/common.c
+++ b/src/common.c
return (r);
}
+/* Don't use the return value of `strerror_r', because the GNU-people got
+ * inventive there.. -octo */
+char *sstrerror (int errnum, char *buf, size_t buflen)
+{
+ buf[0] = '\0';
+ strerror_r (errnum, buf, buflen);
+ return (buf);
+} /* char *sstrerror */
+
void *smalloc (size_t size)
{
void *r;
{
if (mkdir (dir, 0755) == -1)
{
- ERROR ("mkdir (%s): %s", dir, strerror (errno));
+ char errbuf[1024];
+ ERROR ("mkdir (%s): %s", dir,
+ sstrerror (errno,
+ errbuf, sizeof (errbuf)));
return (-1);
}
}
else
{
- ERROR ("stat (%s): %s", dir, strerror (errno));
+ char errbuf[1024];
+ ERROR ("stat (%s): %s", dir,
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
return (-1);
}
}
diff --git a/src/common.h b/src/common.h
index 9164cc2debd45994ab4bdb1944891e07f7975daa..310aa8a5ca2f1a4458c127aad58e8857d7d57c90 100644 (file)
--- a/src/common.h
+++ b/src/common.h
void sstrncpy(char *d, const char *s, int len);
char *sstrdup(const char *s);
void *smalloc(size_t size);
+char *sstrerror (int errnum, char *buf, size_t buflen);
/*
* NAME
diff --git a/src/cpu.c b/src/cpu.c
index 6f18b4f4cc4b2970972cff2e111858677728decb..1dcbdcd2b39b0d323aba0cdf4ea212bc117cc4bf 100644 (file)
--- a/src/cpu.c
+++ b/src/cpu.c
if (sysctlbyname ("hw.ncpu", &numcpu, &numcpu_size, NULL, 0) < 0)
{
- WARNING ("cpu: sysctlbyname: %s", strerror (errno));
+ char errbuf[1024];
+ WARNING ("cpu plugin: sysctlbyname: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
if ((fh = fopen ("/proc/stat", "r")) == NULL)
{
+ char errbuf[1024];
plugin_complain (LOG_ERR, &complain_obj, "cpu plugin: "
"fopen (/proc/stat) failed: %s",
- strerror (errno));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
if (sysctlbyname("kern.cp_time", &cpuinfo, &cpuinfo_size, NULL, 0) < 0)
{
+ char errbuf[1024];
plugin_complain (LOG_ERR, &complain_obj, "cpu plugin: "
"sysctlbyname failed: %s.",
- strerror (errno));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return;
}
diff --git a/src/cpufreq.c b/src/cpufreq.c
index 46e8659882381443dc8dc482b008fa2e6e1a2e72..5ceaacc8601ed92c20d3cc3f5501752d33caba83 100644 (file)
--- a/src/cpufreq.c
+++ b/src/cpufreq.c
if ((fp = fopen (filename, "r")) == NULL)
{
- WARNING ("cpufreq: fopen: %s", strerror (errno));
+ char errbuf[1024];
+ WARNING ("cpufreq: fopen (%s): %s", filename,
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
return (-1);
}
if (fgets (buffer, 16, fp) == NULL)
{
- WARNING ("cpufreq: fgets: %s", strerror (errno));
+ char errbuf[1024];
+ WARNING ("cpufreq: fgets: %s",
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
fclose (fp);
return (-1);
}
if (fclose (fp))
- WARNING ("cpufreq: fclose: %s", strerror (errno));
+ {
+ char errbuf[1024];
+ WARNING ("cpufreq: fclose: %s",
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
+ }
+
/* You're seeing correctly: The file is reporting kHz values.. */
val = atoll (buffer) * 1000;
diff --git a/src/csv.c b/src/csv.c
index 62b6b2c77c48f34e898d90e5a1e496631168c731..4379fe5fe4e4171b3b664406fb55d3be1c0aabb6 100644 (file)
--- a/src/csv.c
+++ b/src/csv.c
csv = fopen (filename, "w");
if (csv == NULL)
{
+ char errbuf[1024];
ERROR ("csv plugin: fopen (%s) failed: %s",
- filename, strerror(errno));
+ filename,
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
}
else
{
- ERROR ("stat(%s) failed: %s",
- filename, strerror (errno));
+ char errbuf[1024];
+ ERROR ("stat(%s) failed: %s", filename,
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
return (-1);
}
}
csv = fopen (filename, "a");
if (csv == NULL)
{
- ERROR ("csv plugin: fopen (%s) failed: %s",
- filename, strerror (errno));
+ char errbuf[1024];
+ ERROR ("csv plugin: fopen (%s) failed: %s", filename,
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
csv_fd = fileno (csv);
status = fcntl (csv_fd, F_SETLK, &fl);
if (status != 0)
{
- ERROR ("csv plugin: flock (%s) failed: %s",
- filename, strerror (errno));
+ char errbuf[1024];
+ ERROR ("csv plugin: flock (%s) failed: %s", filename,
+ sstrerror (errno, errbuf, sizeof (errbuf)));
fclose (csv);
return (-1);
}
diff --git a/src/df.c b/src/df.c
index 6ec51fe314671fb28b885db27deaaa5b17882423..48d58c3fe315197469035cb0ee8f87fbd68c3a21 100644 (file)
--- a/src/df.c
+++ b/src/df.c
{
if (STATANYFS (mnt_ptr->dir, &statbuf) < 0)
{
- ERROR ("statv?fs failed: %s", strerror (errno));
+ char errbuf[1024];
+ ERROR ("statv?fs failed: %s",
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
continue;
}
diff --git a/src/dns.c b/src/dns.c
index 11dc287425fde2e2bc725fb67ccd8481ed536202..255d1760394bdc4f04832fa119b2192d9b621f0a 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
(void *) 0);
if (status != 0)
{
+ char errbuf[1024];
ERROR ("dns plugin: pthread_create failed: %s",
- strerror (status));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
diff --git a/src/email.c b/src/email.c
index a0278336f059bd5a79fe1fde2d69c43e0e4b795e..c8c3982b7a4836be5491ac3196954fa6a4986f44 100644 (file)
--- a/src/email.c
+++ b/src/email.c
FD_SET (src->socket, &fdset);
if (-1 == select (src->socket + 1, &fdset, NULL, NULL, NULL)) {
- log_err ("select() failed: %s", strerror (errno));
+ char errbuf[1024];
+ log_err ("select() failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return '\0';
}
errno = 0;
if (0 > (len = read (src->socket, (void *)&ret, 1))) {
if (EINTR != errno) {
- log_err ("read() failed: %s", strerror (errno));
+ char errbuf[1024];
+ log_err ("read() failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return '\0';
}
}
FD_SET (src->socket, &fdset);
if (-1 == select (src->socket + 1, &fdset, NULL, NULL, NULL)) {
- log_err ("select() failed: %s", strerror (errno));
+ char errbuf[1024];
+ log_err ("select() failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return NULL;
}
(void *)(src->buffer + src->idx),
BUFSIZE - src->idx))) {
if (EINTR != errno) {
- log_err ("read() failed: %s", strerror (errno));
+ char errbuf[1024];
+ log_err ("read() failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return NULL;
}
}
errno = 0;
if (-1 == fcntl (connection->socket, F_GETFL, &flags)) {
- log_err ("fcntl() failed: %s", strerror (errno));
+ char errbuf[1024];
+ log_err ("fcntl() failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
loop = 0;
}
errno = 0;
if (-1 == fcntl (connection->socket, F_SETFL, flags | O_NONBLOCK)) {
- log_err ("fcntl() failed: %s", strerror (errno));
+ char errbuf[1024];
+ log_err ("fcntl() failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
loop = 0;
}
}
/* create UNIX socket */
errno = 0;
if (-1 == (connector_socket = socket (PF_UNIX, SOCK_STREAM, 0))) {
+ char errbuf[1024];
disabled = 1;
- log_err ("socket() failed: %s", strerror (errno));
+ log_err ("socket() failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
pthread_exit ((void *)1);
}
if (-1 == bind (connector_socket, (struct sockaddr *)&addr,
offsetof (struct sockaddr_un, sun_path)
+ strlen(addr.sun_path))) {
+ char errbuf[1024];
disabled = 1;
- log_err ("bind() failed: %s", strerror (errno));
+ log_err ("bind() failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
pthread_exit ((void *)1);
}
errno = 0;
if (-1 == listen (connector_socket, 5)) {
+ char errbuf[1024];
disabled = 1;
- log_err ("listen() failed: %s", strerror (errno));
+ log_err ("listen() failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
pthread_exit ((void *)1);
}
status = getgrnam_r (sock_group, &sg, grbuf, sizeof (grbuf), &grp);
if (status != 0)
{
- log_warn ("getgrnam_r (%s) failed: %s", sock_group, strerror (status));
+ char errbuf[1024];
+ log_warn ("getgrnam_r (%s) failed: %s", sock_group,
+ sstrerror (errno, errbuf, sizeof (errbuf)));
}
else if (grp == NULL)
{
{
status = chown (SOCK_PATH, (uid_t) -1, grp->gr_gid);
if (status != 0)
+ {
+ char errbuf[1024];
log_warn ("chown (%s, -1, %i) failed: %s",
- SOCK_PATH, (int) grp->gr_gid, strerror (errno));
+ SOCK_PATH, (int) grp->gr_gid,
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ }
}
}
else /* geteuid != 0 */
errno = 0;
if (0 != chmod (SOCK_PATH, sock_perms)) {
- log_warn ("chmod() failed: %s", strerror (errno));
+ char errbuf[1024];
+ log_warn ("chmod() failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
}
{ /* initialize collector threads */
if (0 != (err = pthread_create (&collectors[i]->thread, &ptattr,
collect, collectors[i]))) {
- log_err ("pthread_create() failed: %s", strerror (err));
+ char errbuf[1024];
+ log_err ("pthread_create() failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
}
}
errno = 0;
if (-1 == (remote = accept (connector_socket, NULL, NULL))) {
if (EINTR != errno) {
+ char errbuf[1024];
disabled = 1;
- log_err ("accept() failed: %s", strerror (errno));
+ log_err ("accept() failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
pthread_exit ((void *)1);
}
}
if (0 != (err = pthread_create (&connector, NULL,
open_connection, NULL))) {
+ char errbuf[1024];
disabled = 1;
- log_err ("pthread_create() failed: %s", strerror (err));
+ log_err ("pthread_create() failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
diff --git a/src/exec.c b/src/exec.c
index fa0196b3470a85b01fc309fde54973945c17245e..c7c72029e278d686511c378f2f774b8462fd01b1 100644 (file)
--- a/src/exec.c
+++ b/src/exec.c
struct passwd *sp_ptr;
struct passwd sp;
char pwnambuf[2048];
+ char errbuf[1024];
sp_ptr = NULL;
status = getpwnam_r (pl->user, &sp, pwnambuf, sizeof (pwnambuf), &sp_ptr);
if (status != 0)
{
- ERROR ("exec plugin: getpwnam_r failed: %s", strerror (status));
+ ERROR ("exec plugin: getpwnam_r failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
exit (-1);
}
if (sp_ptr == NULL)
status = setuid (uid);
if (status != 0)
{
- ERROR ("exec plugin: setuid failed: %s", strerror (errno));
+ ERROR ("exec plugin: setuid failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
exit (-1);
}
status = execlp (pl->exec, arg0, (char *) 0);
- ERROR ("exec plugin: exec failed: %s", strerror (errno));
+ ERROR ("exec plugin: exec failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
exit (-1);
} /* void exec_child */
status = pipe (fd_pipe);
if (status != 0)
{
- ERROR ("exec plugin: pipe failed: %s", strerror (errno));
+ char errbuf[1024];
+ ERROR ("exec plugin: pipe failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
pl->pid = fork ();
if (pl->pid < 0)
{
- ERROR ("exec plugin: fork failed: %s", strerror (errno));
+ char errbuf[1024];
+ ERROR ("exec plugin: fork failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
else if (pl->pid == 0)
fh = fdopen (fd, "r");
if (fh == NULL)
{
+ char errbuf[1024];
ERROR ("exec plugin: fdopen (%i) failed: %s", fd,
- strerror (errno));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
kill (pl->pid, SIGTERM);
close (fd);
pthread_exit ((void *) 1);
diff --git a/src/hddtemp.c b/src/hddtemp.c
index c2ff19e5773144717bd1657d6f94aa9e46fdc16e..a7758613336ce69a44feba077d4c9940d47cca5d 100644 (file)
--- a/src/hddtemp.c
+++ b/src/hddtemp.c
if ((ai_return = getaddrinfo (host, port, &ai_hints, &ai_list)) != 0)
{
+ char errbuf[1024];
ERROR ("hddtemp: getaddrinfo (%s, %s): %s",
host, port,
- ai_return == EAI_SYSTEM ? strerror (errno) : gai_strerror (ai_return));
+ (ai_return == EAI_SYSTEM)
+ ? sstrerror (errno, errbuf, sizeof (errbuf))
+ : gai_strerror (ai_return));
return (-1);
}
/* create our socket descriptor */
if ((fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol)) < 0)
{
+ char errbuf[1024];
ERROR ("hddtemp: socket: %s",
- strerror (errno));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
continue;
}
/* connect to the hddtemp daemon */
if (connect (fd, (struct sockaddr *) ai_ptr->ai_addr, ai_ptr->ai_addrlen))
{
+ char errbuf[1024];
DEBUG ("hddtemp: connect (%s, %s): %s", host, port,
- strerror (errno));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
close (fd);
fd = -1;
continue;
{
if (status == -1)
{
+ char errbuf[1024];
+
if ((errno == EAGAIN) || (errno == EINTR))
continue;
ERROR ("hddtemp: Error reading from socket: %s",
- strerror (errno));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
close (fd);
return (-1);
}
}
fclose (fh);
}
+#if COLLECT_DEBUG
else
+ {
+ char errbuf[1024];
DEBUG ("Could not open /proc/partitions: %s",
- strerror (errno));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ }
+#endif /* COLLECT_DEBUG */
#endif /* KERNEL_LINUX */
return (0);
diff --git a/src/iptables.c b/src/iptables.c
index bc15559317c3f533c9bca9dcf5e9e306e87f5747..47f0e550ce70e8dac757d18df52ccfe5cc2ba96b 100644 (file)
--- a/src/iptables.c
+++ b/src/iptables.c
value_copy = strdup (value);
if (value_copy == NULL)
{
- ERROR ("strdup failed: %s", strerror (errno));
+ char errbuf[1024];
+ ERROR ("strdup failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (1);
}
list = (ip_chain_t **) realloc (chain_list, (chain_num + 1) * sizeof (ip_chain_t *));
if (list == NULL)
{
- ERROR ("realloc failed: %s", strerror (errno));
- return (1);
+ char errbuf[1024];
+ ERROR ("realloc failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ return (1);
}
chain_list = list;
final = (ip_chain_t *) malloc( sizeof(temp) );
if (final == NULL)
{
- ERROR ("malloc failed: %s", strerror (errno));
- return (1);
+ char errbuf[1024];
+ ERROR ("malloc failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ return (1);
}
memcpy (final, &temp, sizeof (temp));
chain_list[chain_num] = final;
diff --git a/src/irq.c b/src/irq.c
index d44ac0b3a53373c4f994398cfa05000b7091f0ff..e39d0a5721d3bbdef2cbd4e6a9eafcc9d6c05ce9 100644 (file)
--- a/src/irq.c
+++ b/src/irq.c
if ((fh = fopen ("/proc/interrupts", "r")) == NULL)
{
+ char errbuf[1024];
WARNING ("irq plugin: fopen (/proc/interrupts): %s",
- strerror (errno));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
while (fgets (buffer, BUFSIZE, fh) != NULL)
diff --git a/src/load.c b/src/load.c
index aaba3a5f2c650bcf54928000498ba47ec9b18565..b92e54f53b60380b77df26f7e1225a571f36c4d3 100644 (file)
--- a/src/load.c
+++ b/src/load.c
if (getloadavg (load, 3) == 3)
load_submit (load[LOADAVG_1MIN], load[LOADAVG_5MIN], load[LOADAVG_15MIN]);
else
- WARNING ("load: getloadavg failed: %s", strerror (errno));
+ {
+ char errbuf[1024];
+ WARNING ("load: getloadavg failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ }
/* #endif HAVE_GETLOADAVG */
#elif defined(KERNEL_LINUX)
if ((loadavg = fopen ("/proc/loadavg", "r")) == NULL)
{
- WARNING ("load: fopen: %s", strerror (errno));
+ char errbuf[1024];
+ WARNING ("load: fopen: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return;
}
if (fgets (buffer, 16, loadavg) == NULL)
{
- WARNING ("load: fgets: %s", strerror (errno));
+ char errbuf[1024];
+ WARNING ("load: fgets: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
fclose (loadavg);
return;
}
if (fclose (loadavg))
- WARNING ("load: fclose: %s", strerror (errno));
+ {
+ char errbuf[1024];
+ WARNING ("load: fclose: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ }
numfields = strsplit (buffer, fields, 8);
diff --git a/src/mbmon.c b/src/mbmon.c
index 241d7d042b57e8a88f165cb643c0f731c598c3af..fcb4cc747d6ca5dc168fb5b39afe465acd6041c6 100644 (file)
--- a/src/mbmon.c
+++ b/src/mbmon.c
if ((ai_return = getaddrinfo (host, port, &ai_hints, &ai_list)) != 0)
{
+ char errbuf[1024];
ERROR ("mbmon: getaddrinfo (%s, %s): %s",
host, port,
- ai_return == EAI_SYSTEM ? strerror (errno) : gai_strerror (ai_return));
+ (ai_return == EAI_SYSTEM)
+ ? sstrerror (errno, errbuf, sizeof (errbuf))
+ : gai_strerror (ai_return));
return (-1);
}
/* create our socket descriptor */
if ((fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol)) < 0)
{
+ char errbuf[1024];
ERROR ("mbmon: socket: %s",
- strerror (errno));
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
continue;
}
/* connect to the mbmon daemon */
if (connect (fd, (struct sockaddr *) ai_ptr->ai_addr, ai_ptr->ai_addrlen))
{
+ char errbuf[1024];
DEBUG ("mbmon: connect (%s, %s): %s", host, port,
- strerror (errno));
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
close (fd);
fd = -1;
continue;
{
if (status == -1)
{
+ char errbuf[1024];
+
if ((errno == EAGAIN) || (errno == EINTR))
continue;
ERROR ("mbmon: Error reading from socket: %s",
- strerror (errno));
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
close (fd);
return (-1);
}
diff --git a/src/memory.c b/src/memory.c
index 916802794c94b8a1e4339036900c41048fedfc9a..66bcefaee62dd48cd23ea5158ab586189da5d1cc 100644 (file)
--- a/src/memory.c
+++ b/src/memory.c
(void *) &sysctl_vals[i], &len,
NULL, 0)) < 0)
{
+ char errbuf[1024];
ERROR ("memory plugin: sysctlbyname (%s): %s",
- sysctl_keys[i], strerror (errno));
+ sysctl_keys[i],
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
return (-1);
}
DEBUG ("%26s: %6i", sysctl_keys[i], sysctl_vals[i]);
if ((fh = fopen ("/proc/meminfo", "r")) == NULL)
{
- WARNING ("memory: fopen: %s", strerror (errno));
+ char errbuf[1024];
+ WARNING ("memory: fopen: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
}
if (fclose (fh))
- WARNING ("memory: fclose: %s", strerror (errno));
+ {
+ char errbuf[1024];
+ WARNING ("memory: fclose: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ }
if (mem_used >= (mem_free + mem_buffered + mem_cached))
{
diff --git a/src/multimeter.c b/src/multimeter.c
index 04196bbefb3e9d5460aced62e0be2cac47188033..d80c990cebffeaefa00aea2bc1e80008ff27c19e 100644 (file)
--- a/src/multimeter.c
+++ b/src/multimeter.c
if (gettimeofday (&time_end, NULL) < 0)
{
+ char errbuf[1024];
ERROR ("multimeter plugin: gettimeofday failed: %s",
- strerror (errno));
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
return (-1);
}
time_end.tv_sec++;
if (gettimeofday (&time_now, NULL) < 0)
{
+ char errbuf[1024];
ERROR ("multimeter plugin: "
"gettimeofday failed: %s",
- strerror (errno));
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
return (-1);
}
if (multimeter_timeval_sub (&time_end, &time_now, &timeout) == -1)
}
else /* status == -1 */
{
+ char errbuf[1024];
ERROR ("multimeter plugin: "
"select failed: %s",
- strerror (errno));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
break;
}
}
diff --git a/src/network.c b/src/network.c
index 6c6e0f60a69fc1478efab4ba46a3cdb03f0971b1..b59b16d2d4a7cc77c50080d8a0b7656426f66d35 100644 (file)
--- a/src/network.c
+++ b/src/network.c
&network_config_ttl,
sizeof (network_config_ttl)) == -1)
{
- ERROR ("setsockopt: %s", strerror (errno));
+ char errbuf[1024];
+ ERROR ("setsockopt: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
}
&network_config_ttl,
sizeof (network_config_ttl)) == -1)
{
- ERROR ("setsockopt: %s", strerror (errno));
+ char errbuf[1024];
+ ERROR ("setsockopt: %s",
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
return (-1);
}
}
if (bind (se->fd, ai->ai_addr, ai->ai_addrlen) == -1)
{
- ERROR ("bind: %s", strerror (errno));
+ char errbuf[1024];
+ ERROR ("bind: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
@@ -555,14 +562,20 @@ static int network_bind_socket (const sockent_t *se, const struct addrinfo *ai)
if (setsockopt (se->fd, IPPROTO_IP, IP_MULTICAST_LOOP,
&loop, sizeof (loop)) == -1)
{
- ERROR ("setsockopt: %s", strerror (errno));
+ char errbuf[1024];
+ ERROR ("setsockopt: %s",
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
return (-1);
}
if (setsockopt (se->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
&mreq, sizeof (mreq)) == -1)
{
- ERROR ("setsockopt: %s", strerror (errno));
+ char errbuf[1024];
+ ERROR ("setsockopt: %s",
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
return (-1);
}
}
@@ -595,14 +608,20 @@ static int network_bind_socket (const sockent_t *se, const struct addrinfo *ai)
if (setsockopt (se->fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP,
&loop, sizeof (loop)) == -1)
{
- ERROR ("setsockopt: %s", strerror (errno));
+ char errbuf[1024];
+ ERROR ("setsockopt: %s",
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
return (-1);
}
if (setsockopt (se->fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP,
&mreq, sizeof (mreq)) == -1)
{
- ERROR ("setsockopt: %s", strerror (errno));
+ char errbuf[1024];
+ ERROR ("setsockopt: %s",
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
return (-1);
}
}
ai_return = getaddrinfo (node, service, &ai_hints, &ai_list);
if (ai_return != 0)
{
+ char errbuf[1024];
ERROR ("getaddrinfo (%s, %s): %s",
(node == NULL) ? "(null)" : node,
(service == NULL) ? "(null)" : service,
(ai_return == EAI_SYSTEM)
- ? strerror (errno)
+ ? sstrerror (errno, errbuf, sizeof (errbuf))
: gai_strerror (ai_return));
return (NULL);
}
if ((se = (sockent_t *) malloc (sizeof (sockent_t))) == NULL)
{
- ERROR ("malloc: %s", strerror (errno));
+ char errbuf[1024];
+ ERROR ("malloc: %s",
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
continue;
}
if ((se->addr = (struct sockaddr_storage *) malloc (sizeof (struct sockaddr_storage))) == NULL)
{
- ERROR ("malloc: %s", strerror (errno));
+ char errbuf[1024];
+ ERROR ("malloc: %s",
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
free (se);
continue;
}
if (se->fd == -1)
{
- ERROR ("socket: %s", strerror (errno));
+ char errbuf[1024];
+ ERROR ("socket: %s",
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
free (se->addr);
free (se);
continue;
if (status <= 0)
{
+ char errbuf[1024];
if (errno == EINTR)
continue;
ERROR ("poll failed: %s",
- strerror (errno));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
0 /* no flags */);
if (buffer_len < 0)
{
- ERROR ("recv failed: %s", strerror (errno));
+ char errbuf[1024];
+ ERROR ("recv failed: %s",
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
return (-1);
}
(struct sockaddr *) se->addr, se->addrlen);
if (status < 0)
{
+ char errbuf[1024];
if (errno == EINTR)
continue;
ERROR ("network plugin: sendto failed: %s",
- strerror (errno));
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
break;
}
receive_thread, NULL /* no argument */);
if (status != 0)
+ {
+ char errbuf[1024];
ERROR ("network: pthread_create failed: %s",
- strerror (errno));
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
+ }
}
return (0);
} /* int network_init */
diff --git a/src/nfs.c b/src/nfs.c
index 81f07937eb5f3c315c87756ac378df420ee24ea8..d54c838852e0dc9a6a6f0c7afebf4a8ae78ac19f 100644 (file)
--- a/src/nfs.c
+++ b/src/nfs.c
values = (unsigned long long *) malloc (nfs2_procedures_names_num * sizeof (unsigned long long));
if (values == NULL)
{
+ char errbuf[1024];
ERROR ("nfs plugin: malloc "
"failed: %s",
- strerror (errno));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
continue;
}
values = (unsigned long long *) malloc (nfs3_procedures_names_num * sizeof (unsigned long long));
if (values == NULL)
{
+ char errbuf[1024];
ERROR ("nfs plugin: malloc "
"failed: %s",
- strerror (errno));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
continue;
}
diff --git a/src/ntpd.c b/src/ntpd.c
index 668e302dee53f43cedd355e14cae4a556396e6f1..dded360c68114a349533a4b41f41f5324d51fa8d 100644 (file)
--- a/src/ntpd.c
+++ b/src/ntpd.c
if ((status = getaddrinfo (host, port, &ai_hints, &ai_list)) != 0)
{
- DEBUG ("getaddrinfo (%s, %s): %s",
- host, port,
- status == EAI_SYSTEM ? strerror (errno) : gai_strerror (status));
+ char errbuf[1024];
ERROR ("ntpd plugin: getaddrinfo (%s, %s): %s",
host, port,
- status == EAI_SYSTEM ? strerror (errno) : gai_strerror (status));
+ (status == EAI_SYSTEM)
+ ? sstrerror (errno, errbuf, sizeof (errbuf))
+ : gai_strerror (status));
return (-1);
}
if (gettimeofday (&time_end, NULL) < 0)
{
+ char errbuf[1024];
ERROR ("ntpd plugin: gettimeofday failed: %s",
- strerror (errno));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
time_end.tv_sec++; /* wait for a most one second */
{
if (gettimeofday (&time_now, NULL) < 0)
{
+ char errbuf[1024];
ERROR ("ntpd plugin: gettimeofday failed: %s",
- strerror (errno));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
if (status < 0)
{
- DEBUG ("poll failed: %s", strerror (errno));
+ char errbuf[1024];
ERROR ("ntpd plugin: poll failed: %s",
- strerror (errno));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
if (status < 0)
{
- DEBUG ("recv(2) failed: %s", strerror (errno));
+ char errbuf[1024];
+ DEBUG ("recv(2) failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
DEBUG ("Closing socket #%i", sd);
close (sd);
sock_descr = sd = -1;
NULL, 0, 0 /* no flags */);
if (status != 0)
{
+ char errbuf[1024];
ERROR ("ntpd plugin: getnameinfo failed: %s",
- status == EAI_SYSTEM
- ? strerror (errno)
+ (status == EAI_SYSTEM)
+ ? sstrerror (errno, errbuf, sizeof (errbuf))
: gai_strerror (status));
continue;
}
diff --git a/src/ping.c b/src/ping.c
index 48a0ac87ef513c72b28bc73c8922083b088398ac..3ac7aaba0b5715e220bea8241e50e5e56d119f7a 100644 (file)
--- a/src/ping.c
+++ b/src/ping.c
if ((hl = (hostlist_t *) malloc (sizeof (hostlist_t))) == NULL)
{
+ char errbuf[1024];
ERROR ("ping plugin: malloc failed: %s",
- strerror (errno));
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
return (1);
}
if ((host = strdup (value)) == NULL)
{
+ char errbuf[1024];
free (hl);
ERROR ("ping plugin: strdup failed: %s",
- strerror (errno));
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
return (1);
}
diff --git a/src/plugin.c b/src/plugin.c
index 87fdcce69b88bb4fd123ae1ccbd86965f25fadbe..e49963a65175d260a11932ed774da63767a847ac 100644 (file)
--- a/src/plugin.c
+++ b/src/plugin.c
#include <ltdl.h>
+#include "common.h"
#include "plugin.h"
#include "configfile.h"
#include "utils_llist.h"
if (dir == NULL)
plugindir = NULL;
else if ((plugindir = strdup (dir)) == NULL)
- ERROR ("strdup failed: %s", strerror (errno));
+ {
+ char errbuf[1024];
+ ERROR ("strdup failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ }
}
#define BUFSIZE 512
if ((dh = opendir (dir)) == NULL)
{
- ERROR ("opendir (%s): %s", dir, strerror (errno));
+ char errbuf[1024];
+ ERROR ("opendir (%s): %s", dir,
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
if (lstat (filename, &statbuf) == -1)
{
- WARNING ("stat %s: %s", filename, strerror (errno));
+ char errbuf[1024];
+ WARNING ("stat %s: %s", filename,
+ sstrerror (errno, errbuf, sizeof (errbuf)));
continue;
}
else if (!S_ISREG (statbuf.st_mode))
rf = (read_func_t *) malloc (sizeof (read_func_t));
if (rf == NULL)
{
+ char errbuf[1024];
ERROR ("plugin_register_read: malloc failed: %s",
- strerror (errno));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
plugin_log (level, message);
}
+
+const data_set_t *plugin_get_ds (const char *name)
+{
+ data_set_t *ds;
+ llentry_t *le;
+
+ le = llist_search (list_data_set, name);
+ if (le == NULL)
+ {
+ DEBUG ("No such dataset registered: %s", name);
+ return (NULL);
+ }
+
+ ds = (data_set_t *) le->value;
+
+ return (ds);
+} /* data_set_t *plugin_get_ds */
diff --git a/src/plugin.h b/src/plugin.h
index cf2c3f775dcbd66310f8883b4e016e3dc48c1118..f88bc48ab2d93970af4e64a1448cd18f0ac411b6 100644 (file)
--- a/src/plugin.h
+++ b/src/plugin.h
void plugin_complain (int level, complain_t *c, const char *format, ...);
void plugin_relief (int level, complain_t *c, const char *format, ...);
+const data_set_t *plugin_get_ds (const char *name);
+
#endif /* PLUGIN_H */
diff --git a/src/processes.c b/src/processes.c
index e5c25126939e842a8d16ba84a50a677a123573f5..7d918d4fd5645a952a5fadcc2cd559cae21df95d 100644 (file)
--- a/src/processes.c
+++ b/src/processes.c
if ((proc = opendir ("/proc")) == NULL)
{
- ERROR ("Cannot open `/proc': %s", strerror (errno));
+ char errbuf[1024];
+ ERROR ("Cannot open `/proc': %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
diff --git a/src/rrdtool.c b/src/rrdtool.c
index ec04642c8313a3f1b215dc9ab88c40535ad8e964..3bb8e0754439bcf9846a113faf2fa6f4770f93c8 100644 (file)
--- a/src/rrdtool.c
+++ b/src/rrdtool.c
ds_def = (char **) malloc (ds->ds_num * sizeof (char *));
if (ds_def == NULL)
{
+ char errbuf[1024];
ERROR ("rrdtool plugin: malloc failed: %s",
- strerror (errno));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
memset (ds_def, '\0', ds->ds_num * sizeof (char *));
if ((argv = (char **) malloc (sizeof (char *) * (argc + 1))) == NULL)
{
- ERROR ("rrd_create failed: %s", strerror (errno));
+ char errbuf[1024];
+ ERROR ("rrd_create failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
(rc->values_num + 1) * sizeof (char *));
if (rc->values == NULL)
{
+ char errbuf[1024];
ERROR ("rrdtool plugin: realloc failed: %s",
- strerror (errno));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
if (cache != NULL)
{
void *cache_key = NULL;
if (cache_key == NULL)
{
+ char errbuf[1024];
ERROR ("rrdtool plugin: strdup failed: %s",
- strerror (errno));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
sfree (rc->values[0]);
sfree (rc->values);
sfree (rc);
(keys_num + 1) * sizeof (char *));
if (keys == NULL)
{
- DEBUG ("realloc failed: %s", strerror (errno));
+ char errbuf[1024];
ERROR ("rrdtool plugin: "
"realloc failed: %s",
- strerror (errno));
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
avl_iterator_destroy (iter);
return;
}
}
else
{
- ERROR ("stat(%s) failed: %s",
- filename, strerror (errno));
+ char errbuf[1024];
+ ERROR ("stat(%s) failed: %s", filename,
+ sstrerror (errno, errbuf,
+ sizeof (errbuf)));
return (-1);
}
}
diff --git a/src/sensors.c b/src/sensors.c
index 4bb544d566839e1e1f6f5a9dfd95ed57eeaa3cca..544afd1b37e256dfb87b1e2becba6738a70673ff 100644 (file)
--- a/src/sensors.c
+++ b/src/sensors.c
status = stat (conffile, &statbuf);
if (status != 0)
{
- ERROR ("sensors plugin: stat (%s) failed: %s",
- conffile, strerror (errno));
+ char errbuf[1024];
+ ERROR ("sensors plugin: stat (%s) failed: %s", conffile,
+ sstrerror (errno, errbuf, sizeof (errbuf)));
sensors_config_mtime = 0;
}
fh = fopen (conffile, "r");
if (fh == NULL)
{
- ERROR ("sensors plugin: fopen(%s) failed: %s",
- conffile, strerror(errno));
+ char errbuf[1024];
+ ERROR ("sensors plugin: fopen(%s) failed: %s", conffile,
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return;
}
if ((new_feature = (featurelist_t *) malloc (sizeof (featurelist_t))) == NULL)
{
- DEBUG ("malloc: %s", strerror (errno));
- ERROR ("sensors plugin: malloc: %s",
- strerror (errno));
+ char errbuf[1024];
+ ERROR ("sensors plugin: malloc: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
break;
}
diff --git a/src/serial.c b/src/serial.c
index 0cfa382309b0ba8655638f74f3cd5daeaee3fb7e..9fb26df1ea2aee15febba70d6b2be08fe762b97f 100644 (file)
--- a/src/serial.c
+++ b/src/serial.c
if ((fh = fopen ("/proc/tty/driver/serial", "r")) == NULL &&
(fh = fopen ("/proc/tty/driver/ttyS", "r")) == NULL)
{
- WARNING ("serial: fopen: %s", strerror (errno));
+ char errbuf[1024];
+ WARNING ("serial: fopen: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
diff --git a/src/swap.c b/src/swap.c
index 945c7580aef84dfdc944a0dd8f2e268773159d2a..6b0620cd296233a46ba169e67723eb7e2a8d1244 100644 (file)
--- a/src/swap.c
+++ b/src/swap.c
if ((fh = fopen ("/proc/meminfo", "r")) == NULL)
{
- WARNING ("memory: fopen: %s", strerror (errno));
+ char errbuf[1024];
+ WARNING ("memory: fopen: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
}
if (fclose (fh))
- WARNING ("memory: fclose: %s", strerror (errno));
+ {
+ char errbuf[1024];
+ WARNING ("memory: fclose: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ }
if ((swap_total == 0LL) || ((swap_free + swap_cached) > swap_total))
return (-1);
if (swapctl (SC_AINFO, &ai) == -1)
{
+ char errbuf[1024];
ERROR ("swap plugin: swapctl failed: %s",
- strerror (errno));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
diff --git a/src/traffic.c b/src/traffic.c
index 7f62450220072538e1944b3deccb0fce372939d1..dc5daccdf69c6e2dd00899ad3da9a9c89c0c4e84 100644 (file)
--- a/src/traffic.c
+++ b/src/traffic.c
if ((fh = fopen ("/proc/net/dev", "r")) == NULL)
{
- WARNING ("traffic: fopen: %s", strerror (errno));
+ char errbuf[1024];
+ WARNING ("traffic: fopen: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
diff --git a/src/unixsock.c b/src/unixsock.c
index 17956a177fa7486ec329a156fa4dd181387cd354..82cfc60433d78209affcbbae61ccfb31a18cbd85 100644 (file)
--- a/src/unixsock.c
+++ b/src/unixsock.c
/*
* Functions
*/
+static int parse_identifier (char *str, char **ret_host,
+ char **ret_plugin, char **ret_plugin_instance,
+ char **ret_type, char **ret_type_instance)
+{
+ char *hostname = NULL;
+ char *plugin = NULL;
+ char *plugin_instance = NULL;
+ char *type = NULL;
+ char *type_instance = NULL;
+
+ hostname = str;
+ if (hostname == NULL)
+ return (-1);
+
+ plugin = strchr (hostname, '/');
+ if (plugin == NULL)
+ return (-1);
+ *plugin = '\0'; plugin++;
+
+ type = strchr (plugin, '/');
+ if (type == NULL)
+ return (-1);
+ *type = '\0'; type++;
+
+ plugin_instance = strchr (plugin, '-');
+ if (plugin_instance != NULL)
+ {
+ *plugin_instance = '\0';
+ plugin_instance++;
+ }
+
+ type_instance = strchr (type, '-');
+ if (type_instance != NULL)
+ {
+ *type_instance = '\0';
+ type_instance++;
+ }
+
+ *ret_host = hostname;
+ *ret_plugin = plugin;
+ *ret_plugin_instance = plugin_instance;
+ *ret_type = type;
+ *ret_type_instance = type_instance;
+ return (0);
+} /* int parse_identifier */
+
static value_cache_t *cache_search (const char *name)
{
value_cache_t *vc;
vc = (value_cache_t *) malloc (sizeof (value_cache_t));
if (vc == NULL)
{
+ char errbuf[1024];
pthread_mutex_unlock (&cache_lock);
ERROR ("unixsock plugin: malloc failed: %s",
- strerror (errno));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
vc->gauge = (gauge_t *) malloc (sizeof (gauge_t) * vl->values_len);
if (vc->gauge == NULL)
{
+ char errbuf[1024];
pthread_mutex_unlock (&cache_lock);
ERROR ("unixsock plugin: malloc failed: %s",
- strerror (errno));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
free (vc);
return (-1);
}
vc->counter = (counter_t *) malloc (sizeof (counter_t) * vl->values_len);
if (vc->counter == NULL)
{
+ char errbuf[1024];
pthread_mutex_unlock (&cache_lock);
ERROR ("unixsock plugin: malloc failed: %s",
- strerror (errno));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
free (vc->gauge);
free (vc);
return (-1);
sock_fd = socket (PF_UNIX, SOCK_STREAM, 0);
if (sock_fd < 0)
{
+ char errbuf[1024];
ERROR ("unixsock plugin: socket failed: %s",
- strerror (errno));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
status = bind (sock_fd, (struct sockaddr *) &sa, sizeof (sa));
if (status != 0)
{
- DEBUG ("bind failed: %s; sa.sun_path = %s",
- strerror (errno), sa.sun_path);
- ERROR ("unixsock plugin: bind failed: %s",
- strerror (errno));
+ char errbuf[1024];
+ sstrerror (errno, errbuf, sizeof (errbuf));
+ DEBUG ("bind failed: %s; sa.sun_path = %s", errbuf, sa.sun_path);
+ ERROR ("unixsock plugin: bind failed: %s", errbuf);
close (sock_fd);
sock_fd = -1;
return (-1);
status = listen (sock_fd, 8);
if (status != 0)
{
+ char errbuf[1024];
ERROR ("unixsock plugin: listen failed: %s",
- strerror (errno));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
close (sock_fd);
sock_fd = -1;
return (-1);
status = getgrnam_r (grpname, &sg, grbuf, sizeof (grbuf), &g);
if (status != 0)
{
- WARNING ("unixsock plugin: getgrnam_r (%s) failed: %s",
- grpname, strerror (status));
+ char errbuf[1024];
+ WARNING ("unixsock plugin: getgrnam_r (%s) failed: %s", grpname,
+ sstrerror (errno, errbuf, sizeof (errbuf)));
break;
}
if (g == NULL)
if (chown ((sock_file != NULL) ? sock_file : US_DEFAULT_PATH,
(uid_t) -1, g->gr_gid) != 0)
{
+ char errbuf[1024];
WARNING ("unixsock plugin: chown (%s, -1, %i) failed: %s",
(sock_file != NULL) ? sock_file : US_DEFAULT_PATH,
(int) g->gr_gid,
- strerror (errno));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
}
} while (0);
static int us_handle_getval (FILE *fh, char **fields, int fields_num)
{
- char *hostname = fields[1];
+ char *hostname;
char *plugin;
char *plugin_instance;
char *type;
if (fields_num != 2)
return (-1);
- plugin = strchr (hostname, '/');
- if (plugin == NULL)
- return (-1);
- *plugin = '\0'; plugin++;
-
- type = strchr (plugin, '/');
- if (type == NULL)
+ status = parse_identifier (fields[1], &hostname,
+ &plugin, &plugin_instance,
+ &type, &type_instance);
+ if (status != 0)
return (-1);
- *type = '\0'; type++;
-
- plugin_instance = strchr (plugin, '-');
- if (plugin_instance != NULL)
- {
- *plugin_instance = '\0';
- plugin_instance++;
- }
-
- type_instance = strchr (type, '-');
- if (type_instance != NULL)
- {
- *type_instance = '\0';
- type_instance++;
- }
status = cache_alloc_name (name, sizeof (name),
hostname, plugin, plugin_instance, type, type_instance);
return (0);
} /* int us_handle_getval */
+static int us_handle_putval (FILE *fh, char **fields, int fields_num)
+{
+ char *hostname;
+ char *plugin;
+ char *plugin_instance;
+ char *type;
+ char *type_instance;
+ int status;
+ int i;
+
+ const data_set_t *ds;
+ value_list_t vl = VALUE_LIST_INIT;
+
+ char **value_ptr;
+
+ if (fields_num != 3)
+ return (-1);
+
+ status = parse_identifier (fields[1], &hostname,
+ &plugin, &plugin_instance,
+ &type, &type_instance);
+ if (status != 0)
+ return (-1);
+
+ if ((strlen (hostname) > sizeof (vl.host))
+ || (strlen (plugin) > sizeof (vl.plugin))
+ || (strlen (plugin_instance) > sizeof (vl.plugin_instance))
+ || (strlen (type_instance) > sizeof (vl.type_instance)))
+ return (-1);
+
+ strcpy (vl.host, hostname);
+ strcpy (vl.plugin, plugin);
+ strcpy (vl.plugin_instance, plugin_instance);
+ strcpy (vl.type_instance, type_instance);
+
+ { /* parse the time */
+ char *t = fields[2];
+ char *v = strchr (t, ':');
+ if (v == NULL)
+ return (-1);
+ *v = '\0'; v++;
+
+ vl.time = (time_t) atoi (t);
+ if (vl.time == 0)
+ vl.time = time (NULL);
+
+ fields[2] = v;
+ }
+
+ ds = plugin_get_ds (type);
+ if (ds == NULL)
+ return (-1);
+
+ value_ptr = (char **) calloc (ds->ds_num, sizeof (char *));
+ if (value_ptr == NULL)
+ return (-1);
+
+
+ { /* parse the value-list. It's colon-separated. */
+ char *dummy;
+ char *ptr;
+ char *saveptr;
+
+ i = 0;
+ dummy = fields[2];
+ saveptr = NULL;
+ while ((ptr = strtok_r (dummy, ":", &saveptr)) != NULL)
+ {
+ dummy = NULL;
+ if (i >= ds->ds_num)
+ {
+ i = ds->ds_num + 1;
+ break;
+ }
+ value_ptr[i] = ptr;
+ i++;
+ }
+
+ if (i != ds->ds_num)
+ {
+ free (value_ptr);
+ return (-1);
+ }
+ } /* done parsing the value-list */
+
+ vl.values_len = fields_num - 2;
+ vl.values = (value_t *) malloc (vl.values_len * sizeof (value_t));
+ if (vl.values == NULL)
+ {
+ free (value_ptr);
+ return (-1);
+ }
+ vl.values_len = ds->ds_num;
+
+ for (i = 0; i < ds->ds_num; i++)
+ {
+ if (strcmp (value_ptr[i], "U") == 0)
+ vl.values[i].gauge = NAN;
+ else if (ds->ds[i].type == DS_TYPE_COUNTER)
+ vl.values[i].counter = atoll (value_ptr[i]);
+ else if (ds->ds[i].type == DS_TYPE_GAUGE)
+ vl.values[i].gauge = atof (value_ptr[i]);
+ } /* for (i = 2 .. fields_num) */
+ sfree (value_ptr);
+
+ plugin_dispatch_values (type, &vl);
+
+ sfree (vl.values);
+
+ return (0);
+} /* int us_handle_putval */
+
static void *us_handle_client (void *arg)
{
int fd;
fh = fdopen (fd, "r+");
if (fh == NULL)
{
+ char errbuf[1024];
ERROR ("unixsock plugin: fdopen failed: %s",
- strerror (errno));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
close (fd);
pthread_exit ((void *) 1);
}
{
us_handle_getval (fh, fields, fields_num);
}
+ else if (strcasecmp (fields[0], "putval") == 0)
+ {
+ us_handle_putval (fh, fields, fields_num);
+ }
else
{
fprintf (fh, "Unknown command: %s\n", fields[0]);
status = accept (sock_fd, NULL, NULL);
if (status < 0)
{
+ char errbuf[1024];
+
if (errno == EINTR)
continue;
ERROR ("unixsock plugin: accept failed: %s",
- strerror (errno));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
close (sock_fd);
sock_fd = -1;
pthread_exit ((void *) 1);
remote_fd = (int *) malloc (sizeof (int));
if (remote_fd == NULL)
{
+ char errbuf[1024];
WARNING ("unixsock plugin: malloc failed: %s",
- strerror (errno));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
close (status);
continue;
}
status = pthread_create (&th, &th_attr, us_handle_client, (void *) remote_fd);
if (status != 0)
{
+ char errbuf[1024];
WARNING ("unixsock plugin: pthread_create failed: %s",
- strerror (status));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
close (*remote_fd);
free (remote_fd);
continue;
status = pthread_create (&listen_thread, NULL, us_server_thread, NULL);
if (status != 0)
{
+ char errbuf[1024];
ERROR ("unixsock plugin: pthread_create failed: %s",
- strerror (status));
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
diff --git a/src/utils_mount.c b/src/utils_mount.c
index 61eb6d1c109ea5ee556fea4762ab70f3ca9f35a4..eee2eb6c9414d39ddf967bd94c883ab30a0aa860 100644 (file)
--- a/src/utils_mount.c
+++ b/src/utils_mount.c
struct tabmntent *mntlist;
if(listmntent(&mntlist, COLLECTD_MNTTAB, NULL, NULL) < 0) {
- DEBUG("calling listmntent() failed: %s", strerror(errno));
+ char errbuf[1024];
+ DEBUG("calling listmntent() failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
}
for(p = mntlist; p; p = p->next) {
/* Get the number of mounted file systems */
if ((bufsize = CMD_STATFS (NULL, 0, FLAGS_STATFS)) < 1)
{
- DEBUG ("getv?fsstat failed: %s", strerror (errno));
+ char errbuf[1024];
+ DEBUG ("getv?fsstat failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (NULL);
}
* manpage.. -octo */
if ((num = CMD_STATFS (buf, bufsize * sizeof (STRUCT_STATFS), FLAGS_STATFS)) < 1)
{
- DEBUG ("getv?fsstat failed: %s", strerror (errno));
+ char errbuf[1024];
+ DEBUG ("getv?fsstat failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
free (buf);
return (NULL);
}
if ((fp = fopen (COLLECTD_MNTTAB, "r")) == NULL)
{
- ERROR ("fopen (%s): %s", COLLECTD_MNTTAB, strerror (errno));
+ char errbuf[1024];
+ ERROR ("fopen (%s): %s", COLLECTD_MNTTAB,
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (NULL);
}
if ((fp = setmntent (COLLECTD_MNTTAB, "r")) == NULL)
{
- ERROR ("setmntent (%s): %s", COLLECTD_MNTTAB, strerror (errno));
+ char errbuf[1024];
+ ERROR ("setmntent (%s): %s", COLLECTD_MNTTAB,
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (NULL);
}
diff --git a/src/vserver.c b/src/vserver.c
index fef45587a456c455a84e042ad0fd04458ee0e742..e4742e91af4ad75fcdb70e0dc1f1e93ce4c2c14c 100644 (file)
--- a/src/vserver.c
+++ b/src/vserver.c
DIR *proc;
struct dirent *dent; /* 42 */
- static complain_t complain_obj;
-
errno = 0;
if (NULL == (proc = opendir (PROCDIR)))
{
- plugin_complain (LOG_ERR, &complain_obj, "vserver plugin: "
- "fopen (%s) failed: %s", PROCDIR, strerror (errno));
+ char errbuf[1024];
+ ERROR ("vserver plugin: fopen (%s): %s", PROCDIR,
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
- plugin_relief (LOG_NOTICE, &complain_obj, "vserver plugin: "
- "fopen (%s) succeeded.", PROCDIR);
while (NULL != (dent = readdir (proc)))
{
continue;
if (NULL == (fh = fopen (file, "r")))
- ERROR ("Cannot open '%s': %s", file, strerror (errno));
+ {
+ char errbuf[1024];
+ ERROR ("Cannot open '%s': %s", file,
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ }
while ((fh != NULL) && (NULL != fgets (buffer, BUFSIZE, fh)))
{
continue;
if (NULL == (fh = fopen (file, "r")))
- ERROR ("Cannot open '%s': %s", file, strerror (errno));
+ {
+ char errbuf[1024];
+ ERROR ("Cannot open '%s': %s", file,
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ }
while ((fh != NULL) && (NULL != fgets (buffer, BUFSIZE, fh)))
{
continue;
if (NULL == (fh = fopen (file, "r")))
- ERROR ("Cannot open '%s': %s", file, strerror (errno));
+ {
+ char errbuf[1024];
+ ERROR ("Cannot open '%s': %s", file,
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ }
while ((fh != NULL) && (NULL != fgets (buffer, BUFSIZE, fh)))
{
diff --git a/src/wireless.c b/src/wireless.c
index a704047572ecdffddf2598ab8941a8453dfbf1b9..8ce7854c26a59696e0abf24edd544f342382dfee 100644 (file)
--- a/src/wireless.c
+++ b/src/wireless.c
/* there are a variety of names for the wireless device */
if ((fh = fopen (WIRELESS_PROC_FILE, "r")) == NULL)
{
- WARNING ("wireless: fopen: %s", strerror (errno));
+ char errbuf[1024];
+ WARNING ("wireless: fopen: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}