Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
com.ccwangluo.accelerator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sheteng
com.ccwangluo.accelerator
Commits
a61b03c8
Commit
a61b03c8
authored
Mar 01, 2017
by
Max Lv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add 600ms timeout for waitpid
parent
f43362fb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
4 deletions
+28
-4
mobile/src/main/java/com/github/shadowsocks/JniHelper.java
mobile/src/main/java/com/github/shadowsocks/JniHelper.java
+7
-0
mobile/src/main/jni/jni-helper.cpp
mobile/src/main/jni/jni-helper.cpp
+15
-3
mobile/src/main/scala/com/github/shadowsocks/GuardedProcess.scala
...rc/main/scala/com/github/shadowsocks/GuardedProcess.scala
+6
-1
No files found.
mobile/src/main/java/com/github/shadowsocks/JniHelper.java
View file @
a61b03c8
...
...
@@ -54,7 +54,14 @@ public class JniHelper {
?
new
ErrnoException
(
"kill"
,
errno
)
:
new
Exception
(
"kill failed: "
+
errno
);
}
@Deprecated
// Use Process.destroy() since API 24
public
static
int
waitpidCompat
(
Process
process
)
throws
Exception
{
if
(
Build
.
VERSION
.
SDK_INT
>=
24
)
throw
new
UnsupportedOperationException
(
"Never call this method in OpenJDK!"
);
return
waitpid
(
process
);
}
private
static
native
int
sigterm
(
Process
process
);
private
static
native
int
waitpid
(
Process
process
);
public
static
native
int
sendFd
(
int
fd
,
String
path
);
public
static
native
void
close
(
int
fd
);
}
mobile/src/main/jni/jni-helper.cpp
View file @
a61b03c8
...
...
@@ -14,6 +14,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <ancillary.h>
#define LOGI(...) do { __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__); } while(0)
...
...
@@ -41,6 +42,17 @@ jint Java_com_github_shadowsocks_jnihelper_sigterm(JNIEnv *env, jobject thiz, jo
return
kill
(
pid
,
SIGTERM
)
==
-
1
&&
errno
!=
ESRCH
?
errno
:
0
;
}
jint
Java_com_github_shadowsocks_jnihelper_waitpid
(
JNIEnv
*
env
,
jobject
thiz
,
jobject
process
)
{
if
(
!
env
->
IsInstanceOf
(
process
,
ProcessImpl
))
{
THROW
(
env
,
"java/lang/ClassCastException"
,
"Unsupported process object. Only java.lang.ProcessManager$ProcessImpl is accepted."
);
return
-
1
;
}
jint
pid
=
env
->
GetIntField
(
process
,
ProcessImpl_pid
);
int
status
;
return
waitpid
(
pid
,
&
status
,
WNOHANG
);
}
void
Java_com_github_shadowsocks_jnihelper_close
(
JNIEnv
*
env
,
jobject
thiz
,
jint
fd
)
{
close
(
fd
);
}
...
...
@@ -84,11 +96,11 @@ static JNINativeMethod method_table[] = {
{
"sendFd"
,
"(ILjava/lang/String;)I"
,
(
void
*
)
Java_com_github_shadowsocks_jnihelper_sendfd
},
{
"sigterm"
,
"(Ljava/lang/Process;)I"
,
(
void
*
)
Java_com_github_shadowsocks_jnihelper_sigterm
}
(
void
*
)
Java_com_github_shadowsocks_jnihelper_sigterm
},
{
"waitpid"
,
"(Ljava/lang/Process;)I"
,
(
void
*
)
Java_com_github_shadowsocks_jnihelper_waitpid
}
};
/*
* Register several native methods for one class.
*/
...
...
mobile/src/main/scala/com/github/shadowsocks/GuardedProcess.scala
View file @
a61b03c8
...
...
@@ -115,7 +115,12 @@ class GuardedProcess(cmd: String*) {
private
def
destroyProcess
()
{
if
(
Build
.
VERSION
.
SDK_INT
<
24
)
{
JniHelper
.
sigtermCompat
(
process
)
process
.
waitFor
()
var
tries
=
0
while
(
JniHelper
.
waitpidCompat
(
process
)
==
0
&&
tries
<
3
)
{
Log
.
w
(
TAG
,
"still waiting for process "
+
Commandline
.
toString
(
cmd
))
Thread
.
sleep
(
200
)
tries
+=
1
}
}
process
.
destroy
()
}
...
...
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