@@ -1037,6 +1037,28 @@ PyObject *PyFtrace_attach(PyObject *self, PyObject *args, PyObject *kwargs)
return set_destroy(args, kwargs, true);
}
+static bool get_destroy_flag(PyObject *py_obj)
+{
+ PyFtrace_Object_HEAD *obj_head = (PyFtrace_Object_HEAD *)py_obj;
+ return obj_head->destroy;
+}
+
+PyObject *PyFtrace_is_attached(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+ static char *kwlist[] = {"object", NULL};
+ PyObject *py_obj;
+
+ if (!PyArg_ParseTupleAndKeywords(args,
+ kwargs,
+ "O",
+ kwlist,
+ &py_obj)) {
+ return NULL;
+ }
+
+ return get_destroy_flag(py_obj) ? Py_True : Py_False;
+}
+
static char aname_pool[] =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
@@ -125,6 +125,8 @@ PyObject *PyFtrace_detach(PyObject *self, PyObject *args, PyObject *kwargs);
PyObject *PyFtrace_attach(PyObject *self, PyObject *args, PyObject *kwargs);
+PyObject *PyFtrace_is_attached(PyObject *self, PyObject *args, PyObject *kwargs);
+
PyObject *PyFtrace_create_instance(PyObject *self, PyObject *args,
PyObject *kwargs);
@@ -237,6 +237,11 @@ static PyMethodDef ftracepy_methods[] = {
METH_VARARGS | METH_KEYWORDS,
"Attach object to the \'ftracepy\' module."
},
+ {"is_attached",
+ (PyCFunction) PyFtrace_is_attached,
+ METH_VARARGS | METH_KEYWORDS,
+ "Check if the object is attached to the \'ftracepy\' module."
+ },
{"create_instance",
(PyCFunction) PyFtrace_create_instance,
METH_VARARGS | METH_KEYWORDS,
We already have APIs for attaching/detaching an object from/to the 'ftracepy' module. For the sake of completeness we have to add an API that checks if the object is attached. Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com> --- src/ftracepy-utils.c | 22 ++++++++++++++++++++++ src/ftracepy-utils.h | 2 ++ src/ftracepy.c | 5 +++++ 3 files changed, 29 insertions(+)