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
3a0e3c98
Commit
3a0e3c98
authored
Jan 09, 2020
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor adjustments to prevent crashes
parent
fafa92d4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
27 deletions
+16
-27
rootdir.cpp
native/jni/init/rootdir.cpp
+16
-27
No files found.
native/jni/init/rootdir.cpp
View file @
3a0e3c98
...
@@ -221,46 +221,35 @@ static void sbin_overlay(const raw_data &self, const raw_data &config) {
...
@@ -221,46 +221,35 @@ static void sbin_overlay(const raw_data &self, const raw_data &config) {
xsymlink
(
"./magiskinit"
,
"/sbin/supolicy"
);
xsymlink
(
"./magiskinit"
,
"/sbin/supolicy"
);
}
}
static
void
recreate_sbin
(
const
char
*
mirror
)
{
static
void
recreate_sbin
(
const
char
*
mirror
,
bool
use_bind_mount
)
{
int
src
=
xopen
(
mirror
,
O_RDONLY
|
O_CLOEXEC
);
auto
dp
=
xopen_dir
(
mirror
);
int
dest
=
xopen
(
"/sbin"
,
O_RDONLY
|
O_CLOEXEC
);
int
src
=
dirfd
(
dp
.
get
());
DIR
*
fp
=
fdopendir
(
src
);
char
buf
[
4096
];
char
buf
[
256
];
for
(
dirent
*
entry
;
(
entry
=
xreaddir
(
dp
.
get
()));)
{
bool
use_bind_mount
=
true
;
for
(
dirent
*
entry
;
(
entry
=
xreaddir
(
fp
));)
{
if
(
entry
->
d_name
==
"."
sv
||
entry
->
d_name
==
".."
sv
)
if
(
entry
->
d_name
==
"."
sv
||
entry
->
d_name
==
".."
sv
)
continue
;
continue
;
string
sbin_path
=
"/sbin/"
s
+
entry
->
d_name
;
struct
stat
st
;
struct
stat
st
;
fstatat
(
src
,
entry
->
d_name
,
&
st
,
AT_SYMLINK_NOFOLLOW
);
fstatat
(
src
,
entry
->
d_name
,
&
st
,
AT_SYMLINK_NOFOLLOW
);
if
(
S_ISLNK
(
st
.
st_mode
))
{
if
(
S_ISLNK
(
st
.
st_mode
))
{
xreadlinkat
(
src
,
entry
->
d_name
,
buf
,
sizeof
(
buf
));
xreadlinkat
(
src
,
entry
->
d_name
,
buf
,
sizeof
(
buf
));
xsymlink
at
(
buf
,
dest
,
entry
->
d_name
);
xsymlink
(
buf
,
sbin_path
.
data
()
);
}
else
{
}
else
{
char
sbin_path
[
256
];
sprintf
(
buf
,
"%s/%s"
,
mirror
,
entry
->
d_name
);
sprintf
(
buf
,
"%s/%s"
,
mirror
,
entry
->
d_name
);
sprintf
(
sbin_path
,
"/sbin/%s"
,
entry
->
d_name
);
if
(
use_bind_mount
)
{
if
(
use_bind_mount
)
{
auto
mode
=
st
.
st_mode
&
0777
;
// Create dummy
// Create dummy
if
(
S_ISDIR
(
st
.
st_mode
))
if
(
S_ISDIR
(
st
.
st_mode
))
xmkdir
(
sbin_path
,
st
.
st_mode
&
0777
);
xmkdir
(
sbin_path
.
data
(),
mode
);
else
else
close
(
xopen
(
sbin_path
,
O_CREAT
|
O_WRONLY
|
O_CLOEXEC
,
st
.
st_mode
&
0777
));
close
(
xopen
(
sbin_path
.
data
(),
O_CREAT
|
O_WRONLY
|
O_CLOEXEC
,
mode
));
if
(
xmount
(
buf
,
sbin_path
,
nullptr
,
MS_BIND
,
nullptr
))
{
// Bind mount failed, fallback to symlink
remove
(
sbin_path
);
use_bind_mount
=
false
;
}
else
{
continue
;
}
}
xsymlink
(
buf
,
sbin_path
);
xmount
(
buf
,
sbin_path
.
data
(),
nullptr
,
MS_BIND
,
nullptr
);
}
else
{
xsymlink
(
buf
,
sbin_path
.
data
());
}
}
}
}
}
close
(
src
);
close
(
dest
);
}
}
#define ROOTMIR MIRRDIR "/system_root"
#define ROOTMIR MIRRDIR "/system_root"
...
@@ -304,7 +293,7 @@ void SARBase::patch_rootdir() {
...
@@ -304,7 +293,7 @@ void SARBase::patch_rootdir() {
xmount
(
ROOTBLK
,
ROOTMIR
,
"erofs"
,
MS_RDONLY
,
nullptr
);
xmount
(
ROOTBLK
,
ROOTMIR
,
"erofs"
,
MS_RDONLY
,
nullptr
);
// Recreate original sbin structure
// Recreate original sbin structure
recreate_sbin
(
ROOTMIR
"/sbin"
);
recreate_sbin
(
ROOTMIR
"/sbin"
,
true
);
// Patch init
// Patch init
raw_data
init
;
raw_data
init
;
...
@@ -491,7 +480,7 @@ int magisk_proxy_main(int argc, char *argv[]) {
...
@@ -491,7 +480,7 @@ int magisk_proxy_main(int argc, char *argv[]) {
sbin_overlay
(
self
,
config
);
sbin_overlay
(
self
,
config
);
// Create symlinks pointing back to /root
// Create symlinks pointing back to /root
recreate_sbin
(
"/root"
);
recreate_sbin
(
"/root"
,
false
);
setenv
(
"REMOUNT_ROOT"
,
"1"
,
1
);
setenv
(
"REMOUNT_ROOT"
,
"1"
,
1
);
execv
(
"/sbin/magisk"
,
argv
);
execv
(
"/sbin/magisk"
,
argv
);
...
...
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