• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "init_utils.h"
25 
26 uid_t __real_getuid();
__wrap_getuid()27 uid_t __wrap_getuid()
28 {
29     if (!IsBootCompleted()) {
30         return __real_getuid();
31     }
32 
33     INIT_LOGI("getuid begin");
34     uid_t uid = __real_getuid();
35     INIT_LOGI("getuid end");
36     return uid;
37 }
38 
39 int __real_mkdir(const char *pathname, mode_t mode);
__wrap_mkdir(const char * pathname,mode_t mode)40 int __wrap_mkdir(const char *pathname, mode_t mode)
41 {
42     if (!IsBootCompleted()) {
43         return __real_mkdir(pathname, mode);
44     }
45 
46     INIT_LOGI("mkdir begin");
47     int ret = __real_mkdir(pathname, mode);
48     INIT_LOGI("mkdir end");
49     return ret;
50 }
51 
52 int __real_rmdir(const char *pathname);
__wrap_rmdir(const char * pathname)53 int __wrap_rmdir(const char *pathname)
54 {
55     if (!IsBootCompleted()) {
56         return __real_rmdir(pathname);
57     }
58 
59     INIT_LOGI("rmdir begin");
60     int ret = __real_rmdir(pathname);
61     INIT_LOGI("rmdir end");
62     return ret;
63 }
64 
65 pid_t __real_fork(void);
__wrap_fork(void)66 pid_t __wrap_fork(void)
67 {
68     if (!IsBootCompleted()) {
69         return __real_fork();
70     }
71 
72     INIT_LOGI("fork begin");
73     pid_t pid = __real_fork();
74     INIT_LOGI("fork end");
75     return pid;
76 }
77 
78 int __real_mount(const char *source, const char *target,
79                  const char *filesystemtype, unsigned long mountflags,
80                  const void *data);
__wrap_mount(const char * source,const char * target,const char * filesystemtype,unsigned long mountflags,const void * data)81 int __wrap_mount(const char *source, const char *target,
82                  const char *filesystemtype, unsigned long mountflags,
83                  const void *data)
84 {
85     if (!IsBootCompleted()) {
86         return __real_mount(source, target, filesystemtype, mountflags, data);
87     }
88 
89     INIT_LOGI("mount begin");
90     int ret = __real_mount(source, target, filesystemtype, mountflags, data);
91     INIT_LOGI("mount end");
92     return ret;
93 }
94 
95 int __real_chown(const char *pathname, uid_t owner, gid_t group);
__wrap_chown(const char * pathname,uid_t owner,gid_t group)96 int __wrap_chown(const char *pathname, uid_t owner, gid_t group)
97 {
98     if (!IsBootCompleted()) {
99         return __real_chown(pathname, owner, group);
100     }
101 
102     INIT_LOGI("chown begin");
103     int ret = __real_chown(pathname, owner, group);
104     INIT_LOGI("chown end");
105     return ret;
106 }
107 
108 int __real_chmod(const char *filename, int pmode);
__wrap_chmod(const char * filename,int pmode)109 int __wrap_chmod(const char *filename, int pmode)
110 {
111     if (!IsBootCompleted()) {
112         return __real_chmod(filename, pmode);
113     }
114 
115     INIT_LOGI("chmod begin");
116     int ret = __real_chmod(filename, pmode);
117     INIT_LOGI("chmod end");
118     return ret;
119 }
120 
121 int __real_kill(pid_t pid, int sig);
__wrap_kill(pid_t pid,int sig)122 int __wrap_kill(pid_t pid, int sig)
123 {
124     if (!IsBootCompleted()) {
125         return __real_kill(pid, sig);
126     }
127 
128     INIT_LOGI("kill begin");
129     int ret = __real_kill(pid, sig);
130     INIT_LOGI("kill end");
131     return ret;
132 }
133 
134 FILE *__real_fopen(const char *filename, const char *mode);
__wrap_fopen(const char * filename,const char * mode)135 FILE *__wrap_fopen(const char *filename, const char *mode)
136 {
137     if (!IsBootCompleted()) {
138         return __real_fopen(filename, mode);
139     }
140 
141     INIT_LOGI("fopen begin");
142     FILE *file = __real_fopen(filename, mode);
143     INIT_LOGI("fopen end");
144     return file;
145 }