提交 3fb12c30 编写于 作者: X xionglei6

add: 添加suspend支持

Signed-off-by: Nxionglei6 <xionglei6@huawei.com>
上级 dd66b3ad
......@@ -190,13 +190,14 @@ Fstab *ReadFstabFromFile(const char *file, bool procMounts)
ssize_t readn = 0;
Fstab *fstab = NULL;
FILE *fp = NULL;
char *realPath = GetRealPath(file);
if (realPath == NULL) {
BEGET_LOGE("Invalid file");
return NULL;
if (realPath != NULL) {
fp = fopen(realPath, "r");
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) {
BEGET_LOGE("Open %s failed, err = %d", file, errno);
return NULL;
......
......@@ -301,12 +301,19 @@ if (defined(ohos_lite)) {
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") {
deps = [
":boot.group",
":charing.group",
":group",
":init.cfg",
":init.reboot",
":init.usb.cfg",
":init.usb.configfs.cfg",
":ohos.para",
......
......@@ -29,6 +29,7 @@ static int main_cmd(BShellHandle shell, int argc, char* argv[])
if (argc == REBOOT_CMD_NUMBER && strcmp(argv[1], "shutdown") != 0 &&
strcmp(argv[1], "updater") != 0 &&
strcmp(argv[1], "suspend") != 0 &&
strcmp(argv[1], "flashd") != 0 &&
#ifdef INIT_TEST
strcmp(argv[1], "charing") != 0 &&
......@@ -63,6 +64,7 @@ MODULE_CONSTRUCTOR(void)
CmdInfo infos[] = {
{"reboot", main_cmd, "reboot system", "reboot", ""},
{"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[:options]", ""},
{"reboot", main_cmd, "reboot and boot into flashd", "reboot flashd", ""},
......
......@@ -64,6 +64,9 @@ int main(int argc, char *argv[])
number = argc - 1;
args = argv + 1;
}
if (number >= 1 && strcmp(args[0], "devctl") == 0) {
memcpy_s(args[0], strlen(args[0]), "reboot", strlen("reboot"));
}
SetInitLogLevel(0);
BShellParamCmdRegister(g_handle, 0);
#ifdef INIT_TEST
......
......@@ -428,15 +428,6 @@
"chmod 0773 /data/misc/trace",
"chmod 0775 /data/misc/wmtrace"
]
}, {
"name" : "reboot",
"cmds" : [
"stopAllServices ",
"sync ",
"umount /vendor",
"umount /data MNT_FORCE",
"sync "
]
}
],
"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" {
#define SERVICE_ATTR_DYNAMIC 0x100 // dynamic service
#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_NEEDWAIT 0x800 // Mark a service will be started by timer
#define MAX_SERVICE_NAME 32
#define MAX_APL_NAME 32
......
......@@ -961,7 +961,7 @@ void StopAllServices(int flags, const char **exclude, int size,
int (*filter)(const Service *service, const char **exclude, int size))
{
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);
}
......@@ -977,7 +977,7 @@ void StopAllServices(int flags, const char **exclude, int size,
node = GetNextGroupNode(NODE_TYPE_SERVICES, node);
continue;
}
service->attribute |= flags;
service->attribute |= (flags & SERVICE_ATTR_INVALID);
int ret = ServiceStop(service);
if (ret != SERVICE_SUCCESS) {
INIT_LOGE("Service %s stop failed!", service->name);
......
......@@ -304,7 +304,13 @@ static int FilterService(const Service *service, const char **exclude, int size)
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;
}
......
......@@ -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);
}
ret = -1;
if (RBMiscWriteUpdaterMessage(miscFile, &msg) == 0) {
ret = 0;
#ifndef STARTUP_INIT_TEST
ret = reboot(RB_AUTOBOOT);
#endif
return 0;
}
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
DoJobNow("reboot");
#ifndef PRODUCT_RK
return CheckAndRebootToUpdater(NULL, "reboot", NULL, NULL);
#else
reboot(RB_AUTOBOOT);
return 0;
int ret = CheckAndRebootToUpdater(NULL, "reboot", NULL, NULL);
if (ret == 0) {
#ifndef STARTUP_INIT_TEST
return reboot(RB_AUTOBOOT);
#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
DoJobNow("reboot");
int ret = CheckAndRebootToUpdater(NULL, "reboot", NULL, NULL);
if (ret == 0) {
#ifndef STARTUP_INIT_TEST
return reboot(RB_POWER_OFF);
#else
return 0;
return reboot(RB_POWER_OFF);
#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
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
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
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");
return 0;
}
#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
DoJobNow("suspend");
int ret = CheckAndRebootToUpdater(NULL, "reboot", NULL, NULL);
if (ret == 0) {
#ifndef STARTUP_INIT_TEST
return reboot(RB_POWER_OFF);
#else
return 0;
INIT_LOGE("DoSuspendCmd %s RB_SW_SUSPEND.", cmd);
return reboot(RB_SW_SUSPEND);
#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;
#endif
}
#ifdef INIT_TEST
int DoCharingCmd()
static int DoCharingCmd()
{
// by job to stop service and unmount
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
......@@ -230,7 +239,6 @@ struct {
{ "loader", DoLoaderCmd },
#endif
{ "suspend", DoSuspendCmd },
{ "freeze", DoFreezeCmd },
#ifdef INIT_TEST
{ "charing", DoCharingCmd }
#endif
......@@ -249,14 +257,14 @@ void ExecReboot(const char *value)
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++) {
if (strncmp(cmd, g_rebootCmd[i].cmdName, strlen(g_rebootCmd[i].cmdName)) == 0) {
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;
}
}
INIT_LOGE("Invalid rebot cmd %s.", value);
INIT_LOGE("Invalid reboot cmd %s.", value);
return;
}
......@@ -17,6 +17,7 @@
#include "init_adapter.h"
#include "init_log.h"
#include "init_param.h"
#include "init_service_manager.h"
#include "loop_event.h"
......@@ -48,7 +49,9 @@ static void ProcessSignal(const struct signalfd_siginfo *siginfo)
}
case SIGTERM: {
INIT_LOGI("SigHandler, SIGTERM received.");
StopAllServices(0, NULL, 0, NULL);
SystemWriteParam("startup.device.ctl", "stop");
// exec reboot use toybox reboot cmd
ExecReboot("reboot");
break;
}
default:
......
......@@ -168,8 +168,9 @@ int GetProcCmdlineValue(const char *name, const char *buffer, char *value, int l
endIndex = i;
break;
}
if (*tmp == ' ') {
if (*tmp == ' ' || *tmp == '\n' || *tmp == '\r' || *tmp == '\t') {
endIndex = i;
break;
}
if (*tmp == '=') {
if (endIndex != 0) { // for root=uuid=xxxx
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册