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
754fafcf
Commit
754fafcf
authored
Feb 11, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check logd before logging
parent
bd7766b1
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
28 deletions
+73
-28
daemon.c
native/jni/core/daemon.c
+3
-3
log_monitor.c
native/jni/core/log_monitor.c
+52
-19
daemon.h
native/jni/include/daemon.h
+6
-6
logging.h
native/jni/include/logging.h
+1
-0
magiskhide.c
native/jni/magiskhide/magiskhide.c
+11
-0
No files found.
native/jni/core/daemon.c
View file @
754fafcf
...
...
@@ -265,6 +265,9 @@ void start_daemon() {
exit
(
1
);
xlisten
(
fd
,
10
);
// Start the log monitor
monitor_logs
();
if
((
is_daemon_init
=
(
access
(
MAGISKTMP
,
F_OK
)
==
0
)))
{
// Restart stuffs if the daemon is restarted
exec_command_sync
(
"logcat"
,
"-b"
,
"all"
,
"-c"
,
NULL
);
...
...
@@ -274,9 +277,6 @@ void start_daemon() {
daemon_init
();
}
// Start the log monitor
monitor_logs
();
LOGI
(
"Magisk v"
xstr
(
MAGISK_VERSION
)
"("
xstr
(
MAGISK_VER_CODE
)
") daemon started
\n
"
);
// Change process name
...
...
native/jni/core/log_monitor.c
View file @
754fafcf
...
...
@@ -12,8 +12,10 @@
#include "magisk.h"
#include "utils.h"
#include "resetprop.h"
extern
int
is_daemon_init
;
int
logd
=
0
;
static
int
am_proc_start_filter
(
const
char
*
log
)
{
return
strstr
(
log
,
"am_proc_start"
)
!=
NULL
;
...
...
@@ -44,9 +46,20 @@ struct log_listener log_events[] = {
};
#ifdef MAGISK_DEBUG
static
int
debug_log_pid
,
debug_log_fd
;
static
int
debug_log_pid
=
-
1
,
debug_log_fd
=
-
1
;
#endif
static
void
check_logd
()
{
char
*
prop
=
getprop
(
"init.svc.logd"
);
if
(
prop
!=
NULL
)
{
free
(
prop
);
logd
=
1
;
}
else
{
LOGD
(
"log_monitor: logd not started, disable logging"
);
logd
=
0
;
}
}
static
void
*
logger_thread
(
void
*
args
)
{
int
log_fd
=
-
1
,
log_pid
;
char
line
[
4096
];
...
...
@@ -54,6 +67,15 @@ static void *logger_thread(void *args) {
LOGD
(
"log_monitor: logger start"
);
while
(
1
)
{
if
(
!
logd
)
{
// Disable all services
for
(
int
i
=
0
;
i
<
(
sizeof
(
log_events
)
/
sizeof
(
struct
log_listener
));
++
i
)
{
close
(
log_events
[
i
].
fd
);
log_events
[
i
].
fd
=
-
1
;
}
return
NULL
;
}
// Start logcat
log_pid
=
exec_command
(
0
,
&
log_fd
,
NULL
,
"logcat"
,
"-b"
,
"events"
,
"-b"
,
"main"
,
"-v"
,
"threadtime"
,
"-s"
,
"am_proc_start"
,
"-s"
,
"Magisk"
,
NULL
);
while
(
fdgets
(
line
,
sizeof
(
line
),
log_fd
))
{
...
...
@@ -75,6 +97,8 @@ static void *logger_thread(void *args) {
// Clear buffer before restart
exec_command_sync
(
"logcat"
,
"-b"
,
"events"
,
"-b"
,
"main"
,
"-c"
,
NULL
);
check_logd
();
}
// Should never be here, but well...
...
...
@@ -139,6 +163,9 @@ static void *debug_magisk_log_thread(void *args) {
void
monitor_logs
()
{
pthread_t
thread
;
check_logd
();
if
(
logd
)
{
// Start log file dumper before monitor
xpthread_create
(
&
thread
,
NULL
,
magisk_log_thread
,
NULL
);
pthread_detach
(
thread
);
...
...
@@ -146,33 +173,39 @@ void monitor_logs() {
// Start logcat monitor
xpthread_create
(
&
thread
,
NULL
,
logger_thread
,
NULL
);
pthread_detach
(
thread
);
}
}
void
start_debug_full_log
()
{
#ifdef MAGISK_DEBUG
if
(
logd
)
{
// Log everything initially
debug_log_fd
=
xopen
(
DEBUG_LOG
,
O_WRONLY
|
O_CREAT
|
O_CLOEXEC
|
O_TRUNC
,
0644
);
debug_log_pid
=
exec_command
(
0
,
&
debug_log_fd
,
NULL
,
"logcat"
,
"-v"
,
"threadtime"
,
NULL
);
close
(
debug_log_fd
);
}
#endif
}
void
stop_debug_full_log
()
{
#ifdef MAGISK_DEBUG
// Stop recording the boot logcat after every boot task is done
if
(
debug_log_pid
>
0
)
{
kill
(
debug_log_pid
,
SIGTERM
);
waitpid
(
debug_log_pid
,
NULL
,
0
);
// Start debug thread
start_debug_log
();
}
#endif
}
void
start_debug_log
()
{
#ifdef MAGISK_DEBUG
if
(
logd
)
{
pthread_t
thread
;
// Start debug thread
xpthread_create
(
&
thread
,
NULL
,
debug_magisk_log_thread
,
NULL
);
pthread_detach
(
thread
);
}
#endif
}
native/jni/include/daemon.h
View file @
754fafcf
...
...
@@ -13,18 +13,17 @@ extern int is_daemon_init, seperate_vendor;
// Commands require connecting to daemon
enum
{
DO_NOTHING
=
0
,
LAUNCH_MAGISKHIDE
,
STOP_MAGISKHIDE
,
ADD_HIDELIST
,
RM_HIDELIST
,
LS_HIDELIST
,
SUPERUSER
,
CHECK_VERSION
,
CHECK_VERSION_CODE
,
POST_FS
,
POST_FS_DATA
,
LATE_START
,
TEST
LAUNCH_MAGISKHIDE
,
STOP_MAGISKHIDE
,
ADD_HIDELIST
,
RM_HIDELIST
,
LS_HIDELIST
};
// Return codes for daemon
...
...
@@ -32,6 +31,7 @@ enum {
DAEMON_ERROR
=
-
1
,
DAEMON_SUCCESS
=
0
,
ROOT_REQUIRED
,
LOGD_DISABLED
,
HIDE_IS_ENABLED
,
HIDE_NOT_ENABLED
,
HIDE_ITEM_EXIST
,
...
...
native/jni/include/logging.h
View file @
754fafcf
...
...
@@ -58,6 +58,7 @@ struct log_listener {
};
extern
struct
log_listener
log_events
[];
extern
int
logd
;
void
monitor_logs
();
void
start_debug_full_log
();
...
...
native/jni/magiskhide/magiskhide.c
View file @
754fafcf
...
...
@@ -49,6 +49,14 @@ void launch_magiskhide(int client) {
return
;
}
if
(
!
logd
)
{
if
(
client
>
0
)
{
write_int
(
client
,
LOGD_DISABLED
);
close
(
client
);
}
return
;
}
hideEnabled
=
1
;
LOGI
(
"* Starting MagiskHide
\n
"
);
...
...
@@ -136,6 +144,9 @@ int magiskhide_main(int argc, char *argv[]) {
case
ROOT_REQUIRED
:
fprintf
(
stderr
,
"Root is required for this operation
\n
"
);
return
code
;
case
LOGD_DISABLED
:
fprintf
(
stderr
,
"Logd is not running, cannot run logcat
\n
"
);
return
(
code
);
case
HIDE_NOT_ENABLED
:
fprintf
(
stderr
,
"Magisk hide is not enabled yet
\n
"
);
return
code
;
...
...
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