Skip to content

Commit

Permalink
collectd: smart: add patch to check udev_enumerate_scan_devices retur…
Browse files Browse the repository at this point in the history
…n value

The function udev_enumarte_scan_devices returns a value less than 0 on
failure. If this is the case then we terminate the read for this smart
information.

This change was already send upstream. And could be delete in feature
collectd versions.

Signed-off-by: Florian Eckert <[email protected]>
  • Loading branch information
feckert committed Mar 17, 2022
1 parent a9ea1cf commit 896a0f0
Showing 1 changed file with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
From 289f58c9c96d5478cf200f7a3e62b82e86b12d32 Mon Sep 17 00:00:00 2001
From: Florian Eckert <[email protected]>
Date: Tue, 15 Mar 2022 14:56:19 +0100
Subject: [PATCH] Check udev_enumerate_scan_devices return value

This change checks the return value of the function and cancels the call
if the returned integer is not greater than or equal to 0.

Signed-off-by: Florian Eckert <[email protected]>
---
src/smart.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)

--- a/src/smart.c
+++ b/src/smart.c
@@ -104,6 +104,7 @@ static int create_ignorelist_by_serial(i
struct udev_enumerate *enumerate;
struct udev_list_entry *devices, *dev_list_entry;
struct udev_device *dev;
+ int r;

if (ignorelist_by_serial == NULL)
ignorelist_by_serial = ignorelist_create(invert_ignorelist);
@@ -127,7 +128,13 @@ static int create_ignorelist_by_serial(i
}
udev_enumerate_add_match_subsystem(enumerate, "block");
udev_enumerate_add_match_property(enumerate, "DEVTYPE", "disk");
- udev_enumerate_scan_devices(enumerate);
+
+ r = udev_enumerate_scan_devices(enumerate);
+ if (r < 0) {
+ WARNING("smart plugin: udev scan devices failed");
+ return -1;
+ }
+
devices = udev_enumerate_get_list_entry(enumerate);
if (devices == NULL) {
ERROR("udev returned an empty list deviecs");
@@ -597,6 +604,7 @@ static int smart_read(void) {
struct udev_enumerate *enumerate;
struct udev_list_entry *devices, *dev_list_entry;
struct udev_device *dev;
+ int r;

/* Use udev to get a list of disks */
handle_udev = udev_new();
@@ -611,7 +619,13 @@ static int smart_read(void) {
}
udev_enumerate_add_match_subsystem(enumerate, "block");
udev_enumerate_add_match_property(enumerate, "DEVTYPE", "disk");
- udev_enumerate_scan_devices(enumerate);
+
+ r = udev_enumerate_scan_devices(enumerate);
+ if (r < 0) {
+ WARNING("smart plugin: udev scan devices failed");
+ return -1;
+ }
+
devices = udev_enumerate_get_list_entry(enumerate);
if (devices == NULL) {
ERROR("udev returned an empty list deviecs");

0 comments on commit 896a0f0

Please sign in to comment.