[lxc-devel] [PATCH 4/5] python/attach: export CLONE_NEW* constants to Python
Christian Seiler
christian at iwakd.de
Sun Aug 18 22:52:43 UTC 2013
Signed-off-by: Christian Seiler <christian at iwakd.de>
---
src/python-lxc/lxc.c | 36 ++++++++++++++++++++++++++++--------
src/python-lxc/lxc/__init__.py | 6 ++++++
2 files changed, 34 insertions(+), 8 deletions(-)
diff --git a/src/python-lxc/lxc.c b/src/python-lxc/lxc.c
index f4de169..b2abf38 100644
--- a/src/python-lxc/lxc.c
+++ b/src/python-lxc/lxc.c
@@ -25,6 +25,7 @@
#include "structmember.h"
#include <lxc/lxccontainer.h>
#include <lxc/utils.h>
+#include <lxc/namespace.h>
#include <stdio.h>
#include <sys/wait.h>
@@ -718,6 +719,8 @@ static int lxc_attach_python_exec(void* _payload)
return -1;
}
+static void lxc_attach_free_options(lxc_attach_options_t *options);
+
static lxc_attach_options_t *lxc_attach_parse_options(PyObject *kwds)
{
static char *kwlist[] = {"attach_flags", "namespaces", "personality", "initial_cwd", "uid", "gid", "env_policy", "extra_env_vars", "extra_keep_env", "stdin", "stdout", "stderr", NULL};
@@ -1170,14 +1173,31 @@ PyInit__lxc(void)
/* add constants */
d = PyModule_GetDict(m);
- PyDict_SetItemString(d, "LXC_ATTACH_KEEP_ENV", PyLong_FromLong(LXC_ATTACH_KEEP_ENV));
- PyDict_SetItemString(d, "LXC_ATTACH_CLEAR_ENV", PyLong_FromLong(LXC_ATTACH_CLEAR_ENV));
- PyDict_SetItemString(d, "LXC_ATTACH_MOVE_TO_CGROUP", PyLong_FromLong(LXC_ATTACH_MOVE_TO_CGROUP));
- PyDict_SetItemString(d, "LXC_ATTACH_DROP_CAPABILITIES", PyLong_FromLong(LXC_ATTACH_DROP_CAPABILITIES));
- PyDict_SetItemString(d, "LXC_ATTACH_SET_PERSONALITY", PyLong_FromLong(LXC_ATTACH_SET_PERSONALITY));
- PyDict_SetItemString(d, "LXC_ATTACH_APPARMOR", PyLong_FromLong(LXC_ATTACH_APPARMOR));
- PyDict_SetItemString(d, "LXC_ATTACH_REMOUNT_PROC_SYS", PyLong_FromLong(LXC_ATTACH_REMOUNT_PROC_SYS));
- PyDict_SetItemString(d, "LXC_ATTACH_DEFAULT", PyLong_FromLong(LXC_ATTACH_DEFAULT));
+
+ #define PYLXC_EXPORT_CONST(c) PyDict_SetItemString(d, #c, PyLong_FromLong(c))
+
+ /* environment variable handling */
+ PYLXC_EXPORT_CONST(LXC_ATTACH_KEEP_ENV);
+ PYLXC_EXPORT_CONST(LXC_ATTACH_CLEAR_ENV);
+
+ /* attach options */
+ PYLXC_EXPORT_CONST(LXC_ATTACH_MOVE_TO_CGROUP);
+ PYLXC_EXPORT_CONST(LXC_ATTACH_DROP_CAPABILITIES);
+ PYLXC_EXPORT_CONST(LXC_ATTACH_SET_PERSONALITY);
+ PYLXC_EXPORT_CONST(LXC_ATTACH_APPARMOR);
+ PYLXC_EXPORT_CONST(LXC_ATTACH_REMOUNT_PROC_SYS);
+ PYLXC_EXPORT_CONST(LXC_ATTACH_DEFAULT);
+
+ /* namespace flags (no other python lib exports this) */
+ PYLXC_EXPORT_CONST(CLONE_NEWUTS);
+ PYLXC_EXPORT_CONST(CLONE_NEWIPC);
+ PYLXC_EXPORT_CONST(CLONE_NEWUSER);
+ PYLXC_EXPORT_CONST(CLONE_NEWPID);
+ PYLXC_EXPORT_CONST(CLONE_NEWNET);
+ PYLXC_EXPORT_CONST(CLONE_NEWNS);
+
+ #undef PYLXC_EXPORT_CONST
+
return m;
}
diff --git a/src/python-lxc/lxc/__init__.py b/src/python-lxc/lxc/__init__.py
index 1748bac..95d33e5 100644
--- a/src/python-lxc/lxc/__init__.py
+++ b/src/python-lxc/lxc/__init__.py
@@ -459,3 +459,9 @@ LXC_ATTACH_SET_PERSONALITY = _lxc.LXC_ATTACH_SET_PERSONALITY
LXC_ATTACH_APPARMOR = _lxc.LXC_ATTACH_APPARMOR
LXC_ATTACH_REMOUNT_PROC_SYS = _lxc.LXC_ATTACH_REMOUNT_PROC_SYS
LXC_ATTACH_DEFAULT = _lxc.LXC_ATTACH_DEFAULT
+CLONE_NEWUTS = _lxc.CLONE_NEWUTS
+CLONE_NEWIPC = _lxc.CLONE_NEWIPC
+CLONE_NEWUSER = _lxc.CLONE_NEWUSER
+CLONE_NEWPID = _lxc.CLONE_NEWPID
+CLONE_NEWNET = _lxc.CLONE_NEWNET
+CLONE_NEWNS = _lxc.CLONE_NEWNS
--
1.7.10.4
More information about the lxc-devel
mailing list