mirror of
https://github.com/Ascend/ascend-docker-runtime.git
synced 2025-10-11 02:00:14 +08:00
Match-id-da710ec79804990caf850320ea9fadadd25ad256
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include "securec.h"
|
||||
#include "basic.h"
|
||||
#include "utils.h"
|
||||
#include "logger.h"
|
||||
|
||||
#define FILE_MAX_SIZE (1024 * 1024 * 10)
|
||||
#define LOG_PATH_DIR "/var/log/ascend-docker-runtime/"
|
||||
@@ -46,6 +47,9 @@ int GetCurrentLocalTime(char* buffer, int length)
|
||||
|
||||
int CreateLog(const char* filename)
|
||||
{
|
||||
if (filename == NULL) {
|
||||
return -1;
|
||||
}
|
||||
int exist;
|
||||
exist = access(filename, 0);
|
||||
int fd = 0;
|
||||
|
@@ -184,6 +184,9 @@ static bool OptionsCmdArgParser(struct CmdArgs *args, const char *arg)
|
||||
|
||||
static bool CheckWhiteList(const char* fileName)
|
||||
{
|
||||
if (fileName == NULL) {
|
||||
return false;
|
||||
}
|
||||
bool fileExists = false;
|
||||
const char mountWhiteList[WHITE_LIST_NUM][PATH_MAX] = {{"/usr/local/Ascend/driver/lib64"},
|
||||
{"/usr/local/Ascend/driver/include"},
|
||||
|
13
cli/src/ns.c
13
cli/src/ns.c
@@ -13,14 +13,20 @@
|
||||
#include "utils.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";
|
||||
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";
|
||||
return sprintf_s(buf, bufSize, fmtStr, nsType);
|
||||
}
|
||||
@@ -39,6 +45,9 @@ int EnterNsByFd(int fd, int nsType)
|
||||
|
||||
int EnterNsByPath(const char *path, int nsType)
|
||||
{
|
||||
if (path == NULL) {
|
||||
return -1;
|
||||
}
|
||||
int fd;
|
||||
int ret;
|
||||
|
||||
|
@@ -7,8 +7,8 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
int GetNsPath(int pid, const char *nsType, char *buf, size_t bufSize);
|
||||
int GetSelfNsPath(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, const size_t bufSize);
|
||||
int EnterNsByFd(int fd, int nsType);
|
||||
int EnterNsByPath(const char *path, int nsType);
|
||||
|
||||
|
@@ -51,7 +51,7 @@ char *FormatLogMessage(char *format, ...)
|
||||
|
||||
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)
|
||||
|
@@ -126,7 +126,7 @@ static int DelJsonContent(cJSON *root, const char *key)
|
||||
cJSON *existItem = NULL;
|
||||
existItem = cJSON_GetObjectItem(root, key);
|
||||
if (existItem == NULL) {
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
cJSON *removedItem = NULL;
|
||||
@@ -390,6 +390,7 @@ static int DetectAndCreateJsonFile(const char *filePath, const char *tempPath, c
|
||||
} else {
|
||||
root = ModifyContent(pf, runtimePath);
|
||||
fclose(pf);
|
||||
pf = 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) {
|
||||
(void)fprintf(stderr, "error: failed to create file\n");
|
||||
(void)fclose(pf);
|
||||
pf = NULL;
|
||||
cJSON_Delete(root);
|
||||
return -1;
|
||||
}
|
||||
(void)fclose(pf);
|
||||
|
||||
pf = NULL;
|
||||
cJSON_Delete(root);
|
||||
|
||||
return 0;
|
||||
@@ -456,10 +458,8 @@ static int CreateRevisedJsonFile(const char *filePath, const char *tempPath)
|
||||
if (fprintf(pf, "%s", cJSON_Print(newContent)) < 0) {
|
||||
(void)fprintf(stderr, "error: failed to create file\n");
|
||||
cJSON_Delete(newContent);
|
||||
if (pf != NULL) {
|
||||
(void)fclose(pf);
|
||||
pf = NULL;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
(void)fclose(pf);
|
||||
|
Reference in New Issue
Block a user