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
614c552e
Commit
614c552e
authored
Apr 21, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve daemon startup
parent
7db3d84b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
29 deletions
+33
-29
daemon.c
native/jni/core/daemon.c
+15
-13
magiskinit.c
native/jni/core/magiskinit.c
+18
-16
No files found.
native/jni/core/daemon.c
View file @
614c552e
...
...
@@ -137,29 +137,33 @@ void daemon_init() {
DIR
*
dir
;
struct
dirent
*
entry
;
int
root
,
sbin
,
fd
;
char
buf
[
PATH_MAX
]
,
buf2
[
PATH_MAX
]
;
void
*
data
;
size_t
size
;
char
buf
[
PATH_MAX
];
void
*
magisk
,
*
init
;
size_t
magisk_size
,
init_
size
;
// Create hardlink mirror of /sbin to /root
xmount
(
NULL
,
"/"
,
NULL
,
MS_REMOUNT
,
NULL
);
full_read
(
"/sbin/magisk"
,
&
data
,
&
size
);
mkdir
(
"/root"
,
0750
);
full_read
(
"/sbin/magisk"
,
&
magisk
,
&
magisk_size
);
full_read
(
"/sbin/magiskinit"
,
&
init
,
&
init_size
);
root
=
xopen
(
"/root"
,
O_RDONLY
|
O_CLOEXEC
);
sbin
=
xopen
(
"/sbin"
,
O_RDONLY
|
O_CLOEXEC
);
// unlink("/sbin/magisk");
unlink
(
"/sbin/magiskinit"
);
link_dir
(
sbin
,
root
);
unlink
(
"/sbin/magisk"
);
close
(
sbin
);
// Mount the /sbin tmpfs overlay
xmount
(
"tmpfs"
,
"/sbin"
,
"tmpfs"
,
0
,
NULL
);
chmod
(
"/sbin"
,
0755
);
setfilecon
(
"/sbin"
,
"u:object_r:rootfs:s0"
);
sbin
=
xopen
(
"/sbin"
,
O_RDONLY
|
O_CLOEXEC
);
// Setup magisk
fd
=
creat
(
"/sbin/magisk"
,
0755
);
xwrite
(
fd
,
data
,
size
);
xwrite
(
fd
,
magisk
,
magisk_
size
);
close
(
fd
);
free
(
data
);
free
(
magisk
);
setfilecon
(
"/sbin/magisk"
,
"u:object_r:"
SEPOL_FILE_DOMAIN
":s0"
);
for
(
int
i
=
0
;
applet
[
i
];
++
i
)
{
snprintf
(
buf
,
PATH_MAX
,
"/sbin/%s"
,
applet
[
i
]);
...
...
@@ -167,12 +171,10 @@ void daemon_init() {
}
// Setup magiskinit
full_read
(
"/root/magiskinit"
,
&
data
,
&
size
);
unlink
(
"/root/magiskinit"
);
fd
=
creat
(
"/sbin/magiskinit"
,
0755
);
xwrite
(
fd
,
data
,
size
);
xwrite
(
fd
,
init
,
init_
size
);
close
(
fd
);
free
(
data
);
free
(
init
);
setfilecon
(
"/sbin/magiskinit"
,
"u:object_r:"
SEPOL_FILE_DOMAIN
":s0"
);
for
(
int
i
=
0
;
init_applet
[
i
];
++
i
)
{
snprintf
(
buf
,
PATH_MAX
,
"/sbin/%s"
,
init_applet
[
i
]);
...
...
@@ -184,10 +186,10 @@ void daemon_init() {
while
((
entry
=
xreaddir
(
dir
)))
{
if
(
strcmp
(
entry
->
d_name
,
"."
)
==
0
||
strcmp
(
entry
->
d_name
,
".."
)
==
0
)
continue
;
snprintf
(
buf
,
PATH_MAX
,
"/root/%s"
,
entry
->
d_name
);
snprintf
(
buf2
,
PATH_MAX
,
"/sbin/%s"
,
entry
->
d_name
);
xsymlink
(
buf
,
buf2
);
symlinkat
(
buf
,
sbin
,
entry
->
d_name
);
}
close
(
sbin
);
close
(
root
);
xmount
(
NULL
,
"/"
,
NULL
,
MS_REMOUNT
|
MS_RDONLY
,
NULL
);
...
...
native/jni/core/magiskinit.c
View file @
614c552e
...
...
@@ -375,14 +375,8 @@ int main(int argc, char *argv[]) {
if
(
null
>
STDERR_FILENO
)
close
(
null
);
// Extract and link files
mkdir
(
"/overlay"
,
0000
);
dump_magiskrc
(
"/overlay/init.magisk.rc"
,
0750
);
mkdir
(
"/overlay/sbin"
,
0755
);
dump_magisk
(
"/overlay/sbin/magisk"
,
0755
);
patch_socket_name
(
"/overlay/sbin/magisk"
);
mkdir
(
"/overlay/root"
,
0750
);
link
(
"/init"
,
"/overlay/root/magiskinit"
);
// Backup self
link
(
"/init"
,
"/init.bak"
);
struct
cmdline
cmd
;
parse_cmdline
(
&
cmd
);
...
...
@@ -395,7 +389,7 @@ int main(int argc, char *argv[]) {
if
(
cmd
.
skip_initramfs
)
{
// Clear rootfs
excl_list
=
(
char
*
[])
{
"overlay"
,
".backup"
,
NULL
};
excl_list
=
(
char
*
[])
{
"overlay"
,
".backup"
,
"init.bak"
,
NULL
};
frm_rf
(
root
);
}
else
if
(
access
(
"/ramdisk.cpio.xz"
,
R_OK
)
==
0
)
{
// High compression mode
...
...
@@ -464,20 +458,28 @@ int main(int argc, char *argv[]) {
// Only patch rootfs if not intended to run in recovery
if
(
access
(
"/etc/recovery.fstab"
,
F_OK
)
!=
0
)
{
int
overlay
=
open
(
"/overlay"
,
O_RDONLY
|
O_CLOEXEC
);
mv_dir
(
overlay
,
root
);
close
(
overlay
);
rmdir
(
"/overlay"
);
int
fd
;
// Handle ramdisk overlays
fd
=
open
(
"/overlay"
,
O_RDONLY
|
O_CLOEXEC
);
if
(
fd
>=
0
)
{
mv_dir
(
fd
,
root
);
close
(
fd
);
rmdir
(
"/overlay"
);
}
patch_ramdisk
();
patch_sepolicy
();
// Dump binaries
dump_magiskrc
(
"/init.magisk.rc"
,
0750
);
dump_magisk
(
"/sbin/magisk"
,
0755
);
patch_socket_name
(
"/sbin/magisk"
);
rename
(
"/init.bak"
,
"/sbin/magiskinit"
);
}
// Clean up
close
(
root
);
close
(
STDIN_FILENO
);
close
(
STDOUT_FILENO
);
close
(
STDERR_FILENO
);
if
(
!
cmd
.
skip_initramfs
)
umount
(
"/system"
);
umount
(
"/vendor"
);
...
...
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