mirror of
https://gitee.com/openharmony/startup_init
synced 2024-11-24 00:30:12 +00:00
commit
42c1b440b5
@ -64,6 +64,7 @@ static int BootEventDisable(BShellHandle shell, int argc, char **argv)
|
||||
MODULE_CONSTRUCTOR(void)
|
||||
{
|
||||
const CmdInfo infos[] = {
|
||||
{"dump_service", main_cmd, "dump all loop info", "dump_service loop", NULL},
|
||||
{"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},
|
||||
{"dump_service", main_cmd, "dump parameter-service trigger",
|
||||
|
@ -94,6 +94,11 @@ ohos_executable("init") {
|
||||
"//base/startup/init/services/modules/reboot",
|
||||
"//base/startup/init/services/modules/init_context",
|
||||
"${FSCRYPT_PATH}/include/libfscrypt",
|
||||
"//base/startup/init/services/loopevent/task",
|
||||
"//base/startup/init/services/loopevent/loop",
|
||||
"//base/startup/init/services/loopevent/include",
|
||||
"//base/startup/init/interfaces/innerkits/include",
|
||||
"//base/startup/init/services/loopevent/utils",
|
||||
]
|
||||
|
||||
deps = [
|
||||
|
@ -28,6 +28,27 @@
|
||||
#include "init_param.h"
|
||||
#include "hookmgr.h"
|
||||
#include "bootstage.h"
|
||||
#include "le_task.h"
|
||||
#include "loop_event.h"
|
||||
#include "init_hashmap.h"
|
||||
#include "le_loop.h"
|
||||
|
||||
static void DumpLoopNodeInfo(const HashNode *node, const void *context)
|
||||
{
|
||||
INIT_CHECK(node != NULL, return);
|
||||
BaseTask *baseTask = HASHMAP_ENTRY(node, BaseTask, hashNode);
|
||||
INIT_CHECK(baseTask != NULL, return);
|
||||
const TaskHandle task = (void*)baseTask;
|
||||
if (baseTask->dumpTaskInfo != NULL) {
|
||||
baseTask->dumpTaskInfo(task);
|
||||
}
|
||||
}
|
||||
|
||||
static void DumpLoop()
|
||||
{
|
||||
printf(" Dump Loop Info:\n");
|
||||
OH_HashMapTraverse(((EventLoop *)LE_GetDefaultLoop())->taskMap, DumpLoopNodeInfo, NULL);
|
||||
}
|
||||
|
||||
static void DumpServiceArgs(const char *info, const ServiceArgs *args)
|
||||
{
|
||||
@ -114,6 +135,7 @@ static void DumpOneService(const Service *service)
|
||||
printf("\tservice startMode: [%s] \n", startModeMap[service->startMode].name);
|
||||
printf("\tservice status: [%s] \n", serviceStatusMap[service->status]);
|
||||
printf("\tservice perms uID [%u] \n", service->servPerm.uID);
|
||||
printf("\tservice Timer ID [%u] \n", LE_GetSocketFd(service->timer));
|
||||
DumpServiceArgs("path arg", &service->pathArgs);
|
||||
DumpServiceArgs("writepid file", &service->writePidArgs);
|
||||
DumpServiceJobs(service);
|
||||
@ -212,6 +234,10 @@ static void ProcessDumpServiceControlFd(uint16_t type, const char *serviceCmd)
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (strcmp(serviceCmd, "loop") == 0) {
|
||||
DumpLoop();
|
||||
return;
|
||||
}
|
||||
Service *service = GetServiceByName(serviceCmd);
|
||||
if (service != NULL) {
|
||||
if (cmd != NULL) {
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/signalfd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "le_loop.h"
|
||||
@ -47,6 +48,32 @@ static void HandleSignalTaskClose_(const LoopHandle loopHandle, const TaskHandle
|
||||
close(task->taskId.fd);
|
||||
}
|
||||
|
||||
static void PrintSigset(sigset_t mask)
|
||||
{
|
||||
int cnt = 0;
|
||||
for (int sig = 1; sig < NSIG; sig++) {
|
||||
if (sigismember(&mask, sig)) {
|
||||
cnt++;
|
||||
printf("\t %d(%s)\n", sig, strsignal(sig));
|
||||
}
|
||||
}
|
||||
if (cnt == 0) {
|
||||
printf("empty signal set\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void DumpSignalTaskInfo_(const TaskHandle task)
|
||||
{
|
||||
INIT_CHECK(task != NULL, return);
|
||||
BaseTask *baseTask = (BaseTask *)task;
|
||||
SignalTask *signalTask = (SignalTask *)baseTask;
|
||||
printf("\tfd: %d \n", signalTask->base.taskId.fd);
|
||||
printf("\t TaskType: %s \n", "SignalTask");
|
||||
printf("\t sigNumber: %d \n", signalTask->sigNumber);
|
||||
printf("\t signal: \n");
|
||||
PrintSigset(signalTask->mask);
|
||||
}
|
||||
|
||||
LE_STATUS LE_CreateSignalTask(const LoopHandle loopHandle, SignalHandle *signalHandle, LE_ProcessSignal processSignal)
|
||||
{
|
||||
LE_CHECK(loopHandle != NULL && signalHandle != NULL, return LE_INVALID_PARAM, "Invalid parameters");
|
||||
@ -60,6 +87,7 @@ LE_STATUS LE_CreateSignalTask(const LoopHandle loopHandle, SignalHandle *signalH
|
||||
LE_CHECK(task != NULL, return LE_NO_MEMORY, "Failed to create task");
|
||||
task->base.handleEvent = HandleSignalEvent_;
|
||||
task->base.innerClose = HandleSignalTaskClose_;
|
||||
task->base.dumpTaskInfo = DumpSignalTaskInfo_;
|
||||
task->sigNumber = 0;
|
||||
sigemptyset(&task->mask);
|
||||
task->processSignal = processSignal;
|
||||
|
@ -94,6 +94,15 @@ static void HandleAsyncTaskClose_(const LoopHandle loopHandle, const TaskHandle
|
||||
close(task->taskId.fd);
|
||||
}
|
||||
|
||||
static void DumpEventTaskInfo_(const TaskHandle task)
|
||||
{
|
||||
INIT_CHECK(task != NULL, return);
|
||||
BaseTask *baseTask = (BaseTask *)task;
|
||||
AsyncEventTask *eventTask = (AsyncEventTask *)baseTask;
|
||||
printf("\tfd: %d \n", eventTask->stream.base.taskId.fd);
|
||||
printf("\t TaskType: %s\n", "EventTask");
|
||||
}
|
||||
|
||||
LE_STATUS LE_CreateAsyncTask(const LoopHandle loopHandle,
|
||||
TaskHandle *taskHandle, LE_ProcessAsyncEvent processAsyncEvent)
|
||||
{
|
||||
@ -108,7 +117,7 @@ LE_STATUS LE_CreateAsyncTask(const LoopHandle loopHandle,
|
||||
return LE_NO_MEMORY, "Failed to create task");
|
||||
task->stream.base.handleEvent = HandleAsyncEvent_;
|
||||
task->stream.base.innerClose = HandleAsyncTaskClose_;
|
||||
|
||||
task->stream.base.dumpTaskInfo = DumpEventTaskInfo_;
|
||||
OH_ListInit(&task->stream.buffHead);
|
||||
LoopMutexInit(&task->stream.mutex);
|
||||
task->processAsyncEvent = processAsyncEvent;
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/socket.h>
|
||||
#include "securec.h"
|
||||
|
||||
#include "le_socket.h"
|
||||
#include "le_task.h"
|
||||
@ -136,6 +137,42 @@ static void HandleStreamTaskClose_(const LoopHandle loopHandle, const TaskHandle
|
||||
}
|
||||
}
|
||||
|
||||
static void DumpStreamServerTaskInfo_(const TaskHandle task)
|
||||
{
|
||||
INIT_CHECK(task != NULL, return);
|
||||
BaseTask *baseTask = (BaseTask *)task;
|
||||
StreamServerTask *serverTask = (StreamServerTask *)baseTask;
|
||||
printf("\tfd: %d \n", serverTask->base.taskId.fd);
|
||||
printf("\t TaskType: %s \n", "ServerTask");
|
||||
if (strlen(serverTask->server) > 0) {
|
||||
printf("\t Server socket:%s \n", serverTask->server);
|
||||
} else {
|
||||
printf("\t Server socket:%s \n", "NULL");
|
||||
}
|
||||
}
|
||||
|
||||
static void DumpStreamConnectTaskInfo_(const TaskHandle task)
|
||||
{
|
||||
INIT_CHECK(task != NULL, return);
|
||||
BaseTask *baseTask = (BaseTask *)task;
|
||||
StreamConnectTask *connectTask = (StreamConnectTask *)baseTask;
|
||||
TaskHandle taskHandle = (TaskHandle)connectTask;
|
||||
printf("\tfd: %d \n", connectTask->stream.base.taskId.fd);
|
||||
printf("\t TaskType: %s \n", "ConnectTask");
|
||||
printf("\t ServiceInfo: \n");
|
||||
struct ucred cred = {-1, -1, -1};
|
||||
socklen_t credSize = sizeof(struct ucred);
|
||||
if (getsockopt(LE_GetSocketFd(taskHandle), SOL_SOCKET, SO_PEERCRED, &cred, &credSize) == 0) {
|
||||
printf("\t Service Pid: %d \n", cred.pid);
|
||||
printf("\t Service Uid: %d \n", cred.uid);
|
||||
printf("\t Service Gid: %d \n", cred.gid);
|
||||
} else {
|
||||
printf("\t Service Pid: %s \n", "NULL");
|
||||
printf("\t Service Uid: %s \n", "NULL");
|
||||
printf("\t Service Gid: %s \n", "NULL");
|
||||
}
|
||||
}
|
||||
|
||||
static LE_STATUS HandleServerEvent_(const LoopHandle loopHandle, const TaskHandle serverTask, uint32_t oper)
|
||||
{
|
||||
LE_LOGV("HandleServerEvent_ fd %d oper 0x%x", GetSocketFd(serverTask), oper);
|
||||
@ -179,6 +216,7 @@ LE_STATUS LE_CreateStreamServer(const LoopHandle loopHandle,
|
||||
return LE_NO_MEMORY, "Failed to create task");
|
||||
task->base.handleEvent = HandleServerEvent_;
|
||||
task->base.innerClose = HandleStreamTaskClose_;
|
||||
task->base.dumpTaskInfo = DumpStreamServerTaskInfo_;
|
||||
task->incommingConnect = info->incommingConnect;
|
||||
loop->addEvent(loop, (const BaseTask *)task, Event_Read);
|
||||
ret = memcpy_s(task->server, strlen(info->server) + 1, info->server, strlen(info->server) + 1);
|
||||
@ -231,6 +269,7 @@ LE_STATUS LE_AcceptStreamClient(const LoopHandle loopHandle, const TaskHandle se
|
||||
return LE_NO_MEMORY, "Failed to create task");
|
||||
task->stream.base.handleEvent = HandleStreamEvent_;
|
||||
task->stream.base.innerClose = HandleStreamTaskClose_;
|
||||
task->stream.base.dumpTaskInfo = DumpStreamConnectTaskInfo_;
|
||||
task->disConnectComplete = info->disConnectComplete;
|
||||
task->sendMessageComplete = info->sendMessageComplete;
|
||||
task->recvMessage = info->recvMessage;
|
||||
|
@ -51,6 +51,7 @@ typedef struct {
|
||||
#define TASK_FLAGS_INVALID 0x80000000
|
||||
typedef LE_STATUS (*HandleTaskEvent)(const LoopHandle loop, const TaskHandle task, uint32_t oper);
|
||||
typedef void (*HandleTaskClose)(const LoopHandle loop, const TaskHandle task);
|
||||
typedef void (*DumpTaskInfo)(const TaskHandle task);
|
||||
#define TASKINFO \
|
||||
uint32_t flags; \
|
||||
union { \
|
||||
@ -65,6 +66,7 @@ typedef struct LiteTask_ {
|
||||
TASKINFO;
|
||||
HashNode hashNode;
|
||||
LE_Close close;
|
||||
DumpTaskInfo dumpTaskInfo;
|
||||
HandleTaskEvent handleEvent;
|
||||
HandleTaskClose innerClose;
|
||||
uint16_t userDataOffset;
|
||||
|
@ -49,6 +49,16 @@ static void HandleWatcherTaskClose_(const LoopHandle loopHandle, const TaskHandl
|
||||
DelTask((EventLoop *)loopHandle, (BaseTask *)taskHandle);
|
||||
}
|
||||
|
||||
static void DumpWatcherTaskInfo_(const TaskHandle task)
|
||||
{
|
||||
INIT_CHECK(task != NULL, return);
|
||||
BaseTask *baseTask = (BaseTask *)task;
|
||||
|
||||
WatcherTask *watcherTask = (WatcherTask *)baseTask;
|
||||
printf("\tfd: %d \n", watcherTask->base.taskId.fd);
|
||||
printf("\t TaskType: %s \n", "WatcherTask");
|
||||
}
|
||||
|
||||
LE_STATUS LE_StartWatcher(const LoopHandle loopHandle,
|
||||
WatcherHandle *watcherHandle, const LE_WatchInfo *info, const void *context)
|
||||
{
|
||||
@ -60,6 +70,7 @@ LE_STATUS LE_StartWatcher(const LoopHandle loopHandle,
|
||||
LE_CHECK(task != NULL, return LE_NO_MEMORY, "Failed to create task");
|
||||
task->base.handleEvent = HandleWatcherEvent_;
|
||||
task->base.innerClose = HandleWatcherTaskClose_;
|
||||
task->base.dumpTaskInfo = DumpWatcherTaskInfo_;
|
||||
task->processEvent = info->processEvent;
|
||||
task->events = info->events;
|
||||
*(uint64_t *)(task + 1) = (uint64_t)context;
|
||||
|
@ -71,6 +71,17 @@ static void HandleTimerClose_(const LoopHandle loopHandle, const TaskHandle task
|
||||
close(task->taskId.fd);
|
||||
}
|
||||
|
||||
static void DumpTimerTaskInfo_(const TaskHandle task)
|
||||
{
|
||||
INIT_CHECK(task != NULL, return);
|
||||
BaseTask *baseTask = (BaseTask *)task;
|
||||
TimerTask *timerTask = (TimerTask *)baseTask;
|
||||
printf("\tfd: %d \n", timerTask->base.taskId.fd);
|
||||
printf("\t TaskType: %s \n", "TimerTask");
|
||||
printf("\t Service Timeout: %llu \n", timerTask->timeout);
|
||||
printf("\t Service Repeat: %llu \n", timerTask->repeat);
|
||||
}
|
||||
|
||||
LE_STATUS LE_CreateTimer(const LoopHandle loopHandle,
|
||||
TimerHandle *timer, LE_ProcessTimer processTimer, void *context)
|
||||
{
|
||||
@ -88,6 +99,7 @@ LE_STATUS LE_CreateTimer(const LoopHandle loopHandle,
|
||||
return LE_NO_MEMORY, "Failed to create task");
|
||||
task->base.handleEvent = HandleTimerEvent_;
|
||||
task->base.innerClose = HandleTimerClose_;
|
||||
task->base.dumpTaskInfo = DumpTimerTaskInfo_;
|
||||
task->processTimer = processTimer;
|
||||
*(uint64_t *)(task + 1) = (uint64_t)context;
|
||||
*timer = (TimerHandle)task;
|
||||
|
Loading…
Reference in New Issue
Block a user