String8() {
mString = 0;
}
-
+
~String8() {
if (mString) {
free(mString);
}
mString[numChars] = '\0';
}
-
+
const char* string() {
return mString;
}
LOGE("[ trouble with /dev/ptmx - %s ]\n", strerror(errno));
return -1;
}
-
+
pid = fork();
if(pid < 0) {
LOGE("- fork failed: %s -\n", strerror(errno));
int pts;
setsid();
-
+
pts = open(devname, O_RDWR);
if(pts < 0) exit(-1);
int procId;
int ptm = create_subprocess(cmd_8.string(), arg0Str, arg1Str, &procId);
-
+
if (processIdArray) {
int procIdLen = env->GetArrayLength(processIdArray);
if (procIdLen > 0) {
jboolean isCopy;
-
+
int* pProcId = (int*) env->GetPrimitiveArrayCritical(processIdArray, &isCopy);
if (pProcId) {
*pProcId = procId;
}
}
}
-
+
jobject result = env->NewObject(class_fileDescriptor, method_fileDescriptor_init);
-
+
if (!result) {
LOGE("Couldn't create a FileDescriptor.");
}
else {
env->SetIntField(result, field_fileDescriptor_descriptor, ptm);
}
-
+
return result;
}
if (env->ExceptionOccurred() != NULL) {
return;
}
-
+
sz.ws_row = row;
sz.ws_col = col;
sz.ws_xpixel = xpixel;
sz.ws_ypixel = ypixel;
-
+
ioctl(fd, TIOCSWINSZ, &sz);
}
if (env->ExceptionOccurred() != NULL) {
return;
}
-
+
close(fd);
}
static int register_FileDescriptor(JNIEnv *env)
{
- class_fileDescriptor = env->FindClass("java/io/FileDescriptor");
+ jclass localRef_class_fileDescriptor = env->FindClass("java/io/FileDescriptor");
+
+ if (localRef_class_fileDescriptor == NULL) {
+ LOGE("Can't find class java/io/FileDescriptor");
+ return -1;
+ }
+
+ class_fileDescriptor = (jclass) env->NewGlobalRef(localRef_class_fileDescriptor);
+
+ env->DeleteLocalRef(localRef_class_fileDescriptor);
if (class_fileDescriptor == NULL) {
- LOGE("Can't find java/io/FileDescriptor");
+ LOGE("Can't get global ref to class java/io/FileDescriptor");
return -1;
}
*/
static int registerNatives(JNIEnv* env)
{
- if (!registerNativeMethods(env, classPathName, method_table,
+ if (!registerNativeMethods(env, classPathName, method_table,
sizeof(method_table) / sizeof(method_table[0]))) {
return JNI_FALSE;
}
/*
* This is called by the VM when the shared library is first loaded.
*/
-
+
typedef union {
JNIEnv* env;
void* venv;
uenv.venv = NULL;
jint result = -1;
JNIEnv* env = NULL;
-
+
LOGI("JNI_OnLoad");
if (vm->GetEnv(&uenv.venv, JNI_VERSION_1_4) != JNI_OK) {
goto bail;
}
env = uenv.env;
-
+
if ((result = register_FileDescriptor(env)) < 0) {
LOGE("ERROR: registerFileDescriptor failed");
goto bail;
LOGE("ERROR: registerNatives failed");
goto bail;
}
-
+
result = JNI_VERSION_1_4;
-
+
bail:
return result;
}