]> git.itanic.dy.fi Git - rrdd/blobdiff - built_in_parsers.c
onewire_parser.c: Fix compiler warnings about string lengths
[rrdd] / built_in_parsers.c
index 9a0d342cf2d9c749994fc3b07a8ab8f0268ffcf2..c18c080e972283dd4de30a3916fea78630089076 100644 (file)
@@ -11,7 +11,7 @@
 
 #define STATFILE "/proc/stat"
 
-static int cpu_parser(char *data, const char **p)
+static int cpu_parser(char *data, const char **p, void **state)
 {
        char buf[1024];
        char *str = buf;
@@ -46,7 +46,7 @@ static int cpu_parser(char *data, const char **p)
 
 #define MEMFILE "/proc/meminfo"
 
-static int mem_parser(char *data, const char **p)
+static int mem_parser(char *data, const char **p, void **state)
 {
        char buf[1024], word[1024];
        int free = 0, buffered = 0, cache = 0, active = 0, inactive = 0,
@@ -106,65 +106,24 @@ static int mem_parser(char *data, const char **p)
        return 0;
 }
 
-int cpu_mem_parser(char *data, const char **p)
+int cpu_mem_parser(char *data, const char **p, void **state)
 {
+       int ret;
        char cpu[RRD_DATA_MAX_LEN], mem[RRD_DATA_MAX_LEN];
 
-       cpu_parser(cpu, p);
-       mem_parser(mem, p);
-       snprintf(data, RRD_DATA_MAX_LEN, "%s:%s", cpu, mem);
-
-       return 0;
-}
-
-static int digitemp_parser(char *data, const char **p)
-{
-       const char digitemp_cmd[] = "/usr/bin/digitemp";
-       char *const digitemp_args[] = { "", "-o2", "-a", "-q", 0 };
-       FILE *readf;
-       int pid, ret;
-       float t1 = 0, t2 = 0, t3 = 0;
-       char buf[1024];
-
-       pid = run_piped_stream(digitemp_cmd, digitemp_args, 0, &readf, 0);
-       if (pid < 0) {
-               pr_err("Failed to parse digitemp\n");
-               sprintf(data, "U:U");
-               return -1;
-       }
-
-       ret = fscanf(readf, "%f %f %f", &t1, &t2, &t3);
-
-       if (ret != 3) {
-               pr_err("Failed to parse digitemp output: %m\n");
-               sprintf(data, "U:U");
-               return 1;
-       }
+       cpu_parser(cpu, p, state);
+       mem_parser(mem, p, state);
+       ret = snprintf(data, RRD_DATA_MAX_LEN, "%s:%s", cpu, mem);
 
-       t2 += 2.16;
-       t3 += -0.44;
+       /* No actual data overflow, snprintf just couldn't fit all data in the buffer */
+       if (ret >= RRD_DATA_MAX_LEN)
+               pr_err("Buffer overlfow\n");
 
-       /* Read whatever the process might be still printing out */
-       while (fgets(buf, 1024, readf));
-
-       clear_zombie(pid);
-       snprintf(data, RRD_DATA_MAX_LEN, "%.2f:%.2f", t3, t2);
        return 0;
 }
 
-static int digitemp_parser_mod(char *data, const char **p)
-{
-       char buf[1024];
-       int ret;
-
-       ret = digitemp_parser(buf, p);
-       snprintf(data, RRD_DATA_MAX_LEN, "U:%s", buf);
-
-       return ret;
-}
-
 /* Run a command and feed the output from stdout directly to rrdtool */
-static int script_parser(char *rrd_data, const char **parser_data)
+static int script_parser(char *rrd_data, const char **parser_data, void **state)
 {
        FILE *readf;
        int pid, ret;
@@ -247,7 +206,7 @@ static int get_iface_stats(const char *iface, struct iface_stats *stat)
        return -ENODEV;
 }
 
-int netstats_parser(char *rrd_data, const char **parser_data)
+int netstats_parser(char *rrd_data, const char **parser_data, void **state)
 {
        struct iface_stats stat;
        const char **iface_name = parser_data;
@@ -299,14 +258,6 @@ static struct parser_info built_in_parsers[] = {
                .name = "cpu_mem",
                .parse = cpu_mem_parser,
        },
-       {
-               .name = "digitemp",
-               .parse = digitemp_parser,
-       },
-       {
-               .name = "digitemp_mod",
-               .parse = digitemp_parser_mod,
-       },
        {
                .name = "script",
                .parse = script_parser,