Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
6c0ba66f
Commit
6c0ba66f
authored
Jun 07, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add excessive logging for debug mode
parent
f32ce739
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
65 additions
and
47 deletions
+65
-47
bootstages.c
jni/daemon/bootstages.c
+16
-4
daemon.c
jni/daemon/daemon.c
+1
-4
log_monitor.c
jni/daemon/log_monitor.c
+21
-19
magisk.h
jni/magisk.h
+1
-0
proc_monitor.c
jni/magiskhide/proc_monitor.c
+3
-3
resetprop.cpp
jni/resetprop/resetprop.cpp
+1
-0
misc.c
jni/utils/misc.c
+20
-15
utils.h
jni/utils/utils.h
+1
-1
magisk_uninstaller.sh
scripts/magisk_uninstaller.sh
+1
-1
No files found.
jni/daemon/bootstages.c
View file @
6c0ba66f
...
@@ -172,7 +172,7 @@ void exec_common_script(const char* stage) {
...
@@ -172,7 +172,7 @@ void exec_common_script(const char* stage) {
continue
;
continue
;
LOGI
(
"%s.d: exec [%s]
\n
"
,
stage
,
entry
->
d_name
);
LOGI
(
"%s.d: exec [%s]
\n
"
,
stage
,
entry
->
d_name
);
char
*
const
command
[]
=
{
"sh"
,
buf2
,
NULL
};
char
*
const
command
[]
=
{
"sh"
,
buf2
,
NULL
};
int
pid
=
run_command
(
NULL
,
"/system/bin/sh"
,
command
);
int
pid
=
run_command
(
0
,
NULL
,
"/system/bin/sh"
,
command
);
if
(
pid
!=
-
1
)
if
(
pid
!=
-
1
)
waitpid
(
pid
,
NULL
,
0
);
waitpid
(
pid
,
NULL
,
0
);
}
}
...
@@ -189,7 +189,7 @@ void exec_module_script(const char* stage) {
...
@@ -189,7 +189,7 @@ void exec_module_script(const char* stage) {
continue
;
continue
;
LOGI
(
"%s: exec [%s.sh]
\n
"
,
module
,
stage
);
LOGI
(
"%s: exec [%s.sh]
\n
"
,
module
,
stage
);
char
*
const
command
[]
=
{
"sh"
,
buf
,
NULL
};
char
*
const
command
[]
=
{
"sh"
,
buf
,
NULL
};
int
pid
=
run_command
(
NULL
,
"/system/bin/sh"
,
command
);
int
pid
=
run_command
(
0
,
NULL
,
"/system/bin/sh"
,
command
);
if
(
pid
!=
-
1
)
if
(
pid
!=
-
1
)
waitpid
(
pid
,
NULL
,
0
);
waitpid
(
pid
,
NULL
,
0
);
}
}
...
@@ -458,6 +458,10 @@ static void unblock_boot_process() {
...
@@ -458,6 +458,10 @@ static void unblock_boot_process() {
void
post_fs
(
int
client
)
{
void
post_fs
(
int
client
)
{
// Error handler
// Error handler
err_handler
=
unblock_boot_process
;
err_handler
=
unblock_boot_process
;
// Start log monitor
monitor_logs
();
LOGI
(
"** post-fs mode running
\n
"
);
LOGI
(
"** post-fs mode running
\n
"
);
// ack
// ack
write_int
(
client
,
0
);
write_int
(
client
,
0
);
...
@@ -730,8 +734,8 @@ void late_start(int client) {
...
@@ -730,8 +734,8 @@ void late_start(int client) {
"CLASSPATH=/system/framework/pm.jar "
"CLASSPATH=/system/framework/pm.jar "
"/system/bin/app_process /system/bin "
"/system/bin/app_process /system/bin "
"com.android.commands.pm.Pm install -r "
MANAGERAPK
,
NULL
};
"com.android.commands.pm.Pm install -r "
MANAGERAPK
,
NULL
};
int
apk_res
,
pid
;
int
apk_res
=
0
,
pid
;
pid
=
run_command
(
&
apk_res
,
"/system/bin/sh"
,
command
);
pid
=
run_command
(
1
,
&
apk_res
,
"/system/bin/sh"
,
command
);
waitpid
(
pid
,
NULL
,
0
);
waitpid
(
pid
,
NULL
,
0
);
fdgets
(
buf
,
PATH_MAX
,
apk_res
);
fdgets
(
buf
,
PATH_MAX
,
apk_res
);
close
(
apk_res
);
close
(
apk_res
);
...
@@ -746,4 +750,12 @@ void late_start(int client) {
...
@@ -746,4 +750,12 @@ void late_start(int client) {
free
(
buf
);
free
(
buf
);
free
(
buf2
);
free
(
buf2
);
vec_deep_destroy
(
&
module_list
);
vec_deep_destroy
(
&
module_list
);
#ifdef DEBUG
// Stop recording the boot logcat after every boot task is done
extern
int
debug_log_pid
,
debug_log_fd
;
kill
(
debug_log_pid
,
SIGTERM
);
waitpid
(
debug_log_pid
,
NULL
,
0
);
close
(
debug_log_fd
);
#endif
}
}
jni/daemon/daemon.c
View file @
6c0ba66f
...
@@ -162,9 +162,6 @@ void start_daemon(int client) {
...
@@ -162,9 +162,6 @@ void start_daemon(int client) {
// It should stay intact under any circumstances
// It should stay intact under any circumstances
err_handler
=
do_nothing
;
err_handler
=
do_nothing
;
// Start log monitor
monitor_logs
();
LOGI
(
"Magisk v"
xstr
(
MAGISK_VERSION
)
" daemon started
\n
"
);
LOGI
(
"Magisk v"
xstr
(
MAGISK_VERSION
)
" daemon started
\n
"
);
// Unlock all blocks for rw
// Unlock all blocks for rw
...
@@ -174,7 +171,7 @@ void start_daemon(int client) {
...
@@ -174,7 +171,7 @@ void start_daemon(int client) {
xmount
(
NULL
,
"/"
,
NULL
,
MS_REMOUNT
,
NULL
);
xmount
(
NULL
,
"/"
,
NULL
,
MS_REMOUNT
,
NULL
);
create_links
(
NULL
,
"/sbin"
);
create_links
(
NULL
,
"/sbin"
);
xchmod
(
"/sbin"
,
0755
);
xchmod
(
"/sbin"
,
0755
);
x
mkdir
(
"/magisk"
,
0755
);
mkdir
(
"/magisk"
,
0755
);
xchmod
(
"/magisk"
,
0755
);
xchmod
(
"/magisk"
,
0755
);
xmount
(
NULL
,
"/"
,
NULL
,
MS_REMOUNT
|
MS_RDONLY
,
NULL
);
xmount
(
NULL
,
"/"
,
NULL
,
MS_REMOUNT
|
MS_RDONLY
,
NULL
);
...
...
jni/daemon/log_monitor.c
View file @
6c0ba66f
...
@@ -15,41 +15,43 @@
...
@@ -15,41 +15,43 @@
#include "utils.h"
#include "utils.h"
#include "daemon.h"
#include "daemon.h"
#ifdef DEBUG
int
debug_log_pid
,
debug_log_fd
;
#endif
static
void
*
logger_thread
(
void
*
args
)
{
static
void
*
logger_thread
(
void
*
args
)
{
// Setup error handler
// Setup error handler
err_handler
=
exit_thread
;
err_handler
=
exit_thread
;
char
*
buffer
=
xmalloc
(
PATH_MAX
);
rename
(
LOGFILE
,
LASTLOG
);
rename
(
LOGFILE
,
LASTLOG
);
FILE
*
logfile
=
xfdopen
(
xopen
(
LOGFILE
,
O_WRONLY
|
O_CREAT
|
O_CLOEXEC
|
O_TRUNC
,
0644
),
"w"
);
int
log_fd
,
log_pid
;
// Disable buffering
setbuf
(
logfile
,
NULL
);
log_fd
=
xopen
(
LOGFILE
,
O_WRONLY
|
O_CREAT
|
O_CLOEXEC
|
O_TRUNC
,
0644
);
int
fd
,
log_pid
;
while
(
1
)
{
while
(
1
)
{
// Start logcat
// Start logcat
char
*
const
command
[]
=
{
"logcat"
,
"-s"
,
"Magisk"
,
"-v"
,
"time"
,
NULL
};
char
*
const
command
[]
=
{
"logcat"
,
"-s"
,
"Magisk"
,
"-v"
,
"thread"
,
NULL
};
log_pid
=
run_command
(
&
fd
,
"/system/bin/logcat"
,
command
);
log_pid
=
run_command
(
0
,
&
log_fd
,
"/system/bin/logcat"
,
command
);
while
(
fdgets
(
buffer
,
PATH_MAX
,
fd
))
{
fprintf
(
logfile
,
"%s"
,
buffer
);
}
// For some reason it went here, clear buffer and restart
close
(
fd
);
kill
(
log_pid
,
SIGTERM
);
waitpid
(
log_pid
,
NULL
,
0
);
waitpid
(
log_pid
,
NULL
,
0
);
// For some reason it went here, clear buffer and restart
system
(
"logcat -c"
);
system
(
"logcat -c"
);
}
}
// Should never be here, but well...
// Should never be here, but well...
fclose
(
logfile
);
close
(
log_fd
);
free
(
buffer
);
return
NULL
;
return
NULL
;
}
}
/* Start a new thread to monitor logcat and dump to logfile */
/* Start a new thread to monitor logcat and dump to logfile */
void
monitor_logs
()
{
void
monitor_logs
()
{
pthread_t
log_monitor_thread
;
pthread_t
thread
;
xpthread_create
(
&
log_monitor_thread
,
NULL
,
logger_thread
,
NULL
);
xpthread_create
(
&
thread
,
NULL
,
logger_thread
,
NULL
);
pthread_detach
(
log_monitor_thread
);
pthread_detach
(
thread
);
#ifdef DEBUG
// Start debug logs in new process
debug_log_fd
=
xopen
(
DEBUG_LOG
,
O_WRONLY
|
O_CREAT
|
O_CLOEXEC
|
O_TRUNC
,
0644
);
char
*
const
command
[]
=
{
"logcat"
,
"-v"
,
"brief"
,
NULL
};
debug_log_pid
=
run_command
(
0
,
&
debug_log_fd
,
"/system/bin/logcat"
,
command
);
#endif
}
}
jni/magisk.h
View file @
6c0ba66f
...
@@ -26,6 +26,7 @@
...
@@ -26,6 +26,7 @@
#define LOGFILE "/cache/magisk.log"
#define LOGFILE "/cache/magisk.log"
#define LASTLOG "/cache/last_magisk.log"
#define LASTLOG "/cache/last_magisk.log"
#define DEBUG_LOG "/data/magisk_debug.log"
#define UNBLOCKFILE "/dev/.magisk.unblock"
#define UNBLOCKFILE "/dev/.magisk.unblock"
#define DISABLEFILE "/cache/.disable_magisk"
#define DISABLEFILE "/cache/.disable_magisk"
#define UNINSTALLER "/cache/magisk_uninstaller.sh"
#define UNINSTALLER "/cache/magisk_uninstaller.sh"
...
...
jni/magiskhide/proc_monitor.c
View file @
6c0ba66f
...
@@ -19,7 +19,7 @@
...
@@ -19,7 +19,7 @@
static
int
zygote_num
=
0
;
static
int
zygote_num
=
0
;
static
char
init_ns
[
32
],
zygote_ns
[
2
][
32
];
static
char
init_ns
[
32
],
zygote_ns
[
2
][
32
];
static
int
log_pid
=
0
,
log_fd
;
static
int
log_pid
=
0
,
log_fd
=
0
;
static
char
*
buffer
;
static
char
*
buffer
;
static
void
read_namespace
(
const
int
pid
,
char
*
target
,
const
size_t
size
)
{
static
void
read_namespace
(
const
int
pid
,
char
*
target
,
const
size_t
size
)
{
...
@@ -40,7 +40,7 @@ static void quit_pthread(int sig) {
...
@@ -40,7 +40,7 @@ static void quit_pthread(int sig) {
kill
(
log_pid
,
SIGTERM
);
kill
(
log_pid
,
SIGTERM
);
waitpid
(
log_pid
,
NULL
,
0
);
waitpid
(
log_pid
,
NULL
,
0
);
close
(
log_fd
);
close
(
log_fd
);
log_pid
=
0
;
log_
fd
=
log_
pid
=
0
;
}
}
int
kill
=
-
1
;
int
kill
=
-
1
;
// If process monitor dies, kill hide daemon too
// If process monitor dies, kill hide daemon too
...
@@ -107,7 +107,7 @@ void proc_monitor() {
...
@@ -107,7 +107,7 @@ void proc_monitor() {
// Monitor am_proc_start
// Monitor am_proc_start
char
*
const
command
[]
=
{
"logcat"
,
"-b"
,
"events"
,
"-v"
,
"raw"
,
"-s"
,
"am_proc_start"
,
NULL
};
char
*
const
command
[]
=
{
"logcat"
,
"-b"
,
"events"
,
"-v"
,
"raw"
,
"-s"
,
"am_proc_start"
,
NULL
};
log_pid
=
run_command
(
&
log_fd
,
"/system/bin/logcat"
,
command
);
log_pid
=
run_command
(
0
,
&
log_fd
,
"/system/bin/logcat"
,
command
);
while
(
fdgets
(
buffer
,
PATH_MAX
,
log_fd
))
{
while
(
fdgets
(
buffer
,
PATH_MAX
,
log_fd
))
{
int
ret
,
comma
=
0
;
int
ret
,
comma
=
0
;
...
...
jni/resetprop/resetprop.cpp
View file @
6c0ba66f
...
@@ -138,6 +138,7 @@ static void read_prop_info(void* cookie, const char *name, const char *value, ui
...
@@ -138,6 +138,7 @@ static void read_prop_info(void* cookie, const char *name, const char *value, ui
char
*
getprop
(
const
char
*
name
)
{
char
*
getprop
(
const
char
*
name
)
{
const
prop_info
*
pi
=
__system_property_find2
(
name
);
const
prop_info
*
pi
=
__system_property_find2
(
name
);
if
(
pi
==
NULL
)
{
if
(
pi
==
NULL
)
{
PRINT_D
(
"resetprop: failed to get [%s]
\n
"
,
name
);
return
NULL
;
return
NULL
;
}
}
char
value
[
PROP_VALUE_MAX
];
char
value
[
PROP_VALUE_MAX
];
...
...
jni/utils/misc.c
View file @
6c0ba66f
...
@@ -217,29 +217,34 @@ void setup_sighandlers(void (*handler)(int)) {
...
@@ -217,29 +217,34 @@ void setup_sighandlers(void (*handler)(int)) {
}
}
}
}
int
run_command
(
int
*
fd
,
const
char
*
path
,
char
*
const
argv
[])
{
/*
int
sv
[
2
];
fd == NULL -> Ignore output
*fd == 0 -> Open pipe and set *fd to the read end
*fd != 0 -> STDOUT (or STDERR) will be redirected to *fd
*/
int
run_command
(
int
err
,
int
*
fd
,
const
char
*
path
,
char
*
const
argv
[])
{
int
pipefd
[
2
],
writeEnd
=
0
;
if
(
fd
)
{
if
(
fd
)
{
if
(
socketpair
(
AF_LOCAL
,
SOCK_STREAM
,
0
,
sv
)
==
-
1
)
if
(
*
fd
==
0
)
{
return
-
1
;
if
(
pipe
(
pipefd
)
==
-
1
)
// We use sv[0], give them sv[1] for communication
return
-
1
;
if
(
fcntl
(
sv
[
1
],
F_SETFD
,
FD_CLOEXEC
))
writeEnd
=
pipefd
[
1
];
PLOGE
(
"fcntl FD_CLOEXEC"
);
// Give the read end of the pipe
*
fd
=
sv
[
1
];
*
fd
=
pipefd
[
0
];
}
}
}
int
pid
=
fork
();
int
pid
=
fork
();
if
(
pid
!=
0
)
{
if
(
pid
!=
0
)
{
if
(
fd
)
close
(
sv
[
0
]
);
if
(
writeEnd
)
close
(
writeEnd
);
return
pid
;
return
pid
;
}
}
if
(
fd
)
{
if
(
fd
)
{
close
(
sv
[
1
]);
if
(
writeEnd
==
0
)
writeEnd
=
*
fd
;
xdup2
(
sv
[
0
],
STDIN_FILENO
);
xdup2
(
writeEnd
,
STDOUT_FILENO
);
xdup2
(
sv
[
0
],
STDOUT_FILENO
);
if
(
err
)
xdup2
(
writeEnd
,
STDERR_FILENO
);
xdup2
(
sv
[
0
],
STDERR_FILENO
);
}
}
execv
(
path
,
argv
);
execv
(
path
,
argv
);
...
@@ -426,8 +431,8 @@ int get_img_size(const char *img, int *used, int *total) {
...
@@ -426,8 +431,8 @@ int get_img_size(const char *img, int *used, int *total) {
char
buffer
[
PATH_MAX
];
char
buffer
[
PATH_MAX
];
snprintf
(
buffer
,
sizeof
(
buffer
),
"e2fsck -n %s 2>/dev/null | tail -n 1"
,
img
);
snprintf
(
buffer
,
sizeof
(
buffer
),
"e2fsck -n %s 2>/dev/null | tail -n 1"
,
img
);
char
*
const
command
[]
=
{
"sh"
,
"-c"
,
buffer
,
NULL
};
char
*
const
command
[]
=
{
"sh"
,
"-c"
,
buffer
,
NULL
};
int
pid
,
fd
;
int
pid
,
fd
=
0
;
pid
=
run_command
(
&
fd
,
"/system/bin/sh"
,
command
);
pid
=
run_command
(
0
,
&
fd
,
"/system/bin/sh"
,
command
);
fdgets
(
buffer
,
sizeof
(
buffer
),
fd
);
fdgets
(
buffer
,
sizeof
(
buffer
),
fd
);
close
(
fd
);
close
(
fd
);
if
(
pid
==
-
1
)
if
(
pid
==
-
1
)
...
...
jni/utils/utils.h
View file @
6c0ba66f
...
@@ -82,7 +82,7 @@ void ps_filter_proc_name(const char *filter, void (*func)(int));
...
@@ -82,7 +82,7 @@ void ps_filter_proc_name(const char *filter, void (*func)(int));
int
create_links
(
const
char
*
bin
,
const
char
*
path
);
int
create_links
(
const
char
*
bin
,
const
char
*
path
);
void
unlock_blocks
();
void
unlock_blocks
();
void
setup_sighandlers
(
void
(
*
handler
)(
int
));
void
setup_sighandlers
(
void
(
*
handler
)(
int
));
int
run_command
(
int
*
fd
,
const
char
*
path
,
char
*
const
argv
[]);
int
run_command
(
int
err
,
int
*
fd
,
const
char
*
path
,
char
*
const
argv
[]);
int
mkdir_p
(
const
char
*
pathname
,
mode_t
mode
);
int
mkdir_p
(
const
char
*
pathname
,
mode_t
mode
);
int
bind_mount
(
const
char
*
from
,
const
char
*
to
);
int
bind_mount
(
const
char
*
from
,
const
char
*
to
);
int
open_new
(
const
char
*
filename
);
int
open_new
(
const
char
*
filename
);
...
...
scripts/magisk_uninstaller.sh
View file @
6c0ba66f
...
@@ -148,7 +148,7 @@ rm -f stock_boot.img
...
@@ -148,7 +148,7 @@ rm -f stock_boot.img
ui_print_wrap
"- Removing Magisk files"
ui_print_wrap
"- Removing Magisk files"
rm
-rf
/cache/magisk.log /cache/last_magisk.log /cache/magiskhide.log /cache/.disable_magisk
\
rm
-rf
/cache/magisk.log /cache/last_magisk.log /cache/magiskhide.log /cache/.disable_magisk
\
/cache/magisk /cache/magisk_merge /cache/magisk_mount /cache/unblock /cache/magisk_uninstaller.sh
\
/cache/magisk /cache/magisk_merge /cache/magisk_mount /cache/unblock /cache/magisk_uninstaller.sh
\
/data/Magisk.apk /data/magisk.apk /data/magisk.img /data/magisk_merge.img
\
/data/Magisk.apk /data/magisk.apk /data/magisk.img /data/magisk_merge.img
/data/magisk_debug.log
\
/data/busybox /data/magisk /data/custom_ramdisk_patch.sh 2>/dev/null
/data/busybox /data/magisk /data/custom_ramdisk_patch.sh 2>/dev/null
$BOOTMODE
&&
reboot
$BOOTMODE
&&
reboot
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment