Skip to content

Commit 3463fc5

Browse files
author
David Sommerseth
committed
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>
1 parent 505bca3 commit 3463fc5

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

python-ethtool/etherinfo.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ static int _set_device_index(PyEtherInfo *self)
118118
struct nl_cache *link_cache;
119119
struct rtnl_link *link;
120120

121+
/* Reset errno, as we will use it to report errors further on */
122+
errno = 0;
123+
121124
/* Find the interface index we're looking up.
122125
* As we don't expect it to change, we're reusing a "cached"
123126
* interface index if we have that
@@ -129,6 +132,7 @@ static int _set_device_index(PyEtherInfo *self)
129132

130133
link = rtnl_link_get_by_name(link_cache, PyString_AsString(self->device));
131134
if( !link ) {
135+
errno = ENODEV;
132136
nl_cache_free(link_cache);
133137
return 0;
134138
}
@@ -177,6 +181,9 @@ int get_etherinfo_link(PyEtherInfo *self)
177181
}
178182

179183
if( _set_device_index(self) != 1) {
184+
if( errno != 0 ) {
185+
PyErr_SetString(PyExc_IOError, strerror(errno));
186+
}
180187
return 0;
181188
}
182189

@@ -227,6 +234,9 @@ PyObject * get_etherinfo_address(PyEtherInfo *self, nlQuery query)
227234
}
228235

229236
if( _set_device_index(self) != 1) {
237+
if( errno != 0 ) {
238+
return PyErr_SetFromErrno(PyExc_IOError);
239+
}
230240
return NULL;
231241
}
232242

0 commit comments

Comments
 (0)