Match-id-da710ec79804990caf850320ea9fadadd25ad256

This commit is contained in:
BianTanggui
2022-04-28 16:12:49 +08:00
parent 9920c4c165
commit f13720f7bd
6 changed files with 27 additions and 11 deletions

View File

@@ -12,6 +12,7 @@
#include "securec.h" #include "securec.h"
#include "basic.h" #include "basic.h"
#include "utils.h" #include "utils.h"
#include "logger.h"
#define FILE_MAX_SIZE (1024 * 1024 * 10) #define FILE_MAX_SIZE (1024 * 1024 * 10)
#define LOG_PATH_DIR "/var/log/ascend-docker-runtime/" #define LOG_PATH_DIR "/var/log/ascend-docker-runtime/"
@@ -46,6 +47,9 @@ int GetCurrentLocalTime(char* buffer, int length)
int CreateLog(const char* filename) int CreateLog(const char* filename)
{ {
if (filename == NULL) {
return -1;
}
int exist; int exist;
exist = access(filename, 0); exist = access(filename, 0);
int fd = 0; int fd = 0;

View File

@@ -184,6 +184,9 @@ static bool OptionsCmdArgParser(struct CmdArgs *args, const char *arg)
static bool CheckWhiteList(const char* fileName) static bool CheckWhiteList(const char* fileName)
{ {
if (fileName == NULL) {
return false;
}
bool fileExists = false; bool fileExists = false;
const char mountWhiteList[WHITE_LIST_NUM][PATH_MAX] = {{"/usr/local/Ascend/driver/lib64"}, const char mountWhiteList[WHITE_LIST_NUM][PATH_MAX] = {{"/usr/local/Ascend/driver/lib64"},
{"/usr/local/Ascend/driver/include"}, {"/usr/local/Ascend/driver/include"},

View File

@@ -13,14 +13,20 @@
#include "utils.h" #include "utils.h"
#include "logger.h" #include "logger.h"
int GetNsPath(const int pid, const char *nsType, char *buf, size_t bufSize) int GetNsPath(const int pid, const char *nsType, char *buf, const size_t bufSize)
{ {
if ((nsType == NULL) || (buf == NULL)) {
return -1;
}
static const char *fmtStr = "/proc/%d/ns/%s"; static const char *fmtStr = "/proc/%d/ns/%s";
return sprintf_s(buf, bufSize, fmtStr, pid, nsType); return sprintf_s(buf, bufSize, fmtStr, pid, nsType);
} }
int GetSelfNsPath(const char *nsType, char *buf, size_t bufSize) int GetSelfNsPath(const char *nsType, char *buf, const size_t bufSize)
{ {
if ((nsType == NULL) || (buf == NULL)) {
return -1;
}
static const char *fmtStr = "/proc/self/ns/%s"; static const char *fmtStr = "/proc/self/ns/%s";
return sprintf_s(buf, bufSize, fmtStr, nsType); return sprintf_s(buf, bufSize, fmtStr, nsType);
} }
@@ -39,6 +45,9 @@ int EnterNsByFd(int fd, int nsType)
int EnterNsByPath(const char *path, int nsType) int EnterNsByPath(const char *path, int nsType)
{ {
if (path == NULL) {
return -1;
}
int fd; int fd;
int ret; int ret;

View File

@@ -7,8 +7,8 @@
#include <sys/types.h> #include <sys/types.h>
int GetNsPath(int pid, const char *nsType, char *buf, size_t bufSize); int GetNsPath(int pid, const char *nsType, char *buf, const size_t bufSize);
int GetSelfNsPath(const char *nsType, char *buf, size_t bufSize); int GetSelfNsPath(const char *nsType, char *buf, const size_t bufSize);
int EnterNsByFd(int fd, int nsType); int EnterNsByFd(int fd, int nsType);
int EnterNsByPath(const char *path, int nsType); int EnterNsByPath(const char *path, int nsType);

View File

@@ -51,7 +51,7 @@ char *FormatLogMessage(char *format, ...)
int IsStrEqual(const char *s1, const char *s2) int IsStrEqual(const char *s1, const char *s2)
{ {
return (!strcmp(s1, s2)); return (strcmp(s1, s2) == 0);
} }
int StrHasPrefix(const char *str, const char *prefix) int StrHasPrefix(const char *str, const char *prefix)

View File

@@ -126,7 +126,7 @@ static int DelJsonContent(cJSON *root, const char *key)
cJSON *existItem = NULL; cJSON *existItem = NULL;
existItem = cJSON_GetObjectItem(root, key); existItem = cJSON_GetObjectItem(root, key);
if (existItem == NULL) { if (existItem == NULL) {
return 0; return -1;
} }
cJSON *removedItem = NULL; cJSON *removedItem = NULL;
@@ -390,6 +390,7 @@ static int DetectAndCreateJsonFile(const char *filePath, const char *tempPath, c
} else { } else {
root = ModifyContent(pf, runtimePath); root = ModifyContent(pf, runtimePath);
fclose(pf); fclose(pf);
pf = NULL;
} }
if (root == NULL) { if (root == NULL) {
@@ -406,11 +407,12 @@ static int DetectAndCreateJsonFile(const char *filePath, const char *tempPath, c
if (fprintf(pf, "%s", cJSON_Print(root)) < 0) { if (fprintf(pf, "%s", cJSON_Print(root)) < 0) {
(void)fprintf(stderr, "error: failed to create file\n"); (void)fprintf(stderr, "error: failed to create file\n");
(void)fclose(pf); (void)fclose(pf);
pf = NULL;
cJSON_Delete(root); cJSON_Delete(root);
return -1; return -1;
} }
(void)fclose(pf); (void)fclose(pf);
pf = NULL;
cJSON_Delete(root); cJSON_Delete(root);
return 0; return 0;
@@ -456,10 +458,8 @@ static int CreateRevisedJsonFile(const char *filePath, const char *tempPath)
if (fprintf(pf, "%s", cJSON_Print(newContent)) < 0) { if (fprintf(pf, "%s", cJSON_Print(newContent)) < 0) {
(void)fprintf(stderr, "error: failed to create file\n"); (void)fprintf(stderr, "error: failed to create file\n");
cJSON_Delete(newContent); cJSON_Delete(newContent);
if (pf != NULL) { (void)fclose(pf);
(void)fclose(pf); pf = NULL;
pf = NULL;
}
return -1; return -1;
} }
(void)fclose(pf); (void)fclose(pf);