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
7cf4b819
Commit
7cf4b819
authored
Jul 01, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Several small tweaks
parent
9e1aea33
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
41 deletions
+21
-41
bootstages.c
jni/daemon/bootstages.c
+4
-4
misc.c
jni/utils/misc.c
+16
-37
utils.h
jni/utils/utils.h
+1
-0
No files found.
jni/daemon/bootstages.c
View file @
7cf4b819
...
@@ -68,8 +68,8 @@ static int merge_img(const char *source, const char *target) {
...
@@ -68,8 +68,8 @@ static int merge_img(const char *source, const char *target) {
// resize target to worst case
// resize target to worst case
int
s_used
,
s_total
,
t_used
,
t_total
,
n_total
;
int
s_used
,
s_total
,
t_used
,
t_total
,
n_total
;
if
(
get_img_size
(
source
,
&
s_used
,
&
s_total
))
return
1
;
get_img_size
(
source
,
&
s_used
,
&
s_total
)
;
if
(
get_img_size
(
target
,
&
t_used
,
&
t_total
))
return
1
;
get_img_size
(
target
,
&
t_used
,
&
t_total
)
;
n_total
=
round_size
(
s_used
+
t_used
);
n_total
=
round_size
(
s_used
+
t_used
);
if
(
n_total
!=
t_total
)
if
(
n_total
!=
t_total
)
resize_img
(
target
,
n_total
);
resize_img
(
target
,
n_total
);
...
@@ -93,8 +93,8 @@ static int merge_img(const char *source, const char *target) {
...
@@ -93,8 +93,8 @@ static int merge_img(const char *source, const char *target) {
strcmp
(
entry
->
d_name
,
".core"
)
==
0
||
strcmp
(
entry
->
d_name
,
".core"
)
==
0
||
strcmp
(
entry
->
d_name
,
"lost+found"
)
==
0
)
strcmp
(
entry
->
d_name
,
"lost+found"
)
==
0
)
continue
;
continue
;
// Cleanup old module
// Cleanup old module
if exists
snprintf
(
buf
,
PATH_MAX
,
"
/dev/target/%s"
,
entry
->
d_name
);
snprintf
(
buf
,
PATH_MAX
,
"
%s/%s"
,
TARGET_TMP
,
entry
->
d_name
);
if
(
access
(
buf
,
F_OK
)
==
0
)
{
if
(
access
(
buf
,
F_OK
)
==
0
)
{
LOGI
(
"Upgrade module: %s
\n
"
,
entry
->
d_name
);
LOGI
(
"Upgrade module: %s
\n
"
,
entry
->
d_name
);
rm_rf
(
buf
);
rm_rf
(
buf
);
...
...
jni/utils/misc.c
View file @
7cf4b819
...
@@ -300,11 +300,7 @@ int cp_afc(const char *source, const char *target) {
...
@@ -300,11 +300,7 @@ int cp_afc(const char *source, const char *target) {
sfd
=
xopen
(
source
,
O_RDONLY
);
sfd
=
xopen
(
source
,
O_RDONLY
);
tfd
=
xopen
(
target
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
);
tfd
=
xopen
(
target
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
);
xsendfile
(
tfd
,
sfd
,
NULL
,
buf
.
st_size
);
xsendfile
(
tfd
,
sfd
,
NULL
,
buf
.
st_size
);
fchmod
(
tfd
,
buf
.
st_mode
&
0777
);
fclone_attr
(
sfd
,
tfd
);
fchown
(
tfd
,
buf
.
st_uid
,
buf
.
st_gid
);
fgetfilecon
(
sfd
,
&
con
);
fsetfilecon
(
tfd
,
con
);
free
(
con
);
close
(
sfd
);
close
(
sfd
);
close
(
tfd
);
close
(
tfd
);
}
else
if
(
S_ISLNK
(
buf
.
st_mode
))
{
}
else
if
(
S_ISLNK
(
buf
.
st_mode
))
{
...
@@ -360,38 +356,10 @@ int clone_dir(const char *source, const char *target) {
...
@@ -360,38 +356,10 @@ int clone_dir(const char *source, const char *target) {
int
rm_rf
(
const
char
*
target
)
{
int
rm_rf
(
const
char
*
target
)
{
if
(
access
(
target
,
F_OK
)
==
-
1
)
if
(
access
(
target
,
F_OK
)
==
-
1
)
return
0
;
return
0
;
struct
stat
buf
;
// Use external rm command, saves a lot of headache and issues
xlstat
(
target
,
&
buf
);
char
command
[
PATH_MAX
];
char
*
next
;
snprintf
(
command
,
sizeof
(
command
),
"rm -rf %s"
,
target
);
if
(
S_ISDIR
(
buf
.
st_mode
))
{
return
system
(
command
);
DIR
*
dir
;
struct
dirent
*
entry
;
if
(
!
(
dir
=
xopendir
(
target
)))
return
1
;
next
=
xmalloc
(
PATH_MAX
);
while
((
entry
=
xreaddir
(
dir
)))
{
if
(
strcmp
(
entry
->
d_name
,
"."
)
==
0
||
strcmp
(
entry
->
d_name
,
".."
)
==
0
)
continue
;
snprintf
(
next
,
PATH_MAX
,
"%s/%s"
,
target
,
entry
->
d_name
);
switch
(
entry
->
d_type
)
{
case
DT_DIR
:
rm_rf
(
next
);
break
;
case
DT_REG
:
case
DT_LNK
:
unlink
(
next
);
break
;
}
}
free
(
next
);
closedir
(
dir
);
rmdir
(
target
);
}
else
if
(
S_ISREG
(
buf
.
st_mode
)
||
S_ISLNK
(
buf
.
st_mode
))
{
unlink
(
target
);
}
else
{
return
1
;
}
return
0
;
}
}
void
clone_attr
(
const
char
*
source
,
const
char
*
target
)
{
void
clone_attr
(
const
char
*
source
,
const
char
*
target
)
{
...
@@ -405,6 +373,17 @@ void clone_attr(const char *source, const char *target) {
...
@@ -405,6 +373,17 @@ void clone_attr(const char *source, const char *target) {
free
(
con
);
free
(
con
);
}
}
void
fclone_attr
(
const
int
sourcefd
,
const
int
targetfd
)
{
struct
stat
buf
;
fstat
(
sourcefd
,
&
buf
);
fchmod
(
targetfd
,
buf
.
st_mode
&
0777
);
fchown
(
targetfd
,
buf
.
st_uid
,
buf
.
st_gid
);
char
*
con
;
fgetfilecon
(
sourcefd
,
&
con
);
fsetfilecon
(
sourcefd
,
con
);
free
(
con
);
}
void
get_client_cred
(
int
fd
,
struct
ucred
*
cred
)
{
void
get_client_cred
(
int
fd
,
struct
ucred
*
cred
)
{
socklen_t
ucred_length
=
sizeof
(
*
cred
);
socklen_t
ucred_length
=
sizeof
(
*
cred
);
if
(
getsockopt
(
fd
,
SOL_SOCKET
,
SO_PEERCRED
,
cred
,
&
ucred_length
))
if
(
getsockopt
(
fd
,
SOL_SOCKET
,
SO_PEERCRED
,
cred
,
&
ucred_length
))
...
...
jni/utils/utils.h
View file @
7cf4b819
...
@@ -89,6 +89,7 @@ int open_new(const char *filename);
...
@@ -89,6 +89,7 @@ int open_new(const char *filename);
int
cp_afc
(
const
char
*
source
,
const
char
*
target
);
int
cp_afc
(
const
char
*
source
,
const
char
*
target
);
int
clone_dir
(
const
char
*
source
,
const
char
*
target
);
int
clone_dir
(
const
char
*
source
,
const
char
*
target
);
int
rm_rf
(
const
char
*
target
);
int
rm_rf
(
const
char
*
target
);
void
fclone_attr
(
const
int
sourcefd
,
const
int
targetfd
);
void
clone_attr
(
const
char
*
source
,
const
char
*
target
);
void
clone_attr
(
const
char
*
source
,
const
char
*
target
);
void
get_client_cred
(
int
fd
,
struct
ucred
*
cred
);
void
get_client_cred
(
int
fd
,
struct
ucred
*
cred
);
int
switch_mnt_ns
(
int
pid
);
int
switch_mnt_ns
(
int
pid
);
...
...
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