提交 1caff3b2 编写于 作者: S sun_fan

init: init : do reboot cmd delete NoArugment

Signed-off-by: Nsun_fan <sun_fan1@hoperun.com>
上级 7534bf56
...@@ -27,12 +27,19 @@ ...@@ -27,12 +27,19 @@
int DoReboot(const char *cmdContent) int DoReboot(const char *cmdContent)
{ {
char value[MAX_REBOOT_VAUE_SIZE]; char value[MAX_REBOOT_VAUE_SIZE];
if (cmdContent == NULL) { if (cmdContent == NULL || strlen(cmdContent) == 0) {
INIT_LOGE("DoReboot api error, cmdContent is NULL."); if (snprintf_s(value, MAX_REBOOT_NAME_SIZE, MAX_REBOOT_NAME_SIZE - 1, "%s", "reboot") < 0) {
return -1; INIT_LOGE("DoReboot api error, MAX_REBOOT_NAME_SIZE is not enough");
return -1;
}
if (SystemSetParameter("sys.powerctrl", value) != 0) {
INIT_LOGE("DoReboot Api SystemSetParameter error");
return -1;
}
return 0;
} }
int length = strlen(cmdContent); int length = strlen(cmdContent);
if (length == 0 || length > MAX_REBOOT_VAUE_SIZE) { if (length > MAX_REBOOT_VAUE_SIZE) {
INIT_LOGE("DoReboot api error, cmdContent = %s, length = %d.", cmdContent, length); INIT_LOGE("DoReboot api error, cmdContent = %s, length = %d.", cmdContent, length);
return -1; return -1;
} }
......
...@@ -36,7 +36,7 @@ int main(int argc, char* argv[]) ...@@ -36,7 +36,7 @@ int main(int argc, char* argv[])
if (argc == REBOOT_CMD_NUMBER) { if (argc == REBOOT_CMD_NUMBER) {
ret = DoReboot(argv[1]); ret = DoReboot(argv[1]);
} else { } else {
ret = DoReboot("NoArgument"); ret = DoReboot(NULL);
} }
if (ret != 0) { if (ret != 0) {
printf("[reboot command] DoReboot Api return error\n"); printf("[reboot command] DoReboot Api return error\n");
......
...@@ -129,6 +129,61 @@ static int GetMountStatusForMountPoint(const char *mountPoint) ...@@ -129,6 +129,61 @@ static int GetMountStatusForMountPoint(const char *mountPoint)
return 0; return 0;
} }
static int UpdateUpdaterStatus(const char *valueData)
{
const char *miscFile = "/dev/block/platform/soc/10100000.himci.eMMC/by-name/misc";
struct RBMiscUpdateMessage msg;
bool ret = RBMiscReadUpdaterMessage(miscFile, &msg);
if (!ret) {
INIT_LOGE("RBMiscReadUpdaterMessage error.");
return -1;
}
if (snprintf_s(msg.command, MAX_COMMAND_SIZE, MAX_COMMAND_SIZE - 1, "%s", "boot_updater") == -1) {
INIT_LOGE("RBMiscWriteUpdaterMessage error");
return -1;
}
if (strlen(valueData) > strlen("updater:") && strncmp(valueData, "updater:", strlen("updater:")) == 0) {
if (snprintf_s(msg.update, MAX_UPDATE_SIZE, MAX_UPDATE_SIZE - 1, "%s", valueData + strlen("updater:")) == -1) {
INIT_LOGE("RBMiscWriteUpdaterMessage error");
return -1;
}
ret = RBMiscWriteUpdaterMessage(miscFile, &msg);
if (true != ret) {
INIT_LOGE("RBMiscWriteUpdaterMessage error");
return -1;
}
} else if (strlen(valueData) == strlen("updater") && strncmp(valueData, "updater", strlen("updater")) == 0) {
ret = RBMiscWriteUpdaterMessage(miscFile, &msg);
if (true != ret) {
INIT_LOGE("RBMiscWriteUpdaterMessage error");
return -1;
}
} else {
return -1;
}
return 0;
}
static int DoRebootCore(const char *valueData)
{
if (valueData == NULL) {
reboot(RB_AUTOBOOT);
return 0;
} else if (strncmp(valueData, "shutdown", strlen("shutdown")) == 0) {
reboot(RB_POWER_OFF);
return 0;
} else if (strncmp(valueData, "updater", strlen("updater")) == 0) {
int ret = UpdateUpdaterStatus(valueData);
if (ret == 0) {
reboot(RB_AUTOBOOT);
return 0;
}
} else {
return -1;
}
return 0;
}
void DoReboot(const char *value) void DoReboot(const char *value)
{ {
if (value == NULL) { if (value == NULL) {
...@@ -137,26 +192,26 @@ void DoReboot(const char *value) ...@@ -137,26 +192,26 @@ void DoReboot(const char *value)
} }
INIT_LOGI("DoReboot value = %s", value); INIT_LOGI("DoReboot value = %s", value);
if (strlen(value) > MAX_VALUE_LENGTH) { if (strlen(value) > MAX_VALUE_LENGTH || strlen(value) < strlen("reboot") || strlen(value) == strlen("reboot,")) {
INIT_LOGE("DoReboot reboot value error, value = %s.", value); INIT_LOGE("DoReboot reboot value error, value = %s.", value);
return; return;
} }
const char *valueData = NULL; const char *valueData = NULL;
if (strncmp(value, "reboot,", strlen("reboot,")) != 0) { if (strncmp(value, "reboot,", strlen("reboot,")) == 0) {
valueData = value + strlen("reboot,");
} else if (strlen(value) < strlen("reboot,") && strncmp(value, "reboot", strlen("reboot")) == 0) {
valueData = NULL;
} else {
INIT_LOGE("DoReboot reboot value = %s, must started with reboot ,error.", value); INIT_LOGE("DoReboot reboot value = %s, must started with reboot ,error.", value);
return; return;
} else {
valueData = value + strlen("reboot,");
} }
if (strncmp(valueData, "shutdown", strlen("shutdown")) != 0 if (valueData != NULL
&& strncmp(valueData, "shutdown", strlen("shutdown")) != 0
&& strncmp(valueData, "updater:", strlen("updater:")) != 0 && strncmp(valueData, "updater:", strlen("updater:")) != 0
&& strncmp(valueData, "updater", strlen("updater")) != 0 && strncmp(valueData, "updater", strlen("updater")) != 0) {
&& strncmp(valueData, "NoArgument", strlen("NoArgument")) != 0) {
INIT_LOGE("DoReboot value = %s, parameters error.", value); INIT_LOGE("DoReboot value = %s, parameters error.", value);
return; return;
} }
StopAllServicesBeforeReboot(); StopAllServicesBeforeReboot();
if (GetMountStatusForMountPoint("/vendor") != 0) { if (GetMountStatusForMountPoint("/vendor") != 0) {
if (umount("/vendor") != 0) { if (umount("/vendor") != 0) {
...@@ -168,67 +223,10 @@ void DoReboot(const char *value) ...@@ -168,67 +223,10 @@ void DoReboot(const char *value)
INIT_LOGE("DoReboot umount data failed! errno = %d.", errno); INIT_LOGE("DoReboot umount data failed! errno = %d.", errno);
} }
} }
// "shutdown" int ret = DoRebootCore(valueData);
if (strncmp(valueData, "shutdown", strlen("shutdown")) == 0) { if (ret != 0) {
int ret = reboot(RB_POWER_OFF); INIT_LOGE("DoReboot value = %s, error.", value);
if (ret != 0) {
INIT_LOGE("DoReboot reboot(RB_POWER_OFF) failed! syscall ret %d, err %d.", ret, errno);
}
return;
}
// "updater" or "updater:"
const char *miscFile = "/dev/block/platform/soc/10100000.himci.eMMC/by-name/misc";
struct RBMiscUpdateMessage msg;
bool ret = RBMiscReadUpdaterMessage(miscFile, &msg);
if(!ret) {
INIT_LOGE("DoReboot RBMiscReadUpdaterMessage error.");
return;
}
const int commandSize = 12;
if (snprintf_s(msg.command, MAX_COMMAND_SIZE, MAX_COMMAND_SIZE - 1, "%s", "boot_updater") == -1) {
INIT_LOGE("DoReboot updater: RBMiscWriteUpdaterMessage error");
return;
}
msg.command[commandSize] = 0;
if (strlen(valueData) > strlen("updater:") && strncmp(valueData, "updater:", strlen("updater:")) == 0) {
const char *p = valueData + strlen("updater:");
if (snprintf_s(msg.update, MAX_UPDATE_SIZE, MAX_UPDATE_SIZE - 1, "%s", p) == -1) {
INIT_LOGE("DoReboot updater: RBMiscWriteUpdaterMessage error");
return;
}
msg.update[MAX_UPDATE_SIZE - 1] = 0;
ret = RBMiscWriteUpdaterMessage(miscFile, &msg);
if(true != ret) {
INIT_LOGE("DoReboot updater: RBMiscWriteUpdaterMessage error");
return;
}
ret = reboot(RB_AUTOBOOT);
if (ret != 0) {
INIT_LOGE("DoReboot updater: reboot(RB_AUTOBOOT) failed! syscall ret %d, err %d.", ret, errno);
}
return;
}
if (strlen(valueData) == strlen("updater") && strncmp(valueData, "updater", strlen("updater")) == 0) {
ret = RBMiscWriteUpdaterMessage(miscFile, &msg);
if(true != ret) {
INIT_LOGE("DoReboot updater RBMiscWriteUpdaterMessage error");
return;
}
ret = reboot(RB_AUTOBOOT);
if (ret != 0) {
INIT_LOGE("DoReboot updater reboot(RB_AUTOBOOT) failed! syscall ret %d, err %d.", ret, errno);
}
return;
}
if (strlen(valueData) == strlen("NoArgument") && strncmp(valueData, "NoArgument", strlen("NoArgument")) == 0) {
ret = reboot(RB_AUTOBOOT);
if (ret != 0) {
INIT_LOGE("DoReboot updater: reboot(RB_AUTOBOOT) failed! syscall ret %d, err %d.", ret, errno);
}
return;
} }
INIT_LOGE("DoReboot value = %s, error.", value);
return; return;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册