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
742dc137
Commit
742dc137
authored
Dec 05, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More fail proof to magiskinit
parent
39a6bd33
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
14 deletions
+24
-14
magiskinit.c
core/jni/core/magiskinit.c
+24
-14
No files found.
core/jni/core/magiskinit.c
View file @
742dc137
...
@@ -21,6 +21,7 @@
...
@@ -21,6 +21,7 @@
*/
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <unistd.h>
#include <unistd.h>
...
@@ -385,7 +386,6 @@ static void magisk_init_daemon() {
...
@@ -385,7 +386,6 @@ static void magisk_init_daemon() {
exit
(
1
);
exit
(
1
);
}
}
}
}
exit
(
0
);
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
...
@@ -403,6 +403,14 @@ int main(int argc, char *argv[]) {
...
@@ -403,6 +403,14 @@ int main(int argc, char *argv[]) {
return
dump_magiskrc
(
argv
[
3
],
0755
);
return
dump_magiskrc
(
argv
[
3
],
0755
);
}
}
// Prevent file descriptor confusion
mknod
(
"/null"
,
S_IFCHR
|
0666
,
makedev
(
1
,
3
));
int
null
=
open
(
"/null"
,
O_RDWR
|
O_CLOEXEC
);
unlink
(
"/null"
);
dup3
(
null
,
STDIN_FILENO
,
O_CLOEXEC
);
dup3
(
null
,
STDOUT_FILENO
,
O_CLOEXEC
);
dup3
(
null
,
STDERR_FILENO
,
O_CLOEXEC
);
// Extract and link files
// Extract and link files
mkdir
(
"/overlay"
,
0000
);
mkdir
(
"/overlay"
,
0000
);
dump_magiskrc
(
"/overlay/init.magisk.rc"
,
0750
);
dump_magiskrc
(
"/overlay/init.magisk.rc"
,
0750
);
...
@@ -456,24 +464,26 @@ int main(int argc, char *argv[]) {
...
@@ -456,24 +464,26 @@ int main(int argc, char *argv[]) {
link
(
"/.backup/init"
,
"/init"
);
link
(
"/.backup/init"
,
"/init"
);
}
}
int
overlay
=
open
(
"/overlay"
,
O_RDONLY
|
O_CLOEXEC
);
// Only patch initramfs if not intended to run in recovery (legacy devices)
mv_dir
(
overlay
,
root
);
if
(
access
(
"/etc/recovery.fstab"
,
F_OK
)
!=
0
)
{
int
overlay
=
open
(
"/overlay"
,
O_RDONLY
|
O_CLOEXEC
);
// Clean up
mv_dir
(
overlay
,
root
);
rmdir
(
"/overlay"
);
close
(
overlay
);
close
(
root
);
patch_ramdisk
();
// Clean up
patch_sepolicy
();
rmdir
(
"/overlay"
);
close
(
overlay
);
close
(
root
);
umount
(
"/vendor"
);
patch_ramdisk
();
patch_sepolicy
();
if
(
fork_dont_care
()
==
0
)
{
if
(
fork_dont_care
()
==
0
)
{
strcpy
(
argv
[
0
],
"magiskinit"
);
strcpy
(
argv
[
0
],
"magiskinit"
);
magisk_init_daemon
();
magisk_init_daemon
();
}
}
}
umount
(
"/vendor"
);
// Finally, give control back!
// Finally, give control back!
execv
(
"/init"
,
argv
);
execv
(
"/init"
,
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