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
9430dbb9
Commit
9430dbb9
authored
Feb 14, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure logcat process does not become a zombie
parent
4872df6a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
14 deletions
+48
-14
bootstages.cpp
native/jni/core/bootstages.cpp
+16
-4
daemon.cpp
native/jni/core/daemon.cpp
+3
-6
hide_utils.cpp
native/jni/magiskhide/hide_utils.cpp
+2
-4
utils.h
native/jni/utils/include/utils.h
+4
-0
misc.cpp
native/jni/utils/misc.cpp
+23
-0
No files found.
native/jni/core/bootstages.cpp
View file @
9430dbb9
...
...
@@ -645,11 +645,23 @@ static void dump_logs() {
if
(
test
!=
0
)
return
;
rename
(
LOGFILE
,
LOGFILE
".bak"
);
int
fd
=
xopen
(
LOGFILE
,
O_WRONLY
|
O_APPEND
|
O_CREAT
|
O_CLOEXEC
,
0644
);
exec_t
exec
{
.
fd
=
fd
};
exec_command
(
exec
,
"/system/bin/logcat"
,
"-s"
,
"Magisk"
);
log_dump
=
true
;
close
(
fd
);
// Start a daemon thread and wait indefinitely
new_daemon_thread
([](
auto
)
->
void
*
{
int
fd
=
xopen
(
LOGFILE
,
O_WRONLY
|
O_APPEND
|
O_CREAT
|
O_CLOEXEC
,
0644
);
exec_t
exec
{
.
fd
=
fd
,
.
fork
=
fork_no_zombie
};
int
pid
=
exec_command
(
exec
,
"/system/bin/logcat"
,
"-s"
,
"Magisk"
);
close
(
fd
);
if
(
pid
<
0
)
{
log_dump
=
false
;
return
nullptr
;
}
waitpid
(
pid
,
nullptr
,
0
);
return
nullptr
;
});
}
/****************
...
...
native/jni/core/daemon.cpp
View file @
9430dbb9
...
...
@@ -140,20 +140,17 @@ static void main_daemon() {
pthread_sigmask
(
SIG_SETMASK
,
&
block_set
,
nullptr
);
// Loop forever to listen for requests
while
(
true
)
{
for
(;;
)
{
int
*
client
=
new
int
;
*
client
=
xaccept4
(
fd
,
nullptr
,
nullptr
,
SOCK_CLOEXEC
);
pthread_t
thread
;
xpthread_create
(
&
thread
,
nullptr
,
request_handler
,
client
);
// Detach the thread, we will never join it
pthread_detach
(
thread
);
new_daemon_thread
(
request_handler
,
client
);
}
}
int
switch_mnt_ns
(
int
pid
)
{
char
mnt
[
32
];
snprintf
(
mnt
,
sizeof
(
mnt
),
"/proc/%d/ns/mnt"
,
pid
);
if
(
access
(
mnt
,
R_OK
)
==
-
1
)
return
1
;
// Maybe process died..
if
(
access
(
mnt
,
R_OK
)
==
-
1
)
return
1
;
// Maybe process died..
int
fd
,
ret
;
fd
=
xopen
(
mnt
,
O_RDONLY
);
...
...
native/jni/magiskhide/hide_utils.cpp
View file @
9430dbb9
...
...
@@ -366,11 +366,9 @@ void auto_start_magiskhide() {
db_settings
dbs
;
get_db_settings
(
&
dbs
,
HIDE_CONFIG
);
if
(
dbs
[
HIDE_CONFIG
])
{
pthread_t
thread
;
xpthread_create
(
&
thread
,
nullptr
,
[](
void
*
)
->
void
*
{
new_daemon_thread
([](
auto
)
->
void
*
{
launch_magiskhide
(
-
1
);
return
nullptr
;
},
nullptr
);
pthread_detach
(
thread
);
});
}
}
native/jni/utils/include/utils.h
View file @
9430dbb9
...
...
@@ -82,6 +82,7 @@ unsigned get_shell_uid();
unsigned
get_system_uid
();
unsigned
get_radio_uid
();
int
fork_dont_care
();
int
fork_no_zombie
();
void
gen_rand_str
(
char
*
buf
,
int
len
);
int
strend
(
const
char
*
s1
,
const
char
*
s2
);
...
...
@@ -147,6 +148,9 @@ std::vector<std::string> file_to_vector(const char *filename);
// misc.cpp
int
new_daemon_thread
(
void
*
(
*
start_routine
)
(
void
*
),
void
*
arg
=
nullptr
,
const
pthread_attr_t
*
attr
=
nullptr
);
struct
exec_t
{
bool
err
=
false
;
int
fd
=
-
2
;
...
...
native/jni/utils/misc.cpp
View file @
9430dbb9
...
...
@@ -10,6 +10,7 @@
#include <syscall.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/prctl.h>
#include <sys/sysmacros.h>
#include <logging.h>
...
...
@@ -50,6 +51,20 @@ int fork_dont_care() {
return
0
;
}
int
fork_no_zombie
()
{
int
pid
=
xfork
();
if
(
pid
)
return
pid
;
// Unblock all signals
sigset_t
block_set
;
sigfillset
(
&
block_set
);
pthread_sigmask
(
SIG_UNBLOCK
,
&
block_set
,
nullptr
);
prctl
(
PR_SET_PDEATHSIG
,
SIGTERM
);
if
(
getppid
()
==
1
)
exit
(
1
);
return
0
;
}
void
gen_rand_str
(
char
*
buf
,
int
len
)
{
const
char
base
[]
=
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
;
int
urandom
;
...
...
@@ -201,3 +216,11 @@ int exec_command_sync(exec_t &exec) {
return
WEXITSTATUS
(
status
);
}
int
new_daemon_thread
(
void
*
(
*
start_routine
)
(
void
*
),
void
*
arg
,
const
pthread_attr_t
*
attr
)
{
pthread_t
thread
;
int
ret
=
xpthread_create
(
&
thread
,
attr
,
start_routine
,
arg
);
if
(
ret
==
0
)
pthread_detach
(
thread
);
return
ret
;
}
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