You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

66 lines
1.6 KiB

--- a/src/ubi.c
+++ b/src/ubi.c
@@ -84,9 +84,8 @@ static void ubi_submit(const char *dev_n
plugin_dispatch_values(&vl);
} /* void ubi_submit */
-static int ubi_read_dev_attr(const char *dev_name, const char *attr) {
+static int ubi_read_dev_attr(const char *dev_name, const char *attr, int *value) {
FILE *f;
- int val;
char
str[sizeof(SYS_PATH) + strlen(dev_name) + sizeof("/") + strlen(attr) + 1];
int n;
@@ -98,7 +97,7 @@ static int ubi_read_dev_attr(const char
return -1;
}
- n = fscanf(f, "%d", &val);
+ n = fscanf(f, "%d", value);
fclose(f);
if (n != 1) {
@@ -106,17 +105,39 @@ static int ubi_read_dev_attr(const char
return -1;
}
- ubi_submit(dev_name, attr, (gauge_t)val);
-
return 0;
} /* int ubi_read_dev_attr */
static inline int ubi_read_dev_bad_count(const char *dev_name) {
- return ubi_read_dev_attr(dev_name, DEV_BAD_COUNT);
+ int ret;
+ int value;
+
+ ret = ubi_read_dev_attr(dev_name, DEV_BAD_COUNT, &value);
+
+ if (ret != 0) {
+ ERROR(PLUGIN_NAME " : Unable to read bat_peb_count");
+ return -1;
+ }
+
+ ubi_submit(dev_name, DEV_BAD_COUNT, (gauge_t)value);
+
+ return 0;
} /* int ubi_read_dev_bad_count */
static inline int ubi_read_max_ec(const char *dev_name) {
- return ubi_read_dev_attr(dev_name, MAXIMUM_ERASE);
+ int ret;
+ int value;
+
+ ret = ubi_read_dev_attr(dev_name, MAXIMUM_ERASE, &value);
+
+ if (ret != 0) {
+ ERROR(PLUGIN_NAME " : Unable to read max_ec");
+ return -1;
+ }
+
+ ubi_submit(dev_name, MAXIMUM_ERASE, (gauge_t)value);
+
+ return 0;
} /* int ubi_read_max_ec */
static int ubi_read(void) {