From 8f3b150cd86c2eb35229806fda6928501da27cac Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 26 Aug 2014 14:14:22 -0700 Subject: Keep qtaguid quiet by not trying to untag non-sockets. (cherry-pick of f6cf9efb212e572dcd2e902ca461af6323793dbf.) Bug: 17203955 Change-Id: I0999fc0ff295986b92e31568d96e321b9e7ffb2c --- luni/src/main/native/Register.cpp | 1 + luni/src/main/native/java_io_FileDescriptor.cpp | 35 +++++++++++++++++++++++++ luni/src/main/native/sub.mk | 1 + 3 files changed, 37 insertions(+) create mode 100644 luni/src/main/native/java_io_FileDescriptor.cpp (limited to 'luni/src/main/native') diff --git a/luni/src/main/native/Register.cpp b/luni/src/main/native/Register.cpp index 4aaa905..6a2c939 100644 --- a/luni/src/main/native/Register.cpp +++ b/luni/src/main/native/Register.cpp @@ -35,6 +35,7 @@ jint JNI_OnLoad(JavaVM* vm, void*) { #define REGISTER(FN) extern void FN(JNIEnv*); FN(env) REGISTER(register_android_system_OsConstants); REGISTER(register_java_io_File); + REGISTER(register_java_io_FileDescriptor); REGISTER(register_java_io_ObjectStreamClass); REGISTER(register_java_lang_Character); REGISTER(register_java_lang_Double); diff --git a/luni/src/main/native/java_io_FileDescriptor.cpp b/luni/src/main/native/java_io_FileDescriptor.cpp new file mode 100644 index 0000000..fe7e07e --- /dev/null +++ b/luni/src/main/native/java_io_FileDescriptor.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "FileDescriptor" + +#include "JniConstants.h" + +#include +#include + +static jboolean FileDescriptor_isSocket(JNIEnv*, jclass, jint fd) { + int error; + socklen_t error_length = sizeof(error); + return TEMP_FAILURE_RETRY(getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &error_length)); +} + +static JNINativeMethod gMethods[] = { + NATIVE_METHOD(FileDescriptor, isSocket, "(I)Z"), +}; +void register_java_io_FileDescriptor(JNIEnv* env) { + jniRegisterNativeMethods(env, "java/io/FileDescriptor", gMethods, NELEM(gMethods)); +} diff --git a/luni/src/main/native/sub.mk b/luni/src/main/native/sub.mk index 5b581f3..079ecd2 100644 --- a/luni/src/main/native/sub.mk +++ b/luni/src/main/native/sub.mk @@ -15,6 +15,7 @@ LOCAL_SRC_FILES := \ canonicalize_path.cpp \ cbigint.cpp \ java_io_File.cpp \ + java_io_FileDescriptor.cpp \ java_io_ObjectStreamClass.cpp \ java_lang_Character.cpp \ java_lang_Double.cpp \ -- cgit v1.1