This seems ok. On Fri, Mar 06, 2009 at 01:32:58AM +0100, Hans de Goede wrote: > We share the same memory space inside the python process with other > potentially libdevmapper users, for example libparted used libdevmapper too > having our dm_log handler installed, and thus getting called when > libparted tries to add / remove dmraid partitions, does not fare well. > > This patch fixes this by installing / removing our dm_log handler around > libdevmapper usage, instead of permanently installing it once. > --- > dm.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++------------ > 1 files changed, 49 insertions(+), 12 deletions(-) > > diff --git a/dm.c b/dm.c > index 42f70a8..d4e3a6a 100644 > --- a/dm.c > +++ b/dm.c > @@ -50,6 +50,9 @@ > #include "exc.h" > > #define PYDM_ARGS (METH_VARARGS|METH_KEYWORDS) > + > +void pydm_log_fn(int level, const char *file, int line, const char *f, ...); > + > /* dev stuff begin */ > > static void > @@ -645,6 +648,7 @@ PydmTable_FromInfo(loff_t start, u_int64_t size, char *type, char *params) > #define python_error_destroy_task(task, err) \ > if (PyErr_Occurred()) { \ > dm_task_destroy(task); \ > + dm_log_init(NULL); \ > return err; \ > } > > @@ -734,12 +738,14 @@ pydm_map_read(PydmMapObject *map, struct pydm_map_key *key) > return 0; > > memset(info, 0, sizeof (struct dm_info)); > + dm_log_init(pydm_log_fn); > task = dm_task_create(DM_DEVICE_INFO); > if (!task) { > if (!PyErr_Occurred()) { > printf("%s: %d\n", __FILE__, __LINE__); > PyErr_NoMemory(); > } > + dm_log_init(NULL); > return -1; > } > > @@ -755,7 +761,6 @@ pydm_map_read(PydmMapObject *map, struct pydm_map_key *key) > > switch (key->type) { > case NONE: > - python_error_destroy_task(task, -1); > break; > case UUID: > if (!map->uuid) > @@ -776,11 +781,12 @@ pydm_map_read(PydmMapObject *map, struct pydm_map_key *key) > pydm_map_clear(map); > printf("%s: %d\n", __FILE__, __LINE__); > PyErr_NoMemory(); > - dm_task_destroy(task); > - return -1; > - } > - map->initialized = 1; > - return 0; > + } else > + map->initialized = 1; > + > + dm_task_destroy(task); > + dm_log_init(NULL); > + return (map->initialized - 1); > } > > map->uuid = strdup(dm_task_get_uuid(task)); > @@ -789,6 +795,7 @@ pydm_map_read(PydmMapObject *map, struct pydm_map_key *key) > map->dev = PydmDevice_FromMajorMinor(info->major, info->minor); > > dm_task_destroy(task); > + dm_log_init(NULL); > > if (!map->uuid && !map->name && !map->dev) { > pydm_map_clear(map); > @@ -839,12 +846,14 @@ pydm_map_simple(PydmMapObject *map, int taskno) > struct dm_task *task; > int rc; > > + dm_log_init(pydm_log_fn); > task = dm_task_create(taskno); > if (!task) { > if (!PyErr_Occurred()) { > printf("%s: %d\n", __FILE__, __LINE__); > PyErr_NoMemory(); > } > + dm_log_init(NULL); > return NULL; > } > > @@ -853,17 +862,17 @@ pydm_map_simple(PydmMapObject *map, int taskno) > rc = -1; > if (rc < 0) { > PyErr_SetString(PyExc_AssertionError, "map is not initialized"); > - return NULL; > + python_error_destroy_task(task, NULL); > } > > pydm_task_set_key(task, &key); > - rc = dm_task_run(task); > - if (rc < 0 && PyErr_Occurred()) > - return NULL; > + dm_task_run(task); > + python_error_destroy_task(task, NULL); > > dm_task_update_nodes(); > > dm_task_destroy(task); > + dm_log_init(NULL); > > if (PyErr_Occurred()) > return NULL; > @@ -877,12 +886,14 @@ pydm_map_create(PydmMapObject *map, PyObject *table) > struct dm_task *task; > int i; > > + dm_log_init(pydm_log_fn); > task = dm_task_create(DM_DEVICE_CREATE); > if (!task) { > if (!PyErr_Occurred()) { > printf("%s: %d\n", __FILE__, __LINE__); > PyErr_NoMemory(); > } > + dm_log_init(NULL); > return -1; > } > > @@ -901,6 +912,7 @@ pydm_map_create(PydmMapObject *map, PyObject *table) > PyErr_SetString(PyExc_ValueError, > "invalid table type in table list"); > dm_task_destroy(task); > + dm_log_init(NULL); > return -1; > } > dm_task_add_target(task, row->start, row->size, > @@ -920,6 +932,7 @@ pydm_map_create(PydmMapObject *map, PyObject *table) > > dm_task_update_nodes(); > dm_task_destroy(task); > + dm_log_init(NULL); > if (PyErr_Occurred()) > return -1; > map->initialized = 0; > @@ -1012,18 +1025,21 @@ pydm_map_set_name(PydmMapObject *map, const char *name) > if (rc < 0) > return rc; > > + dm_log_init(pydm_log_fn); > task = dm_task_create(DM_DEVICE_RENAME); > if (!task) { > if (!PyErr_Occurred()) { > printf("%s: %d\n", __FILE__, __LINE__); > PyErr_NoMemory(); > } > + dm_log_init(NULL); > return -1; > } > > newname = strdup(name); > if (!newname) { > dm_task_destroy(task); > + dm_log_init(NULL); > printf("%s: %d\n", __FILE__, __LINE__); > PyErr_NoMemory(); > return -1; > @@ -1042,6 +1058,7 @@ pydm_map_set_name(PydmMapObject *map, const char *name) > > dm_task_update_nodes(); > dm_task_destroy(task); > + dm_log_init(NULL); > > free(map->name); > map->name = newname; > @@ -1062,12 +1079,14 @@ pydm_map_set_suspend(PydmMapObject *map, int suspend) > return rc; > } > > + dm_log_init(pydm_log_fn); > task = dm_task_create(suspend ? DM_DEVICE_SUSPEND : DM_DEVICE_RESUME); > if (!task) { > if (!PyErr_Occurred()) { > printf("%s: %d\n", __FILE__, __LINE__); > PyErr_NoMemory(); > } > + dm_log_init(NULL); > return -1; > } > pydm_task_set_key(task, &key); > @@ -1077,6 +1096,7 @@ pydm_map_set_suspend(PydmMapObject *map, int suspend) > > dm_task_update_nodes(); > dm_task_destroy(task); > + dm_log_init(NULL); > > return pydm_map_refresh(map); > } > @@ -1096,17 +1116,20 @@ pydm_map_get_table(PydmMapObject *map) > return NULL; > } > > + dm_log_init(pydm_log_fn); > task = dm_task_create(DM_DEVICE_TABLE); > if (!task) { > if (!PyErr_Occurred()) { > printf("%s: %d\n", __FILE__, __LINE__); > PyErr_NoMemory(); > } > + dm_log_init(NULL); > return NULL; > } > > pydm_task_set_key(task, &key); > dm_task_run(task); > + python_error_destroy_task(task, NULL); > > do { > u_int64_t start, length; > @@ -1142,6 +1165,8 @@ pydm_map_get_table(PydmMapObject *map) > > dm_task_update_nodes(); > dm_task_destroy(task); > + dm_log_init(NULL); > + > return table_list; > } > > @@ -1161,12 +1186,14 @@ pydm_map_get_deps(PydmMapObject *map) > return o; > } > > + dm_log_init(pydm_log_fn); > task = dm_task_create(DM_DEVICE_DEPS); > if (!task) { > if (!PyErr_Occurred()) { > printf("%s: %d\n", __FILE__, __LINE__); > PyErr_NoMemory(); > } > + dm_log_init(NULL); > return o; > } > > @@ -1184,12 +1211,14 @@ pydm_map_get_deps(PydmMapObject *map) > if (!info->exists) { > PyErr_SetString(PyExc_AssertionError, "map does not exist"); > dm_task_destroy(task); > + dm_log_init(NULL); > return o; > } > > o = PyTuple_New(deps->count); > if (!o) { > dm_task_destroy(task); > + dm_log_init(NULL); > if (!PyErr_Occurred()) { > printf("%s: %d\n", __FILE__, __LINE__); > PyErr_NoMemory(); > @@ -1204,6 +1233,7 @@ pydm_map_get_deps(PydmMapObject *map) > > if (!dev) { > dm_task_destroy(task); > + dm_log_init(NULL); > Py_DECREF(o); > if (!PyErr_Occurred()) { > printf("%s: %d\n", __FILE__, __LINE__); > @@ -1214,6 +1244,7 @@ pydm_map_get_deps(PydmMapObject *map) > rc = PyTuple_SetItem(o, i, dev); > if (rc < 0) { > dm_task_destroy(task); > + dm_log_init(NULL); > Py_DECREF(o); > if (!PyErr_Occurred()) { > printf("%s: %d\n", __FILE__, __LINE__); > @@ -1224,6 +1255,7 @@ pydm_map_get_deps(PydmMapObject *map) > } > dm_task_update_nodes(); > dm_task_destroy(task); > + dm_log_init(NULL); > > if (PyErr_Occurred()) { > Py_DECREF(o); > @@ -1494,13 +1526,15 @@ pydm_log_init(PyObject *self, PyObject *args, PyObject *kwds) > { > char *kwlist[] = {"log_function", NULL}; > > + Py_CLEAR(pydm_py_log_fn); > + > if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:log_init", kwlist, > &pydm_py_log_fn)) > return NULL; > > if (pydm_py_log_fn == Py_None) { > - dm_log_init(NULL); > pydm_py_log_fn = NULL; > + Py_INCREF(Py_None); > return Py_None; > } > > @@ -1511,7 +1545,6 @@ pydm_log_init(PyObject *self, PyObject *args, PyObject *kwds) > } > > Py_INCREF(pydm_py_log_fn); > - dm_log_init(pydm_log_fn); > Py_INCREF(Py_None); > return Py_None; > } > @@ -1595,6 +1628,7 @@ pydm_maps(PyObject *self) > goto save_list; > } > > + dm_log_init(pydm_log_fn); > task = dm_task_create(DM_DEVICE_LIST); > if (!task) { > if (!PyErr_Occurred()) { > @@ -1642,6 +1676,7 @@ out: > Py_XDECREF(list); > if (task) > dm_task_destroy(task); > + dm_log_init(NULL); > if (PyErr_Occurred()) { > Py_XDECREF(ret); > return NULL; > @@ -1663,6 +1698,7 @@ pydm_targets(PyObject *self) > if (!list) > goto out; > > + dm_log_init(pydm_log_fn); > task = dm_task_create(DM_DEVICE_LIST_VERSIONS); > if (!task) { > if (!PyErr_Occurred()) > @@ -1714,6 +1750,7 @@ out: > Py_XDECREF(list); > if (task) > dm_task_destroy(task); > + dm_log_init(NULL); > if (PyErr_Occurred()) { > Py_XDECREF(ret); > return NULL; > -- > 1.6.1.3 > > _______________________________________________ > Anaconda-devel-list mailing list > Anaconda-devel-list@xxxxxxxxxx > https://www.redhat.com/mailman/listinfo/anaconda-devel-list -- Joel Andres Granados Brno, Czech Republic, Red Hat. _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list