Description:add system call log support

Feature or Bugfix:Bugfix
Binary Source: No
Signed-off-by: zl_zl <zhenglei28@huawei.com>
This commit is contained in:
z00500798 2024-07-30 09:15:11 +08:00
parent a85567a6f8
commit 85b08e9221
5 changed files with 175 additions and 0 deletions

View File

@ -57,4 +57,7 @@ declare_args() {
# erofs overlay feature switch
init_startup_feature_erofs_overlay = false
# system call wrap switch
init_startup_feature_system_call_switch = false
}

View File

@ -79,6 +79,9 @@ ohos_executable("init") {
"bootstagehooker.c",
]
if (init_startup_feature_system_call_switch) {
sources += [ "../standard/system_call_wrap.c" ]
}
modulemgr_sources = [
"//base/startup/init/interfaces/innerkits/hookmgr/hookmgr.c",
"//base/startup/init/interfaces/innerkits/modulemgr/modulemgr.c",
@ -130,7 +133,21 @@ ohos_executable("init") {
"storage_service:libfscryptutils_static",
]
cflags = []
if (init_startup_feature_system_call_switch) {
ldflags = [
"-Wl,--wrap=getuid",
"-Wl,--wrap=mkdir",
"-Wl,--wrap=rmdir",
"-Wl,--wrap=fork",
"-Wl,--wrap=mount",
"-Wl,--wrap=chown",
"-Wl,--wrap=chmod",
"-Wl,--wrap=kill",
"-Wl,--wrap=fopen",
]
include_dirs += [ "//base/startup/init/services/modules/bootevent" ]
}
if (use_musl) {
external_deps += [
"mksh:sh",

View File

@ -0,0 +1,144 @@
/*
* Copyright (c) 2024-2024 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 <sys/types.h>
#include <sys/mount.h>
#include <unistd.h>
#include "init_log.h"
#include "bootevent.h"
uid_t __real_getuid();
uid_t __wrap_getuid()
{
if (!IsBootCompleted()) {
return __real_getuid();
}
INIT_LOGI("getuid begin");
uid_t uid = __real_getuid();
INIT_LOGI("getuid end");
return uid;
}
int __real_mkdir(const char *pathname, mode_t mode);
int __wrap_mkdir(const char *pathname, mode_t mode)
{
if (!IsBootCompleted()) {
return __real_mkdir(pathname, mode);
}
INIT_LOGI("mkdir begin");
int ret = __real_mkdir(pathname, mode);
INIT_LOGI("mkdir end");
return ret;
}
int __real_rmdir(const char *pathname);
int __wrap_rmdir(const char *pathname)
{
if (!IsBootCompleted()) {
return __real_rmdir(pathname);
}
INIT_LOGI("rmdir begin");
int ret = __real_rmdir(pathname);
INIT_LOGI("rmdir end");
return ret;
}
pid_t __real_fork(void);
pid_t __wrap_fork(void)
{
if (!IsBootCompleted()) {
return __real_fork();
}
INIT_LOGI("fork begin");
pid_t pid = __real_fork();
INIT_LOGI("fork end");
return pid;
}
int __real_mount(const char *source, const char *target,
const char *filesystemtype, unsigned long mountflags,
const void *data);
int __wrap_mount(const char *source, const char *target,
const char *filesystemtype, unsigned long mountflags,
const void *data)
{
if (!IsBootCompleted()) {
return __real_mount(source, target, filesystemtype, mountflags, data);
}
INIT_LOGI("mount begin");
int ret = __real_mount(source, target, filesystemtype, mountflags, data);
INIT_LOGI("mount end");
return ret;
}
int __real_chown(const char *pathname, uid_t owner, gid_t group);
int __wrap_chown(const char *pathname, uid_t owner, gid_t group)
{
if (!IsBootCompleted()) {
return __real_chown(pathname, owner, group);
}
INIT_LOGI("chown begin");
int ret = __real_chown(pathname, owner, group);
INIT_LOGI("chown end");
return ret;
}
int __real_chmod(const char *filename, int pmode);
int __wrap_chmod(const char *filename, int pmode)
{
if (!IsBootCompleted()) {
return __real_chmod(filename, pmode);
}
INIT_LOGI("chmod begin");
int ret = __real_chmod(filename, pmode);
INIT_LOGI("chmod end");
return ret;
}
int __real_kill(pid_t pid, int sig);
int __wrap_kill(pid_t pid, int sig)
{
if (!IsBootCompleted()) {
return __real_kill(pid, sig);
}
INIT_LOGI("kill begin");
int ret = __real_kill(pid, sig);
INIT_LOGI("kill end");
return ret;
}
FILE *__real_fopen(const char *filename, const char *mode);
FILE *__wrap_fopen(const char *filename, const char *mode)
{
if (!IsBootCompleted()) {
return __real_fopen(filename, mode);
}
INIT_LOGI("fopen begin");
FILE *file = __real_fopen(filename, mode);
INIT_LOGI("fopen end");
return file;
}

View File

@ -46,6 +46,8 @@ static int GetBootEventEnable(void)
static int g_bootEventNum = 0;
static bool g_isBootCompleted = false;
static ListNode bootEventList = {&bootEventList, &bootEventList};
static int BootEventParaListCompareProc(ListNode *node, void *data)
@ -323,6 +325,7 @@ static int BootEventParaFireByName(const char *paramName)
// All parameters are fired, set boot completed now ...
INIT_LOGI("All boot events are fired, boot complete now ...");
SystemWriteParam(BOOT_EVENT_BOOT_COMPLETED, "true");
g_isBootCompleted = true;
SaveServiceBootEvent();
// report complete event
ReportSysEvent();
@ -438,6 +441,7 @@ static int DoUnsetBootEventCmd(int id, const char *name, int argc, const char **
SystemWriteParam(argv[0], "false");
if (g_finished != 0) {
SystemWriteParam(BOOT_EVENT_BOOT_COMPLETED, "false");
g_isBootCompleted = false;
g_finished = 0;
}
@ -477,6 +481,11 @@ ListNode *GetBootEventList(void)
return &bootEventList;
}
bool IsBootCompleted(void)
{
return g_isBootCompleted;
}
static void AddCmdBootEvent(INIT_CMD_INFO *cmdCtx)
{
INIT_TIMING_STAT *timeStat = (INIT_TIMING_STAT *)cmdCtx->reserved;

View File

@ -55,6 +55,8 @@ typedef struct tagBOOT_EVENT_PARAM_ITEM {
ListNode *GetBootEventList(void);
bool IsBootCompleted(void);
#ifdef __cplusplus
#if __cplusplus
}