62 lines
1.9 KiB
Diff
62 lines
1.9 KiB
Diff
From 3463fc5556f731aa2e29981bdb27cb50364770dd Mon Sep 17 00:00:00 2001
|
|
From: David Sommerseth <davids@redhat.com>
|
|
Date: Fri, 7 Feb 2014 13:53:36 +0100
|
|
Subject: [PATCH 5/5] Report invalid/non-existing devices as ENODEV
|
|
|
|
Without this patch py-ethtool will just report with a very
|
|
generic system error exception if trying to query a non-existing
|
|
network interface. This patch will change this to report the
|
|
error using ENODEV instead.
|
|
|
|
Signed-off-by: David Sommerseth <davids@redhat.com>
|
|
Reviewed-by: Antoni S. Puimedon <asegurap@redhat.com>
|
|
---
|
|
python-ethtool/etherinfo.c | 10 ++++++++++
|
|
1 file changed, 10 insertions(+)
|
|
|
|
diff --git a/python-ethtool/etherinfo.c b/python-ethtool/etherinfo.c
|
|
index c5e6798..24147bc 100644
|
|
--- a/python-ethtool/etherinfo.c
|
|
+++ b/python-ethtool/etherinfo.c
|
|
@@ -118,6 +118,9 @@ static int _set_device_index(PyEtherInfo *self)
|
|
struct nl_cache *link_cache;
|
|
struct rtnl_link *link;
|
|
|
|
+ /* Reset errno, as we will use it to report errors further on */
|
|
+ errno = 0;
|
|
+
|
|
/* Find the interface index we're looking up.
|
|
* As we don't expect it to change, we're reusing a "cached"
|
|
* interface index if we have that
|
|
@@ -129,6 +132,7 @@ static int _set_device_index(PyEtherInfo *self)
|
|
|
|
link = rtnl_link_get_by_name(link_cache, PyString_AsString(self->device));
|
|
if( !link ) {
|
|
+ errno = ENODEV;
|
|
nl_cache_free(link_cache);
|
|
return 0;
|
|
}
|
|
@@ -177,6 +181,9 @@ int get_etherinfo_link(PyEtherInfo *self)
|
|
}
|
|
|
|
if( _set_device_index(self) != 1) {
|
|
+ if( errno != 0 ) {
|
|
+ PyErr_SetString(PyExc_IOError, strerror(errno));
|
|
+ }
|
|
return 0;
|
|
}
|
|
|
|
@@ -227,6 +234,9 @@ PyObject * get_etherinfo_address(PyEtherInfo *self, nlQuery query)
|
|
}
|
|
|
|
if( _set_device_index(self) != 1) {
|
|
+ if( errno != 0 ) {
|
|
+ return PyErr_SetFromErrno(PyExc_IOError);
|
|
+ }
|
|
return NULL;
|
|
}
|
|
|
|
--
|
|
1.8.3.1
|
|
|