]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
battery plugin: adjusting read_statefs call
authorRinigus <rinigus.git@gmail.com>
Sat, 3 Sep 2016 04:37:52 +0000 (07:37 +0300)
committerRinigus <rinigus.git@gmail.com>
Sat, 3 Sep 2016 04:39:57 +0000 (07:39 +0300)
src/battery.c
src/battery_statefs.c

index ce8030e06e36477ce2831a6a7fac60146b8afb1c..3e6d7bda9de2a088e5763f7518af1bf1f1b072a7 100644 (file)
@@ -73,6 +73,7 @@ int battery_read_statefs (void); /* defined in battery_statefs; used by StateFS
 
 static _Bool report_percent = 0;
 static _Bool report_degraded = 0;
+static _Bool query_statefs = 0;
 
 static void battery_submit2 (char const *plugin_instance, /* {{{ */
                char const *type, char const *type_instance, gauge_t value)
@@ -361,6 +362,9 @@ static int battery_read (void) /* {{{ */
        gauge_t capacity_full = NAN; /* Total capacity */
        gauge_t capacity_design = NAN; /* Full design capacity */
 
+       if (query_statefs)
+               return battery_read_statefs ();
+
 #if HAVE_IOKIT_PS_IOPOWERSOURCES_H
        get_via_io_power_sources (&charge_rel, &current, &voltage);
 #endif
@@ -780,6 +784,9 @@ static int battery_read (void) /* {{{ */
 {
        int status;
 
+       if (query_statefs)
+               return battery_read_statefs ();
+
        DEBUG ("battery plugin: Trying sysfs ...");
        status = read_sysfs ();
        if (status == 0)
@@ -802,8 +809,6 @@ static int battery_read (void) /* {{{ */
 
 static int battery_config (oconfig_item_t *ci)
 {
-       _Bool query_statefs = 0;
-
        for (int i = 0; i < ci->children_num; i++)
        {
                oconfig_item_t *child = ci->children + i;
@@ -820,13 +825,6 @@ static int battery_config (oconfig_item_t *ci)
                                        child->key);
        }
 
-       if (query_statefs)
-       {
-               /* register read function from statefs backend. to avoid conflicts, unregister the current one */  
-               plugin_unregister_read ("battery");
-               plugin_register_read ("battery", battery_read_statefs);
-       }
-
        return (0);
 } /* }}} int battery_config */
 
index 9ede4fb48bd3b8455ab1a6837148689603e92a12..5aa76288f944020aaa2b5bf3679c96cc223cfd78 100644 (file)
@@ -66,6 +66,8 @@ static void battery_submit (const char *type, gauge_t value)
   vl.values_len = 1;
   sstrncpy (vl.host, hostname_g, sizeof (vl.host));
   sstrncpy (vl.plugin, "battery", sizeof (vl.plugin));
+  /* statefs supports 1 battery at present */
+  sstrncpy (vl.plugin_instance, "0", sizeof (vl.plugin_instance));
   sstrncpy (vl.type, type, sizeof (vl.type));
 
   plugin_dispatch_values (&vl);
@@ -102,7 +104,6 @@ int battery_read_statefs (void)
 
   submitted_this_run = 0;
 
-
   if ( getvalue(STATEFS_ROOT "ChargePercentage", &value, buffer, BFSZ) )
     battery_submit( "charge", value );
   // Use capacity as a charge estimate if ChargePercentage is not available
@@ -132,7 +133,7 @@ int battery_read_statefs (void)
 
   if ( submitted_this_run == 0 )
     {
-      ERROR ("statefs_battery plugin: none of the statistics are available.");
+      ERROR ("battery plugin: statefs backend: none of the statistics are available");
       return (-1);
     }