Adds the arch_to_personality function that looks up an architecture and returns the corresponding personality. This may be used in conjunction with the attach/attach_wait keyword argument.
Signed-off-by: Christian Seiler <christ...@iwakd.de> --- src/python-lxc/lxc.c | 32 ++++++++++++++++++++++++++++++++ src/python-lxc/lxc/__init__.py | 8 ++++++++ 2 files changed, 40 insertions(+) diff --git a/src/python-lxc/lxc.c b/src/python-lxc/lxc.c index b2abf38..65be814 100644 --- a/src/python-lxc/lxc.c +++ b/src/python-lxc/lxc.c @@ -26,6 +26,7 @@ #include <lxc/lxccontainer.h> #include <lxc/utils.h> #include <lxc/namespace.h> +#include <lxc/confile.h> #include <stdio.h> #include <sys/wait.h> @@ -887,6 +888,35 @@ LXC_attach_run_shell(PyObject *self, PyObject *arg) } static PyObject * +LXC_arch_to_personality(PyObject *self, PyObject *arg) +{ + long rv = -1; + PyObject *pystr; + char *str; + + if (!PyUnicode_Check(arg)) { + PyErr_SetString(PyExc_ValueError, "Expected a string"); + return NULL; + } + + pystr = PyUnicode_AsUTF8String(arg); + if (!pystr) + return NULL; + + str = PyBytes_AsString(pystr); + if (!str) + goto out; + + rv = lxc_config_parse_arch(str); + if (rv == -1) + PyErr_SetString(PyExc_KeyError, "Failed to lookup architecture."); + +out: + Py_DECREF(pystr); + return rv == -1 ? NULL : PyLong_FromLong(rv); +} + +static PyObject * LXC_attach_run_command(PyObject *self, PyObject *arg) { PyObject *args_obj = NULL; @@ -1140,6 +1170,8 @@ static PyMethodDef LXC_methods[] = { "Starts up a shell when attaching, to use as the run parameter for attach or attach_wait"}, {"attach_run_command", (PyCFunction)LXC_attach_run_command, METH_O, "Runs a command when attaching, to use as the run parameter for attach or attach_wait"}, + {"arch_to_personality", (PyCFunction)LXC_arch_to_personality, METH_O, + "Returns the process personality of the corresponding architecture"}, {"get_default_config_path", (PyCFunction)LXC_get_default_config_path, METH_NOARGS, "Returns the current LXC config path"}, {"get_version", (PyCFunction)LXC_get_version, METH_NOARGS, diff --git a/src/python-lxc/lxc/__init__.py b/src/python-lxc/lxc/__init__.py index 95d33e5..67f22dc 100644 --- a/src/python-lxc/lxc/__init__.py +++ b/src/python-lxc/lxc/__init__.py @@ -450,6 +450,14 @@ def attach_run_shell(): """ return _lxc.attach_run_shell(None) +def arch_to_personality(arch): + """ + Determine the process personality corresponding to the architecture + """ + if isinstance(arch, bytes): + arch = str(arch, 'utf-8') + return _lxc.arch_to_personality(arch) + # Some constants for attach LXC_ATTACH_KEEP_ENV = _lxc.LXC_ATTACH_KEEP_ENV LXC_ATTACH_CLEAR_ENV = _lxc.LXC_ATTACH_CLEAR_ENV -- 1.7.10.4 ------------------------------------------------------------------------------ Get 100% visibility into Java/.NET code with AppDynamics Lite! It's a free troubleshooting tool designed for production. Get down to code-level detail for bottlenecks, with <2% overhead. Download for free and get started troubleshooting in minutes. http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk _______________________________________________ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel