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

!368 add: 添加suspend支持

Merge pull request !368 from 熊磊/init0303xytsuspend
...@@ -190,13 +190,14 @@ Fstab *ReadFstabFromFile(const char *file, bool procMounts) ...@@ -190,13 +190,14 @@ Fstab *ReadFstabFromFile(const char *file, bool procMounts)
ssize_t readn = 0; ssize_t readn = 0;
Fstab *fstab = NULL; Fstab *fstab = NULL;
FILE *fp = NULL;
char *realPath = GetRealPath(file); char *realPath = GetRealPath(file);
if (realPath == NULL) { if (realPath != NULL) {
BEGET_LOGE("Invalid file"); fp = fopen(realPath, "r");
return NULL; free(realPath);
} else {
fp = fopen(file, "r"); // no file system, can not get real path
} }
FILE *fp = fopen(realPath, "r");
free(realPath);
if (fp == NULL) { if (fp == NULL) {
BEGET_LOGE("Open %s failed, err = %d", file, errno); BEGET_LOGE("Open %s failed, err = %d", file, errno);
return NULL; return NULL;
......
...@@ -50,10 +50,10 @@ int DoReboot(const char *option) ...@@ -50,10 +50,10 @@ int DoReboot(const char *option)
BEGET_ERROR_CHECK(ret >= 0, return -1, "Failed to copy boot option \" %s \"", option); BEGET_ERROR_CHECK(ret >= 0, return -1, "Failed to copy boot option \" %s \"", option);
if (strcmp(option, DEVICE_CMD_SUSPEND) == 0) { if (strcmp(option, DEVICE_CMD_SUSPEND) == 0) {
ret = SystemSetParameter(STARTUP_DEVICE_CTL, DEVICE_CMD_SUSPEND); ret = SystemSetParameter(STARTUP_DEVICE_CTL, DEVICE_CMD_STOP);
BEGET_ERROR_CHECK(ret == 0, return -1, "Failed to set stop param"); BEGET_ERROR_CHECK(ret == 0, return -1, "Failed to set stop param");
} else if (strcmp(option, DEVICE_CMD_FREEZE) == 0) { } else if (strcmp(option, DEVICE_CMD_FREEZE) == 0) {
ret = SystemSetParameter(STARTUP_DEVICE_CTL, DEVICE_CMD_FREEZE); ret = SystemSetParameter(STARTUP_DEVICE_CTL, DEVICE_CMD_STOP);
BEGET_ERROR_CHECK(ret == 0, return -1, "Failed to set stop param"); BEGET_ERROR_CHECK(ret == 0, return -1, "Failed to set stop param");
} else { } else {
ret = SystemSetParameter(STARTUP_DEVICE_CTL, DEVICE_CMD_STOP); ret = SystemSetParameter(STARTUP_DEVICE_CTL, DEVICE_CMD_STOP);
......
...@@ -301,12 +301,19 @@ if (defined(ohos_lite)) { ...@@ -301,12 +301,19 @@ if (defined(ohos_lite)) {
part_name = "init" part_name = "init"
} }
ohos_prebuilt_etc("init.reboot") {
source = "//base/startup/init_lite/services/etc/init.reboot.cfg"
part_name = "init"
module_install_dir = "etc/init"
}
group("init_etc") { group("init_etc") {
deps = [ deps = [
":boot.group", ":boot.group",
":charing.group", ":charing.group",
":group", ":group",
":init.cfg", ":init.cfg",
":init.reboot",
":init.usb.cfg", ":init.usb.cfg",
":init.usb.configfs.cfg", ":init.usb.configfs.cfg",
":ohos.para", ":ohos.para",
......
...@@ -29,6 +29,7 @@ static int main_cmd(BShellHandle shell, int argc, char* argv[]) ...@@ -29,6 +29,7 @@ static int main_cmd(BShellHandle shell, int argc, char* argv[])
if (argc == REBOOT_CMD_NUMBER && strcmp(argv[1], "shutdown") != 0 && if (argc == REBOOT_CMD_NUMBER && strcmp(argv[1], "shutdown") != 0 &&
strcmp(argv[1], "updater") != 0 && strcmp(argv[1], "updater") != 0 &&
strcmp(argv[1], "suspend") != 0 &&
strcmp(argv[1], "flashd") != 0 && strcmp(argv[1], "flashd") != 0 &&
#ifdef INIT_TEST #ifdef INIT_TEST
strcmp(argv[1], "charing") != 0 && strcmp(argv[1], "charing") != 0 &&
...@@ -63,6 +64,7 @@ MODULE_CONSTRUCTOR(void) ...@@ -63,6 +64,7 @@ MODULE_CONSTRUCTOR(void)
CmdInfo infos[] = { CmdInfo infos[] = {
{"reboot", main_cmd, "reboot system", "reboot", ""}, {"reboot", main_cmd, "reboot system", "reboot", ""},
{"reboot", main_cmd, "shutdown system", "reboot shutdown", ""}, {"reboot", main_cmd, "shutdown system", "reboot shutdown", ""},
{"reboot", main_cmd, "suspend system", "reboot suspend", ""},
{"reboot", main_cmd, "reboot and boot into updater", "reboot updater", ""}, {"reboot", main_cmd, "reboot and boot into updater", "reboot updater", ""},
{"reboot", main_cmd, "reboot and boot into updater", "reboot updater[:options]", ""}, {"reboot", main_cmd, "reboot and boot into updater", "reboot updater[:options]", ""},
{"reboot", main_cmd, "reboot and boot into flashd", "reboot flashd", ""}, {"reboot", main_cmd, "reboot and boot into flashd", "reboot flashd", ""},
......
...@@ -64,6 +64,9 @@ int main(int argc, char *argv[]) ...@@ -64,6 +64,9 @@ int main(int argc, char *argv[])
number = argc - 1; number = argc - 1;
args = argv + 1; args = argv + 1;
} }
if (number >= 1 && strcmp(args[0], "devctl") == 0) {
(void)memcpy_s(args[0], strlen(args[0]), "reboot", strlen("reboot"));
}
SetInitLogLevel(0); SetInitLogLevel(0);
BShellParamCmdRegister(g_handle, 0); BShellParamCmdRegister(g_handle, 0);
#ifdef INIT_TEST #ifdef INIT_TEST
......
...@@ -428,15 +428,6 @@ ...@@ -428,15 +428,6 @@
"chmod 0773 /data/misc/trace", "chmod 0773 /data/misc/trace",
"chmod 0775 /data/misc/wmtrace" "chmod 0775 /data/misc/wmtrace"
] ]
}, {
"name" : "reboot",
"cmds" : [
"stopAllServices ",
"sync ",
"umount /vendor",
"umount /data MNT_FORCE",
"sync "
]
} }
], ],
"services" : [{ "services" : [{
......
{
"jobs" : [{
"name" : "reboot",
"cmds" : [
"stopAllServices true",
"sync ",
"umount /vendor",
"umount /data MNT_FORCE",
"sync "
]
}, {
"name" : "suspend",
"cmds" : [
"stopAllServices false",
"sync ",
"umount /vendor",
"umount /data MNT_FORCE",
"sync "
]
}
],
"services" : []
}
...@@ -51,6 +51,7 @@ extern "C" { ...@@ -51,6 +51,7 @@ extern "C" {
#define SERVICE_ATTR_DYNAMIC 0x100 // dynamic service #define SERVICE_ATTR_DYNAMIC 0x100 // dynamic service
#define SERVICE_ATTR_ONDEMAND 0x200 // ondemand, manage socket by init #define SERVICE_ATTR_ONDEMAND 0x200 // ondemand, manage socket by init
#define SERVICE_ATTR_TIMERSTART 0x400 // Mark a service will be started by timer #define SERVICE_ATTR_TIMERSTART 0x400 // Mark a service will be started by timer
#define SERVICE_ATTR_NEEDWAIT 0x800 // Mark a service will be started by timer
#define MAX_SERVICE_NAME 32 #define MAX_SERVICE_NAME 32
#define MAX_APL_NAME 32 #define MAX_APL_NAME 32
......
...@@ -961,7 +961,7 @@ void StopAllServices(int flags, const char **exclude, int size, ...@@ -961,7 +961,7 @@ void StopAllServices(int flags, const char **exclude, int size,
int (*filter)(const Service *service, const char **exclude, int size)) int (*filter)(const Service *service, const char **exclude, int size))
{ {
Service *service = GetServiceByName("appspawn"); Service *service = GetServiceByName("appspawn");
if (service != NULL && service->pid != 0) { if (((SERVICE_ATTR_NEEDWAIT & flags) == SERVICE_ATTR_NEEDWAIT) && service != NULL && service->pid != 0) {
waitpid(service->pid, 0, 0); waitpid(service->pid, 0, 0);
} }
...@@ -977,7 +977,7 @@ void StopAllServices(int flags, const char **exclude, int size, ...@@ -977,7 +977,7 @@ void StopAllServices(int flags, const char **exclude, int size,
node = GetNextGroupNode(NODE_TYPE_SERVICES, node); node = GetNextGroupNode(NODE_TYPE_SERVICES, node);
continue; continue;
} }
service->attribute |= flags; service->attribute |= (flags & SERVICE_ATTR_INVALID);
int ret = ServiceStop(service); int ret = ServiceStop(service);
if (ret != SERVICE_SUCCESS) { if (ret != SERVICE_SUCCESS) {
INIT_LOGE("Service %s stop failed!", service->name); INIT_LOGE("Service %s stop failed!", service->name);
......
...@@ -319,7 +319,13 @@ static int FilterService(const Service *service, const char **exclude, int size) ...@@ -319,7 +319,13 @@ static int FilterService(const Service *service, const char **exclude, int size)
static void DoStopAllServices(const struct CmdArgs *ctx) static void DoStopAllServices(const struct CmdArgs *ctx)
{ {
StopAllServices(SERVICE_ATTR_INVALID, (const char **)ctx->argv, ctx->argc, FilterService); int flags = SERVICE_ATTR_INVALID;
if (ctx->argc >= 1 && strcmp(ctx->argv[0], "true") == 0) {
flags |= SERVICE_ATTR_NEEDWAIT;
StopAllServices(flags, (const char **)(&ctx->argv[1]), ctx->argc - 1, FilterService);
} else {
StopAllServices(flags, (const char **)ctx->argv, ctx->argc, FilterService);
}
return; return;
} }
......
...@@ -131,89 +131,98 @@ static int CheckAndRebootToUpdater(const char *valueData, const char *cmd, ...@@ -131,89 +131,98 @@ static int CheckAndRebootToUpdater(const char *valueData, const char *cmd,
INIT_ERROR_CHECK(ret == 0, return -1, "Failed to format update for %s.", cmd); INIT_ERROR_CHECK(ret == 0, return -1, "Failed to format update for %s.", cmd);
} }
ret = -1;
if (RBMiscWriteUpdaterMessage(miscFile, &msg) == 0) { if (RBMiscWriteUpdaterMessage(miscFile, &msg) == 0) {
ret = 0; return 0;
#ifndef STARTUP_INIT_TEST
ret = reboot(RB_AUTOBOOT);
#endif
} }
return ret; return -1;
} }
int DoRebootCmd(const char *cmd, const char *opt) static int DoRebootCmd(const char *cmd, const char *opt)
{ {
// by job to stop service and unmount // by job to stop service and unmount
DoJobNow("reboot"); DoJobNow("reboot");
#ifndef PRODUCT_RK int ret = CheckAndRebootToUpdater(NULL, "reboot", NULL, NULL);
return CheckAndRebootToUpdater(NULL, "reboot", NULL, NULL); if (ret == 0) {
#else #ifndef STARTUP_INIT_TEST
reboot(RB_AUTOBOOT); return reboot(RB_AUTOBOOT);
return 0;
#endif #endif
}
return 0;
} }
int DoShutdownCmd(const char *cmd, const char *opt) static int DoShutdownCmd(const char *cmd, const char *opt)
{ {
// by job to stop service and unmount // by job to stop service and unmount
DoJobNow("reboot"); DoJobNow("reboot");
int ret = CheckAndRebootToUpdater(NULL, "reboot", NULL, NULL);
if (ret == 0) {
#ifndef STARTUP_INIT_TEST #ifndef STARTUP_INIT_TEST
return reboot(RB_POWER_OFF); return reboot(RB_POWER_OFF);
#else
return 0;
#endif #endif
}
return 0;
} }
int DoUpdaterCmd(const char *cmd, const char *opt) static int DoUpdaterCmd(const char *cmd, const char *opt)
{ {
// by job to stop service and unmount // by job to stop service and unmount
DoJobNow("reboot"); DoJobNow("reboot");
return CheckAndRebootToUpdater(opt, "updater", "updater:", "boot_updater"); int ret = CheckAndRebootToUpdater(opt, "updater", "updater:", "boot_updater");
if (ret == 0) {
#ifndef STARTUP_INIT_TEST
return reboot(RB_AUTOBOOT);
#endif
}
return 0;
} }
int DoFlashdCmd(const char *cmd, const char *opt) static int DoFlashdCmd(const char *cmd, const char *opt)
{ {
// by job to stop service and unmount // by job to stop service and unmount
DoJobNow("reboot"); DoJobNow("reboot");
return CheckAndRebootToUpdater(opt, "flash", "flash:", "boot_flash"); int ret = CheckAndRebootToUpdater(opt, "flash", "flash:", "boot_flash");
if (ret == 0) {
#ifndef STARTUP_INIT_TEST
return reboot(RB_AUTOBOOT);
#endif
}
return 0;
} }
#ifdef PRODUCT_RK #ifdef PRODUCT_RK
int DoLoaderCmd(const char *cmd, const char *opt) static int DoLoaderCmd(const char *cmd, const char *opt)
{ {
syscall(__NR_reboot, REBOOT_MAGIC1, REBOOT_MAGIC2, REBOOT_CMD_RESTART2, "loader"); syscall(__NR_reboot, REBOOT_MAGIC1, REBOOT_MAGIC2, REBOOT_CMD_RESTART2, "loader");
return 0; return 0;
} }
#endif #endif
int DoSuspendCmd(const char *cmd, const char *opt) static int DoSuspendCmd(const char *cmd, const char *opt)
{ {
// by job to stop service and unmount // by job to stop service and unmount
DoJobNow("suspend"); DoJobNow("suspend");
int ret = CheckAndRebootToUpdater(NULL, "reboot", NULL, NULL);
if (ret == 0) {
#ifndef STARTUP_INIT_TEST #ifndef STARTUP_INIT_TEST
return reboot(RB_POWER_OFF); INIT_LOGE("DoSuspendCmd %s RB_SW_SUSPEND.", cmd);
#else return reboot(RB_AUTOBOOT);
return 0;
#endif #endif
} }
int DoFreezeCmd(const char *cmd, const char *opt)
{
// by job to stop service and unmount
DoJobNow("freeze");
#ifndef STARTUP_INIT_TEST
return reboot(RB_POWER_OFF);
#else
return 0; return 0;
#endif
} }
#ifdef INIT_TEST #ifdef INIT_TEST
int DoCharingCmd() static int DoCharingCmd()
{ {
// by job to stop service and unmount // by job to stop service and unmount
DoJobNow("reboot"); DoJobNow("reboot");
return CheckAndRebootToUpdater(NULL, "charing", "charing:", "boot_charing"); int ret = CheckAndRebootToUpdater(NULL, "charing", "charing:", "boot_charing");
if (ret == 0) {
#ifndef STARTUP_INIT_TEST
return reboot(RB_AUTOBOOT);
#endif
}
return 0;
} }
#endif #endif
...@@ -230,7 +239,6 @@ struct { ...@@ -230,7 +239,6 @@ struct {
{ "loader", DoLoaderCmd }, { "loader", DoLoaderCmd },
#endif #endif
{ "suspend", DoSuspendCmd }, { "suspend", DoSuspendCmd },
{ "freeze", DoFreezeCmd },
#ifdef INIT_TEST #ifdef INIT_TEST
{ "charing", DoCharingCmd } { "charing", DoCharingCmd }
#endif #endif
...@@ -249,14 +257,14 @@ void ExecReboot(const char *value) ...@@ -249,14 +257,14 @@ void ExecReboot(const char *value)
return; return;
} }
INIT_LOGE("ExecReboot %s.", cmd); INIT_LOGI("ExecReboot %s param %s.", cmd, value);
for (int i = 0; i < (int)ARRAY_LENGTH(g_rebootCmd); i++) { for (int i = 0; i < (int)ARRAY_LENGTH(g_rebootCmd); i++) {
if (strncmp(cmd, g_rebootCmd[i].cmdName, strlen(g_rebootCmd[i].cmdName)) == 0) { if (strncmp(cmd, g_rebootCmd[i].cmdName, strlen(g_rebootCmd[i].cmdName)) == 0) {
int ret = g_rebootCmd[i].doCmd(cmd, cmd); int ret = g_rebootCmd[i].doCmd(cmd, cmd);
INIT_LOGI("Reboot %s %s.", value, (ret == 0) ? "success" : "fail"); INIT_LOGI("Reboot %s %s errno %d .", cmd, (ret == 0) ? "success" : "fail", errno);
return; return;
} }
} }
INIT_LOGE("Invalid rebot cmd %s.", value); INIT_LOGE("Invalid reboot cmd %s.", value);
return; return;
} }
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "init_adapter.h" #include "init_adapter.h"
#include "init_log.h" #include "init_log.h"
#include "init_param.h"
#include "init_service_manager.h" #include "init_service_manager.h"
#include "loop_event.h" #include "loop_event.h"
...@@ -48,7 +49,9 @@ static void ProcessSignal(const struct signalfd_siginfo *siginfo) ...@@ -48,7 +49,9 @@ static void ProcessSignal(const struct signalfd_siginfo *siginfo)
} }
case SIGTERM: { case SIGTERM: {
INIT_LOGI("SigHandler, SIGTERM received."); INIT_LOGI("SigHandler, SIGTERM received.");
StopAllServices(0, NULL, 0, NULL); SystemWriteParam("startup.device.ctl", "stop");
// exec reboot use toybox reboot cmd
ExecReboot("reboot");
break; break;
} }
default: default:
......
...@@ -228,7 +228,7 @@ static int GetTriggerType(const char *type) ...@@ -228,7 +228,7 @@ static int GetTriggerType(const char *type)
} }
const char *triggerTypeStr[] = { const char *triggerTypeStr[] = {
"pre-init", "boot", "early-init", "init", "early-init", "late-init", "post-init", "pre-init", "boot", "early-init", "init", "early-init", "late-init", "post-init",
"fs", "early-fs", "post-fs", "late-fs", "early-boot", "post-fs-data", "reboot" "fs", "early-fs", "post-fs", "late-fs", "early-boot", "post-fs-data", "reboot", "suspend"
}; };
for (size_t i = 0; i < ARRAY_LENGTH(triggerTypeStr); i++) { for (size_t i = 0; i < ARRAY_LENGTH(triggerTypeStr); i++) {
if (strcmp(triggerTypeStr[i], type) == 0) { if (strcmp(triggerTypeStr[i], type) == 0) {
......
...@@ -168,8 +168,9 @@ int GetProcCmdlineValue(const char *name, const char *buffer, char *value, int l ...@@ -168,8 +168,9 @@ int GetProcCmdlineValue(const char *name, const char *buffer, char *value, int l
endIndex = i; endIndex = i;
break; break;
} }
if (*tmp == ' ') { if (*tmp == ' ' || *tmp == '\n' || *tmp == '\r' || *tmp == '\t') {
endIndex = i; endIndex = i;
break;
} }
if (*tmp == '=') { if (*tmp == '=') {
if (endIndex != 0) { // for root=uuid=xxxx if (endIndex != 0) { // for root=uuid=xxxx
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册