iSulad/0004-fix-bug-of-creating-symlink-for-etc-mtab-when-etc-sy.patch
haozi007 812fa9d606 sync openeuler
1. fix bugs
2. improve testcase

Signed-off-by: haozi007 <liuhao27@huawei.com>
2020-06-28 17:07:11 +08:00

60 lines
1.8 KiB
Diff

From 274e8a2964d5d2ab566f92bd0930c08a346cb158 Mon Sep 17 00:00:00 2001
From: gaohuatao <gaohuatao@huawei.com>
Date: Tue, 23 Jun 2020 06:40:17 -0400
Subject: [PATCH 4/6] fix bug of creating symlink for /etc/mtab when /etc
symlink exists
Signed-off-by: gaohuatao <gaohuatao@huawei.com>
---
src/services/execution/execute/execution.c | 23 ++++++++++------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/src/services/execution/execute/execution.c b/src/services/execution/execute/execution.c
index 19b6a751..4ffcde7a 100644
--- a/src/services/execution/execute/execution.c
+++ b/src/services/execution/execute/execution.c
@@ -818,30 +818,27 @@ static int create_mtab_link(const oci_runtime_spec *oci_spec)
goto out;
}
- if (!util_dir_exists(dir)) {
- ret = util_mkdir_p(dir, ETC_FILE_MODE);
- if (ret != 0) {
- ERROR("Unable to create mtab directory %s.", dir);
- goto out;
- }
+ if (unlink(dir) != 0) {
+ WARN("Failed to delete \"%s\": %s", dir, strerror(errno));
}
if (util_file_exists(slink)) {
goto out;
}
- ret = symlink(pathname, slink);
- if (ret < 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);
+ if (!util_dir_exists(dir)) {
+ if (util_mkdir_p(dir, ETC_FILE_MODE) != 0) {
ret = -1;
+ ERROR("Unable to create mtab directory %s.", dir);
goto out;
}
}
- ret = 0;
+ if (symlink(pathname, slink) != 0) {
+ ret = -1;
+ SYSERROR("Failed to create \"%s\"", slink);
+ goto out;
+ }
out:
free(slink);
--
2.25.1