python-ethtool/0002-fix-get_module-errno-setting.patch
David Sommerseth a76dfd064b Adding some extra upstream patches, until they appear in a new release
Signed-off-by: David Sommerseth <davids@redhat.com>
2014-03-20 19:02:54 +01:00

70 lines
2.3 KiB
Diff

From a6f163fafaccd9bea4b2807961ef8ed8776a629a Mon Sep 17 00:00:00 2001
From: "Antoni S. Puimedon" <asegurap@redhat.com>
Date: Mon, 11 Nov 2013 15:21:26 +0000
Subject: [PATCH 2/5] 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>
---
python-ethtool/ethtool.c | 18 ++++++++++++------
1 file 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. */
--
1.8.3.1