lxc/0128-link-proc-mounts-to-etc-mtab.patch

78 lines
2.0 KiB
Diff
Raw Normal View History

From 2bca52aab48cf7337df9dfb64d20f55ceac3a9ff Mon Sep 17 00:00:00 2001
2019-12-25 15:57:42 +08:00
From: wujing <wujing50@huawei.com>
Date: Tue, 10 Dec 2019 21:28:47 +0800
Subject: [PATCH 128/140] link /proc/mounts to /etc/mtab
2019-12-25 15:57:42 +08:00
Signed-off-by: wujing <wujing50@huawei.com>
---
src/lxc/conf.c | 39 ++++++++++++++++++++++++++++++++++++++-
1 file changed, 38 insertions(+), 1 deletion(-)
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index 21ec340..b66e7bc 100644
2019-12-25 15:57:42 +08:00
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -4101,6 +4101,37 @@ static int setup_rootfs_mountopts(const struct lxc_rootfs *rootfs)
return 0;
}
+static int create_mtab_link()
+{
+ ssize_t ret;
+ int mret;
+ struct stat sbuf;
+ const char *pathname = "/proc/mounts";
+ const char *slink = "/etc/mtab";
+
+ if (file_exists(slink)) {
+ return 0;
+ }
+
+ ret = stat(pathname, &sbuf);
+ if (ret < 0) {
+ SYSERROR("Failed to stat %s: %s", pathname, strerror(errno));
+ return -1;
+ }
+
+ mret = symlink(pathname, slink);
+ if (mret < 0 && errno != EEXIST) {
+ if (errno == EROFS) {
+ WARN("Failed to create link %s for target %s. Read-only filesystem", slink, pathname);
+ } else {
+ SYSERROR("Failed to create \"%s\"", slink);
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
int lxc_setup(struct lxc_handler *handler)
{
int ret;
@@ -4331,7 +4362,7 @@ int lxc_setup(struct lxc_handler *handler)
}
}
- //isulad: system container, remount /proc/sys/xxx by mount_list
+ // isulad: system container, remount /proc/sys/xxx by mount_list
if (lxc_conf->systemd != NULL && strcmp(lxc_conf->systemd, "true") == 0) {
if (!lxc_list_empty(&lxc_conf->mount_list)) {
if (remount_proc_sys_mount_entries(&lxc_conf->mount_list)) {
@@ -4341,6 +4372,12 @@ int lxc_setup(struct lxc_handler *handler)
}
}
+ // isulad: create link /etc/mtab for /proc/mounts
+ if (create_mtab_link() != 0) {
+ ERROR("failed to create link /etc/mtab for target /proc/mounts");
+ goto on_error;
+ }
+
if (!lxc_list_empty(&lxc_conf->keepcaps)) {
if (!lxc_list_empty(&lxc_conf->caps)) {
ERROR("Container requests lxc.cap.drop and "
--
1.8.3.1
2019-12-25 15:57:42 +08:00