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
a31c1e80
Commit
a31c1e80
authored
May 03, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
post-fs-data mode done
parent
21891230
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
361 additions
and
48 deletions
+361
-48
bootstages.c
jni/daemon/bootstages.c
+208
-38
log_monitor.c
jni/daemon/log_monitor.c
+2
-4
magisk.h
jni/magisk.h
+12
-0
misc.c
jni/utils/misc.c
+109
-5
utils.h
jni/utils/utils.h
+6
-1
xwrap.c
jni/utils/xwrap.c
+24
-0
No files found.
jni/daemon/bootstages.c
View file @
a31c1e80
This diff is collapsed.
Click to expand it.
jni/daemon/log_monitor.c
View file @
a31c1e80
...
...
@@ -8,7 +8,6 @@
#include <stdio.h>
#include <limits.h>
#include <pthread.h>
#include <unistd.h>
#include "magisk.h"
#include "utils.h"
...
...
@@ -19,8 +18,8 @@ static void *logger_thread(void *args) {
err_handler
=
exit_thread
;
char
buffer
[
PATH_MAX
];
rename
(
"/cache/magisk.log"
,
"/cache/last_magisk.log"
);
FILE
*
logfile
=
xfopen
(
"/cache/magisk.log"
,
"w"
);
rename
(
LOGFILE
,
LASTLOG
);
FILE
*
logfile
=
xfopen
(
LOGFILE
,
"w"
);
// Disable buffering
setbuf
(
logfile
,
NULL
);
// Start logcat
...
...
@@ -30,7 +29,6 @@ static void *logger_thread(void *args) {
while
(
fdgets
(
buffer
,
sizeof
(
buffer
),
fd
))
{
fprintf
(
logfile
,
"%s"
,
buffer
);
}
close
(
fd
);
return
NULL
;
}
...
...
jni/magisk.h
View file @
a31c1e80
...
...
@@ -24,6 +24,18 @@
#define ARG_MAX 4096
#endif
#define LOGFILE "/cache/magisk.log"
#define LASTLOG "/cache/last_magisk.log"
#define UNBLOCKFILE "/dev/.magisk.unblock"
#define DISABLEFILE "/cache/.disable_magisk"
#define UNINSTALLER "/cache/magisk_uninstaller.sh"
#define MOUNTPOINT "/magisk"
#define MAINIMG "/data/magisk.img"
#define DATABIN "/data/magisk"
#define MAGISKTMP "/dev/magisk"
#define MIRRDIR MAGISKTMP "/mirror"
#define DUMMDIR MAGISKTMP "/dummy"
#define SELINUX_PATH "/sys/fs/selinux/"
#define SELINUX_ENFORCE SELINUX_PATH "enforce"
#define SELINUX_POLICY SELINUX_PATH "policy"
...
...
jni/utils/misc.c
View file @
a31c1e80
...
...
@@ -14,6 +14,8 @@
#include <sys/ioctl.h>
#include <sys/mount.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <selinux/selinux.h>
#include "magisk.h"
#include "utils.h"
...
...
@@ -204,11 +206,6 @@ void unlock_blocks() {
closedir
(
dir
);
}
void
unblock_boot_process
()
{
int
fd
=
open
(
"/dev/.magisk.unblock"
,
O_RDONLY
|
O_CREAT
);
close
(
fd
);
}
void
setup_sighandlers
(
void
(
*
handler
)(
int
))
{
struct
sigaction
act
;
memset
(
&
act
,
0
,
sizeof
(
act
));
...
...
@@ -276,3 +273,110 @@ int bind_mount(const char *from, const char *to) {
int
open_new
(
const
char
*
filename
)
{
return
xopen
(
filename
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
0644
);
}
// file/link -> file/link only!!
int
cp_afc
(
const
char
*
source
,
const
char
*
target
)
{
struct
stat
buf
;
xlstat
(
source
,
&
buf
);
unlink
(
target
);
char
*
con
;
if
(
S_ISREG
(
buf
.
st_mode
))
{
int
sfd
,
tfd
;
sfd
=
xopen
(
source
,
O_RDONLY
);
tfd
=
xopen
(
target
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
);
xsendfile
(
tfd
,
sfd
,
NULL
,
buf
.
st_size
);
fchmod
(
tfd
,
buf
.
st_mode
&
0777
);
fchown
(
tfd
,
buf
.
st_uid
,
buf
.
st_gid
);
fgetfilecon
(
sfd
,
&
con
);
fsetfilecon
(
tfd
,
con
);
free
(
con
);
close
(
sfd
);
close
(
tfd
);
}
else
if
(
S_ISLNK
(
buf
.
st_mode
))
{
char
buffer
[
PATH_MAX
];
xreadlink
(
source
,
buffer
,
sizeof
(
buffer
));
xsymlink
(
buffer
,
target
);
lgetfilecon
(
source
,
&
con
);
lsetfilecon
(
target
,
con
);
free
(
con
);
}
else
{
return
1
;
}
return
0
;
}
int
clone_dir
(
const
char
*
source
,
const
char
*
target
)
{
DIR
*
dir
;
struct
dirent
*
entry
;
char
*
s_path
,
*
t_path
,
*
con
;
if
(
!
(
dir
=
xopendir
(
source
)))
return
1
;
s_path
=
xmalloc
(
PATH_MAX
);
t_path
=
xmalloc
(
PATH_MAX
);
struct
stat
buf
;
xstat
(
source
,
&
buf
);
mkdir_p
(
target
,
buf
.
st_mode
&
0777
);
xchmod
(
target
,
buf
.
st_mode
&
0777
);
lgetfilecon
(
source
,
&
con
);
lsetfilecon
(
target
,
con
);
free
(
con
);
while
((
entry
=
xreaddir
(
dir
)))
{
if
(
strcmp
(
entry
->
d_name
,
"."
)
==
0
||
strcmp
(
entry
->
d_name
,
".."
)
==
0
)
continue
;
snprintf
(
s_path
,
PATH_MAX
,
"%s/%s"
,
source
,
entry
->
d_name
);
snprintf
(
t_path
,
PATH_MAX
,
"%s/%s"
,
target
,
entry
->
d_name
);
switch
(
entry
->
d_type
)
{
case
DT_DIR
:
clone_dir
(
s_path
,
t_path
);
break
;
case
DT_REG
:
case
DT_LNK
:
cp_afc
(
s_path
,
t_path
);
break
;
}
}
free
(
s_path
);
free
(
t_path
);
closedir
(
dir
);
return
0
;
}
int
rm_rf
(
const
char
*
target
)
{
struct
stat
buf
;
xlstat
(
target
,
&
buf
);
char
*
next
;
if
(
S_ISDIR
(
buf
.
st_mode
))
{
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
;
}
jni/utils/utils.h
View file @
a31c1e80
...
...
@@ -49,12 +49,15 @@ int xpthread_create(pthread_t *thread, const pthread_attr_t *attr,
void
*
(
*
start_routine
)
(
void
*
),
void
*
arg
);
int
xsocketpair
(
int
domain
,
int
type
,
int
protocol
,
int
sv
[
2
]);
int
xstat
(
const
char
*
pathname
,
struct
stat
*
buf
);
int
xlstat
(
const
char
*
pathname
,
struct
stat
*
buf
);
int
xdup2
(
int
oldfd
,
int
newfd
);
ssize_t
xreadlink
(
const
char
*
pathname
,
char
*
buf
,
size_t
bufsiz
);
int
xsymlink
(
const
char
*
target
,
const
char
*
linkpath
);
int
xmount
(
const
char
*
source
,
const
char
*
target
,
const
char
*
filesystemtype
,
unsigned
long
mountflags
,
const
void
*
data
);
int
xumount
(
const
char
*
target
);
int
xumount2
(
const
char
*
target
,
int
flags
);
int
xchmod
(
const
char
*
pathname
,
mode_t
mode
);
int
xrename
(
const
char
*
oldpath
,
const
char
*
newpath
);
int
xmkdir
(
const
char
*
pathname
,
mode_t
mode
);
...
...
@@ -77,11 +80,13 @@ void ps(void (*func)(int));
void
ps_filter_proc_name
(
const
char
*
filter
,
void
(
*
func
)(
int
));
int
create_links
(
const
char
*
bin
,
const
char
*
path
);
void
unlock_blocks
();
void
unblock_boot_process
();
void
setup_sighandlers
(
void
(
*
handler
)(
int
));
int
run_command
(
int
*
fd
,
const
char
*
path
,
char
*
const
argv
[]);
int
mkdir_p
(
const
char
*
pathname
,
mode_t
mode
);
int
bind_mount
(
const
char
*
from
,
const
char
*
to
);
int
open_new
(
const
char
*
filename
);
int
cp_afc
(
const
char
*
source
,
const
char
*
target
);
int
clone_dir
(
const
char
*
source
,
const
char
*
target
);
int
rm_rf
(
const
char
*
target
);
#endif
jni/utils/xwrap.c
View file @
a31c1e80
...
...
@@ -220,6 +220,14 @@ int xstat(const char *pathname, struct stat *buf) {
return
ret
;
}
int
xlstat
(
const
char
*
pathname
,
struct
stat
*
buf
)
{
int
ret
=
lstat
(
pathname
,
buf
);
if
(
ret
==
-
1
)
{
PLOGE
(
"lstat %s"
,
pathname
);
}
return
ret
;
}
int
xdup2
(
int
oldfd
,
int
newfd
)
{
int
ret
=
dup2
(
oldfd
,
newfd
);
if
(
ret
==
-
1
)
{
...
...
@@ -257,6 +265,22 @@ int xmount(const char *source, const char *target,
return
ret
;
}
int
xumount
(
const
char
*
target
)
{
int
ret
=
umount
(
target
);
if
(
ret
==
-
1
)
{
PLOGE
(
"umount %s"
,
target
);
}
return
ret
;
}
int
xumount2
(
const
char
*
target
,
int
flags
)
{
int
ret
=
umount2
(
target
,
flags
);
if
(
ret
==
-
1
)
{
PLOGE
(
"umount2 %s"
,
target
);
}
return
ret
;
}
int
xchmod
(
const
char
*
pathname
,
mode_t
mode
)
{
int
ret
=
chmod
(
pathname
,
mode
);
if
(
ret
==
-
1
)
{
...
...
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