From e86ebe923f1ecc072d8a99949871b46fe8188ac9 Mon Sep 17 00:00:00 2001 From: wujing Date: Wed, 15 Apr 2020 06:01:36 -0400 Subject: [PATCH 32/49] link proc mounts to etc mtab Signed-off-by: wujing --- src/lxc/conf.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 325e0c2..6856b1d 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -3977,6 +3977,37 @@ struct oci_hook_conf { int which; }; +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; +} + struct wait_conf { pid_t pid; unsigned long long startat; @@ -4696,6 +4727,12 @@ int lxc_setup(struct lxc_handler *handler) return log_error(-1, "failed to setup readonlypaths"); } } + + // 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; + } #endif if (!lxc_list_empty(&lxc_conf->keepcaps)) { -- 1.8.3.1