Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
---
python/sanlock.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 75 insertions(+), 0 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index d953c90..00d97af 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -537,6 +537,79 @@ exit_fail:
return NULL;
}
+/* killpath */
+PyDoc_STRVAR(pydoc_killpath, "\
+killpath(path, args [, slkfd=fd])\n\
+Configure the path and arguments of the executable used to fence a\n\
+process either by causing the pid to exit (kill) or putting it into\n\
+a safe state (resources released).\n\
+The arguments must be in the format: [\"arg1\", \"arg2\",
...]");
+
+static PyObject *
+py_killpath(PyObject *self __unused, PyObject *args, PyObject *keywds)
+{
+ int rv, i, n, num_args, sanlockfd = -1;
+ char *p, *path, kpargs[SANLK_HELPER_ARGS_LEN];
+ PyObject *argslist, *item;
+
+ static char *kwlist[] = {"path", "args", "slkfd",
NULL};
+
+ /* parse python tuple */
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "sO!|i", kwlist,
+ &path, &PyList_Type, &argslist, &sanlockfd)) {
+ return NULL;
+ }
+
+ /* checking the path length */
+ if (strlen(path) + 1 > SANLK_HELPER_PATH_LEN) {
+ __set_exception(EINVAL, "Killpath path argument too long");
+ return NULL;
+ }
+
+ num_args = PyList_Size(argslist);
+ memset(kpargs, 0, SANLK_HELPER_ARGS_LEN);
+
+ /* creating the arguments string from a python list */
+ for (i = 0, n = 0; i < num_args; i++) {
+ size_t arg_len;
+
+ item = PyList_GetItem(argslist, i);
+ p = PyString_AsString(item);
+
+ if (p == NULL) {
+ __set_exception(EINVAL, "Killpath argument not a string");
+ return NULL;
+ }
+
+ /* adding a space between arguments */
+ if (n > 0) {
+ kpargs[n++] = ' ';
+ }
+
+ arg_len = strlen(p);
+
+ if (n + arg_len + 1 > SANLK_HELPER_ARGS_LEN) {
+ __set_exception(EINVAL, "Killpath arguments are too long");
+ return NULL;
+ }
+
+ strncpy(kpargs + n, p, arg_len + 1);
+ n += arg_len;
+ }
+
+ /* configure killpath (gil disabled) */
+ Py_BEGIN_ALLOW_THREADS
+ rv = sanlock_killpath(sanlockfd, 0, path, kpargs);
+ Py_END_ALLOW_THREADS
+
+ if (rv != 0) {
+ __set_exception(rv, "Killpath script not configured");
+ return NULL;
+ }
+
+ Py_RETURN_NONE;
+}
+
/* exception_errno */
PyDoc_STRVAR(pydoc_errno, "exception errno");
@@ -572,6 +645,8 @@ sanlock_methods[] = {
METH_VARARGS|METH_KEYWORDS, pydoc_acquire},
{"release", (PyCFunction) py_release,
METH_VARARGS|METH_KEYWORDS, pydoc_release},
+ {"killpath", (PyCFunction) py_killpath,
+ METH_VARARGS|METH_KEYWORDS, pydoc_killpath},
{NULL, NULL, 0, NULL}
};
--
1.7.1