gentoo: use /var/run for new /run compatibility
[util-vserver.git] / python / _libvserver.c
index 53a46d8..fc2e7b1 100644 (file)
@@ -163,7 +163,7 @@ pyvserver_set_cflags(PyObject UNUSED *self, PyObject *args)
   xid_t xid;
   struct vc_ctx_flags flags;
 
-  if (!PyArg_ParseTuple(args, "I(KK)", &xid, flags.flagword, flags.mask))
+  if (!PyArg_ParseTuple(args, "I(KK)", &xid, &flags.flagword, &flags.mask))
     return NULL;
 
   if (vc_set_cflags(xid, &flags) == -1)
@@ -591,6 +591,7 @@ pyvserver_get_vhi_name(PyObject UNUSED *self, PyObject *args)
   xid_t xid;
   vc_uts_type type;
   char val[65];
+  int i;
 
   if (!PyArg_ParseTuple(args, "Ii", &xid, &type))
     return NULL;
@@ -598,7 +599,10 @@ pyvserver_get_vhi_name(PyObject UNUSED *self, PyObject *args)
   if (vc_get_vhi_name(xid, type, val, sizeof(val)) == -1)
     return PyErr_SetFromErrno(PyExc_OSError);
 
-  return Py_BuildValue("s#", val, sizeof(val));
+  for (i = sizeof(val); i > 0 && val[i - 1] == '\0'; i--)
+    ;
+
+  return Py_BuildValue("s#", val, i);
 }
 
 static PyObject *
@@ -1136,10 +1140,28 @@ PyModule_AddLongLongConstant(PyObject *mod, const char *str, long long val)
                return;
 }
 
+#if PY_MAJOR_VERSION == 2
 PyMODINIT_FUNC init_libvserver(void)
 {
   PyObject *mod;
 
   mod = Py_InitModule("_libvserver", methods);
 #include "_libvserver-constants.c"
+  return mod;
+}
+#else
+PyMODINIT_FUNC
+PyInit__libvserver(void)
+{
+  static struct PyModuleDef lvmodule = {
+    PyModuleDef_HEAD_INIT,
+    "_libvserver",
+    NULL,
+    -1,
+    methods
+  };
+  PyObject *mod = PyModule_Create(&lvmodule);
+#include "_libvserver-constants.c"
+  return mod;
 }
+#endif