提交 8cb57654 编写于 作者: M Mupceet

init: add dump service

Signed-off-by: NMupceet <laiguizhong@huawei.com>
上级 9c0259f6
...@@ -61,6 +61,7 @@ if (defined(ohos_lite)) { ...@@ -61,6 +61,7 @@ if (defined(ohos_lite)) {
ohos_executable("begetctl") { ohos_executable("begetctl") {
sources = [ sources = [
"bootchart_cmd.c", "bootchart_cmd.c",
"dump_service.c",
"init_cmd_reboot.c", "init_cmd_reboot.c",
"main.c", "main.c",
"misc_daemon.cpp", "misc_daemon.cpp",
......
/*
* Copyright (c) 2022 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 <errno.h>
#include <stdio.h>
#include <string.h>
#include "begetctl.h"
#include "control_fd.h"
#include "init_utils.h"
#define DUMP_SERVICE_INFO_CMD_ARGS 2
static int main_cmd(BShellHandle shell, int argc, char **argv)
{
if (argc != DUMP_SERVICE_INFO_CMD_ARGS) {
BShellCmdHelp(shell, argc, argv);
return 0;
}
if (strcmp(argv[0], "dump_service") == 0) {
printf("dump service info \n");
CmdClientInit(INIT_CONTROL_FD_SOCKET_PATH, ACTION_DUMP, argv[1], "FIFO");
} else {
BShellCmdHelp(shell, argc, argv);
}
return 0;
}
MODULE_CONSTRUCTOR(void)
{
CmdInfo infos[] = {
{"dump_service", main_cmd, "dump one service info by serviceName", "dump_service serviceName", NULL},
{"dump_service", main_cmd, "dump all services info", "dump_service all", NULL},
};
for (size_t i = 0; i < sizeof(infos) / sizeof(infos[0]); i++) {
BShellEnvRegitsterCmd(GetShellHandle(), &infos[i]);
}
}
...@@ -46,40 +46,40 @@ static const int CRITICAL_CONFIG_ARRAY_LEN = 3; ...@@ -46,40 +46,40 @@ static const int CRITICAL_CONFIG_ARRAY_LEN = 3;
#ifdef OHOS_SERVICE_DUMP #ifdef OHOS_SERVICE_DUMP
static void DumpServiceArgs(const char *info, const ServiceArgs *args) static void DumpServiceArgs(const char *info, const ServiceArgs *args)
{ {
printf("\tservice %s count %d", info, args->count); printf("\tservice %s count %d \n", info, args->count);
for (int j = 0; j < args->count; j++) { for (int j = 0; j < args->count; j++) {
if (args->argv[j] != NULL) { if (args->argv[j] != NULL) {
printf("\t\tinfo [%d] %s", j, args->argv[j]); printf("\t\tinfo [%d] %s \n", j, args->argv[j]);
} }
} }
} }
static void DumpServiceJobs(const Service *service) static void DumpServiceJobs(const Service *service)
{ {
printf("\tservice job info"); printf("\tservice job info \n");
if (service->serviceJobs.jobsName[JOB_ON_BOOT] != NULL) { if (service->serviceJobs.jobsName[JOB_ON_BOOT] != NULL) {
printf("\t\tservice boot job %s", service->serviceJobs.jobsName[JOB_ON_BOOT]); printf("\t\tservice boot job %s \n", service->serviceJobs.jobsName[JOB_ON_BOOT]);
} }
if (service->serviceJobs.jobsName[JOB_ON_START] != NULL) { if (service->serviceJobs.jobsName[JOB_ON_START] != NULL) {
printf("\t\tservice start job %s", service->serviceJobs.jobsName[JOB_ON_START]); printf("\t\tservice start job %s \n", service->serviceJobs.jobsName[JOB_ON_START]);
} }
if (service->serviceJobs.jobsName[JOB_ON_STOP] != NULL) { if (service->serviceJobs.jobsName[JOB_ON_STOP] != NULL) {
printf("\t\tservice stop job %s", service->serviceJobs.jobsName[JOB_ON_STOP]); printf("\t\tservice stop job %s \n", service->serviceJobs.jobsName[JOB_ON_STOP]);
} }
if (service->serviceJobs.jobsName[JOB_ON_RESTART] != NULL) { if (service->serviceJobs.jobsName[JOB_ON_RESTART] != NULL) {
printf("\t\tservice restart job %s", service->serviceJobs.jobsName[JOB_ON_RESTART]); printf("\t\tservice restart job %s \n", service->serviceJobs.jobsName[JOB_ON_RESTART]);
} }
} }
static void DumpServiceSocket(const Service *service) static void DumpServiceSocket(const Service *service)
{ {
printf("\tservice socket info"); printf("\tservice socket info \n");
ServiceSocket *sockopt = service->socketCfg; ServiceSocket *sockopt = service->socketCfg;
while (sockopt != NULL) { while (sockopt != NULL) {
printf("\t\tsocket name: %s", sockopt->name); printf("\t\tsocket name: %s \n", sockopt->name);
printf("\t\tsocket type: %d", sockopt->type); printf("\t\tsocket type: %d \n", sockopt->type);
printf("\t\tsocket uid: %d", sockopt->uid); printf("\t\tsocket uid: %d \n", sockopt->uid);
printf("\t\tsocket gid: %d", sockopt->gid); printf("\t\tsocket gid: %d \n", sockopt->gid);
sockopt = sockopt->next; sockopt = sockopt->next;
} }
} }
...@@ -93,33 +93,33 @@ void DumpOneService(const Service *service) ...@@ -93,33 +93,33 @@ void DumpOneService(const Service *service)
}; };
int size = 0; int size = 0;
const InitArgInfo *statusMap = GetServieStatusMap(&size); const InitArgInfo *statusMap = GetServieStatusMap(&size);
printf("\tservice name: [%s]", service->name); printf("\tservice name: [%s] \n", service->name);
printf("\tservice pid: [%d]", service->pid); printf("\tservice pid: [%d] \n", service->pid);
printf("\tservice crashCnt: [%d]", service->crashCnt); printf("\tservice crashCnt: [%d] \n", service->crashCnt);
printf("\tservice attribute: [%d]", service->attribute); printf("\tservice attribute: [%d] \n", service->attribute);
printf("\tservice importance: [%d]", service->importance); printf("\tservice importance: [%d] \n", service->importance);
printf("\tservice startMode: [%s]", startModeMap[service->status].name); printf("\tservice startMode: [%s] \n", startModeMap[service->status].name);
printf("\tservice status: [%s]", statusMap[service->status].name); printf("\tservice status: [%s] \n", statusMap[service->status].name);
printf("\tservice perms uID [%d]", service->servPerm.uID); printf("\tservice perms uID [%d] \n", service->servPerm.uID);
DumpServiceArgs("path arg", &service->pathArgs); DumpServiceArgs("path arg", &service->pathArgs);
DumpServiceArgs("writepid file", &service->writePidArgs); DumpServiceArgs("writepid file", &service->writePidArgs);
DumpServiceJobs(service); DumpServiceJobs(service);
DumpServiceSocket(service); DumpServiceSocket(service);
printf("\tservice perms groupId %d", service->servPerm.gIDCnt); printf("\tservice perms groupId %d \n", service->servPerm.gIDCnt);
for (int i = 0; i < service->servPerm.gIDCnt; i++) { for (int i = 0; i < service->servPerm.gIDCnt; i++) {
printf("\t\tservice perms groupId %d", service->servPerm.gIDArray[i]); printf("\t\tservice perms groupId %d \n", service->servPerm.gIDArray[i]);
} }
printf("\tservice perms capability %d", service->servPerm.capsCnt); printf("\tservice perms capability %d \n", service->servPerm.capsCnt);
for (int i = 0; i < (int)service->servPerm.capsCnt; i++) { for (int i = 0; i < (int)service->servPerm.capsCnt; i++) {
printf("\t\tservice perms capability %d", service->servPerm.caps[i]); printf("\t\tservice perms capability %d \n", service->servPerm.caps[i]);
} }
} }
void DumpAllServices() void DumpAllServices()
{ {
printf("Ready to dump all services:"); printf("Ready to dump all services: \n");
printf("total service number: %d", g_serviceSpace.serviceCount); printf("total service number: %d \n", g_serviceSpace.serviceCount);
InitGroupNode *node = GetNextGroupNode(NODE_TYPE_SERVICES, NULL); InitGroupNode *node = GetNextGroupNode(NODE_TYPE_SERVICES, NULL);
while (node != NULL) { while (node != NULL) {
if (node->data.service == NULL) { if (node->data.service == NULL) {
...@@ -130,7 +130,7 @@ void DumpAllServices() ...@@ -130,7 +130,7 @@ void DumpAllServices()
DumpOneService(service); DumpOneService(service);
node = GetNextGroupNode(NODE_TYPE_SERVICES, node); node = GetNextGroupNode(NODE_TYPE_SERVICES, node);
} }
printf("Dump all services finished"); printf("Dump all services finished \n");
} }
#endif #endif
......
...@@ -65,11 +65,6 @@ void SystemConfig(void) ...@@ -65,11 +65,6 @@ void SystemConfig(void)
// read config // read config
ReadConfig(); ReadConfig();
// dump config
#ifdef OHOS_SERVICE_DUMP
DumpAllServices();
#endif
// execute init // execute init
DoJob("pre-init"); DoJob("pre-init");
#ifndef __LINUX__ #ifndef __LINUX__
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册