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
0ab31ab0
Commit
0ab31ab0
authored
Sep 19, 2021
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix log writer
parent
46e8f077
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
23 deletions
+24
-23
logging.cpp
native/jni/core/logging.cpp
+24
-23
No files found.
native/jni/core/logging.cpp
View file @
0ab31ab0
...
...
@@ -38,7 +38,7 @@ void setup_logfile(bool reset) {
#define MAX_MSG_LEN (PIPE_BUF - sizeof(log_meta))
static
void
logfile_writer
(
int
pipefd
)
{
run_finally
close_
socket
([
=
]
{
run_finally
close_
pipes
([
=
]
{
// Close up all logging pipes when thread dies
close
(
pipefd
);
close
(
logd_fd
.
exchange
(
-
1
));
...
...
@@ -47,8 +47,9 @@ static void logfile_writer(int pipefd) {
struct
{
void
*
data
;
size_t
len
;
}
tmp_buf
{};
stream
*
strm
=
new
byte_stream
(
tmp_buf
.
data
,
tmp_buf
.
len
);
}
tmp
{};
stream_ptr
strm
=
make_unique
<
byte_stream
>
(
tmp
.
data
,
tmp
.
len
);
bool
switched
=
false
;
log_meta
meta
{};
char
buf
[
MAX_MSG_LEN
];
...
...
@@ -60,32 +61,32 @@ static void logfile_writer(int pipefd) {
for
(;;)
{
// Read meta data
if
(
x
read
(
pipefd
,
&
meta
,
sizeof
(
meta
))
!=
sizeof
(
meta
))
if
(
read
(
pipefd
,
&
meta
,
sizeof
(
meta
))
!=
sizeof
(
meta
))
return
;
if
(
meta
.
prio
<
0
&&
tmp_buf
.
len
>=
0
)
{
run_finally
free_buf
([
&
]
{
free
(
tmp_buf
.
data
);
tmp_buf
.
data
=
nullptr
;
tmp_buf
.
len
=
-
1
;
});
if
(
meta
.
prio
<
0
)
{
if
(
!
switched
)
{
run_finally
free_tmp
([
&
]
{
free
(
tmp
.
data
);
tmp
.
data
=
nullptr
;
tmp
.
len
=
0
;
});
if
(
meta
.
len
)
rename
(
LOGFILE
,
LOGFILE
".bak"
);
int
fd
=
open
(
LOGFILE
,
O_WRONLY
|
O_APPEND
|
O_CREAT
|
O_CLOEXEC
,
0644
);
if
(
fd
<
0
)
return
;
if
(
tmp_buf
.
data
)
write
(
fd
,
tmp_buf
.
data
,
tmp_buf
.
len
);
delete
strm
;
strm
=
new
fd_stream
(
fd
);
int
fd
=
open
(
LOGFILE
,
O_WRONLY
|
O_APPEND
|
O_CREAT
|
O_CLOEXEC
,
0644
);
if
(
fd
<
0
)
return
;
if
(
tmp
.
data
)
write
(
fd
,
tmp
.
data
,
tmp
.
len
);
strm
=
make_unique
<
fd_stream
>
(
fd
);
switched
=
true
;
}
continue
;
}
// Read message
if
(
x
read
(
pipefd
,
buf
,
meta
.
len
)
!=
meta
.
len
)
if
(
read
(
pipefd
,
buf
,
meta
.
len
)
!=
meta
.
len
)
return
;
timeval
tv
;
...
...
@@ -109,10 +110,10 @@ static void logfile_writer(int pipefd) {
type
=
'E'
;
break
;
}
int
ms
=
tv
.
tv_usec
/
1000
;
long
ms
=
tv
.
tv_usec
/
1000
;
size_t
off
=
strftime
(
aux
,
sizeof
(
aux
),
"%m-%d %T"
,
&
tm
);
off
+=
snprintf
(
aux
+
off
,
sizeof
(
aux
)
-
off
,
".%03d %5d %5d %c : "
,
ms
,
meta
.
pid
,
meta
.
tid
,
type
);
".%03
l
d %5d %5d %c : "
,
ms
,
meta
.
pid
,
meta
.
tid
,
type
);
iov
[
0
].
iov_len
=
off
;
iov
[
1
].
iov_len
=
meta
.
len
;
...
...
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