未验证 提交 fa8aafa5 编写于 作者: O openharmony_ci 提交者: Gitee

!532 optimize sandbox global variable as const

Merge pull request !532 from handy/0419
...@@ -53,7 +53,7 @@ struct SandboxMountFlags { ...@@ -53,7 +53,7 @@ struct SandboxMountFlags {
unsigned long value; unsigned long value;
}; };
struct SandboxMountFlags g_flags[] = { static const struct SandboxMountFlags g_flags[] = {
{ {
.flag = "bind", .flag = "bind",
.value = MS_BIND, .value = MS_BIND,
...@@ -84,7 +84,7 @@ struct SandboxMap { ...@@ -84,7 +84,7 @@ struct SandboxMap {
const char *configfile; const char *configfile;
}; };
struct SandboxMap g_map[] = { static const struct SandboxMap g_map[] = {
{ {
.name = "system", .name = "system",
.sandbox = &g_systemSandbox, .sandbox = &g_systemSandbox,
...@@ -276,7 +276,7 @@ static int ParseSandboxConfig(sandbox_t *sandbox, const char *sandboxConfig) ...@@ -276,7 +276,7 @@ static int ParseSandboxConfig(sandbox_t *sandbox, const char *sandboxConfig)
return 0; return 0;
} }
static struct SandboxMap *GetSandboxMapByName(const char *name) static const struct SandboxMap *GetSandboxMapByName(const char *name)
{ {
if (name == NULL) { if (name == NULL) {
BEGET_LOGE("Failed get sandbox map name is NULL."); BEGET_LOGE("Failed get sandbox map name is NULL.");
...@@ -445,7 +445,7 @@ int PrepareSandbox(const char *name) ...@@ -445,7 +445,7 @@ int PrepareSandbox(const char *name)
{ {
BEGET_ERROR_CHECK(name != NULL, return -1, "Prepare sandbox name is NULL."); BEGET_ERROR_CHECK(name != NULL, return -1, "Prepare sandbox name is NULL.");
BEGET_ERROR_CHECK(getuid() == 0, return -1, "Current process uid is not root, exit."); BEGET_ERROR_CHECK(getuid() == 0, return -1, "Current process uid is not root, exit.");
struct SandboxMap *map = GetSandboxMapByName(name); const struct SandboxMap *map = GetSandboxMapByName(name);
BEGET_ERROR_CHECK(map != NULL, return -1, "Failed get sandbox map by name %s.", name); BEGET_ERROR_CHECK(map != NULL, return -1, "Failed get sandbox map by name %s.", name);
sandbox_t *sandbox = map->sandbox; sandbox_t *sandbox = map->sandbox;
BEGET_CHECK(IsValidSandbox(sandbox) == true, return -1); BEGET_CHECK(IsValidSandbox(sandbox) == true, return -1);
...@@ -549,7 +549,7 @@ bool InitSandboxWithName(const char *name) ...@@ -549,7 +549,7 @@ bool InitSandboxWithName(const char *name)
BEGET_LOGE("Init sandbox name is NULL."); BEGET_LOGE("Init sandbox name is NULL.");
return isFound; return isFound;
} }
struct SandboxMap *map = GetSandboxMapByName(name); const struct SandboxMap *map = GetSandboxMapByName(name);
if (map != NULL) { if (map != NULL) {
InitSandbox(map->sandbox, map->configfile, name); InitSandbox(map->sandbox, map->configfile, name);
isFound = true; isFound = true;
...@@ -567,7 +567,7 @@ void DestroySandbox(const char *name) ...@@ -567,7 +567,7 @@ void DestroySandbox(const char *name)
BEGET_LOGE("Destroy sandbox name is NULL."); BEGET_LOGE("Destroy sandbox name is NULL.");
return; return;
} }
struct SandboxMap *map = GetSandboxMapByName(name); const struct SandboxMap *map = GetSandboxMapByName(name);
if (map == NULL) { if (map == NULL) {
BEGET_LOGE("Failed get sandbox map by name %s.", name); BEGET_LOGE("Failed get sandbox map by name %s.", name);
return; return;
...@@ -597,7 +597,7 @@ int EnterSandbox(const char *name) ...@@ -597,7 +597,7 @@ int EnterSandbox(const char *name)
BEGET_LOGE("Sandbox name is NULL."); BEGET_LOGE("Sandbox name is NULL.");
return -1; return -1;
} }
struct SandboxMap *map = GetSandboxMapByName(name); const struct SandboxMap *map = GetSandboxMapByName(name);
if (map == NULL) { if (map == NULL) {
BEGET_LOGE("Failed to get sandbox map by name %s.", name); BEGET_LOGE("Failed to get sandbox map by name %s.", name);
return -1; return -1;
...@@ -629,7 +629,7 @@ void DumpSandboxByName(const char *name) ...@@ -629,7 +629,7 @@ void DumpSandboxByName(const char *name)
BEGET_LOGE("Init sandbox name is NULL."); BEGET_LOGE("Init sandbox name is NULL.");
return; return;
} }
struct SandboxMap *map = GetSandboxMapByName(name); const struct SandboxMap *map = GetSandboxMapByName(name);
if (map == NULL) { if (map == NULL) {
return; return;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册