1 /*
2  * Copyright (c) 2024-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <sys/types.h>
19 #include <sys/mount.h>
20 #include <unistd.h>
21 
22 #include "init_log.h"
23 #include "bootevent.h"
24 
25 uid_t __real_getuid();
__wrap_getuid()26 uid_t __wrap_getuid()
27 {
28     if (!IsBootCompleted()) {
29         return __real_getuid();
30     }
31 
32     INIT_LOGI("getuid begin");
33     uid_t uid = __real_getuid();
34     INIT_LOGI("getuid end");
35     return uid;
36 }
37 
38 int __real_mkdir(const char *pathname, mode_t mode);
__wrap_mkdir(const char * pathname,mode_t mode)39 int __wrap_mkdir(const char *pathname, mode_t mode)
40 {
41     if (!IsBootCompleted()) {
42         return __real_mkdir(pathname, mode);
43     }
44 
45     INIT_LOGI("mkdir begin");
46     int ret = __real_mkdir(pathname, mode);
47     INIT_LOGI("mkdir end");
48     return ret;
49 }
50 
51 int __real_rmdir(const char *pathname);
__wrap_rmdir(const char * pathname)52 int __wrap_rmdir(const char *pathname)
53 {
54     if (!IsBootCompleted()) {
55         return __real_rmdir(pathname);
56     }
57 
58     INIT_LOGI("rmdir begin");
59     int ret = __real_rmdir(pathname);
60     INIT_LOGI("rmdir end");
61     return ret;
62 }
63 
64 pid_t __real_fork(void);
__wrap_fork(void)65 pid_t __wrap_fork(void)
66 {
67     if (!IsBootCompleted()) {
68         return __real_fork();
69     }
70 
71     INIT_LOGI("fork begin");
72     pid_t pid = __real_fork();
73     INIT_LOGI("fork end");
74     return pid;
75 }
76 
77 int __real_mount(const char *source, const char *target,
78                  const char *filesystemtype, unsigned long mountflags,
79                  const void *data);
__wrap_mount(const char * source,const char * target,const char * filesystemtype,unsigned long mountflags,const void * data)80 int __wrap_mount(const char *source, const char *target,
81                  const char *filesystemtype, unsigned long mountflags,
82                  const void *data)
83 {
84     if (!IsBootCompleted()) {
85         return __real_mount(source, target, filesystemtype, mountflags, data);
86     }
87 
88     INIT_LOGI("mount begin");
89     int ret = __real_mount(source, target, filesystemtype, mountflags, data);
90     INIT_LOGI("mount end");
91     return ret;
92 }
93 
94 int __real_chown(const char *pathname, uid_t owner, gid_t group);
__wrap_chown(const char * pathname,uid_t owner,gid_t group)95 int __wrap_chown(const char *pathname, uid_t owner, gid_t group)
96 {
97     if (!IsBootCompleted()) {
98         return __real_chown(pathname, owner, group);
99     }
100 
101     INIT_LOGI("chown begin");
102     int ret = __real_chown(pathname, owner, group);
103     INIT_LOGI("chown end");
104     return ret;
105 }
106 
107 int __real_chmod(const char *filename, int pmode);
__wrap_chmod(const char * filename,int pmode)108 int __wrap_chmod(const char *filename, int pmode)
109 {
110     if (!IsBootCompleted()) {
111         return __real_chmod(filename, pmode);
112     }
113 
114     INIT_LOGI("chmod begin");
115     int ret = __real_chmod(filename, pmode);
116     INIT_LOGI("chmod end");
117     return ret;
118 }
119 
120 int __real_kill(pid_t pid, int sig);
__wrap_kill(pid_t pid,int sig)121 int __wrap_kill(pid_t pid, int sig)
122 {
123     if (!IsBootCompleted()) {
124         return __real_kill(pid, sig);
125     }
126 
127     INIT_LOGI("kill begin");
128     int ret = __real_kill(pid, sig);
129     INIT_LOGI("kill end");
130     return ret;
131 }
132 
133 FILE *__real_fopen(const char *filename, const char *mode);
__wrap_fopen(const char * filename,const char * mode)134 FILE *__wrap_fopen(const char *filename, const char *mode)
135 {
136     if (!IsBootCompleted()) {
137         return __real_fopen(filename, mode);
138     }
139 
140     INIT_LOGI("fopen begin");
141     FILE *file = __real_fopen(filename, mode);
142     INIT_LOGI("fopen end");
143     return file;
144 }