X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=python%2Fvserverimpl.c;h=931357b71b18b3203c8140352b1058cf4d644a21;hb=322d0b4dbdc5b5621e2deb7e4188a64fce95e5aa;hp=a568fb278d6e39361fc5a805986aef91827824cb;hpb=867fdb7b3dcc453dd35b25923bce30fa90039035;p=util-vserver-pl.git diff --git a/python/vserverimpl.c b/python/vserverimpl.c index a568fb2..931357b 100644 --- a/python/vserverimpl.c +++ b/python/vserverimpl.c @@ -59,6 +59,8 @@ static inline PyObject *inc_and_ret_none(void) #define NONE inc_and_ret_none() +#define PL_INSECURE_BCAPS (vc_get_insecurebcaps() | (1 << VC_CAP_NET_BIND_SERVICE)) + /* * context create */ @@ -71,7 +73,7 @@ vserver_chcontext(PyObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "I|K", &ctx, &bcaps)) return NULL; - bcaps |= ~(vc_get_insecurebcaps() | (1 << VC_CAP_NET_BIND_SERVICE)); + bcaps |= ~PL_INSECURE_BCAPS; if ((ctx_is_new = pl_chcontext(ctx, bcaps, 0)) < 0) return PyErr_SetFromErrno(PyExc_OSError); @@ -301,7 +303,7 @@ vserver_set_bcaps(PyObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "IK", &ctx, &caps.bcaps)) return NULL; - caps.bmask = vc_get_insecurebcaps(); + caps.bmask = PL_INSECURE_BCAPS; caps.cmask = caps.ccaps = 0; if (vc_set_ccaps(ctx, &caps) == -1 && errno != ESRCH) return PyErr_SetFromErrno(PyExc_OSError); @@ -341,7 +343,7 @@ vserver_get_bcaps(PyObject *self, PyObject *args) caps.bcaps = 0; } - return Py_BuildValue("K", caps.bcaps & vc_get_insecurebcaps()); + return Py_BuildValue("K", caps.bcaps & PL_INSECURE_BCAPS); } static PyObject * @@ -610,7 +612,7 @@ vserver_mount(PyObject *self, PyObject *args) if (secure_chdir(&dirs, guest, target) == -1) goto out; - if (mount(source, ".", type, flags, data) == -1) + if (mount(source, ".", type, flags, data) == -1 && errno != EBUSY) goto out; restore_dirs(&dirs); @@ -664,6 +666,43 @@ vserver_set_runlevel(PyObject *self, PyObject *args) return NONE; } +static PyObject * +vserver_set_name(PyObject *self, PyObject *args) +{ + xid_t ctx, slice_id; + char buf[sizeof(long int)*3+2]; + PyObject *ret; + + if (!PyArg_ParseTuple(args, "II", &ctx, &slice_id)) + return NULL; + + snprintf(buf, sizeof(buf), "%d", slice_id); + + if (vc_set_vhi_name(ctx, vcVHI_CONTEXT, buf, sizeof(buf)) != 0) { + return PyErr_SetFromErrno(PyExc_OSError); + } else { + return NONE; + } +} + +static PyObject * +vserver_get_name(PyObject *self, PyObject *args) +{ + xid_t ctx; + char buf[sizeof(long int)*3+2]; + PyObject *ret; + + if (!PyArg_ParseTuple(args, "I", &ctx)) + return NULL; + + if (vc_get_vhi_name(ctx, vcVHI_CONTEXT, buf, sizeof(buf)) !=0 ) { + ret = PyErr_SetFromErrno(PyExc_OSError); + } else { + ret = Py_BuildValue("i", atoi(buf)); + } + return ret; +} + static PyMethodDef methods[] = { { "chcontext", vserver_chcontext, METH_VARARGS, "chcontext to vserver with provided flags" }, @@ -703,6 +742,10 @@ static PyMethodDef methods[] = { "Perform the umount2() system call" }, { "setrunlevel", vserver_set_runlevel, METH_VARARGS, "Set the runlevel in utmp" }, + { "setname", vserver_set_name, METH_VARARGS, + "Set the vcVHI_CONTEXT for a xid." }, + { "getname", vserver_get_name, METH_VARARGS, + "Get the vcVHI_CONTEXT for a xid." }, { NULL, NULL, 0, NULL } };