Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/libvirt_private.syms | 1 +
src/lxc/lxc_controller.c | 16 +---------------
src/util/virfile.c | 43 +++++++++++++++++++++++++++++++++++++++++--
src/util/virfile.h | 4 ++++
4 files changed, 47 insertions(+), 17 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index b984fa1..9653247 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1603,6 +1603,7 @@ virFileResolveLink;
virFileRewrite;
virFileSanitizePath;
virFileSetupDev;
+virFileSetupDevPTS;
virFileSkipRoot;
virFileStripSuffix;
virFileTouch;
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 3ab155f..d5e8359 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -2110,8 +2110,6 @@ virLXCControllerSetupDevPTS(virLXCControllerPtr ctrl)
ctrl->def);
if (virAsprintf(&devpts, "%s/%s.devpts",
- LXC_STATE_DIR, ctrl->def->name) < 0 ||
- virAsprintf(&ctrl->devptmx, "%s/%s.devpts/ptmx",
LXC_STATE_DIR, ctrl->def->name) < 0)
goto cleanup;
@@ -2133,20 +2131,8 @@ virLXCControllerSetupDevPTS(virLXCControllerPtr ctrl)
ptsgid, (mount_options ? mount_options : "")) < 0)
goto cleanup;
- VIR_DEBUG("Mount devpts on %s type=tmpfs flags=%x, opts=%s",
- devpts, MS_NOSUID, opts);
- if (mount("devpts", devpts, "devpts", MS_NOSUID, opts) < 0) {
- virReportSystemError(errno,
- _("Failed to mount devpts on %s"),
- devpts);
+ if (virFileSetupDevPTS(devpts, opts, &ctrl->devptmx) < 0)
goto cleanup;
- }
-
- if (access(ctrl->devptmx, R_OK) < 0) {
- virReportSystemError(ENOSYS, "%s",
- _("Kernel does not support private devpts"));
- goto cleanup;
- }
if ((lxcContainerChown(ctrl->def, ctrl->devptmx) < 0) ||
(lxcContainerChown(ctrl->def, devpts) < 0))
diff --git a/src/util/virfile.c b/src/util/virfile.c
index d86acbf..aa81ae3 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -3549,8 +3549,8 @@ virFileSetupDev(const char *path,
goto cleanup;
}
- VIR_DEBUG("Mount devfs on %s type=tmpfs flags=%lx, opts=%s",
- path, mount_flags, mount_options);
+ VIR_DEBUG("Mount devfs on %s type=%s flags=%lx, opts=%s",
+ path, mount_fs, mount_flags, mount_options);
if (mount("devfs", path, mount_fs, mount_flags, mount_options) < 0) {
virReportSystemError(errno,
_("Failed to mount devfs on %s type %s (%s)"),
@@ -3562,3 +3562,42 @@ virFileSetupDev(const char *path,
cleanup:
return ret;
}
+
+
+int
+virFileSetupDevPTS(const char *path,
+ const char *mount_options,
+ char **ptmx_ret)
+{
+ const unsigned long mount_flags = MS_NOSUID;
+ const char *mount_fs = "devpts";
+ char *devptmx = NULL;
+ int ret = -1;
+
+ if (virAsprintf(&devptmx, "%s/ptmx", path) < 0)
+ goto cleanup;
+
+ VIR_DEBUG("Mount devpts on %s type=%s flags=%lx, opts=%s",
+ path, mount_fs, mount_flags, mount_options);
+ if (mount("devpts", path, mount_fs, mount_flags, mount_options) < 0) {
+ virReportSystemError(errno,
+ _("Failed to mount devpts on %s type %s (%s)"),
+ path, mount_fs, mount_options);
+ goto cleanup;
+ }
+
+ if (access(devptmx, R_OK) < 0) {
+ virReportSystemError(ENOSYS, "%s",
+ _("Kernel does not support private devpts"));
+ goto cleanup;
+ }
+
+ if (ptmx_ret) {
+ *ptmx_ret = devptmx;
+ devptmx = NULL;
+ }
+ ret = 0;
+ cleanup:
+ VIR_FREE(devptmx);
+ return ret;
+}
diff --git a/src/util/virfile.h b/src/util/virfile.h
index 1b3830d..2dab6e7 100644
--- a/src/util/virfile.h
+++ b/src/util/virfile.h
@@ -322,4 +322,8 @@ int virFilePopulateDevices(const char *prefix,
int virFileSetupDev(const char *path,
const char *mount_options);
+
+int virFileSetupDevPTS(const char *path,
+ const char *mount_options,
+ char **ptmx_ret);
#endif /* __VIR_FILE_H */
--
2.8.4