ipc/android: Dup the fd from JVM and maintain it in native

- dup the fd in native part to avoid fd_san error
This commit is contained in:
Hui Xu 2023-08-09 15:47:24 +08:00 committed by Jakob Bornecrantz
parent 4cc68f07c0
commit d5b9ae137e
2 changed files with 9 additions and 2 deletions

View file

@ -64,7 +64,11 @@ public class MonadoImpl extends IMonado.Stub {
throw new IllegalStateException("server not available");
} else {
Log.i(TAG, "connect: fd ownership transferred");
parcelFileDescriptor.detachFd();
try {
parcelFileDescriptor.close();
} catch (IOException e) {
Log.e(TAG, "connect: close FileDescriptor fail!");
}
}
}

View file

@ -157,8 +157,11 @@ Java_org_freedesktop_monado_ipc_MonadoImpl_nativeAddClient(JNIEnv *env, jobject
jni::Object monadoImpl(thiz);
U_LOG_D("service: Called nativeAddClient with fd %d", fd);
int native_fd = dup(fd);
U_LOG_D("service: transfer ownership to native and native_fd %d", native_fd);
// We try pushing the fd number to the server. If and only if we get a 0 return, has the server taken ownership.
return IpcServerHelper::instance().addClient(fd);
return IpcServerHelper::instance().addClient(native_fd);
}
extern "C" JNIEXPORT void JNICALL