--- rpm-4.3.3/lib/poptALL.c.vzctl 2005-08-25 15:23:04.000000000 +0400 +++ rpm-4.3.3/lib/poptALL.c 2005-08-26 14:29:44.000000000 +0400 @@ -104,6 +104,8 @@ /*@unchecked@*/ extern int _rpmio_debug; +/*@unchecked@*/ +extern int rpm_veid; /*@=exportheadervar@*/ /*@unchecked@*/ @@ -328,6 +330,8 @@ NULL, NULL}, { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1, N_("debug URL cache handling"), NULL}, + { "veid", '\0', POPT_ARG_INT|POPT_ARGFLAG_DOC_HIDDEN, &rpm_veid, 0, + N_("veid to run under"), NULL}, POPT_TABLEEND }; --- rpm-4.3.3/lib/psm.c.vzctl 2005-08-25 15:23:04.000000000 +0400 +++ rpm-4.3.3/lib/psm.c 2005-08-26 14:38:01.000000000 +0400 @@ -489,6 +489,13 @@ static const char * ldconfig_path = NULL; #endif +int rpm_veid; + +void rpmpsmSetVPS(int veid) +{ + rpm_veid = veid; +} + /** * Run scriptlet with args. * @@ -768,13 +775,24 @@ rootDir = strchr(rootDir, '/'); /*@fallthrough@*/ case URL_IS_UNKNOWN: - if (!rpmtsChrootDone(ts) && + if (!rpm_veid && !rpmtsChrootDone(ts) && !(rootDir[0] == '/' && rootDir[1] == '\0')) { /*@-superuser -noeffect @*/ xx = chroot(rootDir); /*@=superuser =noeffect @*/ } + if (rpm_veid) { + const char ** _argv = alloca((argc+3+1) * sizeof(char *)); + if (rpmtsChrootDone(ts)) + xx = chroot("."); + _argv[0] = "/usr/sbin/vzctl"; + _argv[1] = "exec3"; + _argv[2] = alloca(sizeof(int)*4); + sprintf(_argv[2], "%d", rpm_veid); + memcpy(_argv+3, argv, (argc+1) * sizeof(char *)); + argv = _argv; + } else xx = chdir("/"); rpmMessage(RPMMESS_DEBUG, _("%s: %s(%s-%s-%s.%s)\texecv(%s) pid %d\n"), psm->stepName, sln, n, v, r, a, --- rpm-4.3.3/lib/psm.h.vzctl 2005-08-25 15:23:04.000000000 +0400 +++ rpm-4.3.3/lib/psm.h 2005-08-26 14:44:36.000000000 +0400 @@ -183,6 +183,12 @@ /*@modifies psm, rpmGlobalMacroContext, fileSystem, internalState @*/; #define rpmpsmUNSAFE rpmpsmSTAGE +/** + * Sets VPS ID, so all scripts will be executed inside given VE. + * @param veid VPS ID + */ +void rpmpsmSetVPS(int veid); + #ifdef __cplusplus } #endif --- rpm-4.3.3/python/rpmts-py.c.vzctl 2005-08-25 15:23:04.000000000 +0400 +++ rpm-4.3.3/python/rpmts-py.c 2005-08-26 14:52:14.000000000 +0400 @@ -7,6 +7,7 @@ #include #include #include +#include "psm.h" #include "header-py.h" #include "rpmds-py.h" /* XXX for rpmdsNew */ @@ -112,6 +113,9 @@ * - ts.order() Do a topological sort of added element relations. * @return None * + * - ts.setVPS(veid) Set VPS ID, so all scripts will be executed in VPS. + * @return None + * * - ts.setFlags(transFlags) Set transaction set flags. * @param transFlags - bit(s) to controll transaction operations. The * following values can be logically OR'ed together: @@ -1077,6 +1081,19 @@ /** \ingroup py_c */ +static PyObject * rpmts_SetVPS(rpmtsObject * s, PyObject * args) +{ + int veid = 0; + + if (!PyArg_ParseTuple(args, "i:SetVPS", &veid)) + return NULL; + + rpmpsmSetVPS(veid); + return Py_BuildValue("i", veid); +} + +/** \ingroup python + */ static PyObject * rpmts_SetFlags(rpmtsObject * s, PyObject * args) /*@modifies s @*/ { @@ -1333,6 +1350,9 @@ NULL }, {"order", (PyCFunction) rpmts_Order, METH_VARARGS, NULL }, + {"setVPS", rpmts_SetVPS, METH_VARARGS, +"ts.setVPS(veid) -> None \n\ +- Sets VPS ID, so all scripts will be executed in context of given VPS.\n" }, {"setFlags", (PyCFunction) rpmts_SetFlags, METH_VARARGS, "ts.setFlags(transFlags) -> previous transFlags\n\ - Set control bit(s) for executing ts.run().\n\