Match-id-e09f4bfabe86ff28154841143128cab741c4e76a

This commit is contained in:
BianTanggui
2020-10-27 15:33:37 +08:00
parent 62c2d9a004
commit 230b2759a6
2 changed files with 14 additions and 3 deletions

View File

@@ -18,7 +18,7 @@
#define MAX_DEVICE_NR 1024
#define MAX_MOUNT_NR 512
#define LOG(level, fmt, ...) \
#define LOG_ERROR(fmt, ...) \
do { \
char _content[BUF_SIZE] = {0}; \
int _ret = sprintf_s(_content, BUF_SIZE, fmt, ##__VA_ARGS__); \
@@ -29,8 +29,6 @@
} \
} while (0)
#define LOG_ERROR(fmt, ...) LOG('E', fmt, ##__VA_ARGS__)
#define ALLOW_PATH "/devices.allow"
#define ROOT_GAP 4
#define FSTYPE_GAP 2

View File

@@ -96,6 +96,19 @@ int MountDevice(const char *rootfs, const char *deviceName)
return -1;
}
errno = 0;
struct stat dstStat;
ret = stat((const char *)dst, &dstStat);
if (ret == 0 && S_ISCHR(dstStat.st_mode)) {
return 0; // 特权容器自动挂载HOST所有设备故此处跳过
} else if (ret == 0) {
LOG_ERROR("error: %s already exists but not a char device as expected.", dst);
return -1;
} else if (ret < 0 && errno != ENOENT) {
LOG_ERROR("error: failed to check dst %s stat: %s.", dst, strerror(errno));
return -1;
}
ret = CreateFile(dst, srcStat.st_mode);
if (ret < 0) {
LOG_ERROR("error: failed to create mount dst file: %s.", dst);