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
d3b7b419
Commit
d3b7b419
authored
Nov 18, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix kmsg logging in magiskinit
parent
da159e46
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
39 deletions
+33
-39
init.cpp
native/jni/init/init.cpp
+32
-21
init.h
native/jni/init/init.h
+1
-0
rootdir.cpp
native/jni/init/rootdir.cpp
+0
-18
No files found.
native/jni/init/init.cpp
View file @
d3b7b419
...
@@ -31,31 +31,44 @@ constexpr int (*init_applet_main[])(int, char *[]) =
...
@@ -31,31 +31,44 @@ constexpr int (*init_applet_main[])(int, char *[]) =
#ifdef MAGISK_DEBUG
#ifdef MAGISK_DEBUG
static
FILE
*
kmsg
;
static
FILE
*
kmsg
;
static
char
kmsg_buf
[
4096
];
static
int
vprintk
(
const
char
*
fmt
,
va_list
ap
)
{
static
int
vprintk
(
const
char
*
fmt
,
va_list
ap
)
{
fprintf
(
kmsg
,
"magiskinit: "
);
vsnprintf
(
kmsg_buf
+
12
,
sizeof
(
kmsg_buf
)
-
12
,
fmt
,
ap
);
return
vfprintf
(
kmsg
,
fmt
,
ap
);
return
fprintf
(
kmsg
,
"%s"
,
kmsg_buf
);
}
}
static
void
setup_klog
()
{
void
setup_klog
()
{
mknod
(
"/kmsg"
,
S_IFCHR
|
0666
,
makedev
(
1
,
11
));
// Shut down first 3 fds
int
fd
=
xopen
(
"/kmsg"
,
O_WRONLY
|
O_CLOEXEC
);
int
null
;
kmsg
=
fdopen
(
fd
,
"w"
);
if
(
access
(
"/dev/null"
,
W_OK
)
==
0
)
{
setbuf
(
kmsg
,
nullptr
);
null
=
xopen
(
"/dev/null"
,
O_RDWR
|
O_CLOEXEC
);
unlink
(
"/kmsg"
);
}
else
{
log_cb
.
d
=
log_cb
.
i
=
log_cb
.
w
=
log_cb
.
e
=
vprintk
;
log_cb
.
ex
=
nop_ex
;
// Prevent file descriptor confusion
mknod
(
"/null"
,
S_IFCHR
|
0666
,
makedev
(
1
,
3
));
mknod
(
"/null"
,
S_IFCHR
|
0666
,
makedev
(
1
,
3
));
int
null
=
xopen
(
"/null"
,
O_RDWR
|
O_CLOEXEC
);
null
=
xopen
(
"/null"
,
O_RDWR
|
O_CLOEXEC
);
unlink
(
"/null"
);
unlink
(
"/null"
);
}
xdup3
(
null
,
STDIN_FILENO
,
O_CLOEXEC
);
xdup3
(
null
,
STDIN_FILENO
,
O_CLOEXEC
);
xdup3
(
null
,
STDOUT_FILENO
,
O_CLOEXEC
);
xdup3
(
null
,
STDOUT_FILENO
,
O_CLOEXEC
);
xdup3
(
null
,
STDERR_FILENO
,
O_CLOEXEC
);
xdup3
(
null
,
STDERR_FILENO
,
O_CLOEXEC
);
if
(
null
>
STDERR_FILENO
)
if
(
null
>
STDERR_FILENO
)
close
(
null
);
close
(
null
);
int
fd
;
if
(
access
(
"/proc/kmsg"
,
W_OK
)
==
0
)
{
fd
=
xopen
(
"/proc/kmsg"
,
O_WRONLY
|
O_CLOEXEC
);
}
else
{
mknod
(
"/kmsg"
,
S_IFCHR
|
0666
,
makedev
(
1
,
11
));
fd
=
xopen
(
"/kmsg"
,
O_WRONLY
|
O_CLOEXEC
);
unlink
(
"/kmsg"
);
}
kmsg
=
fdopen
(
fd
,
"w"
);
setbuf
(
kmsg
,
nullptr
);
log_cb
.
d
=
log_cb
.
i
=
log_cb
.
w
=
log_cb
.
e
=
vprintk
;
log_cb
.
ex
=
nop_ex
;
strcpy
(
kmsg_buf
,
"magiskinit: "
);
}
}
#else
#else
#define setup_klog(...)
void
setup_klog
()
{}
#endif
#endif
static
bool
unxz
(
int
fd
,
const
uint8_t
*
buf
,
size_t
size
)
{
static
bool
unxz
(
int
fd
,
const
uint8_t
*
buf
,
size_t
size
)
{
...
@@ -131,13 +144,11 @@ public:
...
@@ -131,13 +144,11 @@ public:
}
}
};
};
class
TestInit
:
public
SAR
Init
{
class
TestInit
:
public
Base
Init
{
public
:
public
:
TestInit
(
char
*
argv
[],
cmdline
*
cmd
)
:
SAR
Init
(
argv
,
cmd
)
{};
TestInit
(
char
*
argv
[],
cmdline
*
cmd
)
:
Base
Init
(
argv
,
cmd
)
{};
void
start
()
override
{
void
start
()
override
{
early_mount
();
// Write init tests here
patch_rootdir
();
cleanup
();
}
}
};
};
...
...
native/jni/init/init.h
View file @
d3b7b419
...
@@ -168,3 +168,4 @@ public:
...
@@ -168,3 +168,4 @@ public:
void
load_kernel_info
(
cmdline
*
cmd
);
void
load_kernel_info
(
cmdline
*
cmd
);
int
dump_magisk
(
const
char
*
path
,
mode_t
mode
);
int
dump_magisk
(
const
char
*
path
,
mode_t
mode
);
int
magisk_proxy_main
(
int
argc
,
char
*
argv
[]);
int
magisk_proxy_main
(
int
argc
,
char
*
argv
[]);
void
setup_klog
();
native/jni/init/rootdir.cpp
View file @
d3b7b419
...
@@ -8,7 +8,6 @@
...
@@ -8,7 +8,6 @@
#include <utils.h>
#include <utils.h>
#include "init.h"
#include "init.h"
#include "flags.h"
#include "magiskrc.h"
#include "magiskrc.h"
#ifdef USE_64BIT
#ifdef USE_64BIT
...
@@ -466,23 +465,6 @@ void AFirstStageInit::prepare() {
...
@@ -466,23 +465,6 @@ void AFirstStageInit::prepare() {
rename
(
"/.backup/init"
,
"/init"
);
rename
(
"/.backup/init"
,
"/init"
);
}
}
#ifdef MAGISK_DEBUG
static
FILE
*
kmsg
;
static
int
vprintk
(
const
char
*
fmt
,
va_list
ap
)
{
fprintf
(
kmsg
,
"magiskinit: "
);
return
vfprintf
(
kmsg
,
fmt
,
ap
);
}
static
void
setup_klog
()
{
int
fd
=
xopen
(
"/proc/kmsg"
,
O_WRONLY
|
O_CLOEXEC
);
kmsg
=
fdopen
(
fd
,
"w"
);
setbuf
(
kmsg
,
nullptr
);
log_cb
.
d
=
log_cb
.
i
=
log_cb
.
w
=
log_cb
.
e
=
vprintk
;
log_cb
.
ex
=
nop_ex
;
}
#else
#define setup_klog(...)
#endif
int
magisk_proxy_main
(
int
argc
,
char
*
argv
[])
{
int
magisk_proxy_main
(
int
argc
,
char
*
argv
[])
{
setup_klog
();
setup_klog
();
...
...
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