Commit 67b7a0f2 authored by Mygod's avatar Mygod

clang-tidy jni-helper

parent 3d2d485a
...@@ -319,14 +319,12 @@ include $(CLEAR_VARS) ...@@ -319,14 +319,12 @@ include $(CLEAR_VARS)
LOCAL_MODULE:= jni-helper LOCAL_MODULE:= jni-helper
LOCAL_CFLAGS := -std=c++11 LOCAL_CFLAGS := -std=c++17
LOCAL_C_INCLUDES:= $(LOCAL_PATH)/libancillary LOCAL_C_INCLUDES:= $(LOCAL_PATH)/libancillary
LOCAL_SRC_FILES:= jni-helper.cpp LOCAL_SRC_FILES:= jni-helper.cpp
LOCAL_LDLIBS := -ldl -llog
LOCAL_STATIC_LIBRARIES := libancillary LOCAL_STATIC_LIBRARIES := libancillary
include $(BUILD_SHARED_LIBRARY) include $(BUILD_SHARED_LIBRARY)
......
...@@ -24,7 +24,7 @@ static void throwException(JNIEnv* env, jclass exceptionClass, jmethodID ctor2, ...@@ -24,7 +24,7 @@ static void throwException(JNIEnv* env, jclass exceptionClass, jmethodID ctor2,
static void throwErrnoException(JNIEnv* env, const char* functionName) { static void throwErrnoException(JNIEnv* env, const char* functionName) {
int error = errno; int error = errno;
static auto ErrnoException = static_cast<jclass>(env->NewGlobalRef( static auto ErrnoException = reinterpret_cast<jclass>(env->NewGlobalRef(
env->FindClass("android/system/ErrnoException"))); env->FindClass("android/system/ErrnoException")));
static jmethodID ctor2 = env->GetMethodID(ErrnoException, "<init>", "(Ljava/lang/String;I)V"); static jmethodID ctor2 = env->GetMethodID(ErrnoException, "<init>", "(Ljava/lang/String;I)V");
throwException(env, ErrnoException, ctor2, functionName, error); throwException(env, ErrnoException, ctor2, functionName, error);
...@@ -34,29 +34,16 @@ static void throwErrnoException(JNIEnv* env, const char* functionName) { ...@@ -34,29 +34,16 @@ static void throwErrnoException(JNIEnv* env, const char* functionName) {
extern "C" { extern "C" {
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_com_github_shadowsocks_JniHelper_sendFd(JNIEnv *env, jclass type, jint tun_fd, jstring path) { Java_com_github_shadowsocks_JniHelper_sendFd(JNIEnv *env, jclass type, jint tun_fd, jstring path) {
int fd;
struct sockaddr_un addr;
const char *sock_str = env->GetStringUTFChars(path, nullptr); const char *sock_str = env->GetStringUTFChars(path, nullptr);
if (int fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); fd == -1) {
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
throwErrnoException(env, "socket"); throwErrnoException(env, "socket");
goto quit2; } else {
} sockaddr_un addr { .sun_family = AF_UNIX };
strncpy(addr.sun_path, sock_str, sizeof(addr.sun_path) - 1);
memset(&addr, 0, sizeof(addr)); if (connect(fd, (sockaddr*) &addr, sizeof(addr)) == -1) throwErrnoException(env, "connect");
addr.sun_family = AF_UNIX; else if (ancil_send_fd(fd, tun_fd)) throwErrnoException(env, "ancil_send_fd");
strncpy(addr.sun_path, sock_str, sizeof(addr.sun_path)-1); close(fd);
if (connect(fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
throwErrnoException(env, "connect");
goto quit;
} }
if (ancil_send_fd(fd, tun_fd)) throwErrnoException(env, "ancil_send_fd");
quit:
close(fd);
quit2:
env->ReleaseStringUTFChars(path, sock_str); env->ReleaseStringUTFChars(path, sock_str);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment