mirror of
https://github.com/Ascend/ascend-docker-runtime.git
synced 2025-10-11 18:20:08 +08:00
Match-id-c25fd09e916068308714c720e95c14dc885d8b41
This commit is contained in:
@@ -4,18 +4,14 @@
|
|||||||
*/
|
*/
|
||||||
#include "basic.h"
|
#include "basic.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "logger.h"
|
#include <stdio.h>
|
||||||
|
|
||||||
void InitParsedConfig(struct ParsedConfig *parsedConfig)
|
void InitParsedConfig(struct ParsedConfig *parsedConfig)
|
||||||
{
|
{
|
||||||
<<<<<<< HEAD
|
if (parsedConfig == NULL) {
|
||||||
if (parsedConfig != NULL) {
|
fprintf(stderr, "parsedConfig pointer is null!\n");
|
||||||
=======
|
|
||||||
if (parsedConfig != NULL)
|
|
||||||
{
|
|
||||||
>>>>>>> fd706c08945c4519bcefe0d295d55c42c7ad1711
|
|
||||||
Logger("parsedConfig Pointer is null!.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
parsedConfig->devicesNr = MAX_DEVICE_NR;
|
parsedConfig->devicesNr = MAX_DEVICE_NR;
|
||||||
}
|
}
|
@@ -21,6 +21,11 @@
|
|||||||
|
|
||||||
bool TakeNthWord(char **pLine, unsigned int n, char **word)
|
bool TakeNthWord(char **pLine, unsigned int n, char **word)
|
||||||
{
|
{
|
||||||
|
if (pLine == NULL || word == NULL) {
|
||||||
|
fprintf(stderr, "pLine, word pointer is null!\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
char *w = NULL;
|
char *w = NULL;
|
||||||
for (unsigned int i = 0; i < n; i++) {
|
for (unsigned int i = 0; i < n; i++) {
|
||||||
w = strsep(pLine, " ");
|
w = strsep(pLine, " ");
|
||||||
@@ -35,6 +40,11 @@ bool TakeNthWord(char **pLine, unsigned int n, char **word)
|
|||||||
|
|
||||||
bool CheckRootDir(char **pLine)
|
bool CheckRootDir(char **pLine)
|
||||||
{
|
{
|
||||||
|
if (pLine == NULL) {
|
||||||
|
fprintf(stderr, "pLine pointer is null!\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
char *rootDir = NULL;
|
char *rootDir = NULL;
|
||||||
if (!TakeNthWord(pLine, ROOT_GAP, &rootDir)) {
|
if (!TakeNthWord(pLine, ROOT_GAP, &rootDir)) {
|
||||||
return false;
|
return false;
|
||||||
@@ -45,6 +55,11 @@ bool CheckRootDir(char **pLine)
|
|||||||
|
|
||||||
bool CheckFsType(char **pLine)
|
bool CheckFsType(char **pLine)
|
||||||
{
|
{
|
||||||
|
if (pLine == NULL) {
|
||||||
|
fprintf(stderr, "pLine pointer is null!\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
char* fsType = NULL;
|
char* fsType = NULL;
|
||||||
if (!TakeNthWord(pLine, FSTYPE_GAP, &fsType)) {
|
if (!TakeNthWord(pLine, FSTYPE_GAP, &fsType)) {
|
||||||
return false;
|
return false;
|
||||||
@@ -55,6 +70,11 @@ bool CheckFsType(char **pLine)
|
|||||||
|
|
||||||
bool CheckSubStr(char **pLine, const char *subsys)
|
bool CheckSubStr(char **pLine, const char *subsys)
|
||||||
{
|
{
|
||||||
|
if (pLine == NULL || subsys == NULL) {
|
||||||
|
fprintf(stderr, "pLine, subsys pointer is null!\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
char* substr = NULL;
|
char* substr = NULL;
|
||||||
if (!TakeNthWord(pLine, MOUNT_SUBSTR_GAP, &substr)) {
|
if (!TakeNthWord(pLine, MOUNT_SUBSTR_GAP, &substr)) {
|
||||||
return false;
|
return false;
|
||||||
@@ -66,6 +86,11 @@ bool CheckSubStr(char **pLine, const char *subsys)
|
|||||||
typedef char *(*ParseFileLine)(char *, const char *);
|
typedef char *(*ParseFileLine)(char *, const char *);
|
||||||
int ParseFileByLine(char* buffer, int bufferSize, const ParseFileLine fn, const char* filepath)
|
int ParseFileByLine(char* buffer, int bufferSize, const ParseFileLine fn, const char* filepath)
|
||||||
{
|
{
|
||||||
|
if (buffer == NULL || filepath == NULL) {
|
||||||
|
fprintf(stderr, "buffer, filepath pointer is null!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
char *result = NULL;
|
char *result = NULL;
|
||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
@@ -107,6 +132,11 @@ int ParseFileByLine(char* buffer, int bufferSize, const ParseFileLine fn, const
|
|||||||
|
|
||||||
char *GetCgroupMount(char *line, const char *subsys)
|
char *GetCgroupMount(char *line, const char *subsys)
|
||||||
{
|
{
|
||||||
|
if (line == NULL || subsys == NULL) {
|
||||||
|
fprintf(stderr, "line, subsys pointer is null!\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (!CheckRootDir(&line)) {
|
if (!CheckRootDir(&line)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -131,6 +161,11 @@ char *GetCgroupMount(char *line, const char *subsys)
|
|||||||
|
|
||||||
char *GetCgroupRoot(char *line, const char *subSystem)
|
char *GetCgroupRoot(char *line, const char *subSystem)
|
||||||
{
|
{
|
||||||
|
if (line == NULL || subSystem == NULL) {
|
||||||
|
fprintf(stderr, "line, subSystem pointer is null!\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
char *token = NULL;
|
char *token = NULL;
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < ROOT_SUBSTR_GAP; ++i) {
|
for (i = 0; i < ROOT_SUBSTR_GAP; ++i) {
|
||||||
@@ -156,6 +191,11 @@ char *GetCgroupRoot(char *line, const char *subSystem)
|
|||||||
|
|
||||||
int SetupDeviceCgroup(FILE *cgroupAllow, const char *devName)
|
int SetupDeviceCgroup(FILE *cgroupAllow, const char *devName)
|
||||||
{
|
{
|
||||||
|
if (cgroupAllow == NULL || devName == NULL) {
|
||||||
|
fprintf(stderr, "cgroupAllow, devName pointer is null!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
struct stat devStat;
|
struct stat devStat;
|
||||||
char devPath[BUF_SIZE];
|
char devPath[BUF_SIZE];
|
||||||
@@ -188,8 +228,12 @@ int SetupDeviceCgroup(FILE *cgroupAllow, const char *devName)
|
|||||||
|
|
||||||
int SetupDriverCgroup(FILE *cgroupAllow)
|
int SetupDriverCgroup(FILE *cgroupAllow)
|
||||||
{
|
{
|
||||||
int ret;
|
if (cgroupAllow == NULL) {
|
||||||
|
fprintf(stderr, "cgroupAllow pointer is null!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ret;
|
||||||
ret = SetupDeviceCgroup(cgroupAllow, DAVINCI_MANAGER);
|
ret = SetupDeviceCgroup(cgroupAllow, DAVINCI_MANAGER);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
char* str = FormatLogMessage("failed to setup cgroup for %s.", DAVINCI_MANAGER);
|
char* str = FormatLogMessage("failed to setup cgroup for %s.", DAVINCI_MANAGER);
|
||||||
@@ -219,6 +263,11 @@ int SetupDriverCgroup(FILE *cgroupAllow)
|
|||||||
|
|
||||||
int GetCgroupPath(int pid, char *effPath, size_t maxSize)
|
int GetCgroupPath(int pid, char *effPath, size_t maxSize)
|
||||||
{
|
{
|
||||||
|
if (effPath == NULL) {
|
||||||
|
fprintf(stderr, "effPath pointer is null!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
char mountPath[BUF_SIZE] = {0x0};
|
char mountPath[BUF_SIZE] = {0x0};
|
||||||
char mount[BUF_SIZE] = {0x0};
|
char mount[BUF_SIZE] = {0x0};
|
||||||
@@ -267,12 +316,15 @@ int GetCgroupPath(int pid, char *effPath, size_t maxSize)
|
|||||||
|
|
||||||
int SetupCgroup(const struct ParsedConfig *config)
|
int SetupCgroup(const struct ParsedConfig *config)
|
||||||
{
|
{
|
||||||
int ret;
|
if (config == NULL) {
|
||||||
|
fprintf(stderr, "config pointer is null!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
char *str = NULL;
|
char *str = NULL;
|
||||||
char deviceName[BUF_SIZE] = {0};
|
char deviceName[BUF_SIZE] = {0};
|
||||||
char resolvedCgroupPath[PATH_MAX] = {0};
|
char resolvedCgroupPath[PATH_MAX] = {0};
|
||||||
FILE *cgroupAllow = NULL;
|
FILE *cgroupAllow = NULL;
|
||||||
|
|
||||||
if (realpath(config->cgroupPath, resolvedCgroupPath) == NULL && errno != ENOENT) {
|
if (realpath(config->cgroupPath, resolvedCgroupPath) == NULL && errno != ENOENT) {
|
||||||
Logger("cannot canonicalize cgroup.", LEVEL_ERROR, SCREEN_YES);
|
Logger("cannot canonicalize cgroup.", LEVEL_ERROR, SCREEN_YES);
|
||||||
free(str);
|
free(str);
|
||||||
@@ -289,26 +341,23 @@ int SetupCgroup(const struct ParsedConfig *config)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = SetupDriverCgroup(cgroupAllow);
|
if (SetupDriverCgroup(cgroupAllow) < 0) {
|
||||||
if (ret < 0) {
|
|
||||||
fclose(cgroupAllow);
|
fclose(cgroupAllow);
|
||||||
Logger("failed to setup driver cgroup.", LEVEL_ERROR, SCREEN_YES);
|
Logger("failed to setup driver cgroup.", LEVEL_ERROR, SCREEN_YES);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t idx = 0; idx < config->devicesNr; idx++) {
|
for (size_t idx = 0; idx < config->devicesNr; idx++) {
|
||||||
int ret = sprintf_s(deviceName, BUF_SIZE, "%s%u",
|
if (sprintf_s(deviceName, BUF_SIZE, "%s%u",
|
||||||
(IsVirtual() ? VDEVICE_NAME : DEVICE_NAME),
|
(IsVirtual() ? VDEVICE_NAME : DEVICE_NAME),
|
||||||
config->devices[idx]);
|
config->devices[idx]) < 0) {
|
||||||
if (ret < 0) {
|
|
||||||
fclose(cgroupAllow);
|
fclose(cgroupAllow);
|
||||||
str = FormatLogMessage("failed to assemble device path for no.%u.", config->devices[idx]);
|
str = FormatLogMessage("failed to assemble device path for no.%u.", config->devices[idx]);
|
||||||
Logger(str, LEVEL_ERROR, SCREEN_YES);
|
Logger(str, LEVEL_ERROR, SCREEN_YES);
|
||||||
free(str);
|
free(str);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ret = SetupDeviceCgroup(cgroupAllow, (const char *)deviceName);
|
|
||||||
if (ret < 0) {
|
if (SetupDeviceCgroup(cgroupAllow, (const char *)deviceName) < 0) {
|
||||||
fclose(cgroupAllow);
|
fclose(cgroupAllow);
|
||||||
Logger("failed to setup cgroup.", LEVEL_ERROR, SCREEN_YES);
|
Logger("failed to setup cgroup.", LEVEL_ERROR, SCREEN_YES);
|
||||||
free(str);
|
free(str);
|
||||||
|
@@ -22,6 +22,11 @@
|
|||||||
|
|
||||||
int GetCurrentLocalTime(char* buffer, int length)
|
int GetCurrentLocalTime(char* buffer, int length)
|
||||||
{
|
{
|
||||||
|
if (buffer == NULL) {
|
||||||
|
fprintf(stderr, "buffer pointer is null!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
time_t timep = time(NULL);
|
time_t timep = time(NULL);
|
||||||
struct tm result = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
struct tm result = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||||
struct tm *timeinfo = localtime_r(&timep, &result);
|
struct tm *timeinfo = localtime_r(&timep, &result);
|
||||||
@@ -56,6 +61,11 @@ int CreateLog(const char* filename)
|
|||||||
|
|
||||||
long GetLogSize(const char* filename)
|
long GetLogSize(const char* filename)
|
||||||
{
|
{
|
||||||
|
if (filename == NULL) {
|
||||||
|
fprintf(stderr, "filename pointer is null!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
ret = CreateLog(filename);
|
ret = CreateLog(filename);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
@@ -85,6 +95,11 @@ long GetLogSize(const char* filename)
|
|||||||
|
|
||||||
int LogLoop(const char* filename)
|
int LogLoop(const char* filename)
|
||||||
{
|
{
|
||||||
|
if (filename == NULL) {
|
||||||
|
fprintf(stderr, "filename pointer is null!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
char* loopPath = LOG_PATH_DIR"docker-runtime-log.log.1";
|
char* loopPath = LOG_PATH_DIR"docker-runtime-log.log.1";
|
||||||
int exist;
|
int exist;
|
||||||
@@ -105,6 +120,11 @@ int LogLoop(const char* filename)
|
|||||||
|
|
||||||
void WriteLogFile(const char* filename, long maxSize, const char* buffer, unsigned bufferSize)
|
void WriteLogFile(const char* filename, long maxSize, const char* buffer, unsigned bufferSize)
|
||||||
{
|
{
|
||||||
|
if (filename == NULL || buffer == NULL) {
|
||||||
|
fprintf(stderr, "filename, buffer pointer is null!\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (filename != NULL && buffer != NULL) {
|
if (filename != NULL && buffer != NULL) {
|
||||||
char path[PATH_MAX + 1] = {0x00};
|
char path[PATH_MAX + 1] = {0x00};
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
|
@@ -47,6 +47,11 @@ typedef bool (*CmdArgParser)(struct CmdArgs *args, const char *arg);
|
|||||||
|
|
||||||
static bool DevicesCmdArgParser(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");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
errno_t err = strcpy_s(args->devices, BUF_SIZE, arg);
|
errno_t err = strcpy_s(args->devices, BUF_SIZE, arg);
|
||||||
if (err != EOK) {
|
if (err != EOK) {
|
||||||
Logger("failed to get devices from cmd args.", LEVEL_ERROR, SCREEN_YES);
|
Logger("failed to get devices from cmd args.", LEVEL_ERROR, SCREEN_YES);
|
||||||
@@ -58,6 +63,11 @@ static bool DevicesCmdArgParser(struct CmdArgs *args, const char *arg)
|
|||||||
|
|
||||||
static bool PidCmdArgParser(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");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
args->pid = strtol(optarg, NULL, DECIMAL);
|
args->pid = strtol(optarg, NULL, DECIMAL);
|
||||||
if (errno != 0) {
|
if (errno != 0) {
|
||||||
@@ -79,6 +89,11 @@ static bool PidCmdArgParser(struct CmdArgs *args, const char *arg)
|
|||||||
|
|
||||||
static bool RootfsCmdArgParser(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");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
errno_t err = strcpy_s(args->rootfs, BUF_SIZE, arg);
|
errno_t err = strcpy_s(args->rootfs, BUF_SIZE, arg);
|
||||||
if (err != EOK) {
|
if (err != EOK) {
|
||||||
Logger("failed to get rootfs path from cmd args", LEVEL_ERROR, SCREEN_YES);
|
Logger("failed to get rootfs path from cmd args", LEVEL_ERROR, SCREEN_YES);
|
||||||
@@ -90,6 +105,11 @@ static bool RootfsCmdArgParser(struct CmdArgs *args, const char *arg)
|
|||||||
|
|
||||||
static bool OptionsCmdArgParser(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");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
errno_t err = strcpy_s(args->options, BUF_SIZE, arg);
|
errno_t err = strcpy_s(args->options, BUF_SIZE, arg);
|
||||||
if (err != EOK) {
|
if (err != EOK) {
|
||||||
Logger("failed to get options string from cmd args", LEVEL_ERROR, SCREEN_YES);
|
Logger("failed to get options string from cmd args", LEVEL_ERROR, SCREEN_YES);
|
||||||
@@ -101,6 +121,11 @@ static bool OptionsCmdArgParser(struct CmdArgs *args, const char *arg)
|
|||||||
|
|
||||||
static bool MountFileCmdArgParser(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");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (args->files.count == MAX_MOUNT_NR) {
|
if (args->files.count == MAX_MOUNT_NR) {
|
||||||
char* str = FormatLogMessage("too many files to mount, max number is %u", MAX_MOUNT_NR);
|
char* str = FormatLogMessage("too many files to mount, max number is %u", MAX_MOUNT_NR);
|
||||||
Logger(str, LEVEL_ERROR, SCREEN_YES);
|
Logger(str, LEVEL_ERROR, SCREEN_YES);
|
||||||
@@ -122,6 +147,11 @@ static bool MountFileCmdArgParser(struct CmdArgs *args, const char *arg)
|
|||||||
|
|
||||||
static bool MountDirCmdArgParser(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");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (args->dirs.count == MAX_MOUNT_NR) {
|
if (args->dirs.count == MAX_MOUNT_NR) {
|
||||||
char* str = FormatLogMessage("too many directories to mount, max number is %u", MAX_MOUNT_NR);
|
char* str = FormatLogMessage("too many directories to mount, max number is %u", MAX_MOUNT_NR);
|
||||||
Logger(str, LEVEL_ERROR, SCREEN_YES);
|
Logger(str, LEVEL_ERROR, SCREEN_YES);
|
||||||
@@ -157,6 +187,11 @@ static struct {
|
|||||||
|
|
||||||
static int ParseOneCmdArg(struct CmdArgs *args, char indicator, const char *value)
|
static int ParseOneCmdArg(struct CmdArgs *args, char indicator, const char *value)
|
||||||
{
|
{
|
||||||
|
if (args == NULL || value == NULL) {
|
||||||
|
fprintf(stderr, "args, value pointer is null!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < NUM_OF_CMD_ARGS; i++) {
|
for (i = 0; i < NUM_OF_CMD_ARGS; i++) {
|
||||||
if (g_cmdArgParsers[i].c == indicator) {
|
if (g_cmdArgParsers[i].c == indicator) {
|
||||||
@@ -182,11 +217,20 @@ static int ParseOneCmdArg(struct CmdArgs *args, char indicator, const char *valu
|
|||||||
|
|
||||||
static inline bool IsCmdArgsValid(const struct CmdArgs *args)
|
static inline bool IsCmdArgsValid(const struct CmdArgs *args)
|
||||||
{
|
{
|
||||||
|
if (args == NULL) {
|
||||||
|
fprintf(stderr, "args pointer is null!\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return (strlen(args->devices) > 0) && (strlen(args->rootfs) > 0) && (args->pid > 0);
|
return (strlen(args->devices) > 0) && (strlen(args->rootfs) > 0) && (args->pid > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ParseDeviceIDs(unsigned int *idList, size_t *idListSize, char *devices)
|
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");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
static const char *sep = ",";
|
static const char *sep = ",";
|
||||||
char *token = NULL;
|
char *token = NULL;
|
||||||
char *context = NULL;
|
char *context = NULL;
|
||||||
@@ -220,6 +264,11 @@ static int ParseDeviceIDs(unsigned int *idList, size_t *idListSize, char *device
|
|||||||
|
|
||||||
int DoPrepare(const struct CmdArgs *args, struct ParsedConfig *config)
|
int DoPrepare(const struct CmdArgs *args, struct ParsedConfig *config)
|
||||||
{
|
{
|
||||||
|
if (args == NULL || config == NULL) {
|
||||||
|
fprintf(stderr, "args, config pointer is null!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
errno_t err;
|
errno_t err;
|
||||||
|
|
||||||
@@ -272,6 +321,11 @@ int DoPrepare(const struct CmdArgs *args, struct ParsedConfig *config)
|
|||||||
|
|
||||||
int SetupContainer(struct CmdArgs *args)
|
int SetupContainer(struct CmdArgs *args)
|
||||||
{
|
{
|
||||||
|
if (args == NULL) {
|
||||||
|
fprintf(stderr, "args pointer is null!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
struct ParsedConfig config;
|
struct ParsedConfig config;
|
||||||
|
|
||||||
@@ -324,6 +378,10 @@ int SetupContainer(struct CmdArgs *args)
|
|||||||
|
|
||||||
int Process(int argc, char **argv)
|
int Process(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
if (argv == NULL) {
|
||||||
|
fprintf(stderr, "argv pointer is null!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
int c;
|
int c;
|
||||||
int ret;
|
int ret;
|
||||||
int optionIndex;
|
int optionIndex;
|
||||||
|
@@ -24,6 +24,11 @@ static struct {
|
|||||||
|
|
||||||
void ParseRuntimeOptions(const char *options)
|
void ParseRuntimeOptions(const char *options)
|
||||||
{
|
{
|
||||||
|
if (options == NULL) {
|
||||||
|
fprintf(stderr, "options pointer is null!\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// set defaults value
|
// set defaults value
|
||||||
g_runtimeOptions.noDrv = false;
|
g_runtimeOptions.noDrv = false;
|
||||||
g_runtimeOptions.isVirtual = false;
|
g_runtimeOptions.isVirtual = false;
|
||||||
|
@@ -18,6 +18,11 @@
|
|||||||
|
|
||||||
int Mount(const char *src, const char *dst)
|
int Mount(const char *src, const char *dst)
|
||||||
{
|
{
|
||||||
|
if (src == NULL || dst == NULL) {
|
||||||
|
fprintf(stderr, "src pointer or dst pointer is null!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
static const unsigned long mountFlags = MS_BIND;
|
static const unsigned long mountFlags = MS_BIND;
|
||||||
static const unsigned long remountFlags = MS_BIND | MS_REMOUNT | MS_RDONLY | MS_NOSUID;
|
static const unsigned long remountFlags = MS_BIND | MS_REMOUNT | MS_RDONLY | MS_NOSUID;
|
||||||
int ret;
|
int ret;
|
||||||
@@ -44,6 +49,11 @@ int Mount(const char *src, const char *dst)
|
|||||||
static int GetDeviceMntSrcDst(const char *rootfs, const char *srcDeviceName,
|
static int GetDeviceMntSrcDst(const char *rootfs, const char *srcDeviceName,
|
||||||
const char *dstDeviceName, struct PathInfo* pathInfo)
|
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");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
errno_t err;
|
errno_t err;
|
||||||
char unresolvedDst[BUF_SIZE] = {0};
|
char unresolvedDst[BUF_SIZE] = {0};
|
||||||
@@ -96,21 +106,23 @@ static int GetDeviceMntSrcDst(const char *rootfs, const char *srcDeviceName,
|
|||||||
|
|
||||||
int MountDevice(const char *rootfs, const char *srcDeviceName, const char *dstDeviceName)
|
int MountDevice(const char *rootfs, const char *srcDeviceName, const char *dstDeviceName)
|
||||||
{
|
{
|
||||||
int ret;
|
if (rootfs == NULL || srcDeviceName == NULL || dstDeviceName == NULL) {
|
||||||
|
fprintf(stderr, "rootfs, srcDeviceName, dstDeviceName pointer is null!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
char *str = NULL;
|
char *str = NULL;
|
||||||
char src[BUF_SIZE] = {0};
|
char src[BUF_SIZE] = {0};
|
||||||
char dst[BUF_SIZE] = {0};
|
char dst[BUF_SIZE] = {0};
|
||||||
struct PathInfo pathInfo = {src, BUF_SIZE, dst, BUF_SIZE};
|
struct PathInfo pathInfo = {src, BUF_SIZE, dst, BUF_SIZE};
|
||||||
ret = GetDeviceMntSrcDst(rootfs, srcDeviceName, dstDeviceName, &pathInfo);
|
if (GetDeviceMntSrcDst(rootfs, srcDeviceName, dstDeviceName, &pathInfo) < 0) {
|
||||||
if (ret < 0) {
|
|
||||||
str = FormatLogMessage("failed to get mount src and dst path, device name: %s.", srcDeviceName);
|
str = FormatLogMessage("failed to get mount src and dst path, device name: %s.", srcDeviceName);
|
||||||
Logger(str, LEVEL_ERROR, SCREEN_YES);
|
Logger(str, LEVEL_ERROR, SCREEN_YES);
|
||||||
free(str);
|
free(str);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
struct stat srcStat;
|
struct stat srcStat;
|
||||||
ret = stat((const char *)src, &srcStat);
|
if (stat((const char *)src, &srcStat) < 0) {
|
||||||
if (ret < 0) {
|
|
||||||
str = FormatLogMessage("failed to stat src: %s.", src);
|
str = FormatLogMessage("failed to stat src: %s.", src);
|
||||||
Logger(str, LEVEL_ERROR, SCREEN_YES);
|
Logger(str, LEVEL_ERROR, SCREEN_YES);
|
||||||
free(str);
|
free(str);
|
||||||
@@ -118,6 +130,7 @@ int MountDevice(const char *rootfs, const char *srcDeviceName, const char *dstDe
|
|||||||
}
|
}
|
||||||
errno = 0;
|
errno = 0;
|
||||||
struct stat dstStat;
|
struct stat dstStat;
|
||||||
|
int ret;
|
||||||
ret = stat((const char *)dst, &dstStat);
|
ret = stat((const char *)dst, &dstStat);
|
||||||
if (ret == 0 && S_ISCHR(dstStat.st_mode)) {
|
if (ret == 0 && S_ISCHR(dstStat.st_mode)) {
|
||||||
return 0; // 特权容器自动挂载HOST所有设备,故此处跳过
|
return 0; // 特权容器自动挂载HOST所有设备,故此处跳过
|
||||||
@@ -130,15 +143,15 @@ int MountDevice(const char *rootfs, const char *srcDeviceName, const char *dstDe
|
|||||||
Logger("failed to check dst stat", LEVEL_ERROR, SCREEN_YES);
|
Logger("failed to check dst stat", LEVEL_ERROR, SCREEN_YES);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ret = MakeMountPoints(dst, srcStat.st_mode);
|
|
||||||
if (ret < 0) {
|
if (MakeMountPoints(dst, srcStat.st_mode) < 0) {
|
||||||
str = FormatLogMessage("failed to create mount dst file: %s.", dst);
|
str = FormatLogMessage("failed to create mount dst file: %s.", dst);
|
||||||
Logger(str, LEVEL_ERROR, SCREEN_YES);
|
Logger(str, LEVEL_ERROR, SCREEN_YES);
|
||||||
free(str);
|
free(str);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ret = Mount(src, dst);
|
|
||||||
if (ret < 0) {
|
if (Mount(src, dst) < 0) {
|
||||||
Logger("failed to mount dev.", LEVEL_ERROR, SCREEN_YES);
|
Logger("failed to mount dev.", LEVEL_ERROR, SCREEN_YES);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -148,6 +161,11 @@ 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)
|
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");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
char srcDeviceName[BUF_SIZE] = {0};
|
char srcDeviceName[BUF_SIZE] = {0};
|
||||||
char dstDeviceName[BUF_SIZE] = {0};
|
char dstDeviceName[BUF_SIZE] = {0};
|
||||||
|
|
||||||
@@ -174,6 +192,11 @@ int DoDeviceMounting(const char *rootfs, const char *device_name, const unsigned
|
|||||||
|
|
||||||
int MountFile(const char *rootfs, const char *filepath)
|
int MountFile(const char *rootfs, const char *filepath)
|
||||||
{
|
{
|
||||||
|
if (rootfs == NULL || filepath == NULL) {
|
||||||
|
fprintf(stderr, "rootfs, filepath pointer is null!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
char dst[BUF_SIZE] = {0};
|
char dst[BUF_SIZE] = {0};
|
||||||
|
|
||||||
@@ -210,6 +233,11 @@ int MountFile(const char *rootfs, const char *filepath)
|
|||||||
|
|
||||||
int MountDir(const char *rootfs, const char *src)
|
int MountDir(const char *rootfs, const char *src)
|
||||||
{
|
{
|
||||||
|
if (rootfs == NULL || src == NULL) {
|
||||||
|
fprintf(stderr, "rootfs, src pointer is null!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
char dst[BUF_SIZE] = {0};
|
char dst[BUF_SIZE] = {0};
|
||||||
|
|
||||||
@@ -245,6 +273,11 @@ int MountDir(const char *rootfs, const char *src)
|
|||||||
|
|
||||||
int DoCtrlDeviceMounting(const char *rootfs)
|
int DoCtrlDeviceMounting(const char *rootfs)
|
||||||
{
|
{
|
||||||
|
if (rootfs == NULL) {
|
||||||
|
fprintf(stderr, "rootfs pointer is null!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/* device */
|
/* device */
|
||||||
int ret = MountDevice(rootfs, DAVINCI_MANAGER, NULL);
|
int ret = MountDevice(rootfs, DAVINCI_MANAGER, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
@@ -275,8 +308,12 @@ int DoCtrlDeviceMounting(const char *rootfs)
|
|||||||
|
|
||||||
int DoDirectoryMounting(const char *rootfs, const struct MountList *list)
|
int DoDirectoryMounting(const char *rootfs, const struct MountList *list)
|
||||||
{
|
{
|
||||||
int ret;
|
if (rootfs == NULL || list == NULL) {
|
||||||
|
fprintf(stderr, "rootfs, list pointer is null!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ret;
|
||||||
for (unsigned int i = 0; i < list->count; i++) {
|
for (unsigned int i = 0; i < list->count; i++) {
|
||||||
ret = MountDir(rootfs, (const char *)&list->list[i][0]);
|
ret = MountDir(rootfs, (const char *)&list->list[i][0]);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
@@ -292,8 +329,12 @@ int DoDirectoryMounting(const char *rootfs, const struct MountList *list)
|
|||||||
|
|
||||||
int DoFileMounting(const char *rootfs, const struct MountList *list)
|
int DoFileMounting(const char *rootfs, const struct MountList *list)
|
||||||
{
|
{
|
||||||
int ret;
|
if (rootfs == NULL || list == NULL) {
|
||||||
|
fprintf(stderr, "rootfs, list pointer is null!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ret;
|
||||||
for (unsigned int i = 0; i < list->count; i++) {
|
for (unsigned int i = 0; i < list->count; i++) {
|
||||||
ret = MountFile(rootfs, (const char *)&list->list[i][0]);
|
ret = MountFile(rootfs, (const char *)&list->list[i][0]);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
@@ -309,6 +350,11 @@ int DoFileMounting(const char *rootfs, const struct MountList *list)
|
|||||||
|
|
||||||
int DoMounting(const struct ParsedConfig *config)
|
int DoMounting(const struct ParsedConfig *config)
|
||||||
{
|
{
|
||||||
|
if (config == NULL) {
|
||||||
|
fprintf(stderr, "config pointer is null!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
ret = DoDeviceMounting(config->rootfs,
|
ret = DoDeviceMounting(config->rootfs,
|
||||||
(IsVirtual() ? VDEVICE_NAME : DEVICE_NAME),
|
(IsVirtual() ? VDEVICE_NAME : DEVICE_NAME),
|
||||||
|
@@ -18,6 +18,11 @@
|
|||||||
|
|
||||||
char *FormatLogMessage(char *format, ...)
|
char *FormatLogMessage(char *format, ...)
|
||||||
{
|
{
|
||||||
|
if (format == NULL) {
|
||||||
|
fprintf(stderr, "format pointer is null!\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
va_list list;
|
va_list list;
|
||||||
// 获取格式化后字符串的长度
|
// 获取格式化后字符串的长度
|
||||||
va_start(list, format);
|
va_start(list, format);
|
||||||
@@ -55,6 +60,11 @@ int StrHasPrefix(const char *str, const char *prefix)
|
|||||||
|
|
||||||
int MkDir(const char *dir, int mode)
|
int MkDir(const char *dir, int mode)
|
||||||
{
|
{
|
||||||
|
if (dir == NULL) {
|
||||||
|
fprintf(stderr, "dir pointer is null!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return mkdir(dir, mode);
|
return mkdir(dir, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,6 +78,11 @@ int VerifyPathInfo(const struct PathInfo* pathInfo)
|
|||||||
|
|
||||||
int CheckDirExists(const char *dir)
|
int CheckDirExists(const char *dir)
|
||||||
{
|
{
|
||||||
|
if (dir == NULL) {
|
||||||
|
fprintf(stderr, "dir pointer is null!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
DIR *ptr = opendir(dir);
|
DIR *ptr = opendir(dir);
|
||||||
if (NULL == ptr) {
|
if (NULL == ptr) {
|
||||||
return -1;
|
return -1;
|
||||||
@@ -79,6 +94,11 @@ int CheckDirExists(const char *dir)
|
|||||||
|
|
||||||
int GetParentPathStr(const char *path, char *parent, size_t bufSize)
|
int GetParentPathStr(const char *path, char *parent, size_t bufSize)
|
||||||
{
|
{
|
||||||
|
if (path == NULL || parent == NULL) {
|
||||||
|
fprintf(stderr, "path pointer or parentPath is null!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
char *ptr = strrchr(path, '/');
|
char *ptr = strrchr(path, '/');
|
||||||
if (ptr == NULL) {
|
if (ptr == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -99,6 +119,11 @@ int GetParentPathStr(const char *path, char *parent, size_t bufSize)
|
|||||||
|
|
||||||
int MakeDirWithParent(const char *path, mode_t mode)
|
int MakeDirWithParent(const char *path, mode_t mode)
|
||||||
{
|
{
|
||||||
|
if (path == NULL) {
|
||||||
|
fprintf(stderr, "path pointer is null!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (*path == '\0' || *path == '.') {
|
if (*path == '\0' || *path == '.') {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -122,6 +147,11 @@ int MakeDirWithParent(const char *path, mode_t mode)
|
|||||||
|
|
||||||
int MakeMountPoints(const char *path, mode_t mode)
|
int MakeMountPoints(const char *path, mode_t mode)
|
||||||
{
|
{
|
||||||
|
if (path == NULL) {
|
||||||
|
fprintf(stderr, "path pointer is null!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/* directory */
|
/* directory */
|
||||||
char parentDir[BUF_SIZE] = {0};
|
char parentDir[BUF_SIZE] = {0};
|
||||||
GetParentPathStr(path, parentDir, BUF_SIZE);
|
GetParentPathStr(path, parentDir, BUF_SIZE);
|
||||||
@@ -155,6 +185,11 @@ int MakeMountPoints(const char *path, mode_t mode)
|
|||||||
|
|
||||||
int CheckLegality(const char* filename)
|
int CheckLegality(const char* filename)
|
||||||
{
|
{
|
||||||
|
if (filename == NULL) {
|
||||||
|
fprintf(stderr, "filename pointer is null!\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
char buf[PATH_MAX + 1] = {0x00};
|
char buf[PATH_MAX + 1] = {0x00};
|
||||||
errno_t ret = strncpy_s(buf, PATH_MAX + 1, filename, strlen(filename));
|
errno_t ret = strncpy_s(buf, PATH_MAX + 1, filename, strlen(filename));
|
||||||
if (ret != EOK) {
|
if (ret != EOK) {
|
||||||
|
@@ -28,8 +28,9 @@ static void ReadJsonFile(FILE *pf, char *text, int maxBufferSize)
|
|||||||
{
|
{
|
||||||
if (pf == NULL || text == NULL) {
|
if (pf == NULL || text == NULL) {
|
||||||
fprintf(stderr, "file pointer or text pointer are null!\n");
|
fprintf(stderr, "file pointer or text pointer are null!\n");
|
||||||
return NULL;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)fseek(pf, 0, SEEK_END);
|
(void)fseek(pf, 0, SEEK_END);
|
||||||
|
|
||||||
int size = (int)ftell(pf);
|
int size = (int)ftell(pf);
|
||||||
@@ -47,10 +48,11 @@ static void ReadJsonFile(FILE *pf, char *text, int maxBufferSize)
|
|||||||
|
|
||||||
static cJSON *CreateAscendRuntimeInfo(const char *runtimePath)
|
static cJSON *CreateAscendRuntimeInfo(const char *runtimePath)
|
||||||
{
|
{
|
||||||
if (runtimePath = NULL) {
|
if (runtimePath == NULL) {
|
||||||
fprintf(stderr, "runtimePath pointer are null!\n");
|
fprintf(stderr, "runtimePath pointer are null!\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON *root = NULL;
|
cJSON *root = NULL;
|
||||||
root = cJSON_CreateObject();
|
root = cJSON_CreateObject();
|
||||||
if (root == NULL) {
|
if (root == NULL) {
|
||||||
@@ -87,6 +89,7 @@ static cJSON *CreateRuntimes(const char *runtimePath)
|
|||||||
fprintf(stderr, "runtimePath pointer is null!\n");
|
fprintf(stderr, "runtimePath pointer is null!\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON *ascendRuntime = NULL;
|
cJSON *ascendRuntime = NULL;
|
||||||
ascendRuntime = CreateAscendRuntimeInfo(runtimePath);
|
ascendRuntime = CreateAscendRuntimeInfo(runtimePath);
|
||||||
if (ascendRuntime == NULL) {
|
if (ascendRuntime == NULL) {
|
||||||
@@ -111,8 +114,9 @@ static int DelJsonContent(cJSON *root, const char *key)
|
|||||||
{
|
{
|
||||||
if (root == NULL || key == NULL) {
|
if (root == NULL || key == NULL) {
|
||||||
fprintf(stderr, "userInfo pointer is null!\n");
|
fprintf(stderr, "userInfo pointer is null!\n");
|
||||||
return NULL;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON *existItem = NULL;
|
cJSON *existItem = NULL;
|
||||||
existItem = cJSON_GetObjectItem(root, key);
|
existItem = cJSON_GetObjectItem(root, key);
|
||||||
if (existItem == NULL) {
|
if (existItem == NULL) {
|
||||||
@@ -136,6 +140,7 @@ static cJSON *CreateContent(const char *runtimePath)
|
|||||||
fprintf(stderr, "runtimePath pointer is null!\n");
|
fprintf(stderr, "runtimePath pointer is null!\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 插入ascend runtime */
|
/* 插入ascend runtime */
|
||||||
cJSON *runtimes = NULL;
|
cJSON *runtimes = NULL;
|
||||||
runtimes = CreateRuntimes(runtimePath);
|
runtimes = CreateRuntimes(runtimePath);
|
||||||
@@ -174,6 +179,7 @@ static cJSON *ModifyContent(FILE *pf, const char *runtimePath)
|
|||||||
fprintf(stderr, "file pointer or runtimePath pointer is null!\n");
|
fprintf(stderr, "file pointer or runtimePath pointer is null!\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
char jsonStr[MAX_JSON_FILE_SIZE] = {0x0};
|
char jsonStr[MAX_JSON_FILE_SIZE] = {0x0};
|
||||||
ReadJsonFile(pf, &jsonStr[0], MAX_JSON_FILE_SIZE);
|
ReadJsonFile(pf, &jsonStr[0], MAX_JSON_FILE_SIZE);
|
||||||
|
|
||||||
@@ -231,6 +237,7 @@ static cJSON *RemoveContent(FILE *pf)
|
|||||||
fprintf(stderr, "file pointer is null!\n");
|
fprintf(stderr, "file pointer is null!\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
char jsonStr[MAX_JSON_FILE_SIZE] = {0x0};
|
char jsonStr[MAX_JSON_FILE_SIZE] = {0x0};
|
||||||
ReadJsonFile(pf, &jsonStr[0], MAX_JSON_FILE_SIZE);
|
ReadJsonFile(pf, &jsonStr[0], MAX_JSON_FILE_SIZE);
|
||||||
|
|
||||||
@@ -269,10 +276,11 @@ static cJSON *RemoveContent(FILE *pf)
|
|||||||
|
|
||||||
static int DetectAndCreateJsonFile(const char *filePath, const char *tempPath, const char *runtimePath)
|
static int DetectAndCreateJsonFile(const char *filePath, const char *tempPath, const char *runtimePath)
|
||||||
{
|
{
|
||||||
if (filePath = NULL || tempPath = NULL || runtimePath = NULL) {
|
if (filePath == NULL || tempPath == NULL || runtimePath == NULL) {
|
||||||
fprintf(stderr, "filePath Pointer or tempPath or runtimePath are null!\n");
|
fprintf(stderr, "filePath, tempPath or runtimePath are null!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON *root = NULL;
|
cJSON *root = NULL;
|
||||||
FILE *pf = NULL;
|
FILE *pf = NULL;
|
||||||
pf = fopen(filePath, "r+");
|
pf = fopen(filePath, "r+");
|
||||||
@@ -310,9 +318,10 @@ static int DetectAndCreateJsonFile(const char *filePath, const char *tempPath, c
|
|||||||
static int CreateRevisedJsonFile(const char *filePath, const char *tempPath)
|
static int CreateRevisedJsonFile(const char *filePath, const char *tempPath)
|
||||||
{
|
{
|
||||||
if (filePath == NULL || tempPath == NULL) {
|
if (filePath == NULL || tempPath == NULL) {
|
||||||
fprintf(stderr, "filePath Pointer or tempPath are null!\n");
|
fprintf(stderr, "filePath or tempPath are null!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *pf = NULL;
|
FILE *pf = NULL;
|
||||||
pf = fopen(filePath, "r+");
|
pf = fopen(filePath, "r+");
|
||||||
if (pf == NULL) {
|
if (pf == NULL) {
|
||||||
|
Reference in New Issue
Block a user