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) {
xsymlink
(
"./magiskinit"
,
"/sbin/supolicy"
);
}
static
void
recreate_sbin
(
const
char
*
mirror
)
{
int
src
=
xopen
(
mirror
,
O_RDONLY
|
O_CLOEXEC
);
int
dest
=
xopen
(
"/sbin"
,
O_RDONLY
|
O_CLOEXEC
);
DIR
*
fp
=
fdopendir
(
src
);
char
buf
[
256
];
bool
use_bind_mount
=
true
;
for
(
dirent
*
entry
;
(
entry
=
xreaddir
(
fp
));)
{
static
void
recreate_sbin
(
const
char
*
mirror
,
bool
use_bind_mount
)
{
auto
dp
=
xopen_dir
(
mirror
);
int
src
=
dirfd
(
dp
.
get
());
char
buf
[
4096
];
for
(
dirent
*
entry
;
(
entry
=
xreaddir
(
dp
.
get
()));)
{
if
(
entry
->
d_name
==
"."
sv
||
entry
->
d_name
==
".."
sv
)
continue
;
string
sbin_path
=
"/sbin/"
s
+
entry
->
d_name
;
struct
stat
st
;
fstatat
(
src
,
entry
->
d_name
,
&
st
,
AT_SYMLINK_NOFOLLOW
);
if
(
S_ISLNK
(
st
.
st_mode
))
{
xreadlinkat
(
src
,
entry
->
d_name
,
buf
,
sizeof
(
buf
));
xsymlink
at
(
buf
,
dest
,
entry
->
d_name
);
xsymlink
(
buf
,
sbin_path
.
data
()
);
}
else
{
char
sbin_path
[
256
];
sprintf
(
buf
,
"%s/%s"
,
mirror
,
entry
->
d_name
);
sprintf
(
sbin_path
,
"/sbin/%s"
,
entry
->
d_name
);
if
(
use_bind_mount
)
{
auto
mode
=
st
.
st_mode
&
0777
;
// Create dummy
if
(
S_ISDIR
(
st
.
st_mode
))
xmkdir
(
sbin_path
,
st
.
st_mode
&
0777
);
xmkdir
(
sbin_path
.
data
(),
mode
);
else
close
(
xopen
(
sbin_path
,
O_CREAT
|
O_WRONLY
|
O_CLOEXEC
,
st
.
st_mode
&
0777
));
if
(
xmount
(
buf
,
sbin_path
,
nullptr
,
MS_BIND
,
nullptr
))
{
// Bind mount failed, fallback to symlink
remove
(
sbin_path
);
use_bind_mount
=
false
;
}
else
{
continue
;
}
}
close
(
xopen
(
sbin_path
.
data
(),
O_CREAT
|
O_WRONLY
|
O_CLOEXEC
,
mode
));
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"
...
...
@@ -304,7 +293,7 @@ void SARBase::patch_rootdir() {
xmount
(
ROOTBLK
,
ROOTMIR
,
"erofs"
,
MS_RDONLY
,
nullptr
);
// Recreate original sbin structure
recreate_sbin
(
ROOTMIR
"/sbin"
);
recreate_sbin
(
ROOTMIR
"/sbin"
,
true
);
// Patch init
raw_data
init
;
...
...
@@ -491,7 +480,7 @@ int magisk_proxy_main(int argc, char *argv[]) {
sbin_overlay
(
self
,
config
);
// Create symlinks pointing back to /root
recreate_sbin
(
"/root"
);
recreate_sbin
(
"/root"
,
false
);
setenv
(
"REMOUNT_ROOT"
,
"1"
,
1
);
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