context: check self->cxt and rc in assign_device
Assert self->cxt before calling libfdisk fdisk_assign_device. Also check for its return code and raise exception if libfdisk report any error assigning the device.master
parent
99a98f9236
commit
88c7374db2
12
context.c
12
context.c
|
|
@ -84,9 +84,14 @@ static int Context_init(ContextObject *self, PyObject *args, PyObject *kwds)
|
||||||
static PyObject *Context_assign_device(ContextObject *self, PyObject *args, PyObject *kwds)
|
static PyObject *Context_assign_device(ContextObject *self, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
static char *kwlist[] = { "readonly", NULL };
|
static char *kwlist[] = { "readonly", NULL };
|
||||||
int readonly = 0;
|
int rc, readonly = 0;
|
||||||
char *fname;
|
char *fname;
|
||||||
|
|
||||||
|
if (!self->cxt) {
|
||||||
|
PyErr_SetString(PyExc_TypeError, ARG_ERR);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args,
|
if (!PyArg_ParseTupleAndKeywords(args,
|
||||||
kwds, "s|p", kwlist,
|
kwds, "s|p", kwlist,
|
||||||
&readonly)) {
|
&readonly)) {
|
||||||
|
|
@ -94,7 +99,10 @@ static PyObject *Context_assign_device(ContextObject *self, PyObject *args, PyOb
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
fdisk_assign_device(self->cxt, fname, readonly);
|
if ((rc = fdisk_assign_device(self->cxt, fname, readonly)) < 0) {
|
||||||
|
set_PyErr_from_rc(-rc);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
fdisk_get_partitions(self->cxt, &self->tb);
|
fdisk_get_partitions(self->cxt, &self->tb);
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue