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
09935e59
Commit
09935e59
authored
Jun 25, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Proper SARInit test
parent
4a212dba
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
15 deletions
+36
-15
init.cpp
native/jni/init/init.cpp
+36
-15
No files found.
native/jni/init/init.cpp
View file @
09935e59
...
@@ -45,6 +45,16 @@ static void setup_klog() {
...
@@ -45,6 +45,16 @@ static void setup_klog() {
unlink
(
"/kmsg"
);
unlink
(
"/kmsg"
);
log_cb
.
d
=
log_cb
.
i
=
log_cb
.
w
=
log_cb
.
e
=
vprintk
;
log_cb
.
d
=
log_cb
.
i
=
log_cb
.
w
=
log_cb
.
e
=
vprintk
;
log_cb
.
ex
=
nop_ex
;
log_cb
.
ex
=
nop_ex
;
// Prevent file descriptor confusion
mknod
(
"/null"
,
S_IFCHR
|
0666
,
makedev
(
1
,
3
));
int
null
=
open
(
"/null"
,
O_RDWR
|
O_CLOEXEC
);
unlink
(
"/null"
);
xdup3
(
null
,
STDIN_FILENO
,
O_CLOEXEC
);
xdup3
(
null
,
STDOUT_FILENO
,
O_CLOEXEC
);
xdup3
(
null
,
STDERR_FILENO
,
O_CLOEXEC
);
if
(
null
>
STDERR_FILENO
)
close
(
null
);
}
}
#else
#else
#define setup_klog(...)
#define setup_klog(...)
...
@@ -158,6 +168,31 @@ public:
...
@@ -158,6 +168,31 @@ public:
}
}
};
};
static
void
setup_test
(
const
char
*
dir
)
{
// Log to console
cmdline_logging
();
log_cb
.
ex
=
nop_ex
;
// Switch to isolate namespace
xunshare
(
CLONE_NEWNS
);
xmount
(
nullptr
,
"/"
,
nullptr
,
MS_PRIVATE
|
MS_REC
,
nullptr
);
// Unmount everything in reverse
vector
<
string
>
mounts
;
parse_mnt
(
"/proc/mounts"
,
[
&
](
mntent
*
me
)
{
if
(
me
->
mnt_dir
!=
"/"
sv
)
mounts
.
emplace_back
(
me
->
mnt_dir
);
return
true
;
});
for
(
auto
m
=
mounts
.
rbegin
();
m
!=
mounts
.
rend
();
++
m
)
xumount
(
m
->
data
());
// chroot jail
chdir
(
dir
);
chroot
(
"."
);
chdir
(
"/"
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
umask
(
0
);
umask
(
0
);
...
@@ -180,25 +215,11 @@ int main(int argc, char *argv[]) {
...
@@ -180,25 +215,11 @@ int main(int argc, char *argv[]) {
#endif
#endif
if
(
run_test
)
{
if
(
run_test
)
{
chdir
(
dirname
(
argv
[
0
]));
setup_test
(
dirname
(
argv
[
0
]));
chroot
(
"."
);
chdir
(
"/"
);
cmdline_logging
();
log_cb
.
ex
=
nop_ex
;
}
else
{
}
else
{
if
(
getpid
()
!=
1
)
if
(
getpid
()
!=
1
)
return
1
;
return
1
;
setup_klog
();
setup_klog
();
// Prevent file descriptor confusion
mknod
(
"/null"
,
S_IFCHR
|
0666
,
makedev
(
1
,
3
));
int
null
=
open
(
"/null"
,
O_RDWR
|
O_CLOEXEC
);
unlink
(
"/null"
);
xdup3
(
null
,
STDIN_FILENO
,
O_CLOEXEC
);
xdup3
(
null
,
STDOUT_FILENO
,
O_CLOEXEC
);
xdup3
(
null
,
STDERR_FILENO
,
O_CLOEXEC
);
if
(
null
>
STDERR_FILENO
)
close
(
null
);
}
}
cmdline
cmd
{};
cmdline
cmd
{};
...
...
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