system_server crash现象研究

现象:当system server进程crash时,发现zygote进程会被杀掉,此后Zyogote进程和system server被重新启动。


分析:在init解析init.rc时,Zygote进程作为一个服务被定义,且被声明为自动重启。因此一旦Zygote进程退出,则init会收到子进程退出信号从而重新启动zygote服务,进而Zygote启动System Server。同样,在System server被Zygote作为子进程启动后,Zygote通过信号监听该子进程状态,一旦退出Zygote将会杀死自身等待init再次运行。另外system server进程将监听service manager进程,如service manager退出则杀掉自身从而导致zygote被重启。


下面为相关代码:


Zygote启动system server入口:

libcore/dalvik/src/main/java/dalvik/system/Zygote.java

    /**
     * Special method to start the system server process.
     * @deprecated use {@link Zygote#forkSystemServer(int, int, int[], int, int[][])}
     */
    @Deprecated
    public static int forkSystemServer(int uid, int gid, int[] gids,
            boolean enableDebugger, int[][] rlimits) {
        int debugFlags = enableDebugger ? DEBUG_ENABLE_DEBUGGER : 0;
        return forkAndSpecialize(uid, gid, gids, debugFlags, rlimits);
    }

forkAndSpecialize是一个JNI函数,其定义见Dalvik_dalvik_system_Zygote_fork(),在其中注册信号处理函数,在有子进程退出时将检查进程pid,仅当中止的子进程pid为system server时才杀掉本进程(zygote进程)。

dalvik_system_Zygote.c

/* native public static int fork(); */
static void Dalvik_dalvik_system_Zygote_fork(const u4* args, JValue* pResult)
{
    pid_t pid;

    if (!gDvm.zygote) {
        dvmThrowException("Ljava/lang/IllegalStateException;",
            "VM instance not started with -Xzygote");

        RETURN_VOID();
    }

    if (!dvmGcPreZygoteFork()) {
        LOGE("pre-fork heap failed\n");
        dvmAbort();
    }

    setSignalHandler();   //这里注册信号处理,以监测子进程状态

    dvmDumpLoaderStats("zygote");
    pid = fork();

#ifdef HAVE_ANDROID_OS
    if (pid == 0) {
        /* child process */
        extern int gMallocLeakZygoteChild;
        gMallocLeakZygoteChild = 1;
    }
#endif

    RETURN_INT(pid);
}

/*
 * configure sigchld handler for the zygote process
 * This is configured very late, because earlier in the dalvik lifecycle
 * we can fork() and exec() for the verifier/optimizer, and we
 * want to waitpid() for those rather than have them be harvested immediately.
 *
 * This ends up being called repeatedly before each fork(), but there's
 * no real harm in that.
 */
static void setSignalHandler()
{
    int err;
    struct sigaction sa;

    memset(&sa, 0, sizeof(sa));

    sa.sa_handler = sigchldHandler;          //信号处理函数地址 

    err = sigaction (SIGCHLD, &sa, NULL);    //设置子进程中止时的信号处理函数

    if (err < 0) {
        LOGW("Error setting SIGCHLD handler: %s", strerror(errno));
    }
}

/*
 * This signal handler is for zygote mode, since the zygote
 * must reap its children
 */
static void sigchldHandler(int s)
{
    pid_t pid;
    int status;

    
10-15 03:02:22.942 19206 19206 E crash_dump64: failed to get the guest state header for thread 17881: Bad address 10-15 03:02:22.943 19206 19206 E crash_dump64: failed to get the guest state header for thread 17888: Bad address 10-15 03:02:22.944 19206 19206 E crash_dump64: failed to get the guest state header for thread 17889: Bad address 10-15 03:02:22.945 19206 19206 E crash_dump64: failed to get the guest state header for thread 17890: Bad address 10-15 03:02:22.953 19206 19206 I crash_dump64: obtaining output fd from tombstoned, type: kDebuggerdNativeBacktrace 10-15 03:02:22.954 01047 01047 I tombstoned: received crash request for pid 1173 10-15 03:02:22.955 01047 01047 I tombstoned: found intercept fd 512 for pid 1173 and type kDebuggerdNativeBacktrace 10-15 03:02:22.955 19206 19206 I crash_dump64: performing dump of process 1173 (target tid = 1173) 10-15 03:02:22.958 19206 19206 I crash_dump64: ***crash_dump->dump_backtrace*** 10-15 03:02:22.963 01453 02097 D DeviceStorageMonitor: oplusCheckStorage: in!!!!!! 10-15 03:02:22.965 01453 02097 D DeviceStorageMonitor: oplusCheckData: in! 10-15 03:02:22.965 01453 02097 D DeviceStorageMonitor: oplusCheckData: mDataFree = 45.92GB 10-15 03:02:22.965 01453 02097 D DeviceStorageMonitor: oplusCheckStorage: out!!!!!! 10-15 03:02:23.032 01453 01534 I system_server: libdebuggerd_client: done dumping process 1173 10-15 03:02:23.032 01047 01047 W tombstoned: skipping tombstone file creation due to intercept 10-15 03:02:23.035 01453 01534 I ActivityManager: Collecting stacks for native pid 1174 10-15 03:02:23.037 01453 01534 E system_server: Could not open /dev/binderfs/binder_logs/transactions. Likely a permissions issue. errno: 2 10-15 03:02:23.037 01453 01534 E android.os.Debug: Failed to get binder state info for pid: 1174 status: -2: No such file or directory 10-15 03:02:23.039 01453 01534 I system_server: libdebuggerd_client: started dumping process 1174 10-15 03:02:23.041 01047 01047 I tombstoned: registered intercept for pid 1174 and type kDebuggerdNativeBacktrace 10-15 03:02:23.044 01047 01047 I tombstoned: received crash request for pid 1174 10-15 03:02:23.044 01047 01047 I tombstoned: found intercept fd 512 for pid 1174 and type kDebuggerdNativeBacktrace 10-15 03:02:23.195 01047 01047 W tombstoned: skipping tombstone file creation due to intercept 10-15 03:02:23.196 01453 01534 I system_server: libdebuggerd_client: done dumping process 1174 10-15 03:02:23.198 01453 01534 I ActivityManager: Collecting stacks for native pid 1175 10-15 03:02:23.198 01453 01534 E system_server: Could not open /dev/binderfs/binder_logs/transactions. Likely a permissions issue. errno: 2 10-15 03:02:23.198 01453 01534 E android.os.Debug: Failed to get binder state info for pid: 1175 status: -2: No such file or directory 10-15 03:02:23.201 01453 01534 I system_server: libdebuggerd_client: started dumping process 1175 10-15 03:02:23.202 01047 01047 I tombstoned: registered intercept for pid 1175 and type kDebuggerdNativeBacktrace 10-15 03:02:23.205 01047 01047 I tombstoned: received crash request for pid 1175 10-15 03:02:23.205 01047 01047 I tombstoned: found intercept fd 512 for pid 1175 and type kDebuggerdNativeBacktrace 10-15 03:02:23.303 01437 01545 E bms_heating: BmsHeatingCheckThread status: 0 10-15 03:02:23.320 01453 01453 W ServiceManagerCppClient: Waited one second for DefragService (is service started? Number of threads started in the threadpool: 32. Are binder threads started and available?) 10-15 03:02:23.394 02049 02279 I ServiceManagerCppClient: Waiting for service 'ocenter' on '/dev/binder'... 10-15 03:02:23.598 07805 08167 I Finsky:background: [105] DSC::L: Update all listeners for download <325:RUNNING:21%[21%]> in group com.google.android.webview:LLD-GbNOQ86W2NJ_EfYvXA 10-15 03:02:23.599 07805 08167 I Finsky:background: [105] DSC::L: Updating listener DownloadServiceManagerListener::rlc@ec0bede for download <325:RUNNING:21%[21%]> 10-15 03:02:23.599 07805 08167 I Finsky:background: [105] DSC::L: Updating listener tek@fed18bf for download <325:RUNNING:21%[21%]> 10-15 03:02:23.600 07805 08167 I Finsky:background: [105] DSC::L: Updating listener DownloadServiceManagerListener::ajxp@4491751 for download <325:RUNNING:21%[21%]> 10-15 03:02:23.601 07805 08167 I Finsky:background: [105] DS: Received onProgress request_id=325 10-15 03:02:23.601 07805 08167 I Finsky:background: [105] RM: receive resource status onProgress download_request_id=325, group_id=com.google.android.webview.apk reason: auto_update isid: LLD-GbNOQ86W2NJ_EfYvXA, status_code=RESOURCE_STATUS_IN_PROGRESS, legacy_status_code=192, size: 7805965/36581983 10-15 03:02:23.602 07805 08167 I Finsky:background: [105] DS::IDC: updateWith: <325:RUNNING:21%[21%]> 10-15 03:02:23.604 07805 07905 I Finsky:background: [65] RM: getStatus resourceRequestId=f7176d98-0cd3-4d27-ae00-867043245529 requestId=325 package=com.google.android.webview artifact=com.google.android.webview.apk isid=LLD-GbNOQ86W2NJ_EfYvXA 10-15 03:02:23.605 07805 07905 I Finsky:background: [65] DSC: getDownload(325) 10-15 03:02:23.606 07805 07905 I Finsky:background: [65] DS: getDownload(request_id=325) 10-15 03:02:23.607 07805 08167 I Finsky:background: [105] DS: DS: onGetDownload(request_id=325, files_to_download=[com.google.android.webview.apk(size:36581983)], context[group_id=com.google.android.webview:LLD-GbNOQ86W2NJ_EfYvXA], display_data[invisible=true, title=Android System WebView], network_restrictions=ANY_NETWORK status=running, bytes_downloaded=7805965, total_bytes=36581983, retry[count=1, next_retry=2025-10-15T02:58:58.504+08:00[Asia/Shanghai]]) 10-15 03:02:23.612 07805 07805 I Finsky:background: [2] RF: onProgress request_id=325 isid=LLD-GbNOQ86W2NJ_EfYvXA 10-15 03:02:23.612 07805 07805 I Finsky:background: [2] RF: resourceStatus for request_id=325 group=com.google.android.webview artifact=com.google.android.webview.apk collectedBytes= 7805965 / 36581983 10-15 03:02:23.613 07805 07805 I Finsky:background: [2] RF: Group=com.google.android.webview totalBytesDownloaded= 7843068 / 36619086 for 2 artifacts 10-15 03:02:23.615 07805 07805 I Finsky:background: [2] Updated time lastBroadcast=2025-10-14T19:02:21.485Z current=2025-10-14T19:02:23.614Z 10-15 03:02:23.615 07805 07805 I Finsky:background: [2] bytesCompleted/bytesTotal/ratio = 7843068 / 36619086 / 0.214180 10-15 03:02:23.620 07805 07892 I Finsky:background: [59] IV2: onTaskProgress com.google.android.webview[iid:55] [isid:LLD-GbNOQ86W2NJ_EfYvXA] status:RESOURCE_FETCH_PROGRESS, size: 7843068/94176391 10-15 03:02:23.624 07805 18697 I Finsky:background: [521] IQ: Notifying installation update. [Package:com.google.android.webview, isid:LLD-GbNOQ86W2NJ_EfYvXA], status=DOWNLOADING, status_code=0, reason=auto_update, tsc=PT1H41M15.445S, attempt=0 10-15 03:02:23.629 07805 07805 I Finsky:background: [2] PIM: Ignore install package event for: com.google.android.webview, isid: LLD-GbNOQ86W2NJ_EfYvXA 10-15 03:02:23.634 01453 03593 V ActivityManager: Broadcast: Intent { act=com.android.launcher.action.ACTION_PACKAGE_DOWNLOADING pkg=com.google.android.googlequicksearchbox } ordered=false userid=0 resultTo null 10-15 03:02:23.634 01453 03593 V ActivityManager: broadcastIntentLocked callingPid: 17176 callingUid=10122 10-15 03:02:23.634 01453 03593 D OplusBenchHelper: benchMode:true; pkgNamecom.google.android.googlequicksearchbox 10-15 03:02:23.636 17176 17176 I Finsky : [2] DL: Data loader session turned off due to Incremental install not requested: com.google.android.webview 10-15 03:02:23.637 17176 17176 I Finsky : [2] IQ::HLD: if pauseAppUpdates is called now, it must wait for these ongoing installs: [[Package:com.google.android.webview, isid:LLD-GbNOQ86W2NJ_EfYvXA]] 10-15 03:02:23.737 01453 01534 I system_server: libdebuggerd_client: done dumping process 1175 10-15 03:02:23.737 01047 01047 W tombstoned: skipping tombstone file creation due to intercept 10-15 03:02:23.740 01453 03039 D Osense-PsiDetector: newPressureState = 0, 0 10-15 03:02:23.741 01453 03039 D Osense-ReentrantPolicy: bundle: Bundle[{stateType=update, currentAvailmem=2746, type=iolevel, killTriggerMem=1800, ioLevel=0}] 10-15 03:02:23.741 01453 01534 I ActivityManager: Collecting stacks for native pid 14360 10-15 03:02:23.742 01453 03039 D OsenseResEventManager: handleOsenseResultEvent: OsenseEventResult : eventType is :112 eventStateType is :2 ExtraData is : Bundle[{currentAvailmem=2746, killTriggerMem=1800, ioLevel=0}] 10-15 03:02:23.742 01453 01534 E system_server: Could not open /dev/binderfs/binder_logs/transactions. Likely a permissions issue. errno: 2 10-15 03:02:23.742 01453 01534 E android.os.Debug: Failed to get binder state info for pid: 14360 status: -2: No such file or directory 10-15 03:02:23.745 01453 01534 I system_server: libdebuggerd_client: started dumping process 14360 10-15 03:02:23.748 01047 01047 I tombstoned: registered intercept for pid 14360 and type kDebuggerdNativeBacktrace 10-15 03:02:23.750 14360 14360 I libc : Requested dump for pid 14360 (Binder:oplus_de) 10-15 03:02:23.803 19213 19213 E crash_dump64: failed to get the guest state header for thread 14360: Bad address 10-15 03:02:23.805 19213 19213 E crash_dump64: failed to get the guest state header for thread 14542: Bad address 10-15 03:02:23.806 19213 19213 E crash_dump64: failed to get the guest state header for thread 14543: Bad address 10-15 03:02:23.808 19213 19213 E crash_dump64: failed to get the guest state header for thread 18958: Bad address 10-15 03:02:23.810 19213 19213 E crash_dump64: failed to get the guest state header for thread 19212: Bad address 10-15 03:02:23.812 19213 19213 E crash_dump64: failed to get the guest state header for thread 20960: Bad address 10-15 03:02:23.814 19213 19213 E crash_dump64: failed to get the guest state header for thread 28906: Bad address 10-15 03:02:23.823 19213 19213 I crash_dump64: obtaining output fd from tombstoned, type: kDebuggerdNativeBacktrace 10-15 03:02:23.826 01047 01047 I tombstoned: received crash request for pid 14360 10-15 03:02:23.826 01047 01047 I tombstoned: found intercept fd 512 for pid 14360 and type kDebuggerdNativeBacktrace 10-15 03:02:23.827 19213 19213 I crash_dump64: performing dump of process 14360 (target tid = 14360) 10-15 03:02:23.830 19213 19213 I crash_dump64: ***crash_dump->dump_backtrace*** 10-15 03:02:23.868 01453 01534 I system_server: libdebuggerd_client: done dumping process 14360 10-15 03:02:23.869 01047 01047 W tombstoned: skipping tombstone file creation due to intercept 10-15 03:02:23.870 01453 01534 I ActivityManager: Collecting stacks for native pid 1113 10-15 03:02:23.871 01453 01534 E system_server: Could not open /dev/binderfs/binder_logs/transactions. Likely a permissions issue. errno: 2 10-15 03:02:23.871 01453 01534 E android.os.Debug: Failed to get binder state info for pid: 1113 status: -2: No such file or directory 10-15 03:02:23.873 01453 01534 I system_server: libdebuggerd_client: started dumping process 1113 10-15 03:02:23.874 01047 01047 I tombstoned: registered intercept for pid 1113 and type kDebuggerdNativeBacktrace 10-15 03:02:23.877 01113 01113 I libc : Requested dump for pid 1113 (main) 10-15 03:02:23.949 19218 19218 I crash_dump32: obtaining output fd from tombstoned, type: kDebuggerdNativeBacktrace 10-15 03:02:23.950 01047 01047 I tombstoned: received crash request for pid 1113 10-15 03:02:23.951 01047 01047 I tombstoned: found intercept fd 512 for pid 1113 and type kDebuggerdNativeBacktrace 10-15 03:02:23.951 19218 19218 I crash_dump32: performing dump of process 1113 (target tid = 1113) 10-15 03:02:23.960 19218 19218 I crash_dump32: ***crash_dump->dump_backtrace*** 10-15 03:02:24.050 01453 01973 D AlarmManager: get result from waitForAlarm: result = 0x8 10-15 03:02:24.051 01453 01973 V AlarmManager: Checking for alarms... rtc=1760468544050, elapsed=290400748, nextNoWakeup = 295716699, PendingNonWakeupAlarmsSize = 3, result = 0x8, hasPendingIdle = false 10-15 03:02:24.089 01453 03039 D Osense-PsiDetector: newPressureState = 0, 3 10-15 03:02:24.090 01453 03039 D Osense-ReentrantPolicy: bundle: Bundle[{stateType=update, currentAvailmem=2742, type=iolevel, killTriggerMem=1800, ioLevel=3}] 10-15 03:02:24.090 01453 03039 D OsenseResEventManager: handleOsenseResultEvent: OsenseEventResult : eventType is :112 eventStateType is :2 ExtraData is : Bundle[{currentAvailmem=2742, killTriggerMem=1800, ioLevel=3}] 10-15 03:02:24.090 01453 03039 D Osense-FeatureManager: notifySceneToNRTFeature... scene:SCENE_RES_IO_PSI, bundle:Bundle[{ioLevel=3}] 10-15 03:02:24.091 01453 03039 D Osense-IOFeature: dispatchScene...sceneType:SCENE_RES_IO_PSI, bundle:Bundle[{ioLevel=3}] 10-15 03:02:24.091 01453 02953 I Osense-BaseDecisionMaker: notifySceneToAthenaPolicy: SCENE_RES_IO_PSI, bundle: Bundle[{ioLevel=3}] 10-15 03:02:24.092 01453 02953 I Osense-BaseDecisionMaker: OSense not supported scene! SCENE_RES_IO_PSI 10-15 03:02:24.127 01952 05035 I oplus_theia: Waiting for OCenterService 10-15 03:02:24.153 01453 01534 I system_server: libdebuggerd_client: done dumping process 1113 10-15 03:02:24.154 01047 01047 W tombstoned: skipping tombstone file creation due to intercept 10-15 03:02:24.157 01453 01534 I ActivityManager: Collecting stacks for native pid 1435 10-15 03:02:24.158 01453 01534 E system_server: Could not open /dev/binderfs/binder_logs/transactions. Likely a permissions issue. errno: 2 10-15 03:02:24.158 01453 01534 E android.os.Debug: Failed to get binder state info for pid: 1435 status: -2: No such file or directory 10-15 03:02:24.160 01453 01534 I system_server: libdebuggerd_client: started dumping process 1435分析log
最新发布
10-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值