mirror of
https://github.com/Ascend/ascend-docker-runtime.git
synced 2025-10-11 13:10:04 +08:00
Match-id-2dde9f027721ce1b2cc97d2c9c433ea457db8afd
This commit is contained in:
@@ -73,20 +73,20 @@ int SetupDeviceCgroup(FILE *cgroupAllow, const char *devName)
|
|||||||
|
|
||||||
ret = snprintf_s(devPath, BUF_SIZE, BUF_SIZE, "/dev/%s", devName);
|
ret = snprintf_s(devPath, BUF_SIZE, BUF_SIZE, "/dev/%s", devName);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to assemble dev path for %s\n", devName);
|
LogError("error: failed to assemble dev path for %s\n", devName);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = stat((const char *)devPath, &devStat);
|
ret = stat((const char *)devPath, &devStat);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to get stat of %s\n", devPath);
|
LogError("error: failed to get stat of %s\n", devPath);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isFailed = fprintf(cgroupAllow, "c %u:%u rw", major(devStat.st_rdev), minor(devStat.st_rdev)) < 0 ||
|
bool isFailed = fprintf(cgroupAllow, "c %u:%u rw", major(devStat.st_rdev), minor(devStat.st_rdev)) < 0 ||
|
||||||
fflush(cgroupAllow) == EOF || ferror(cgroupAllow) < 0;
|
fflush(cgroupAllow) == EOF || ferror(cgroupAllow) < 0;
|
||||||
if (isFailed) {
|
if (isFailed) {
|
||||||
logError("error: write devices failed\n");
|
LogError("error: write devices failed\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,19 +99,19 @@ int SetupDriverCgroup(FILE *cgroupAllow)
|
|||||||
|
|
||||||
ret = SetupDeviceCgroup(cgroupAllow, DAVINCI_MANAGER);
|
ret = SetupDeviceCgroup(cgroupAllow, DAVINCI_MANAGER);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to setup cgroup for %s\n", DAVINCI_MANAGER);
|
LogError("error: failed to setup cgroup for %s\n", DAVINCI_MANAGER);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = SetupDeviceCgroup(cgroupAllow, DEVMM_SVM);
|
ret = SetupDeviceCgroup(cgroupAllow, DEVMM_SVM);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to setup cgroup for %s\n", DEVMM_SVM);
|
LogError("error: failed to setup cgroup for %s\n", DEVMM_SVM);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = SetupDeviceCgroup(cgroupAllow, HISI_HDC);
|
ret = SetupDeviceCgroup(cgroupAllow, HISI_HDC);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to setup cgroup for %s\n", HISI_HDC);
|
LogError("error: failed to setup cgroup for %s\n", HISI_HDC);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,13 +126,13 @@ int GetCgroupPath(const struct CmdArgs *args, char *effPath, const size_t maxSiz
|
|||||||
|
|
||||||
ret = snprintf_s(mountPath, BUF_SIZE, BUF_SIZE, "/proc/%d/mountinfo", (int)getppid());
|
ret = snprintf_s(mountPath, BUF_SIZE, BUF_SIZE, "/proc/%d/mountinfo", (int)getppid());
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: assemble mount info path failed: ppid(%d)\n", getppid());
|
LogError("error: assemble mount info path failed: ppid(%d)\n", getppid());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = CatFileContent(mount, BUF_SIZE, GetCgroupMount, mountPath);
|
ret = CatFileContent(mount, BUF_SIZE, GetCgroupMount, mountPath);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: cat file content failed\n");
|
LogError("error: cat file content failed\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,13 +140,13 @@ int GetCgroupPath(const struct CmdArgs *args, char *effPath, const size_t maxSiz
|
|||||||
char cgroupPath[BUF_SIZE] = {0x0};
|
char cgroupPath[BUF_SIZE] = {0x0};
|
||||||
ret = snprintf_s(cgroupPath, BUF_SIZE, BUF_SIZE, "/proc/%d/cgroup", args->pid);
|
ret = snprintf_s(cgroupPath, BUF_SIZE, BUF_SIZE, "/proc/%d/cgroup", args->pid);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: assemble cgroup path failed: pid(%d)\n", args->pid);
|
LogError("error: assemble cgroup path failed: pid(%d)\n", args->pid);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = CatFileContent(cgroup, BUF_SIZE, GetCgroupRoot, cgroupPath);
|
ret = CatFileContent(cgroup, BUF_SIZE, GetCgroupRoot, cgroupPath);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: cat file content failed\n");
|
LogError("error: cat file content failed\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,7 +155,7 @@ int GetCgroupPath(const struct CmdArgs *args, char *effPath, const size_t maxSiz
|
|||||||
|
|
||||||
ret = snprintf_s(effPath, BUF_SIZE, maxSize, "%s%s%s", mount, cgroup, ALLOW_PATH);
|
ret = snprintf_s(effPath, BUF_SIZE, maxSize, "%s%s%s", mount, cgroup, ALLOW_PATH);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: assemble cgroup device path failed: \n");
|
LogError("error: assemble cgroup device path failed: \n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,7 +170,7 @@ int SetupCgroup(struct CmdArgs *args, const char *cgroupPath)
|
|||||||
FILE *cgroupAllow = NULL;
|
FILE *cgroupAllow = NULL;
|
||||||
|
|
||||||
if (realpath(cgroupPath, resolvedCgroupPath) == NULL && errno != ENOENT) {
|
if (realpath(cgroupPath, resolvedCgroupPath) == NULL && errno != ENOENT) {
|
||||||
logError("error: cannot canonicalize cgroup path: %s\n", cgroupPath);
|
LogError("error: cannot canonicalize cgroup path: %s\n", cgroupPath);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,14 +184,14 @@ int SetupCgroup(struct CmdArgs *args, const char *cgroupPath)
|
|||||||
|
|
||||||
cgroupAllow = fopen((const char *)resolvedCgroupPath, "a");
|
cgroupAllow = fopen((const char *)resolvedCgroupPath, "a");
|
||||||
if (cgroupAllow == NULL) {
|
if (cgroupAllow == NULL) {
|
||||||
logError("error: failed to open cgroup file: %s\n", resolvedCgroupPath);
|
LogError("error: failed to open cgroup file: %s\n", resolvedCgroupPath);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = SetupDriverCgroup(cgroupAllow);
|
ret = SetupDriverCgroup(cgroupAllow);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
fclose(cgroupAllow);
|
fclose(cgroupAllow);
|
||||||
logError("error: failed to setup driver cgroup\n");
|
LogError("error: failed to setup driver cgroup\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,14 +200,14 @@ int SetupCgroup(struct CmdArgs *args, const char *cgroupPath)
|
|||||||
ret = snprintf_s(deviceName, BUF_SIZE, BUF_SIZE, "%s%s", DEVICE_NAME, token);
|
ret = snprintf_s(deviceName, BUF_SIZE, BUF_SIZE, "%s%s", DEVICE_NAME, token);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
fclose(cgroupAllow);
|
fclose(cgroupAllow);
|
||||||
logError("error: failed to assemble device path for no.%s\n", token);
|
LogError("error: failed to assemble device path for no.%s\n", token);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = SetupDeviceCgroup(cgroupAllow, (const char *)deviceName);
|
ret = SetupDeviceCgroup(cgroupAllow, (const char *)deviceName);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
fclose(cgroupAllow);
|
fclose(cgroupAllow);
|
||||||
logError("error: failed to setup cgroup %s\n", token);
|
LogError("error: failed to setup cgroup %s\n", token);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
void logError(const char *fmt, ...)
|
void LogError(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ void logError(const char *fmt, ...)
|
|||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void logInfo(const char *fmt, ...)
|
void LogInfo(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
|
@@ -5,7 +5,7 @@
|
|||||||
#ifndef _LOGGING_H
|
#ifndef _LOGGING_H
|
||||||
#define _LOGGING_H
|
#define _LOGGING_H
|
||||||
|
|
||||||
void logError(const char *fmt, ...);
|
void LogError(const char *fmt, ...);
|
||||||
void logInfo(const char *fmt, ...);
|
void LogInfo(const char *fmt, ...);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -44,26 +44,26 @@ int DoPrepare(const struct CmdArgs *args, struct ParsedConfig *config)
|
|||||||
|
|
||||||
ret = GetNsPath(args->pid, "mnt", config->containerNsPath, BUF_SIZE);
|
ret = GetNsPath(args->pid, "mnt", config->containerNsPath, BUF_SIZE);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to get container mnt ns path: pid(%d)\n", args->pid);
|
LogError("error: failed to get container mnt ns path: pid(%d)\n", args->pid);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = GetCgroupPath(args, config->cgroupPath, BUF_SIZE);
|
ret = GetCgroupPath(args, config->cgroupPath, BUF_SIZE);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to get cgroup path\n");
|
LogError("error: failed to get cgroup path\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char originNsPath[BUF_SIZE] = {0};
|
char originNsPath[BUF_SIZE] = {0};
|
||||||
ret = GetSelfNsPath("mnt", originNsPath, BUF_SIZE);
|
ret = GetSelfNsPath("mnt", originNsPath, BUF_SIZE);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to get self ns path\n");
|
LogError("error: failed to get self ns path\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
config->originNsFd = open((const char *)originNsPath, O_RDONLY); // proc接口,非外部输入
|
config->originNsFd = open((const char *)originNsPath, O_RDONLY); // proc接口,非外部输入
|
||||||
if (config->originNsFd < 0) {
|
if (config->originNsFd < 0) {
|
||||||
logError("error: failed to get self ns fd: %s\n", originNsPath);
|
LogError("error: failed to get self ns fd: %s\n", originNsPath);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,28 +77,28 @@ int SetupContainer(struct CmdArgs *args)
|
|||||||
|
|
||||||
ret = DoPrepare(args, &config);
|
ret = DoPrepare(args, &config);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to prepare nesessary config\n");
|
LogError("error: failed to prepare nesessary config\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// enter container's mount namespace
|
// enter container's mount namespace
|
||||||
ret = EnterNsByPath((const char *)config.containerNsPath, CLONE_NEWNS);
|
ret = EnterNsByPath((const char *)config.containerNsPath, CLONE_NEWNS);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to set to container ns: %s\n", config.containerNsPath);
|
LogError("error: failed to set to container ns: %s\n", config.containerNsPath);
|
||||||
close(config.originNsFd);
|
close(config.originNsFd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = DoMounting(args);
|
ret = DoMounting(args);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to do mounting\n");
|
LogError("error: failed to do mounting\n");
|
||||||
close(config.originNsFd);
|
close(config.originNsFd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = SetupCgroup(args, (const char *)config.cgroupPath);
|
ret = SetupCgroup(args, (const char *)config.cgroupPath);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to set up cgroup\n");
|
LogError("error: failed to set up cgroup\n");
|
||||||
close(config.originNsFd);
|
close(config.originNsFd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -106,7 +106,7 @@ int SetupContainer(struct CmdArgs *args)
|
|||||||
// back to original namespace
|
// back to original namespace
|
||||||
ret = EnterNsByFd(config.originNsFd, CLONE_NEWNS);
|
ret = EnterNsByFd(config.originNsFd, CLONE_NEWNS);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to set ns back\n");
|
LogError("error: failed to set ns back\n");
|
||||||
close(config.originNsFd);
|
close(config.originNsFd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -151,14 +151,14 @@ int Process(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
logError("unrecongnized option\n");
|
LogError("unrecongnized option\n");
|
||||||
isSucceed = false; // unrecognized option
|
isSucceed = false; // unrecognized option
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isSucceed || !IsCmdArgsValid(&args)) {
|
if (!isSucceed || !IsCmdArgsValid(&args)) {
|
||||||
logError("error: information not completed or valid.\n");
|
LogError("error: information not completed or valid.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -41,13 +41,13 @@ static int GetDeviceMntSrcDst(const char *rootfs, const char *deviceName,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (realpath(unresolvedDst, resolvedDst) == NULL && errno != ENOENT) {
|
if (realpath(unresolvedDst, resolvedDst) == NULL && errno != ENOENT) {
|
||||||
logError("error: cannot canonicalize device dst: %s\n", dst);
|
LogError("error: cannot canonicalize device dst: %s\n", dst);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = strcpy_s(dst, dstBufSize, (const char *)resolvedDst);
|
err = strcpy_s(dst, dstBufSize, (const char *)resolvedDst);
|
||||||
if (err != EOK) {
|
if (err != EOK) {
|
||||||
logError("error: failed to copy resolved device mnt path to dst: %s\n", resolvedDst);
|
LogError("error: failed to copy resolved device mnt path to dst: %s\n", resolvedDst);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,26 +63,26 @@ int MountDevice(const char *rootfs, const char *deviceName)
|
|||||||
|
|
||||||
ret = GetDeviceMntSrcDst(rootfs, deviceName, &pathInfo);
|
ret = GetDeviceMntSrcDst(rootfs, deviceName, &pathInfo);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to get device mount src and(or) dst path, device name: %s\n", deviceName);
|
LogError("error: failed to get device mount src and(or) dst path, device name: %s\n", deviceName);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct stat srcStat;
|
struct stat srcStat;
|
||||||
ret = stat((const char *)src, &srcStat);
|
ret = stat((const char *)src, &srcStat);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to stat src: %s\n", src);
|
LogError("error: failed to stat src: %s\n", src);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = CreateFile(dst, srcStat.st_mode);
|
ret = CreateFile(dst, srcStat.st_mode);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to create mount dst file: %s\n", dst);
|
LogError("error: failed to create mount dst file: %s\n", dst);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = Mount(src, dst);
|
ret = Mount(src, dst);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to mount dev\n");
|
LogError("error: failed to mount dev\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,13 +105,13 @@ int DoDeviceMounting(const char *rootfs, const char *devicesList)
|
|||||||
while (token != NULL) {
|
while (token != NULL) {
|
||||||
int ret = snprintf_s(deviceName, BUF_SIZE, BUF_SIZE, "%s%s", DEVICE_NAME, token);
|
int ret = snprintf_s(deviceName, BUF_SIZE, BUF_SIZE, "%s%s", DEVICE_NAME, token);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: assemble device name failed, id: %s\n", token);
|
LogError("error: assemble device name failed, id: %s\n", token);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = MountDevice(rootfs, deviceName);
|
ret = MountDevice(rootfs, deviceName);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to mount device no. %s\n", token);
|
LogError("error: failed to mount device no. %s\n", token);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,7 +144,7 @@ int MountDir(const char *rootfs, const char *src)
|
|||||||
mode_t parentMode = DEFAULT_DIR_MODE;
|
mode_t parentMode = DEFAULT_DIR_MODE;
|
||||||
ret = MakeParentDir(parentDir, parentMode);
|
ret = MakeParentDir(parentDir, parentMode);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to make dir: %s\n", parentDir);
|
LogError("error: failed to make dir: %s\n", parentDir);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -153,14 +153,14 @@ int MountDir(const char *rootfs, const char *src)
|
|||||||
const mode_t curMode = srcStat.st_mode;
|
const mode_t curMode = srcStat.st_mode;
|
||||||
ret = MkDir(dst, curMode);
|
ret = MkDir(dst, curMode);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to make dir: %s\n", dst);
|
LogError("error: failed to make dir: %s\n", dst);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = Mount(src, dst);
|
ret = Mount(src, dst);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to mount dir: %s to %s\n", src, dst);
|
LogError("error: failed to mount dir: %s to %s\n", src, dst);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,19 +172,19 @@ int DoCtrlDeviceMounting(const char *rootfs)
|
|||||||
/* device */
|
/* device */
|
||||||
int ret = MountDevice(rootfs, DAVINCI_MANAGER);
|
int ret = MountDevice(rootfs, DAVINCI_MANAGER);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to mount device %s\n", DAVINCI_MANAGER);
|
LogError("error: failed to mount device %s\n", DAVINCI_MANAGER);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = MountDevice(rootfs, DEVMM_SVM);
|
ret = MountDevice(rootfs, DEVMM_SVM);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to mount device %s\n", DEVMM_SVM);
|
LogError("error: failed to mount device %s\n", DEVMM_SVM);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = MountDevice(rootfs, HISI_HDC);
|
ret = MountDevice(rootfs, HISI_HDC);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to mount device %s\n", HISI_HDC);
|
LogError("error: failed to mount device %s\n", HISI_HDC);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,13 +196,13 @@ int DoDirectoryMounting(const char *rootfs)
|
|||||||
/* directory */
|
/* directory */
|
||||||
int ret = MountDir(rootfs, ASCEND_DRIVER_PATH);
|
int ret = MountDir(rootfs, ASCEND_DRIVER_PATH);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to do mount %s\n", ASCEND_DRIVER_PATH);
|
LogError("error: failed to do mount %s\n", ASCEND_DRIVER_PATH);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = MountDir(rootfs, ASCEND_ADDONS_PATH);
|
ret = MountDir(rootfs, ASCEND_ADDONS_PATH);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to do mount %s\n", ASCEND_ADDONS_PATH);
|
LogError("error: failed to do mount %s\n", ASCEND_ADDONS_PATH);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,19 +215,19 @@ int DoMounting(const struct CmdArgs *args)
|
|||||||
|
|
||||||
ret = DoDeviceMounting(args->rootfs, args->devices);
|
ret = DoDeviceMounting(args->rootfs, args->devices);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to do mounts\n");
|
LogError("error: failed to do mounts\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = DoCtrlDeviceMounting(args->rootfs);
|
ret = DoCtrlDeviceMounting(args->rootfs);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to do mount files\n");
|
LogError("error: failed to do mount files\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = DoDirectoryMounting(args->rootfs);
|
ret = DoDirectoryMounting(args->rootfs);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to do mount directory\n");
|
LogError("error: failed to do mount directory\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -28,7 +28,7 @@ int EnterNsByFd(int fd, int nsType)
|
|||||||
{
|
{
|
||||||
int ret = setns(fd, nsType);
|
int ret = setns(fd, nsType);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to set ns: fd(%d)\n", fd);
|
LogError("error: failed to set ns: fd(%d)\n", fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,13 +42,13 @@ int EnterNsByPath(const char *path, int nsType)
|
|||||||
|
|
||||||
fd = open(path, O_RDONLY); // proc文件接口,非外部输入
|
fd = open(path, O_RDONLY); // proc文件接口,非外部输入
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
logError("error: failed to open ns path: %s\n", path);
|
LogError("error: failed to open ns path: %s\n", path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = EnterNsByFd(fd, nsType);
|
ret = EnterNsByFd(fd, nsType);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to set ns: %s\n", path);
|
LogError("error: failed to set ns: %s\n", path);
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@@ -75,13 +75,13 @@ int CatFileContent(char* buffer, int bufferSize, ParseFileLine fn, const char* f
|
|||||||
char resolvedPath[PATH_MAX] = {0x0};
|
char resolvedPath[PATH_MAX] = {0x0};
|
||||||
|
|
||||||
if (realpath(filepath, resolvedPath) == NULL && errno != ENOENT) {
|
if (realpath(filepath, resolvedPath) == NULL && errno != ENOENT) {
|
||||||
logError("error: cannot canonicalize path %s\n", filepath);
|
LogError("error: cannot canonicalize path %s\n", filepath);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fp = fopen(resolvedPath, "r");
|
fp = fopen(resolvedPath, "r");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
logError("cannot open file.\n");
|
LogError("cannot open file.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,11 +122,11 @@ int CheckDirExists(const char *dir)
|
|||||||
{
|
{
|
||||||
DIR *ptr = opendir(dir);
|
DIR *ptr = opendir(dir);
|
||||||
if (NULL == ptr) {
|
if (NULL == ptr) {
|
||||||
logError("path %s not exist\n", dir);
|
LogError("path %s not exist\n", dir);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
logInfo("path %s exist\n", dir);
|
LogInfo("path %s exist\n", dir);
|
||||||
closedir(ptr);
|
closedir(ptr);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -169,7 +169,7 @@ int MakeParentDir(const char *path, mode_t mode)
|
|||||||
struct stat s;
|
struct stat s;
|
||||||
int ret = stat(path, &s);
|
int ret = stat(path, &s);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to stat path: %s\n", path);
|
LogError("error: failed to stat path: %s\n", path);
|
||||||
return (MkDir(path, mode));
|
return (MkDir(path, mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,13 +180,13 @@ int CreateFile(const char *path, mode_t mode)
|
|||||||
{
|
{
|
||||||
char resolvedPath[PATH_MAX] = {0};
|
char resolvedPath[PATH_MAX] = {0};
|
||||||
if (realpath(path, resolvedPath) == NULL && errno != ENOENT) {
|
if (realpath(path, resolvedPath) == NULL && errno != ENOENT) {
|
||||||
logError("error: failed to resolve path %s\n", path);
|
LogError("error: failed to resolve path %s\n", path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fd = open(resolvedPath, O_NOFOLLOW | O_CREAT, mode);
|
int fd = open(resolvedPath, O_NOFOLLOW | O_CREAT, mode);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
logError("error: cannot create file: %s\n", resolvedPath);
|
LogError("error: cannot create file: %s\n", resolvedPath);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
@@ -200,13 +200,13 @@ int Mount(const char *src, const char *dst)
|
|||||||
|
|
||||||
ret = mount(src, dst, NULL, MS_BIND, NULL);
|
ret = mount(src, dst, NULL, MS_BIND, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to mount\n");
|
LogError("error: failed to mount\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = mount(NULL, dst, NULL, remountFlags, NULL);
|
ret = mount(NULL, dst, NULL, remountFlags, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
logError("error: failed to re-mount\n");
|
LogError("error: failed to re-mount\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user