提交 df51f3bd 编写于 作者: O openharmony_ci 提交者: Gitee

!186 init部件相关命令合并到begetctl中

Merge pull request !186 from handy/120720
......@@ -6,7 +6,7 @@
"//base/startup/init_lite/services:startup_init",
"//base/startup/init_lite/ueventd:startup_ueventd",
"//base/startup/init_lite/watchdog:watchdog",
"//base/startup/init_lite/services/cmds/misc:misc_daemon"
"//base/startup/init_lite/services/begetctl:begetctl"
],
"test_list": [
"//base/startup/init_lite/test/unittest:init_test"
......
......@@ -173,9 +173,6 @@ if (defined(ohos_lite)) {
"//base/startup/init_lite/interfaces/innerkits/fs_manager:libfsmanager_shared",
"//base/startup/init_lite/interfaces/innerkits/reboot:libreboot",
"//base/startup/init_lite/interfaces/innerkits/socket:libsocket",
"//base/startup/init_lite/services/cmds/reboot:reboot",
"//base/startup/init_lite/services/cmds/service_control:service_control",
"//base/startup/init_lite/services/param:param",
"//base/startup/init_lite/services/param:param_client",
"//base/startup/init_lite/services/param:param_service",
"//base/startup/init_lite/services/param:param_watcher",
......
......@@ -13,18 +13,53 @@
import("//build/ohos.gni")
ohos_executable("misc_daemon") {
sources = [ "misc_daemon.cpp" ]
ohos_executable("begetctl") {
sources = [
"main.c",
"misc_daemon.cpp",
"init_cmd_reboot.c",
"service_control.c",
"param_cmd.c"
]
defines = [ "INIT_AGENT" ]
include_dirs = [
"//base/update/updater/interfaces/kits/include/misc_info",
"//base/startup/init_lite/services/include",
"//base/startup/init_lite/services/log",
"//base/startup/init_lite/interfaces/innerkits/include",
"//base/update/updater/interfaces/kits/include/misc_info",
"//base/startup/syspara_lite/interfaces/innerkits/native/syspara/include",
"//base/startup/init_lite/services/include/param/",
"//base/startup/init_lite/services/param/include",
"//third_party/bounds_checking_function/include",
"//base/update/updateservice/interfaces/innerkits/include",
]
deps = [
"//base/startup/init_lite/interfaces/innerkits/fs_manager:libfsmanager_shared",
"//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara",
"//base/startup/init_lite/interfaces/innerkits/reboot:libreboot_static",
"//base/startup/init_lite/services/log:agent_log",
"//base/startup/init_lite/services/param:param_client",
"//third_party/bounds_checking_function:libsec_static",
]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
symlink_target_name = [
"misc_daemon",
"reboot",
"devctl",
"service",
"service_control",
"start_service",
"stop_service",
"service",
"param"
]
install_images = [ "system" ]
install_enable = true
part_name = "init"
}
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __BEGETCTL_CMD_H
#define __BEGETCTL_CMD_H
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif
typedef int (*BegetCtlCmdPtr)(int argc, char **argv);
int BegetCtlCmdAdd(const char *name, BegetCtlCmdPtr cmd);
#define MODULE_CONSTRUCTOR() static void _init(void) __attribute__((constructor)); static void _init(void)
#define MODULE_DESTRUCTOR() static void _destroy(void) __attribute__((destructor)); static void _destroy(void)
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif
#endif // INIT_UTILS_H
......@@ -17,6 +17,7 @@
#include <string.h>
#include <unistd.h>
#include "init_reboot.h"
#include "begetctl.h"
#define REBOOT_CMD_NUMBER 2
#define USAGE_INFO "usage: reboot shutdown\n"\
......@@ -27,7 +28,7 @@
" reboot loader\n" \
" reboot\n"
int main(int argc, char* argv[])
static int main_cmd(int argc, char* argv[])
{
if (argc > REBOOT_CMD_NUMBER) {
printf("%s", USAGE_INFO);
......@@ -60,3 +61,8 @@ int main(int argc, char* argv[])
return 0;
}
MODULE_CONSTRUCTOR()
{
(void)BegetCtlCmdAdd("reboot", main_cmd);
(void)BegetCtlCmdAdd("devctl", main_cmd);
}
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "begetctl.h"
struct CMD_LIST_ST {
struct CMD_LIST_ST *next;
const char *name;
BegetCtlCmdPtr cmd;
};
static struct CMD_LIST_ST *m_cmdList = NULL;
int BegetCtlCmdAdd(const char *name, BegetCtlCmdPtr cmd)
{
struct CMD_LIST_ST *item;
if (name == NULL) {
return -1;
}
item = (struct CMD_LIST_ST *)malloc(sizeof(struct CMD_LIST_ST));
if (item == NULL) {
return -1;
}
item->name = strdup(name);
if (item->name == NULL) {
free((void *)item);
return -1;
}
item->cmd = cmd;
item->next = m_cmdList;
m_cmdList = item;
return 0;
}
static const struct CMD_LIST_ST *BegetCtlCmdFind(const char *name)
{
const struct CMD_LIST_ST *item = m_cmdList;
while (item != NULL) {
if (strcmp(item->name, name) == 0) {
return item;
}
item = item->next;
}
return NULL;
}
static void BegetCtlUsage(const char *command)
{
const struct CMD_LIST_ST *item = m_cmdList;
int notFirst = 0;
while (item != NULL) {
if (notFirst) {
printf(" ");
}
notFirst = 1;
printf("%s", item->name);
item = item->next;
}
printf("\n");
}
int main(int argc, char **argv)
{
const struct CMD_LIST_ST *cmd;
const char *last = strrchr(argv[0], '/');
// Get the first ending command name
if (last != NULL) {
last = last + 1;
} else {
last = argv[0];
}
// If it is begetctl with subcommand name, try to do subcommand first
if ((argc > 1) && (strcmp(last, "begetctl") == 0)) {
argc = argc - 1;
argv = argv + 1;
last = argv[0];
}
// Match the command
cmd = BegetCtlCmdFind(last);
if (cmd == NULL) {
BegetCtlUsage(last);
return 0;
}
// Do command
return cmd->cmd(argc, argv);
}
......@@ -23,6 +23,7 @@
#include "fs_manager/fs_manager.h"
#include "misc_info.h"
#include "param_wrapper.h"
#include "begetctl.h"
constexpr int PARTITION_INFO_POS = 1144;
constexpr int PARTITION_INFO_MAX_LENGTH = 256;
......@@ -218,7 +219,7 @@ static void WriteLogoToMisc(const std::string &logoPath)
close(fd1);
}
int main(int argc, char **argv)
static int main_cmd(int argc, char **argv)
{
int rc = -1;
int optIndex = -1;
......@@ -240,4 +241,10 @@ int main(int argc, char **argv)
break;
}
}
return 0;
}
MODULE_CONSTRUCTOR()
{
(void)BegetCtlCmdAdd("misc_daemon", main_cmd);
}
......@@ -19,6 +19,7 @@
#include "param_manager.h"
#include "param_utils.h"
#include "sys_param.h"
#include "begetctl.h"
#define USAGE_INFO_PARAM_GET "param get [key]"
#define USAGE_INFO_PARAM_SET "param set key value"
......@@ -185,8 +186,13 @@ int RunParamCommand(int argc, char *argv[])
}
#ifndef STARTUP_INIT_TEST
int main(int argc, char *argv[])
static int main_cmd(int argc, char *argv[])
{
return RunParamCommand(argc, argv);
}
MODULE_CONSTRUCTOR()
{
(void)BegetCtlCmdAdd("param", main_cmd);
}
#endif
......@@ -17,6 +17,7 @@
#include <stdio.h>
#include "securec.h"
#include "sys_param.h"
#include "begetctl.h"
#define SERVICE_START_NUMBER 2
#define SERVICE_CONTROL_NUMBER 3
......@@ -61,7 +62,7 @@ static void ServiceControl(int argc, char** argv)
return;
}
int main(int argc, char** argv)
static int main_cmd(int argc, char** argv)
{
if (argc != SERVICE_START_NUMBER && argc != SERVICE_CONTROL_NUMBER) {
ServiceControlUsage();
......@@ -90,3 +91,11 @@ int main(int argc, char** argv)
}
return 0;
}
MODULE_CONSTRUCTOR()
{
(void)BegetCtlCmdAdd("service", main_cmd);
(void)BegetCtlCmdAdd("service_control", main_cmd);
(void)BegetCtlCmdAdd("start_service", main_cmd);
(void)BegetCtlCmdAdd("stop_service", main_cmd);
}
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/ohos.gni")
ohos_executable("reboot") {
sources = [ "init_cmd_reboot.c" ]
include_dirs = [
"//base/startup/init_lite/interfaces/innerkits/include",
"//base/startup/init_lite/services/include/param/",
"//third_party/bounds_checking_function/include",
]
deps = [
"//base/startup/init_lite/interfaces/innerkits/reboot:libreboot_static",
]
install_enable = true
part_name = "init"
}
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/ohos.gni")
ohos_executable("service_control") {
sources = [ "service_control.c" ]
include_dirs = [
"//base/startup/init_lite/services/include/param",
"//base/startup/init_lite/services/include",
]
deps = [
"//base/startup/init_lite/services/param:param_client",
"//third_party/bounds_checking_function:libsec_static",
]
symlink_target_name = [
"start_service",
"stop_service",
]
install_images = [ "system" ]
install_enable = true
part_name = "init"
}
......@@ -206,36 +206,3 @@ ohos_shared_library("param_watcher") {
install_images = [ "system" ]
part_name = "init"
}
ohos_executable("param") {
sources = [ "cmd/param_cmd.c" ]
include_dirs = [
"include",
"//base/startup/init_lite/services/include/param",
"//base/startup/init_lite/services/include",
"//base/startup/init_lite/services/log",
"//base/update/updateservice/interfaces/innerkits/include",
]
defines = [ "INIT_AGENT" ]
deps = [
"//base/startup/init_lite/services/log:agent_log",
"//base/startup/init_lite/services/param:param_client",
"//third_party/bounds_checking_function:libsec_static",
]
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
if (param_test == "true") {
defines += [ "PARAM_TEST" ]
deps += [ "//base/startup/init_lite/services/param:param_watcheragent" ]
} else {
install_images = [
"system",
"updater",
]
}
install_enable = true
part_name = "init"
}
......@@ -39,6 +39,7 @@ ohos_unittest("init_ut") {
"//base/startup/init_lite/interfaces/innerkits/fs_manager/fstab_mount.c",
"//base/startup/init_lite/interfaces/innerkits/reboot/init_reboot_innerkits.c",
"//base/startup/init_lite/interfaces/innerkits/socket/init_socket.c",
"//base/startup/init_lite/services/begetctl/param_cmd.c",
"//base/startup/init_lite/services/init/adapter/init_adapter.c",
"//base/startup/init_lite/services/init/init_capability.c",
"//base/startup/init_lite/services/init/init_common_cmds.c",
......@@ -61,7 +62,6 @@ ohos_unittest("init_ut") {
"//base/startup/init_lite/services/param/adapter/param_persistadp.c",
"//base/startup/init_lite/services/param/adapter/param_selinux.c",
"//base/startup/init_lite/services/param/client/param_request.c",
"//base/startup/init_lite/services/param/cmd/param_cmd.c",
"//base/startup/init_lite/services/param/manager/param_manager.c",
"//base/startup/init_lite/services/param/manager/param_message.c",
"//base/startup/init_lite/services/param/manager/param_trie.c",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册