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
731455f1
Commit
731455f1
authored
Nov 26, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update exec functions signatures
parent
b01a8cac
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
18 deletions
+17
-18
bootstages.cpp
native/jni/daemon/bootstages.cpp
+3
-4
log_daemon.cpp
native/jni/daemon/log_daemon.cpp
+2
-2
utils.h
native/jni/utils/include/utils.h
+2
-2
misc.cpp
native/jni/utils/misc.cpp
+10
-10
No files found.
native/jni/daemon/bootstages.cpp
View file @
731455f1
...
@@ -317,7 +317,7 @@ static void exec_common_script(const char* stage) {
...
@@ -317,7 +317,7 @@ static void exec_common_script(const char* stage) {
if
(
access
(
entry
->
d_name
,
X_OK
)
==
-
1
)
if
(
access
(
entry
->
d_name
,
X_OK
)
==
-
1
)
continue
;
continue
;
LOGI
(
"%s.d: exec [%s]
\n
"
,
stage
,
entry
->
d_name
);
LOGI
(
"%s.d: exec [%s]
\n
"
,
stage
,
entry
->
d_name
);
int
pid
=
exec_command
(
0
,
nullptr
,
int
pid
=
exec_command
(
false
,
nullptr
,
strcmp
(
stage
,
"post-fs-data"
)
?
set_path
:
set_mirror_path
,
strcmp
(
stage
,
"post-fs-data"
)
?
set_path
:
set_mirror_path
,
"sh"
,
entry
->
d_name
,
nullptr
);
"sh"
,
entry
->
d_name
,
nullptr
);
if
(
pid
!=
-
1
)
if
(
pid
!=
-
1
)
...
@@ -336,8 +336,7 @@ static void exec_module_script(const char* stage) {
...
@@ -336,8 +336,7 @@ static void exec_module_script(const char* stage) {
if
(
access
(
buf2
,
F_OK
)
==
-
1
||
access
(
buf
,
F_OK
)
==
0
)
if
(
access
(
buf2
,
F_OK
)
==
-
1
||
access
(
buf
,
F_OK
)
==
0
)
continue
;
continue
;
LOGI
(
"%s: exec [%s.sh]
\n
"
,
module
,
stage
);
LOGI
(
"%s: exec [%s.sh]
\n
"
,
module
,
stage
);
int
pid
=
exec_command
(
int
pid
=
exec_command
(
false
,
nullptr
,
0
,
nullptr
,
strcmp
(
stage
,
"post-fs-data"
)
?
set_path
:
set_mirror_path
,
strcmp
(
stage
,
"post-fs-data"
)
?
set_path
:
set_mirror_path
,
"sh"
,
buf2
,
nullptr
);
"sh"
,
buf2
,
nullptr
);
if
(
pid
!=
-
1
)
if
(
pid
!=
-
1
)
...
@@ -555,7 +554,7 @@ static void install_apk(const char *apk) {
...
@@ -555,7 +554,7 @@ static void install_apk(const char *apk) {
sleep
(
5
);
sleep
(
5
);
LOGD
(
"apk_install: attempting to install APK"
);
LOGD
(
"apk_install: attempting to install APK"
);
int
apk_res
=
-
1
,
pid
;
int
apk_res
=
-
1
,
pid
;
pid
=
exec_command
(
1
,
&
apk_res
,
nullptr
,
"/system/bin/pm"
,
"install"
,
"-r"
,
apk
,
nullptr
);
pid
=
exec_command
(
true
,
&
apk_res
,
nullptr
,
"/system/bin/pm"
,
"install"
,
"-r"
,
apk
,
nullptr
);
if
(
pid
!=
-
1
)
{
if
(
pid
!=
-
1
)
{
int
err
=
0
;
int
err
=
0
;
while
(
fdgets
(
buf
,
PATH_MAX
,
apk_res
)
>
0
)
{
while
(
fdgets
(
buf
,
PATH_MAX
,
apk_res
)
>
0
)
{
...
...
native/jni/daemon/log_daemon.cpp
View file @
731455f1
...
@@ -83,7 +83,7 @@ static void *logcat_thread(void *) {
...
@@ -83,7 +83,7 @@ static void *logcat_thread(void *) {
char
line
[
4096
];
char
line
[
4096
];
while
(
1
)
{
while
(
1
)
{
// Start logcat
// Start logcat
log_pid
=
exec_array
(
0
,
&
log_fd
,
nullptr
,
log_cmd
.
data
());
log_pid
=
exec_array
(
false
,
&
log_fd
,
nullptr
,
log_cmd
.
data
());
FILE
*
logs
=
fdopen
(
log_fd
,
"r"
);
FILE
*
logs
=
fdopen
(
log_fd
,
"r"
);
while
(
fgets
(
line
,
sizeof
(
line
),
logs
))
{
while
(
fgets
(
line
,
sizeof
(
line
),
logs
))
{
if
(
line
[
0
]
==
'-'
)
if
(
line
[
0
]
==
'-'
)
...
@@ -104,7 +104,7 @@ static void *logcat_thread(void *) {
...
@@ -104,7 +104,7 @@ static void *logcat_thread(void *) {
LOGI
(
"magisklogd: logcat output EOF"
);
LOGI
(
"magisklogd: logcat output EOF"
);
// Clear buffer
// Clear buffer
log_pid
=
exec_array
(
0
,
nullptr
,
nullptr
,
clear_cmd
.
data
());
log_pid
=
exec_array
(
false
,
nullptr
,
nullptr
,
clear_cmd
.
data
());
waitpid
(
log_pid
,
nullptr
,
0
);
waitpid
(
log_pid
,
nullptr
,
0
);
}
}
}
}
...
...
native/jni/utils/include/utils.h
View file @
731455f1
...
@@ -91,8 +91,8 @@ unsigned get_system_uid();
...
@@ -91,8 +91,8 @@ unsigned get_system_uid();
unsigned
get_radio_uid
();
unsigned
get_radio_uid
();
ssize_t
fdgets
(
char
*
buf
,
size_t
size
,
int
fd
);
ssize_t
fdgets
(
char
*
buf
,
size_t
size
,
int
fd
);
int
is_num
(
const
char
*
s
);
int
is_num
(
const
char
*
s
);
int
exec_array
(
int
err
,
int
*
fd
,
void
(
*
cb
)(
void
),
const
char
*
argv
[]
);
int
exec_array
(
bool
err
,
int
*
fd
,
void
(
*
cb
)(
void
),
const
char
**
argv
);
int
exec_command
(
int
err
,
int
*
fd
,
void
(
*
cb
)(
void
),
const
char
*
argv0
,
...);
int
exec_command
(
bool
err
,
int
*
fd
,
void
(
*
cb
)(
void
),
const
char
*
argv0
,
...);
int
exec_command_sync
(
const
char
*
argv0
,
...);
int
exec_command_sync
(
const
char
*
argv0
,
...);
int
fork_dont_care
();
int
fork_dont_care
();
void
gen_rand_str
(
char
*
buf
,
int
len
);
void
gen_rand_str
(
char
*
buf
,
int
len
);
...
...
native/jni/utils/misc.cpp
View file @
731455f1
...
@@ -181,21 +181,21 @@ int __fsetxattr(int fd, const char *name, const void *value, size_t size, int fl
...
@@ -181,21 +181,21 @@ int __fsetxattr(int fd, const char *name, const void *value, size_t size, int fl
}
}
/*
/*
fd ==
NULL
-> Ignore output
fd ==
nullptr
-> Ignore output
*fd < 0 -> Open pipe and set *fd to the read end
*fd < 0 -> Open pipe and set *fd to the read end
*fd >= 0 -> STDOUT (or STDERR) will be redirected to *fd
*fd >= 0 -> STDOUT (or STDERR) will be redirected to *fd
*cb -> A callback function which calls after forking
*cb -> A callback function which calls after forking
*/
*/
int
exec_array
(
int
err
,
int
*
fd
,
void
(
*
cb
)(
void
),
const
char
*
argv
[]
)
{
int
exec_array
(
bool
err
,
int
*
fd
,
void
(
*
cb
)(
void
),
const
char
**
argv
)
{
int
pipefd
[
2
],
write_en
d
=
-
1
;
int
pipefd
[
2
],
outf
d
=
-
1
;
if
(
fd
)
{
if
(
fd
)
{
if
(
*
fd
<
0
)
{
if
(
*
fd
<
0
)
{
if
(
xpipe2
(
pipefd
,
O_CLOEXEC
)
==
-
1
)
if
(
xpipe2
(
pipefd
,
O_CLOEXEC
)
==
-
1
)
return
-
1
;
return
-
1
;
write_en
d
=
pipefd
[
1
];
outf
d
=
pipefd
[
1
];
}
else
{
}
else
{
write_en
d
=
*
fd
;
outf
d
=
*
fd
;
}
}
}
}
...
@@ -210,9 +210,9 @@ int exec_array(int err, int *fd, void (*cb)(void), const char *argv[]) {
...
@@ -210,9 +210,9 @@ int exec_array(int err, int *fd, void (*cb)(void), const char *argv[]) {
}
}
if
(
fd
)
{
if
(
fd
)
{
xdup2
(
write_en
d
,
STDOUT_FILENO
);
xdup2
(
outf
d
,
STDOUT_FILENO
);
if
(
err
)
if
(
err
)
xdup2
(
write_en
d
,
STDERR_FILENO
);
xdup2
(
outf
d
,
STDERR_FILENO
);
}
}
// Setup environment
// Setup environment
...
@@ -224,7 +224,7 @@ int exec_array(int err, int *fd, void (*cb)(void), const char *argv[]) {
...
@@ -224,7 +224,7 @@ int exec_array(int err, int *fd, void (*cb)(void), const char *argv[]) {
return
-
1
;
return
-
1
;
}
}
static
int
v_exec_command
(
int
err
,
int
*
fd
,
void
(
*
cb
)(
void
),
const
char
*
argv0
,
va_list
argv
)
{
static
int
v_exec_command
(
bool
err
,
int
*
fd
,
void
(
*
cb
)(
void
),
const
char
*
argv0
,
va_list
argv
)
{
// Collect va_list into vector
// Collect va_list into vector
Vector
<
const
char
*>
args
;
Vector
<
const
char
*>
args
;
args
.
push_back
(
argv0
);
args
.
push_back
(
argv0
);
...
@@ -239,7 +239,7 @@ int exec_command_sync(const char *argv0, ...) {
...
@@ -239,7 +239,7 @@ int exec_command_sync(const char *argv0, ...) {
va_list
argv
;
va_list
argv
;
va_start
(
argv
,
argv0
);
va_start
(
argv
,
argv0
);
int
pid
,
status
;
int
pid
,
status
;
pid
=
v_exec_command
(
0
,
NULL
,
NULL
,
argv0
,
argv
);
pid
=
v_exec_command
(
false
,
nullptr
,
nullptr
,
argv0
,
argv
);
va_end
(
argv
);
va_end
(
argv
);
if
(
pid
<
0
)
if
(
pid
<
0
)
return
pid
;
return
pid
;
...
@@ -247,7 +247,7 @@ int exec_command_sync(const char *argv0, ...) {
...
@@ -247,7 +247,7 @@ int exec_command_sync(const char *argv0, ...) {
return
WEXITSTATUS
(
status
);
return
WEXITSTATUS
(
status
);
}
}
int
exec_command
(
int
err
,
int
*
fd
,
void
(
*
cb
)(
void
),
const
char
*
argv0
,
...)
{
int
exec_command
(
bool
err
,
int
*
fd
,
void
(
*
cb
)(
void
),
const
char
*
argv0
,
...)
{
va_list
argv
;
va_list
argv
;
va_start
(
argv
,
argv0
);
va_start
(
argv
,
argv0
);
int
pid
=
v_exec_command
(
err
,
fd
,
cb
,
argv0
,
argv
);
int
pid
=
v_exec_command
(
err
,
fd
,
cb
,
argv0
,
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