diff options
author | David Sommerseth <davids@redhat.com> | 2014-02-07 13:53:36 +0100 |
---|---|---|
committer | David Sommerseth <davids@redhat.com> | 2014-02-21 16:13:04 +0100 |
commit | 3463fc5556f731aa2e29981bdb27cb50364770dd (patch) | |
tree | c815d3ea7f9f02647867539ece3e7f46d9f6036c | |
parent | 505bca305c4c0e2d3a29e24b27bf03c358db11cf (diff) | |
download | python-ethtool-3463fc5556f731aa2e29981bdb27cb50364770dd.tar.gz python-ethtool-3463fc5556f731aa2e29981bdb27cb50364770dd.tar.xz python-ethtool-3463fc5556f731aa2e29981bdb27cb50364770dd.zip |
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>
-rw-r--r-- | python-ethtool/etherinfo.c | 10 |
1 files changed, 10 insertions, 0 deletions
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; } |