projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add more test stuff to .gitignore
[collectd.git]
/
src
/
serial.c
diff --git
a/src/serial.c
b/src/serial.c
index
c278672
..
0878d3c
100644
(file)
--- a/
src/serial.c
+++ b/
src/serial.c
@@
-18,64
+18,42
@@
*
* Authors:
* David Bacher <drbacher at gmail.com>
*
* Authors:
* David Bacher <drbacher at gmail.com>
- * Florian octo Forster <octo at
verplant
.org>
+ * Florian octo Forster <octo at
collectd
.org>
**/
#include "collectd.h"
#include "common.h"
#include "plugin.h"
**/
#include "collectd.h"
#include "common.h"
#include "plugin.h"
-#if defined(KERNEL_LINUX)
-# define SERIAL_HAVE_READ 1
-#else
-# define SERIAL_HAVE_READ 0
+#if !KERNEL_LINUX
+# error "No applicable input method."
#endif
#endif
-static data_source_t octets_dsrc[2] =
-{
- {"rx", DS_TYPE_COUNTER, 0, 4294967295.0},
- {"tx", DS_TYPE_COUNTER, 0, 4294967295.0}
-};
-
-static data_set_t octets_ds =
-{
- "serial_octets", 2, octets_dsrc
-};
-
-#if SERIAL_HAVE_READ
static void serial_submit (const char *type_instance,
static void serial_submit (const char *type_instance,
-
counter_t rx, counter
_t tx)
+
derive_t rx, derive
_t tx)
{
value_t values[2];
value_list_t vl = VALUE_LIST_INIT;
{
value_t values[2];
value_list_t vl = VALUE_LIST_INIT;
- values[0].
counter
= rx;
- values[1].
counter
= tx;
+ values[0].
derive
= rx;
+ values[1].
derive
= tx;
vl.values = values;
vl.values_len = 2;
vl.values = values;
vl.values_len = 2;
-
vl.time = time (NULL
);
- s
trcpy (vl.host, hostname_g
);
- s
trcpy (vl.plugin, "serial"
);
- strncpy (vl.type_instance, type_instance,
+
sstrncpy (vl.host, hostname_g, sizeof (vl.host)
);
+ s
strncpy (vl.plugin, "serial", sizeof (vl.plugin)
);
+ s
strncpy (vl.type, "serial_octets", sizeof (vl.type)
);
+ s
s
trncpy (vl.type_instance, type_instance,
sizeof (vl.type_instance));
sizeof (vl.type_instance));
- plugin_dispatch_values (
"serial_octets",
&vl);
+ plugin_dispatch_values (&vl);
}
static int serial_read (void)
{
}
static int serial_read (void)
{
-#ifdef KERNEL_LINUX
FILE *fh;
char buffer[1024];
FILE *fh;
char buffer[1024];
- counter_t rx = 0;
- counter_t tx = 0;
-
- char *fields[16];
- int i, numfields;
- int len;
-
/* there are a variety of names for the serial device */
if ((fh = fopen ("/proc/tty/driver/serial", "r")) == NULL &&
(fh = fopen ("/proc/tty/driver/ttyS", "r")) == NULL)
/* there are a variety of names for the serial device */
if ((fh = fopen ("/proc/tty/driver/serial", "r")) == NULL &&
(fh = fopen ("/proc/tty/driver/ttyS", "r")) == NULL)
@@
-88,10
+66,16
@@
static int serial_read (void)
while (fgets (buffer, sizeof (buffer), fh) != NULL)
{
while (fgets (buffer, sizeof (buffer), fh) != NULL)
{
- int have_rx = 0, have_tx = 0;
+ derive_t rx = 0;
+ derive_t tx = 0;
+ _Bool have_rx = 0, have_tx = 0;
+ size_t len;
- numfields = strsplit (buffer, fields, 16);
+ char *fields[16];
+ int numfields;
+ int i;
+ numfields = strsplit (buffer, fields, STATIC_ARRAY_SIZE (fields));
if (numfields < 6)
continue;
if (numfields < 6)
continue;
@@
-99,12
+83,12
@@
static int serial_read (void)
* 0: uart:16550A port:000003F8 irq:4 tx:0 rx:0
* 1: uart:16550A port:000002F8 irq:3 tx:0 rx:0
*/
* 0: uart:16550A port:000003F8 irq:4 tx:0 rx:0
* 1: uart:16550A port:000002F8 irq:3 tx:0 rx:0
*/
- len = strlen (fields[0])
- 1
;
- if (len <
1
)
+ len = strlen (fields[0]);
+ if (len <
2
)
continue;
continue;
- if (fields[0][len] != ':')
+ if (fields[0][len
- 1
] != ':')
continue;
continue;
- fields[0][len
] = '\0'
;
+ fields[0][len
- 1] = 0
;
for (i = 1; i < numfields; i++)
{
for (i = 1; i < numfields; i++)
{
@@
-114,35
+98,25
@@
static int serial_read (void)
if (strncmp (fields[i], "tx:", 3) == 0)
{
if (strncmp (fields[i], "tx:", 3) == 0)
{
- tx = atoll (fields[i] + 3);
-
have_tx++
;
+ if (strtoderive (fields[i] + 3, &tx) == 0)
+
have_tx = 1
;
}
else if (strncmp (fields[i], "rx:", 3) == 0)
{
}
else if (strncmp (fields[i], "rx:", 3) == 0)
{
- rx = atoll (fields[i] + 3);
-
have_rx++
;
+ if (strtoderive (fields[i] + 3, &rx) == 0)
+
have_rx = 1
;
}
}
}
}
- if ((have_rx == 0) || (have_tx == 0))
- continue;
-
- serial_submit (fields[0], rx, tx);
+ if (have_rx && have_tx)
+ serial_submit (fields[0], rx, tx);
}
fclose (fh);
return (0);
}
fclose (fh);
return (0);
-#endif /* KERNEL_LINUX */
} /* int serial_read */
} /* int serial_read */
-#endif /* SERIAL_HAVE_READ */
-void module_register (
modreg_e loa
d)
+void module_register (
voi
d)
{
{
- if (load & MR_DATASETS)
- plugin_register_data_set (&octets_ds);
-
-#if SERIAL_HAVE_READ
- if (load & MR_READ)
- plugin_register_read ("serial", serial_read);
-#endif /* SERIAL_HAVE_READ */
+ plugin_register_read ("serial", serial_read);
} /* void module_register */
} /* void module_register */