现象:在系统上面,点击应用会退出的问题。报如下错误:Failed to open /dev/null 原因:/dev/null权限组导致的 代码路径: frameworks/base/core/jni/com_android_internal_os_Zygote.cpp 在com_android_internal_os_Zygote.cpp文件中DetachDescriptors方法中修改/dev/null权限
static void DetachDescriptors(JNIEnv* env, jintArray fdsToClose) {
if (!fdsToClose) {
return;
}
jsize count = env->GetArrayLength(fdsToClose);
ScopedIntArrayRO ar(env, fdsToClose);
if (ar.get() == NULL) {
RuntimeAbort(env, __LINE__, "Bad fd array");
}
jsize i;
int devnull;
for (i = 0; i < count; i++) {
+ chmod("/dev/null", 0666);
+ chown("/dev/null", AID_ROOT, AID_ROOT);
+ //ALOGW("chmod /dev/null: %d", rec);
devnull = open("/dev/null", O_RDWR);
if (devnull < 0) {
ALOGE("Failed to open /dev/null: %s", strerror(errno));
RuntimeAbort(env, __LINE__, "Failed to open /dev/null");
continue;
}
ALOGV("Switching descriptor %d to /dev/null: %s", ar[i], strerror(errno));
if (dup2(devnull, ar[i]) < 0) {
ALOGE("Failed dup2() on descriptor %d: %s", ar[i], strerror(errno));
RuntimeAbort(env, __LINE__, "Failed dup2()");
}
close(devnull);
}
}
|