build python extension for python3
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Wed, 2 Jan 2019 14:34:09 +0000 (15:34 +0100)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Wed, 2 Jan 2019 14:34:09 +0000 (15:34 +0100)
Makefile
setns.c

index 2ae9071..44bc3fd 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@ vsh: vsh.c
        gcc vsh.c -o vsh
 
 setns: setns.c
-       python setup.py build
+       python3 setup.py build
 
 ########## sync
 # for use with the test framework; push local stuff on a test node
@@ -22,7 +22,7 @@ setns: setns.c
 # this will attempt to compile vsh from vsh.c
 # so you might have to yum install gcc
 
-LOCAL_RSYNC_EXCLUDES   := --exclude '*.pyc' 
+LOCAL_RSYNC_EXCLUDES   := --exclude '*.pyc'
 RSYNC_EXCLUDES         := --exclude .git  --exclude .svn --exclude '*~' --exclude TAGS $(LOCAL_RSYNC_EXCLUDES)
 RSYNC_COND_DRY_RUN     := $(if $(findstring n,$(MAKEFLAGS)),--dry-run,)
 RSYNC                  := rsync -e "ssh -i $(NODE).key.rsa" -a -v $(RSYNC_COND_DRY_RUN) $(RSYNC_EXCLUDES)
@@ -79,4 +79,4 @@ install: setns vsh
        chmod u+s /usr/sbin/lxcsu
        chmod u+s /usr/sbin/slicesu
        chmod u+s /usr/sbin/vsh
-       cp build/lib*/setns.so /usr/sbin
+       cp build/lib*/setns.*.so /usr/sbin/setns.so
diff --git a/setns.c b/setns.c
index e8a4302..84116d9 100644 (file)
--- a/setns.c
+++ b/setns.c
@@ -101,9 +101,21 @@ static PyMethodDef SetnsMethods[] =
        {NULL, NULL, 0, NULL}
 };
 
-PyMODINIT_FUNC
+static struct PyModuleDef moduledef = {
+       PyModuleDef_HEAD_INIT,
+       "setns",
+       "http://git.onelab.eu/?p=lxc-userspace.git;a=summary",
+       -1,
+       SetnsMethods,
+       NULL,
+       NULL,
+       NULL,
+       NULL
+};
 
-initsetns(void)
-{
-       (void) Py_InitModule("setns", SetnsMethods);
+PyObject *PyInit_setns(void){
+       PyObject *module = PyModule_Create(&moduledef);
+    if (module == NULL)
+        return NULL;
+       return module;
 }