Match-id-b41545d32eead089c026321fc41ab95f4dcde85c

This commit is contained in:
BianTanggui
2021-09-27 15:30:44 +08:00
parent 5cffff9f65
commit f05abca8a4
5 changed files with 22 additions and 11 deletions

View File

@@ -16,6 +16,7 @@
#define HISI_HDC "hisi_hdc"
#define DEFAULT_DIR_MODE 0755
#define DEFAULT_LOG_MODE 0640
#define DUMP_LOG_MODE 0440
#define DEFAULT_LOGDIR_MODE 0750
#define BUF_SIZE 1024
#define MAX_DEVICE_NR 1024

View File

@@ -5,6 +5,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
#include <unistd.h>
@@ -90,6 +91,9 @@ int LogLoop(const char* filename)
unlink(loopPath);
}
rename(filename, loopPath);
if (chmod(loopPath, DUMP_LOG_MODE) != 0) {
return -1;
}
ret = CreateLog(filename);
if (ret < 0) {
return -1;

View File

@@ -255,10 +255,13 @@ int DoPrepare(const struct CmdArgs *args, struct ParsedConfig *config)
Logger("failed to get self ns path.", LEVEL_ERROR, SCREEN_YES);
return -1;
}
config->originNsFd = open((const char *)originNsPath, O_RDONLY); // proc接口非外部输入
char realPath[PATH_MAX] = {0};
if (realpath(originNsPath, realPath) == NULL) {
Logger("failed to check reaplath GetSelfNsPath", LEVEL_ERROR, SCREEN_YES);
}
config->originNsFd = open((const char *)realPath, O_RDONLY); // proc接口非外部输入
if (config->originNsFd < 0) {
char* str = FormatLogMessage("failed to get self ns fd: %s.", originNsPath);
char* str = FormatLogMessage("failed to get self ns fd: %s.", realPath);
Logger(str, LEVEL_ERROR, SCREEN_YES);
free(str);
return -1;
@@ -350,7 +353,7 @@ int Process(int argc, char **argv)
Logger("failed to setup container.", LEVEL_ERROR, SCREEN_YES);
return ret;
}
Logger("prestart-hook setup container successful.", LEVEL_INFO, SCREEN_YES);
Logger("prestart-hook setup container successful1.", LEVEL_INFO, SCREEN_YES);
return 0;
}

View File

@@ -40,12 +40,15 @@ int EnterNsByFd(int fd, int nsType)
int EnterNsByPath(const char *path, int nsType)
{
int fd;
int fd = 0;
int ret;
fd = open(path, O_RDONLY); // proc文件接口非外部输入
char realPath[PATH_MAX] = {0};
if (realpath(path, realPath) == NULL) {
Logger("failed to check reaplath: EnterNsByPath", LEVEL_ERROR, SCREEN_YES);
}
fd = open(realPath, O_RDONLY); // proc文件接口非外部输入
if (fd < 0) {
char* str = FormatLogMessage("failed to open ns path: %s.", path);
char* str = FormatLogMessage("failed to open ns path: %s.", realPath);
Logger(str, LEVEL_ERROR, SCREEN_YES);
free(str);
return -1;
@@ -53,7 +56,7 @@ int EnterNsByPath(const char *path, int nsType)
ret = EnterNsByFd(fd, nsType);
if (ret < 0) {
char* str = FormatLogMessage("failed to set ns: %s.", path);
char* str = FormatLogMessage("failed to set ns: %s.", realPath);
Logger(str, LEVEL_ERROR, SCREEN_YES);
free(str);
close(fd);

View File

@@ -1006,7 +1006,7 @@ TEST(DoPrepare, StatusOne)
config.devicesNr = 1024;
int ret = DoPrepare(&args, &config);
GlobalMockObject::verify();
EXPECT_EQ(0, ret);
EXPECT_EQ(-1, ret);
}
TEST(DoPrepare, StatusTwo)
@@ -1021,7 +1021,7 @@ TEST(DoPrepare, StatusTwo)
config.devicesNr = 1024;
int ret = DoPrepare(&args, &config);
GlobalMockObject::verify();
EXPECT_EQ(0, ret);
EXPECT_EQ(-1, ret);
}
TEST(DoPrepare, StatusThree)