On Thu, May 23, 2013 at 12:06:52PM +0800, Gao feng wrote: > Since these tty devices will be used by container, > the owner of them should be the root user of container. > > Signed-off-by: Gao feng <gaofeng@xxxxxxxxxxxxxx> > --- > src/lxc/lxc_controller.c | 43 +++++++++++++++++++++++++++++++++++++------ > 1 file changed, 37 insertions(+), 6 deletions(-) > > diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c > index 7d10660..4660f25 100644 > --- a/src/lxc/lxc_controller.c > +++ b/src/lxc/lxc_controller.c > @@ -1552,18 +1560,41 @@ virLXCControllerSetupConsoles(virLXCControllerPtr ctrl, > char **containerTTYPaths) > { > size_t i; > + int ret = -1; > + uid_t uid = (uid_t)-1; > + gid_t gid = (gid_t)-1; > + char *ttyHostPath = NULL; > + > + if (ctrl->def->idmap.uidmap) { > + uid = ctrl->def->idmap.uidmap[0].target; > + gid = ctrl->def->idmap.gidmap[0].target; > + } > > for (i = 0; i < ctrl->nconsoles; i++) { > VIR_DEBUG("Opening tty on private %s", ctrl->devptmx); > - if (lxcCreateTty(ctrl->devptmx, > + if (lxcCreateTty(ctrl, > &ctrl->consoles[i].contFd, > - &containerTTYPaths[i]) < 0) { > + &containerTTYPaths[i], &ttyHostPath) < 0) { > virReportSystemError(errno, "%s", > _("Failed to allocate tty")); > - return -1; > + goto out; > } > + > + /* Change the owner of tty device to the root user of container */ > + if (chown(ttyHostPath, uid, gid) < 0) { > + virReportSystemError(errno, > + _("Failed to change owner of tty" > + " %s to %u:%u"), > + ttyHostPath, uid, gid); > + goto out; > + } > + VIR_FREE(ttyHostPath); > } > - return 0; > + > + ret = 0; > +out: Replace 'out' with 'cleanup' to follow normal naming conventions in libvirt. > + VIR_FREE(ttyHostPath); > + return ret; > } daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :| -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list