Match-id-03c6b5a4046afc799a0d6bf35a11291200e65832

This commit is contained in:
BianTanggui
2022-02-24 20:33:04 +08:00
parent f8c2998383
commit f68fa3bf99
3 changed files with 35 additions and 37 deletions

View File

@@ -48,7 +48,7 @@ typedef bool (*CmdArgParser)(struct CmdArgs *args, const char *arg);
static bool DevicesCmdArgParser(struct CmdArgs *args, const char *arg)
{
if (args == NULL || arg == NULL) {
fprintf(stderr, "args, arg pointer is null!\n");
Logger("args, arg pointer is null!", LEVEL_ERROR, SCREEN_YES);
return false;
}
@@ -64,7 +64,7 @@ static bool DevicesCmdArgParser(struct CmdArgs *args, const char *arg)
static bool PidCmdArgParser(struct CmdArgs *args, const char *arg)
{
if (args == NULL || arg == NULL) {
fprintf(stderr, "args, arg pointer is null!\n");
Logger("args, arg pointer is null!", LEVEL_ERROR, SCREEN_YES);
return false;
}
@@ -90,7 +90,7 @@ static bool PidCmdArgParser(struct CmdArgs *args, const char *arg)
static bool RootfsCmdArgParser(struct CmdArgs *args, const char *arg)
{
if (args == NULL || arg == NULL) {
fprintf(stderr, "args, arg pointer is null!\n");
Logger("args, arg pointer is null!", LEVEL_ERROR, SCREEN_YES);
return false;
}
@@ -106,7 +106,7 @@ static bool RootfsCmdArgParser(struct CmdArgs *args, const char *arg)
static bool OptionsCmdArgParser(struct CmdArgs *args, const char *arg)
{
if (args == NULL || arg == NULL) {
fprintf(stderr, "args, arg pointer is null!\n");
Logger("args, arg pointer is null!", LEVEL_ERROR, SCREEN_YES);
return false;
}
@@ -122,7 +122,7 @@ static bool OptionsCmdArgParser(struct CmdArgs *args, const char *arg)
static bool MountFileCmdArgParser(struct CmdArgs *args, const char *arg)
{
if (args == NULL || arg == NULL) {
fprintf(stderr, "args, arg pointer is null!\n");
Logger("args, arg pointer is null!", LEVEL_ERROR, SCREEN_YES);
return false;
}
@@ -148,7 +148,7 @@ static bool MountFileCmdArgParser(struct CmdArgs *args, const char *arg)
static bool MountDirCmdArgParser(struct CmdArgs *args, const char *arg)
{
if (args == NULL || arg == NULL) {
fprintf(stderr, "args, arg pointer is null!\n");
Logger("args, arg pointer is null!", LEVEL_ERROR, SCREEN_YES);
return false;
}
@@ -188,7 +188,7 @@ static struct {
static int ParseOneCmdArg(struct CmdArgs *args, char indicator, const char *value)
{
if (args == NULL || value == NULL) {
fprintf(stderr, "args, value pointer is null!\n");
Logger("args, value pointer is null!", LEVEL_ERROR, SCREEN_YES);
return -1;
}
@@ -218,7 +218,7 @@ static int ParseOneCmdArg(struct CmdArgs *args, char indicator, const char *valu
static inline bool IsCmdArgsValid(const struct CmdArgs *args)
{
if (args == NULL) {
fprintf(stderr, "args pointer is null!\n");
Logger("args pointer is null!", LEVEL_ERROR, SCREEN_YES);
return false;
}
return (strlen(args->devices) > 0) && (strlen(args->rootfs) > 0) && (args->pid > 0);
@@ -227,7 +227,7 @@ static inline bool IsCmdArgsValid(const struct CmdArgs *args)
static int ParseDeviceIDs(unsigned int *idList, size_t *idListSize, char *devices)
{
if (idList == NULL || idListSize == NULL || devices == NULL) {
fprintf(stderr, "idList, idListSize, devices pointer is null!\n");
Logger("idList, idListSize, devices pointer is null!", LEVEL_ERROR, SCREEN_YES);
return -1;
}
@@ -265,7 +265,7 @@ static int ParseDeviceIDs(unsigned int *idList, size_t *idListSize, char *device
int DoPrepare(const struct CmdArgs *args, struct ParsedConfig *config)
{
if (args == NULL || config == NULL) {
fprintf(stderr, "args, config pointer is null!\n");
Logger("args, config pointer is null!", LEVEL_ERROR, SCREEN_YES);
return -1;
}
@@ -322,7 +322,7 @@ int DoPrepare(const struct CmdArgs *args, struct ParsedConfig *config)
int SetupContainer(struct CmdArgs *args)
{
if (args == NULL) {
fprintf(stderr, "args pointer is null!\n");
Logger("args pointer is null!", LEVEL_ERROR, SCREEN_YES);
return -1;
}
@@ -379,7 +379,7 @@ int SetupContainer(struct CmdArgs *args)
int Process(int argc, char **argv)
{
if (argv == NULL) {
fprintf(stderr, "argv pointer is null!\n");
Logger("argv pointer is null!", LEVEL_ERROR, SCREEN_YES);
return -1;
}

View File

@@ -19,7 +19,7 @@
int Mount(const char *src, const char *dst)
{
if (src == NULL || dst == NULL) {
fprintf(stderr, "src pointer or dst pointer is null!\n");
Logger("src pointer or dst pointer is null!", LEVEL_ERROR, SCREEN_YES);
return -1;
}
@@ -49,8 +49,8 @@ int Mount(const char *src, const char *dst)
static int GetDeviceMntSrcDst(const char *rootfs, const char *srcDeviceName,
const char *dstDeviceName, struct PathInfo* pathInfo)
{
if (rootfs == NULL || srcDeviceName == NULL || dstDeviceName == NULL || pathInfo == NULL) {
fprintf(stderr, "rootfs, srcDeviceName, dstDeviceName, pathInfo pointer are null!\n");
if (rootfs == NULL || srcDeviceName == NULL || pathInfo == NULL) {
Logger("rootfs, srcDeviceName, pathInfo pointer are null!", LEVEL_ERROR, SCREEN_YES);
return -1;
}
@@ -106,23 +106,22 @@ static int GetDeviceMntSrcDst(const char *rootfs, const char *srcDeviceName,
int MountDevice(const char *rootfs, const char *srcDeviceName, const char *dstDeviceName)
{
if (rootfs == NULL || srcDeviceName == NULL || dstDeviceName == NULL) {
fprintf(stderr, "rootfs, srcDeviceName, dstDeviceName pointer is null!\n");
return -1;
}
int ret;
char *str = NULL;
char src[BUF_SIZE] = {0};
char dst[BUF_SIZE] = {0};
struct PathInfo pathInfo = {src, BUF_SIZE, dst, BUF_SIZE};
if (GetDeviceMntSrcDst(rootfs, srcDeviceName, dstDeviceName, &pathInfo) < 0) {
ret = GetDeviceMntSrcDst(rootfs, srcDeviceName, dstDeviceName, &pathInfo);
if (ret < 0) {
str = FormatLogMessage("failed to get mount src and dst path, device name: %s.", srcDeviceName);
Logger(str, LEVEL_ERROR, SCREEN_YES);
free(str);
return -1;
}
struct stat srcStat;
if (stat((const char *)src, &srcStat) < 0) {
ret = stat((const char *)src, &srcStat);
if (ret < 0) {
str = FormatLogMessage("failed to stat src: %s.", src);
Logger(str, LEVEL_ERROR, SCREEN_YES);
free(str);
@@ -130,7 +129,6 @@ int MountDevice(const char *rootfs, const char *srcDeviceName, const char *dstDe
}
errno = 0;
struct stat dstStat;
int ret;
ret = stat((const char *)dst, &dstStat);
if (ret == 0 && S_ISCHR(dstStat.st_mode)) {
return 0; // 特权容器自动挂载HOST所有设备故此处跳过
@@ -143,15 +141,16 @@ int MountDevice(const char *rootfs, const char *srcDeviceName, const char *dstDe
Logger("failed to check dst stat", LEVEL_ERROR, SCREEN_YES);
return -1;
}
if (MakeMountPoints(dst, srcStat.st_mode) < 0) {
ret = MakeMountPoints(dst, srcStat.st_mode);
if (ret < 0) {
str = FormatLogMessage("failed to create mount dst file: %s.", dst);
Logger(str, LEVEL_ERROR, SCREEN_YES);
free(str);
return -1;
}
if (Mount(src, dst) < 0) {
ret = Mount(src, dst);
if (ret < 0) {
Logger("failed to mount dev.", LEVEL_ERROR, SCREEN_YES);
return -1;
}
@@ -162,7 +161,7 @@ int MountDevice(const char *rootfs, const char *srcDeviceName, const char *dstDe
int DoDeviceMounting(const char *rootfs, const char *device_name, const unsigned int ids[], size_t idsNr)
{
if (rootfs == NULL || device_name == NULL) {
fprintf(stderr, "rootfs, device_name pointer is null!\n");
Logger("rootfs, device_name pointer is null!", LEVEL_ERROR, SCREEN_YES);
return -1;
}
@@ -193,7 +192,7 @@ int DoDeviceMounting(const char *rootfs, const char *device_name, const unsigned
int MountFile(const char *rootfs, const char *filepath)
{
if (rootfs == NULL || filepath == NULL) {
fprintf(stderr, "rootfs, filepath pointer is null!\n");
Logger("rootfs, filepath pointer is null!", LEVEL_ERROR, SCREEN_YES);
return -1;
}
@@ -234,7 +233,7 @@ int MountFile(const char *rootfs, const char *filepath)
int MountDir(const char *rootfs, const char *src)
{
if (rootfs == NULL || src == NULL) {
fprintf(stderr, "rootfs, src pointer is null!\n");
Logger("rootfs, src pointer is null!", LEVEL_ERROR, SCREEN_YES);
return -1;
}
@@ -274,14 +273,14 @@ int MountDir(const char *rootfs, const char *src)
int DoCtrlDeviceMounting(const char *rootfs)
{
if (rootfs == NULL) {
fprintf(stderr, "rootfs pointer is null!\n");
Logger("rootfs pointer is null!", LEVEL_ERROR, SCREEN_YES);
return -1;
}
/* device */
int ret = MountDevice(rootfs, DAVINCI_MANAGER, NULL);
if (ret < 0) {
char* str = FormatLogMessage("failed to mount device %s.", DAVINCI_MANAGER);
char* str = FormatLogMessage("failed to mount device %s.", DAVINCI_MANAGER); // error1
Logger(str, LEVEL_ERROR, SCREEN_YES);
free(str);
return -1;
@@ -309,7 +308,7 @@ int DoCtrlDeviceMounting(const char *rootfs)
int DoDirectoryMounting(const char *rootfs, const struct MountList *list)
{
if (rootfs == NULL || list == NULL) {
fprintf(stderr, "rootfs, list pointer is null!\n");
Logger("rootfs, list pointer is null!", LEVEL_ERROR, SCREEN_YES);
return -1;
}
@@ -330,7 +329,7 @@ int DoDirectoryMounting(const char *rootfs, const struct MountList *list)
int DoFileMounting(const char *rootfs, const struct MountList *list)
{
if (rootfs == NULL || list == NULL) {
fprintf(stderr, "rootfs, list pointer is null!\n");
Logger("rootfs, list pointer is null!", LEVEL_ERROR, SCREEN_YES);
return -1;
}
@@ -351,7 +350,7 @@ int DoFileMounting(const char *rootfs, const struct MountList *list)
int DoMounting(const struct ParsedConfig *config)
{
if (config == NULL) {
fprintf(stderr, "config pointer is null!\n");
Logger("config pointer is null!", LEVEL_ERROR, SCREEN_YES);
return -1;
}

View File

@@ -49,8 +49,7 @@ extern "C" char *GetCgroupRoot(char *line, const char *subSystem);
extern "C" int ParseFileByLine(char* buffer, int bufferSize, ParseFileLine fn, const char* filepath);
extern "C" int SetupDeviceCgroup(FILE *cgroupAllow, const char *devPath);
extern "C" int SetupDriverCgroup(FILE *cgroupAllow);
//extern "C" int GetCgroupPath(const struct CmdArgs *args, char *effPath, const size_t maxSize);
extern "C" int GetCgroupPath(int pid, char *effPath, size_t maxSize);
extern "C" int GetCgroupPath(const struct CmdArgs *args, char *effPath, const size_t maxSize);
extern "C" int SetupCgroup(const struct ParsedConfig *config);
extern "C" int SetupContainer(struct CmdArgs *args);
extern "C" int Process(int argc, char **argv);
@@ -797,7 +796,7 @@ TEST(GetCgroupPath, StatusOne)
MOCKER(ParseFileByLine).stubs().will(invoke(Stub_ParseFileByLine_Success));
char cgroupPath[BUF_SIZE] = {0};
int ret = GetCgroupPath(args.pid, cgroupPath, BUF_SIZE);
int ret = GetCgroupPath(&args, cgroupPath, BUF_SIZE);
EXPECT_EQ(0, ret);
}