@@ -97,7 +97,7 @@ v_current = (uintptr_t) v + v_size - sizeof(char *); \
9797 ARG_PUSH_FMT (argv, " -Djava.class.path=%s" , apk_path)
9898 ARG_PUSH_FMT (argv, " -Dkeymapper_sysbridge.library.path=%s" , lib_path)
9999 ARG_PUSH_FMT (argv, " -Dkeymapper_sysbridge.package=%s" , package_name)
100- ARG_PUSH_FMT (argv, " -Dkeymapper_sysbridge.version_code =%s" , version_code)
100+ ARG_PUSH_FMT (argv, " -Dkeymapper_sysbridge.version =%s" , version_code)
101101 ARG_PUSH_DEBUG_VM_PARAMS (argv)
102102 ARG_PUSH (argv, " /system/bin" )
103103 ARG_PUSH_FMT (argv, " --nice-name=%s" , process_name)
@@ -120,7 +120,7 @@ static void start_server(const char *apk_path, const char *lib_path, const char
120120 LOGD (" child" );
121121 run_server (apk_path, lib_path, main_class, process_name, package_name, version_code);
122122 } else {
123- perrorf (" fatal: can't fork\n " );
123+ LOGE (" fatal: can't fork" );
124124 exit (EXIT_FATAL_FORK);
125125 }
126126}
@@ -130,8 +130,7 @@ static int check_selinux(const char *s, const char *t, const char *c, const char
130130#ifndef DEBUG
131131 if (res != 0 ) {
132132#endif
133- printf (" info: selinux_check_access %s %s %s %s: %d\n " , s, t, c, p, res);
134- fflush (stdout);
133+ LOGI (" selinux_check_access %s %s %s %s: %d" , s, t, c, p, res);
135134#ifndef DEBUG
136135 }
137136#endif
@@ -143,28 +142,23 @@ static int switch_cgroup() {
143142 int spid = getpid ();
144143
145144 if (cgroup::get_cgroup (spid, &s_cuid, &s_cpid) != 0 ) {
146- printf (" warn: can't read cgroup\n " );
147- fflush (stdout);
145+ LOGW (" can't read cgroup" );
148146 return -1 ;
149147 }
150148
151- printf (" info: cgroup is /uid_%d/pid_%d\n " , s_cuid, s_cpid);
152- fflush (stdout);
149+ LOGI (" cgroup is /uid_%d/pid_%d" , s_cuid, s_cpid);
153150
154151 if (cgroup::switch_cgroup (spid, -1 , -1 ) != 0 ) {
155- printf (" warn: can't switch cgroup\n " );
156- fflush (stdout);
152+ LOGW (" can't switch cgroup" );
157153 return -1 ;
158154 }
159155
160156 if (cgroup::get_cgroup (spid, &s_cuid, &s_cpid) != 0 ) {
161- printf (" info: switch cgroup succeeded\n " );
162- fflush (stdout);
157+ LOGI (" switch cgroup succeeded" );
163158 return 0 ;
164159 }
165160
166- printf (" warn: can't switch self, current cgroup is /uid_%d/pid_%d\n " , s_cuid, s_cpid);
167- fflush (stdout);
161+ LOGW (" can't switch self, current cgroup is /uid_%d/pid_%d" , s_cuid, s_cpid);
168162 return -1 ;
169163}
170164
@@ -174,7 +168,7 @@ int starter_main(int argc, char *argv[]) {
174168 char *apk_path = nullptr ;
175169 char *lib_path = nullptr ;
176170 char *package_name = nullptr ;
177- char *version_code = nullptr ;
171+ char *version = nullptr ;
178172
179173 // Get the apk path from the program arguments. This gets the path by setting the
180174 // start of the apk path array to after the "--apk=" by offsetting by 6 characters.
@@ -185,19 +179,19 @@ int starter_main(int argc, char *argv[]) {
185179 lib_path = argv[i] + 6 ;
186180 } else if (strncmp (argv[i], " --package=" , 10 ) == 0 ) {
187181 package_name = argv[i] + 10 ;
188- } else if (strncmp (argv[i], " --version_code =" , 15 ) == 0 ) {
189- version_code = argv[i] + 15 ;
182+ } else if (strncmp (argv[i], " --version =" , 10 ) == 0 ) {
183+ version = argv[i] + 10 ;
190184 }
191185 }
192186
193- printf ( " info: apk path = %s\n " , apk_path);
194- printf ( " info: lib path = %s\n " , lib_path);
195- printf ( " info: package name = %s\n " , package_name);
196- printf ( " info: version code = %s\n " , version_code );
187+ LOGI ( " apk path = %s" , apk_path);
188+ LOGI ( " lib path = %s" , lib_path);
189+ LOGI ( " package name = %s" , package_name);
190+ LOGI ( " version = %s" , version );
197191
198192 int uid = getuid ();
199193 if (uid != 0 && uid != 2000 ) {
200- perrorf (" fatal: run system bridge from non root nor adb user (uid=%d).\n " , uid);
194+ LOGE (" fatal: run system bridge from non root nor adb user (uid=%d)." , uid);
201195 exit (EXIT_FATAL_UID);
202196 }
203197
@@ -215,7 +209,7 @@ int starter_main(int argc, char *argv[]) {
215209 sdkLevel = atoi (buf);
216210
217211 if (sdkLevel >= 29 ) {
218- printf ( " info: switching mount namespace to init...\n " );
212+ LOGI ( " switching mount namespace to init..." );
219213 switch_mnt_ns (1 );
220214 }
221215 }
@@ -228,27 +222,18 @@ int starter_main(int argc, char *argv[]) {
228222 res |= check_selinux (" u:r:untrusted_app:s0" , context, " binder" , " transfer" );
229223
230224 if (res != 0 ) {
231- perrorf (" fatal: the su you are using does not allow app (u:r:untrusted_app:s0) to connect to su (%s) with binder.\n " ,
225+ LOGE (" fatal: the su you are using does not allow app (u:r:untrusted_app:s0) to connect to su (%s) with binder." ,
232226 context);
233227 exit (EXIT_FATAL_BINDER_BLOCKED_BY_SELINUX);
234228 }
235229 se::freecon (context);
236230 }
237231 }
238232
239- mkdir (" /data/local/tmp/keymapper_sysbridge" , 0707 );
240- chmod (" /data/local/tmp/keymapper_sysbridge" , 0707 );
241- if (uid == 0 ) {
242- chown (" /data/local/tmp/keymapper_sysbridge" , 2000 , 2000 );
243- se::setfilecon (" /data/local/tmp/keymapper_sysbridge" , " u:object_r:shell_data_file:s0" );
244- }
245-
246- printf (" info: starter begin\n " );
247- fflush (stdout);
233+ LOGI (" starter begin" );
248234
249235 // kill old server
250- printf (" info: killing old process...\n " );
251- fflush (stdout);
236+ LOGI (" killing old process..." );
252237
253238 foreach_proc ([](pid_t pid) {
254239 if (pid == getpid ()) return ;
@@ -259,47 +244,42 @@ int starter_main(int argc, char *argv[]) {
259244 if (strcmp (SERVER_NAME, name) != 0 ) return ;
260245
261246 if (kill (pid, SIGKILL) == 0 )
262- printf ( " info: killed %d (%s)\n " , pid, name);
247+ LOGI ( " killed %d (%s)" , pid, name);
263248 else if (errno == EPERM) {
264- perrorf (" fatal: can't kill %d, please try to stop existing sysbridge from app first.\n " ,
249+ LOGE (" fatal: can't kill %d, please try to stop existing sysbridge from app first." ,
265250 pid);
266251 exit (EXIT_FATAL_KILL);
267252 } else {
268- printf ( " warn: failed to kill %d (%s)\n " , pid, name);
253+ LOGW ( " failed to kill %d (%s)" , pid, name);
269254 }
270255 });
271256
272257 if (access (apk_path, R_OK) == 0 ) {
273- printf (" info: use apk path from argv\n " );
274- fflush (stdout);
258+ LOGI (" use apk path from argv" );
275259 }
276260
277261 if (access (lib_path, R_OK) == 0 ) {
278- printf (" info: use lib path from argv\n " );
279- fflush (stdout);
262+ LOGI (" use lib path from argv" );
280263 }
281264
282265 if (!apk_path) {
283- perrorf (" fatal: can't get path of manager\n " );
266+ LOGE (" fatal: can't get path of manager" );
284267 exit (EXIT_FATAL_PM_PATH);
285268 }
286269
287270 if (!lib_path) {
288- perrorf (" fatal: can't get path of native libraries\n " );
271+ LOGE (" fatal: can't get path of native libraries" );
289272 exit (EXIT_FATAL_PM_PATH);
290273 }
291274
292- printf (" info: apk path is %s\n " , apk_path);
293- printf (" info: lib path is %s\n " , lib_path);
294275 if (access (apk_path, R_OK) != 0 ) {
295- perrorf (" fatal: can't access manager %s\n " , apk_path);
276+ LOGE (" fatal: can't access manager %s" , apk_path);
296277 exit (EXIT_FATAL_PM_PATH);
297278 }
298279
299- printf (" info: starting server...\n " );
300- fflush (stdout);
280+ LOGI (" starting server..." );
301281 LOGD (" start_server" );
302- start_server (apk_path, lib_path, SERVER_CLASS_PATH, SERVER_NAME, package_name, version_code );
282+ start_server (apk_path, lib_path, SERVER_CLASS_PATH, SERVER_NAME, package_name, version );
303283 exit (EXIT_SUCCESS);
304284}
305285
0 commit comments