Using jniThrowErrnoException in android_util_Process

Since libnativehelper now has an implementation of jniThrowErrnoException,
this method is now used when a system error occurs to avoid code
duplication.

Bug: 180958753
Test: m
Change-Id: I14b8f6c5fb7179624450ecaae10c6bb1f48b4029
This commit is contained in:
Sorin Basca
2021-03-04 15:10:13 +00:00
parent 039e79a2a5
commit 9c5c46d2b3

View File

@@ -1290,24 +1290,6 @@ void android_os_Process_removeAllProcessGroups(JNIEnv* env, jobject clazz)
return removeAllProcessGroups();
}
static void throwErrnoException(JNIEnv* env, const char* functionName, int error) {
ScopedLocalRef<jstring> detailMessage(env, env->NewStringUTF(functionName));
if (detailMessage.get() == NULL) {
// Not really much we can do here. We're probably dead in the water,
// but let's try to stumble on...
env->ExceptionClear();
}
static jclass errnoExceptionClass =
MakeGlobalRefOrDie(env, FindClassOrDie(env, "android/system/ErrnoException"));
static jmethodID errnoExceptionCtor =
GetMethodIDOrDie(env, errnoExceptionClass, "<init>", "(Ljava/lang/String;I)V");
jobject exception =
env->NewObject(errnoExceptionClass, errnoExceptionCtor, detailMessage.get(), error);
env->Throw(reinterpret_cast<jthrowable>(exception));
}
// Wrapper function to the syscall pidfd_open, which creates a file
// descriptor that refers to the process whose PID is specified in pid.
static inline int sys_pidfd_open(pid_t pid, unsigned int flags) {
@@ -1317,7 +1299,7 @@ static inline int sys_pidfd_open(pid_t pid, unsigned int flags) {
static jint android_os_Process_nativePidFdOpen(JNIEnv* env, jobject, jint pid, jint flags) {
int fd = sys_pidfd_open(pid, flags);
if (fd < 0) {
throwErrnoException(env, "nativePidFdOpen", errno);
jniThrowErrnoException(env, "nativePidFdOpen", errno);
return -1;
}
return fd;