提交 2ba89831 编写于 作者: X xionglei6

init: fix bugs

Signed-off-by: Nxionglei6 <xionglei6@huawei.com>
上级 59b51bd1
...@@ -35,5 +35,8 @@ ohos_shared_library("libsocket") { ...@@ -35,5 +35,8 @@ ohos_shared_library("libsocket") {
include_dirs = service_socket_include include_dirs = service_socket_include
deps = service_socket_deps deps = service_socket_deps
part_name = "init" part_name = "init"
install_images = [ "system" ] install_images = [
"system",
"updater",
]
} }
...@@ -116,6 +116,9 @@ static int CheckAndRebootToUpdater(const char *valueData, const char *cmd, const ...@@ -116,6 +116,9 @@ static int CheckAndRebootToUpdater(const char *valueData, const char *cmd, const
ret = snprintf_s(msg.update, MAX_UPDATE_SIZE, MAX_UPDATE_SIZE - 1, "%s", p); ret = snprintf_s(msg.update, MAX_UPDATE_SIZE, MAX_UPDATE_SIZE - 1, "%s", p);
INIT_ERROR_CHECK(ret > 0, return -1, "Failed to format param for %s.", cmd); INIT_ERROR_CHECK(ret > 0, return -1, "Failed to format param for %s.", cmd);
msg.update[MAX_UPDATE_SIZE - 1] = 0; msg.update[MAX_UPDATE_SIZE - 1] = 0;
} else {
ret = memset_s(msg.update, MAX_UPDATE_SIZE, 0, MAX_UPDATE_SIZE);
INIT_ERROR_CHECK(ret == 0, return -1, "Failed to format update for %s.", cmd);
} }
ret = -1; ret = -1;
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include "init_utils.h"
#include "param_persist.h" #include "param_persist.h"
#include "param_utils.h" #include "param_utils.h"
...@@ -29,9 +30,11 @@ typedef struct { ...@@ -29,9 +30,11 @@ typedef struct {
static int LoadPersistParam(PersistParamGetPtr persistParamGet, void *context) static int LoadPersistParam(PersistParamGetPtr persistParamGet, void *context)
{ {
CheckAndCreateDir(PARAM_PERSIST_SAVE_PATH); CheckAndCreateDir(PARAM_PERSIST_SAVE_PATH);
FILE *fp = fopen(PARAM_PERSIST_SAVE_TMP_PATH, "r"); int updaterMode = InUpdaterMode();
char *tmpPath = (updaterMode == 0) ? PARAM_PERSIST_SAVE_TMP_PATH : "/param/tmp_persist_parameters";
FILE *fp = fopen(tmpPath, "r");
if (fp == NULL) { if (fp == NULL) {
fp = fopen(PARAM_PERSIST_SAVE_PATH, "r"); fp = fopen((updaterMode == 0) ? PARAM_PERSIST_SAVE_PATH : "/param/persist_parameters", "r");
PARAM_LOGI("LoadPersistParam open file %s", PARAM_PERSIST_SAVE_PATH); PARAM_LOGI("LoadPersistParam open file %s", PARAM_PERSIST_SAVE_PATH);
} }
PARAM_CHECK(fp != NULL, return -1, "No valid persist parameter file %s", PARAM_PERSIST_SAVE_PATH); PARAM_CHECK(fp != NULL, return -1, "No valid persist parameter file %s", PARAM_PERSIST_SAVE_PATH);
...@@ -65,7 +68,7 @@ static int SavePersistParam(const char *name, const char *value) ...@@ -65,7 +68,7 @@ static int SavePersistParam(const char *name, const char *value)
static int BatchSavePersistParamBegin(PERSIST_SAVE_HANDLE *handle) static int BatchSavePersistParamBegin(PERSIST_SAVE_HANDLE *handle)
{ {
FILE *fp = fopen(PARAM_PERSIST_SAVE_TMP_PATH, "w"); FILE *fp = fopen((InUpdaterMode() == 0) ? PARAM_PERSIST_SAVE_TMP_PATH : "/param/tmp_persist_parameters", "w");
PARAM_CHECK(fp != NULL, return -1, "Open file %s fail error %d", PARAM_PERSIST_SAVE_TMP_PATH, errno); PARAM_CHECK(fp != NULL, return -1, "Open file %s fail error %d", PARAM_PERSIST_SAVE_TMP_PATH, errno);
*handle = (PERSIST_SAVE_HANDLE)fp; *handle = (PERSIST_SAVE_HANDLE)fp;
return 0; return 0;
...@@ -82,10 +85,16 @@ static int BatchSavePersistParam(PERSIST_SAVE_HANDLE handle, const char *name, c ...@@ -82,10 +85,16 @@ static int BatchSavePersistParam(PERSIST_SAVE_HANDLE handle, const char *name, c
static void BatchSavePersistParamEnd(PERSIST_SAVE_HANDLE handle) static void BatchSavePersistParamEnd(PERSIST_SAVE_HANDLE handle)
{ {
int ret;
FILE *fp = (FILE *)handle; FILE *fp = (FILE *)handle;
(void)fclose(fp); (void)fclose(fp);
unlink(PARAM_PERSIST_SAVE_PATH); if (InUpdaterMode() == 0) {
int ret = rename(PARAM_PERSIST_SAVE_TMP_PATH, PARAM_PERSIST_SAVE_PATH); unlink(PARAM_PERSIST_SAVE_PATH);
ret = rename(PARAM_PERSIST_SAVE_TMP_PATH, PARAM_PERSIST_SAVE_PATH);
} else {
unlink("/param/persist_parameters");
ret = rename("/param/tmp_persist_parameters", "/param/persist_parameters");
}
PARAM_CHECK(ret == 0, return, "BatchSavePersistParamEnd %s fail error %d", PARAM_PERSIST_SAVE_TMP_PATH, errno); PARAM_CHECK(ret == 0, return, "BatchSavePersistParamEnd %s fail error %d", PARAM_PERSIST_SAVE_TMP_PATH, errno);
} }
...@@ -98,4 +107,4 @@ int RegisterPersistParamOps(PersistParamOps *ops) ...@@ -98,4 +107,4 @@ int RegisterPersistParamOps(PersistParamOps *ops)
ops->batchSave = BatchSavePersistParam; ops->batchSave = BatchSavePersistParam;
ops->batchSaveEnd = BatchSavePersistParamEnd; ops->batchSaveEnd = BatchSavePersistParamEnd;
return 0; return 0;
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册