/** * virDomainLxcEnterNamespace: * @domain: a domain object * @nfdlist: number of FDs in @fdlist * @fdlist: list of namespace file descriptors * @noldfdlist: filled with number of old FDs * @oldfdlist: pointer to hold list of old namespace file descriptors * @flags: currently unused, pass 0 * * This API is LXC specific, so it will only work with hypervisor * connections to the LXC driver. * * Attaches the process to the namespaces associated * with the FDs in @fdlist * * If @oldfdlist is non-NULL, it will be populated with file * descriptors representing the old namespace. This allows * the caller to switch back to its current namespace later * * Returns 0 on success, -1 on error */ int virDomainLxcEnterNamespace(virDomainPtr domain, unsigned int nfdlist, int *fdlist, unsigned int *noldfdlist, int **oldfdlist, unsigned int flags) { size_t i; VIR_DOMAIN_DEBUG(domain, "nfdlist=%d, fdlist=%p, " "noldfdlist=%p, oldfdlist=%p, flags=%x", nfdlist, fdlist, noldfdlist, oldfdlist, flags); virResetLastError(); virCheckFlagsGoto(0, error); if (noldfdlist && oldfdlist) { size_t nfds; if (virProcessGetNamespaces(getpid(), &nfds, oldfdlist) < 0) goto error; *noldfdlist = nfds; } if (virProcessSetNamespaces(nfdlist, fdlist) < 0) { if (oldfdlist && noldfdlist) { for (i = 0; i < *noldfdlist; i++) VIR_FORCE_CLOSE((*oldfdlist)[i]); VIR_FREE(*oldfdlist); *noldfdlist = 0; } goto error; } return 0; error: virDispatchError(domain->conn); return -1; }
/** * virDomainLxcEnterNamespace: * @domain: a domain object * @nfdlist: number of FDs in @fdlist * @fdlist: list of namespace file descriptors * @noldfdlist: filled with number of old FDs * @oldfdlist: pointer to hold list of old namespace file descriptors * @flags: currently unused, pass 0 * * This API is LXC specific, so it will only work with hypervisor * connections to the LXC driver. * * Attaches the process to the namespaces associated * with the FDs in @fdlist * * If @oldfdlist is non-NULL, it will be populated with file * descriptors representing the old namespace. This allows * the caller to switch back to its current namespace later * * Returns 0 on success, -1 on error */ int virDomainLxcEnterNamespace(virDomainPtr domain, unsigned int nfdlist, int *fdlist, unsigned int *noldfdlist, int **oldfdlist, unsigned int flags) { int i; virCheckFlagsGoto(0, error); if (noldfdlist && oldfdlist) { size_t nfds; if (virProcessGetNamespaces(getpid(), &nfds, oldfdlist) < 0) goto error; *noldfdlist = nfds; } if (virProcessSetNamespaces(nfdlist, fdlist) < 0) { if (oldfdlist && noldfdlist) { for (i = 0 ; i < *noldfdlist ; i++) { VIR_FORCE_CLOSE((*oldfdlist)[i]); } VIR_FREE(*oldfdlist); *noldfdlist = 0; } goto error; } return 0; error: virDispatchError(domain->conn); return -1; }