diff options
author | Antoni S. Puimedon <asegurap@redhat.com> | 2013-11-11 15:21:26 +0000 |
---|---|---|
committer | David Sommerseth <davids@redhat.com> | 2014-01-10 20:16:07 +0100 |
commit | a6f163fafaccd9bea4b2807961ef8ed8776a629a (patch) | |
tree | a15ee7e0168d73e9cde1167e7607681f41b6586f | |
parent | b15cd540acf49a283d30c28e1424230e51440772 (diff) | |
download | python-ethtool-a6f163fafaccd9bea4b2807961ef8ed8776a629a.tar.gz python-ethtool-a6f163fafaccd9bea4b2807961ef8ed8776a629a.tar.xz python-ethtool-a6f163fafaccd9bea4b2807961ef8ed8776a629a.zip |
fix get_module errno setting.
The current code is only setting the errno string but doesn't set
the first argument to the IOError exception, i.e., errno.
This patch builds a tuple (errno, strerror(errno)) so that the
Exception has the errno properly set.
Signed-off-by: Antoni S. Puimedon <asegurap@redhat.com>
Signed-off-by: David Sommerseth <davids@redhat.com>
-rw-r--r-- | python-ethtool/ethtool.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/python-ethtool/ethtool.c b/python-ethtool/ethtool.c index 65abb21..453f08b 100644 --- a/python-ethtool/ethtool.c +++ b/python-ethtool/ethtool.c @@ -450,6 +450,7 @@ static PyObject *get_module(PyObject *self __unused, PyObject *args) if (err < 0) { /* failed? */ int eno = errno; + PyObject *err_obj; FILE *file; int found = 0; char driver[101], dev[101]; @@ -458,8 +459,11 @@ static PyObject *get_module(PyObject *self __unused, PyObject *args) /* Before bailing, maybe it is a PCMCIA/PC Card? */ file = fopen("/var/lib/pcmcia/stab", "r"); if (file == NULL) { - sprintf(buf, "[Errno %d] %s", eno, strerror(eno)); - PyErr_SetString(PyExc_IOError, buf); + err_obj = Py_BuildValue("(is)", eno, strerror(eno)); + if (err_obj != NULL) { + PyErr_SetObject(PyExc_IOError, err_obj); + Py_DECREF(err_obj); + } return NULL; } @@ -480,8 +484,11 @@ static PyObject *get_module(PyObject *self __unused, PyObject *args) } fclose(file); if (!found) { - sprintf(buf, "[Errno %d] %s", eno, strerror(eno)); - PyErr_SetString(PyExc_IOError, buf); + err_obj = Py_BuildValue("(is)", eno, strerror(eno)); + if (err_obj != NULL) { + PyErr_SetObject(PyExc_IOError, err_obj); + Py_DECREF(err_obj); + } return NULL; } else return PyString_FromString(driver); @@ -514,8 +521,7 @@ static PyObject *get_businfo(PyObject *self __unused, PyObject *args) /* Open control socket. */ fd = socket(AF_INET, SOCK_DGRAM, 0); if (fd < 0) { - PyErr_SetString(PyExc_OSError, strerror(errno)); - return NULL; + return PyErr_SetFromErrno(PyExc_OSError); } /* Get current settings. */ |