X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=python%2F_libvserver.c;h=fc2e7b1835b905fce6a466f6059a01ffc634b321;hb=d644358f28547545a360401e4b3a5536dda53257;hp=d433d4b983b716e9b895f423d818b846390a0490;hpb=d76191e6b008d6f0e76b23a3b24f915e690144b4;p=util-vserver.git diff --git a/python/_libvserver.c b/python/_libvserver.c index d433d4b..fc2e7b1 100644 --- a/python/_libvserver.c +++ b/python/_libvserver.c @@ -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