zdev: fix unexpected warning due to non-existent interface

Using option --by-interface with a non-existent network interface name
results in an unexpected duplicate warning message:

  $ lszdev --by-interface xx
  Could not open directory /sys/class/net/xx: No such file or directory
  Could not open directory /sys/class/net/xx: No such file or directory
  lszdev: Could not determine device that provides xx (xx)

Fix this by checking for the existence of the associated /sys/class/net
directory before initiating the associated directory traversal.

Reviewed-by: Vineeth Vijayan <vneethv@linux.ibm.com>
Signed-off-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Peter Oberparleiter
2023-06-30 16:56:11 +02:00
committed by Jan Höppner
parent 42611a787d
commit 552772d2a9

View File

@@ -11,6 +11,8 @@
#include <stdbool.h>
#include <string.h>
#include "lib/util_path.h"
#include "devnode.h"
#include "misc.h"
#include "net.h"
@@ -55,7 +57,8 @@ static bool add_devnodes_from_link(struct util_list *list,
cb_data.prefix_len = strlen(prefix);
cb_data.result = false;
path = path_get_sys_class("net", devnode->name);
path_for_each(path, add_linked_cb, &cb_data);
if (util_path_exists(path))
path_for_each(path, add_linked_cb, &cb_data);
free(path);
return cb_data.result;