SIGPIPE received in android system native app on Jellybean

时间:2022-01-22 18:24:05

 GENERAL DESCRIPTION
12-16 06:21:18.779   436   459 I ActivityManager: Start proc com.xxxxxx.crashmonitor for service com.xxxxxx.crashmonitor/.service.CrashMonitorService: pid=19174 uid=10118 gids={1007, 1015, 1028}
12-16 06:21:18.829 19174 19174 E Trace   : error opening trace file: No such file or directory (2)
12-16 06:21:18.829 19174 19174 D ActivityThread: setTargetHeapUtilization:0.25
12-16 06:21:18.829 19174 19174 D ActivityThread: setTargetHeapIdealFree:8388608
12-16 06:21:18.829 19174 19174 D ActivityThread: setTargetHeapConcurrentStart:2097152
12-16 06:21:18.869 19174 19174 V CrashMonitor: CrashMonitorService: [Enter]onCreate
12-16 06:21:18.869 19174 19174 I CrashMonitor: CrashMonitorService: Service Started...
12-16 06:21:18.879 19174 19174 D CrashMonitor: Configuration: Configuration created...
12-16 06:21:18.889 19174 19174 D CrashMonitor: RuntimeData: RuntimeData created...
12-16 06:21:18.889 19174 19174 V CrashMonitor: CrashMonitorService: [Exit]onCreate
12-16 06:21:18.889 19174 19187 V CrashMonitor: CrashMonitorService: [Enter]onHandleIntent
12-16 06:21:18.889 19174 19187 D CrashMonitor: CrashMonitorService: onHandleIntent action: android.intent.action.DROPBOX_ENTRY_ADDED
12-16 06:21:18.899 19174 19187 D CrashMonitor: Util: crashlevel: 0
12-16 06:21:18.909 19174 19187 D CrashMonitor: MiscTaInfo: MiscTaInfo created...
12-16 06:21:18.909 19174 19187 V CrashMonitor: CrashMonitorService: executing DropBoxHandler(0)
12-16 06:21:18.909 19174 19187 V CrashMonitor: DropBoxHandler: [Enter]execute
12-16 06:21:19.419 19174 19187 D CrashMonitor: DropBoxHandler: New DropBox entry: system_app_crash
12-16 06:21:19.429 19174 19187 V CrashMonitor: DropBoxParser: [Enter]parse
12-16 06:21:19.439 19174 19187 V CrashMonitor: DropBoxParser: [Exit]parseDropBoxEntry
12-16 06:21:19.449 19174 19187 V CrashMonitor: DropBoxHandler: [Enter]createBugReportFileName
12-16 06:21:19.469 19174 19187 V CrashMonitor: DropBoxHandler: [Exit]createBugReportFileName
12-16 06:21:19.469 19174 19187 V CrashMonitor: DropBoxHandler: [Enter]startbugreportcatcher
12-16 06:21:19.499 19174 19187 V CrashMonitor: DropBoxHandler: [Exit]startbugreportcatcher
12-16 06:21:19.499 19174 19187 V CrashMonitor: DropBoxHandler: [Enter]store
12-16 06:21:19.499 19174 19187 D CrashMonitor: RuntimeData: updating Runtime
12-16 06:21:19.519 19174 19187 D CrashMonitor: RuntimeData: timediff=310391
12-16 06:21:19.519 19190 19190 E Trace   : error opening trace file: No such file or directory (2)
12-16 06:21:19.519 19190 19190 D ActivityThread: setTargetHeapUtilization:0.25
12-16 06:21:19.519 19190 19190 D ActivityThread: setTargetHeapIdealFree:8388608
12-16 06:21:19.519 19190 19190 D ActivityThread: setTargetHeapConcurrentStart:2097152
12-16 06:21:19.539 19174 19187 D CrashMonitor: RuntimeData: updated crash counters
12-16 06:21:19.549 19190 19190 D BugreportCatcher: BugreportCatcher standby
12-16 06:21:19.569 19190 19190 D BugreportCatcher: Create bugreport instance(/mnt/ext_card/BugReport/.gz)
12-16 06:21:19.589 19174 19187 V CrashMonitor: IDDStorer: [Enter]store
12-16 06:21:19.639   513   513 D SizeAdaptiveLayout: com.android.internal.widget.SizeAdaptiveLayout@41b51488child view android.widget.FrameLayout@41b9d5f8 measured out of bounds at 63px clamped to 64px
12-16 06:21:19.719 19174 19187 D CrashMonitor: TimeStamp: TimeStamp is different! Directory: /system/lib
12-16 06:21:19.719 19174 19187 E IddJniLib: Failed to load libiddjni - disabling IDD
12-16 06:21:19.729 19174 19187 D CrashMonitor: IDDStorer: forceUploadDelay: 0 uptime: 17842803
12-16 06:21:19.729 19174 19187 E IddJniLib: Failed to load libiddjni - disabling IDD
12-16 06:21:19.729 19174 19187 V CrashMonitor: IDDStorer: [Exit]store
12-16 06:21:19.729 19174 19187 V CrashMonitor: MiscTaStorer: [Enter]store
12-16 06:21:19.729 19174 19187 D CrashMonitor: IDDEvent: Creating IDD event
12-16 06:21:19.739 19174 19187 D CrashMonitor: TimeStamp: TimeStamp is different! Directory: /system/lib
12-16 06:21:19.739 19174 19187 D CrashMonitor: MiscTaStorer: Storing to MiscTa
12-16 06:21:19.759 19174 19187 D CrashMonitor: MiscTaStorer: storeCrashData report: system=false unit=0
12-16 06:21:19.759 19174 19187 D CrashMonitor: MiscTaStorer: MiscTa crash data index = 1:1 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0 0:0
12-16 06:21:19.759 19174 19187 V CrashMonitor: MiscTaStorer: [Exit]store
12-16 06:21:19.759 19174 19187 V CrashMonitor: CrashSMSStorer: [Enter]store
12-16 06:21:19.759 19174 19187 V CrashMonitor: CrashSMSStorer: [Enter]storeToCrashSMS
12-16 06:21:19.759 19174 19187 D CrashMonitor: CrashSMSStorer: Creating CrashSMS file
12-16 06:21:19.769 19174 19187 D CrashMonitor: CrashSMSStorer: Storing crash data: /data/crashsms/crashes/1355610030.txt
12-16 06:21:19.789 19174 19187 V CrashMonitor: CrashSMSStorer: [Exit]storeToCrashSMS
12-16 06:21:19.789 19174 19187 V CrashMonitor: CrashSMSStorer: [Exit]store
12-16 06:21:19.789 19174 19187 V CrashMonitor: DropBoxHandler: [Exit]store
12-16 06:21:19.799 19174 19187 V CrashMonitor: DropBoxHandler: [Exit]execute
12-16 06:21:19.799 19174 19187 V CrashMonitor: CrashMonitorService: completed DropBoxHandler(0)
12-16 06:21:19.809 19174 19187 E CrashMonitor: MiscTaInfo: MiscTa service disconnect failed: java.lang.IllegalArgumentException: Service not registered: com.xxxxxxxxx.crashmonitor.MiscTaInfo$MiscTaServiceConnection@41b1ce80
12-16 06:21:19.959 19174 19187 V CrashMonitor: CrashMonitorService: [Exit]onHandleIntent
12-16 06:21:19.959 19174 19174 V CrashMonitor: CrashMonitorService: [Enter]onDestroy
12-16 06:21:19.959 19174 19174 I CrashMonitor: CrashMonitorService: Service Stoped...
12-16 06:21:19.959 19174 19174 V CrashMonitor: CrashMonitorService: [Exit]onDestroy
12-16 06:21:20.799   436 22830 I ActivityManager: Process com.xxxxxx.crashmonitor (pid 19174) has died.   !!!!!!!!!!

12-16 06:21:37.399 19453 19453 F libc    : Fatal signal 13 (SIGPIPE) at 0x00004bfd (code=0), thread 19453 (logcat)
12-16 06:21:37.399 18911 18911 I DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
12-16 06:21:37.399 18911 18911 I DEBUG   : Build fingerprint: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:userdebug/release-keys'
12-16 06:21:37.399 18911 18911 I DEBUG   : pid: 19453, tid: 19453, name: logcat  >>> logcat <<<
12-16 06:21:37.409 18911 18911 I DEBUG   : signal 13 (SIGPIPE), code -6 (?), fault addr --------
12-16 06:21:37.409 18911 18911 I DEBUG   :     r0 ffffffe0  r1 bec6969c  r2 00000027  r3 bec696c4
12-16 06:21:37.409 18911 18911 I DEBUG   :     r4 4020ba6c  r5 00000000  r6 00000004  r7 00000004
12-16 06:21:37.409 18911 18911 I DEBUG   :     r8 40de7898  r9 40100f38  sl 00000005  fp 40101440
12-16 06:21:37.409 18911 18911 I DEBUG   :     ip 40100f58  sp bec69690  lr 400fdeb3  pc 401c7978  cpsr 00000010
12-16 06:21:37.409 18911 18911 I DEBUG   :     d0  676f6c2f7665642f  d1  20676e696e6e6973
12-16 06:21:37.449 18911 18911 I DEBUG   :     d2  0000000000000079  d3  0000000000000073
12-16 06:21:37.449 18911 18911 I DEBUG   :     d4  0000000000000000  d5  0000000000000000
12-16 06:21:37.449 18911 18911 I DEBUG   :     d6  0000000000000000  d7  45cbe64800000000
12-16 06:21:37.449 18911 18911 I DEBUG   :     d8  0000000000000000  d9  0000000000000000
12-16 06:21:37.449 18911 18911 I DEBUG   :     d10 0000000000000000  d11 0000000000000000
12-16 06:21:37.449 18911 18911 I DEBUG   :     d12 0000000000000000  d13 0000000000000000
12-16 06:21:37.449 18911 18911 I DEBUG   :     d14 0000000000000000  d15 0000000000000000
12-16 06:21:37.449 18911 18911 I DEBUG   :     d16 41d172f99231ba5e  d17 3f50624dd2f1a9fc
12-16 06:21:37.449 18911 18911 I DEBUG   :     d18 41c2f41e24800000  d19 0000000000000000
12-16 06:21:37.449 18911 18911 I DEBUG   :     d20 0000000000000000  d21 0000000000000000
12-16 06:21:37.449 18911 18911 I DEBUG   :     d22 0000000000000000  d23 0000000000000000
12-16 06:21:37.449 18911 18911 I DEBUG   :     d24 0000000000000000  d25 0000000000000000
12-16 06:21:37.449 18911 18911 I DEBUG   :     d26 0000000000000000  d27 0000000000000000
12-16 06:21:37.449 18911 18911 I DEBUG   :     d28 0000000000000000  d29 0000000000000000
12-16 06:21:37.449 18911 18911 I DEBUG   :     d30 0000000000000000  d31 0000000000000000
12-16 06:21:37.449 18911 18911 I DEBUG   :     scr 00000010
12-16 06:21:37.449 18911 18911 I DEBUG   :
12-16 06:21:37.449 18911 18911 I DEBUG   : backtrace:
12-16 06:21:37.449 18911 18911 I DEBUG   :     #00  pc 0000c978  /system/lib/libc.so (write+12)
12-16 06:21:37.449 18911 18911 I DEBUG   :     #01  pc 00000eaf  /system/bin/logcat
12-16 06:21:37.449 18911 18911 I DEBUG   :
12-16 06:21:37.449 18911 18911 I DEBUG   : stack:
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec69650  00000000 
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec69654  00000000 
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec69658  00000000 
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec6965c  00000000 
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec69660  00000000 
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec69664  bec69624  [stack]
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec69668  00000000 
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec6966c  00000000 
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec69670  00000000 
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec69674  00000000 
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec69678  00000000 
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec6967c  00000000 
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec69680  00000000 
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec69684  00000000 
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec69688  df0027ad 
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec6968c  00000000 
12-16 06:21:37.449 18911 18911 I DEBUG   :     #00  bec69690  4020ba6c 
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec69694  40de5068  [heap]
12-16 06:21:37.449 18911 18911 I DEBUG   :     #01  bec69698  4017d6b7  /system/bin/linker
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec6969c  2d2d2d2d 
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec696a0  2d2d2d2d 
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec696a4  6562202d 
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec696a8  6e6e6967 
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec696ac  20676e69 
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec696b0  2f20666f 
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec696b4  2f766564 
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec696b8  2f676f6c 
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec696bc  74737973 
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec696c0  000a6d65 
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec696c4  00000000 
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec696c8  40170bd9  /system/bin/linker
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec696cc  00000000 
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec696d0  00000000 
12-16 06:21:37.449 18911 18911 I DEBUG   :          bec696d4  00008000 
12-16 06:21:37.449 18911 18911 I DEBUG   :
12-16 06:21:37.449 18911 18911 I DEBUG   : memory near r1:
12-16 06:21:37.449 18911 18911 I DEBUG   :     bec6967c 00000000 00000000 00000000 df0027ad  .............'..
12-16 06:21:37.449 18911 18911 I DEBUG   :     bec6968c 00000000 4020ba6c 40de5068 4017d6b7  ....l. @hP.@...@
12-16 06:21:37.449 18911 18911 I DEBUG   :     bec6969c 2d2d2d2d 2d2d2d2d 6562202d 6e6e6967  --------- beginn
12-16 06:21:37.449 18911 18911 I DEBUG   :     bec696ac 20676e69 2f20666f 2f766564 2f676f6c  ing of /dev/log/
12-16 06:21:37.449 18911 18911 I DEBUG   :     bec696bc 74737973 000a6d65 00000000 40170bd9  system.........@
12-16 06:21:37.449 18911 18911 I DEBUG   :
12-16 06:21:37.449 18911 18911 I DEBUG   : memory near r3:
12-16 06:21:37.449 18911 18911 I DEBUG   :     bec696a4 6562202d 6e6e6967 20676e69 2f20666f  - beginning of /
12-16 06:21:37.449 18911 18911 I DEBUG   :     bec696b4 2f766564 2f676f6c 74737973 000a6d65  dev/log/system..
12-16 06:21:37.449 18911 18911 I DEBUG   :     bec696c4 00000000 40170bd9 00000000 00000000  .......@........
12-16 06:21:37.449 18911 18911 I DEBUG   :     bec696d4 00008000 0000b30b 00000000 00000000  ................
12-16 06:21:37.449 18911 18911 I DEBUG   :     bec696e4 00000489 000081a4 00000001 00000000  ................
12-16 06:21:37.449 18911 18911 I DEBUG   :
12-16 06:21:37.449 18911 18911 I DEBUG   : memory near r4:
12-16 06:21:37.449 18911 18911 I DEBUG   :     4020ba4c 00000000 00000000 00000000 00000000  ................
12-16 06:21:37.449 18911 18911 I DEBUG   :     4020ba5c 00000000 00000000 00000000 00000000  ................
12-16 06:21:37.449 18911 18911 I DEBUG   :     4020ba6c 47a6a4ae 00000000 00000000 00000000  ...G............
12-16 06:21:37.449 18911 18911 I DEBUG   :     4020ba7c 00000000 00000000 00000000 00000000  ................
12-16 06:21:37.449 18911 18911 I DEBUG   :     4020ba8c 00000000 00000000 00000000 00000000  ................
12-16 06:21:37.449 18911 18911 I DEBUG   :
12-16 06:21:37.449 18911 18911 I DEBUG   : memory near r8:
12-16 06:21:37.449 18911 18911 I DEBUG   :     40de7878 00000000 00000000 00000000 00000000  ................
12-16 06:21:37.449 18911 18911 I DEBUG   :     40de7888 00000000 00000000 00000000 00000000  ................
12-16 06:21:37.449 18911 18911 I DEBUG   :     40de7898 00000000 40de8cb8 00000000 00001413  .......@........
12-16 06:21:37.449 18911 18911 I DEBUG   :     40de78a8 00000021 00005b49 00005b49 50ccf64c  !...I[..I[..L..P
12-16 06:21:37.449 18911 18911 I DEBUG   :     40de78b8 0a21f390 61724204 65674174 4400746e  ..!..BratAgent.D
12-16 06:21:37.449 18911 18911 I DEBUG   :
12-16 06:21:37.449 18911 18911 I DEBUG   : memory near r9:
12-16 06:21:37.449 18911 18911 I DEBUG   :     40100f18 00000000 00000000 00000000 401ff670  ............p..@
12-16 06:21:37.449 18911 18911 I DEBUG   :     40100f28 4020ba6c 402043c8 401ff7dc 401ff64c  l. @.C @...@L..@
12-16 06:21:37.449 18911 18911 I DEBUG   :     40100f38 00000000 00000000 00000000 401d20ed  ............. .@
12-16 06:21:37.449 18911 18911 I DEBUG   :     40100f48 401d6165 401d6225 401d75ad 401d211c  ea.@%b.@.u.@.!.@
12-16 06:21:37.449 18911 18911 I DEBUG   :     40100f58 401c796c 401d4d0d 401da535 401e5745  ly.@.M.@5..@EW.@
12-16 06:21:37.449 18911 18911 I DEBUG   :
12-16 06:21:37.449 18911 18911 I DEBUG   : memory near fp:
12-16 06:21:37.449 18911 18911 I DEBUG   :     40101420 00000000 00000000 00000000 00000000  ................
12-16 06:21:37.449 18911 18911 I DEBUG   :     40101430 00000000 00000000 00000000 00000000  ................
12-16 06:21:37.449 18911 18911 I DEBUG   :     40101440 00000000 00000002 00000000 00000000  ................
12-16 06:21:37.449 18911 18911 I DEBUG   :     40101450 00000000 00000000 00000000 00000000  ................
12-16 06:21:37.449 18911 18911 I DEBUG   :     40101460 00000000 00000000 00000000 00000000  ................
12-16 06:21:37.449 18911 18911 I DEBUG   :
12-16 06:21:37.449 18911 18911 I DEBUG   : memory near ip:
12-16 06:21:37.449 18911 18911 I DEBUG   :     40100f38 00000000 00000000 00000000 401d20ed  ............. .@
12-16 06:21:37.449 18911 18911 I DEBUG   :     40100f48 401d6165 401d6225 401d75ad 401d211c  ea.@%b.@.u.@.!.@
12-16 06:21:37.449 18911 18911 I DEBUG   :     40100f58 401c796c 401d4d0d 401da535 401e5745  ly.@.M.@5..@EW.@
12-16 06:21:37.449 18911 18911 I DEBUG   :     40100f68 4026e9e1 4026e949 4026e695 4026edd1  ..&@I.&@..&@..&@
12-16 06:21:37.449 18911 18911 I DEBUG   :     40100f78 401c7a0c 401d59c1 401c80cc 401ce959  .z.@.Y.@...@Y..@
12-16 06:21:37.449 18911 18911 I DEBUG   :
12-16 06:21:37.449 18911 18911 I DEBUG   : memory near sp:
12-16 06:21:37.449 18911 18911 I DEBUG   :     bec69670 00000000 00000000 00000000 00000000  ................
12-16 06:21:37.449 18911 18911 I DEBUG   :     bec69680 00000000 00000000 df0027ad 00000000  .........'......
12-16 06:21:37.449 18911 18911 I DEBUG   :     bec69690 4020ba6c 40de5068 4017d6b7 2d2d2d2d  l. @hP.@...@----
12-16 06:21:37.449 18911 18911 I DEBUG   :     bec696a0 2d2d2d2d 6562202d 6e6e6967 20676e69  ----- beginning
12-16 06:21:37.449 18911 18911 I DEBUG   :     bec696b0 2f20666f 2f766564 2f676f6c 74737973  of /dev/log/syst
12-16 06:21:37.449 18911 18911 I DEBUG   :
12-16 06:21:37.449 18911 18911 I DEBUG   : code around pc:
12-16 06:21:37.449 18911 18911 I DEBUG   :     401c7958 ef000000 e8bd0090 e1b00000 512fff1e  ............../Q
12-16 06:21:37.449 18911 18911 I DEBUG   :     401c7968 ea00b4ac e92d0090 e3a07004 ef000000  ......-..p......
12-16 06:21:37.449 18911 18911 I DEBUG   :     401c7978 e8bd0090 e1b00000 512fff1e ea00b4a5  ........../Q....
12-16 06:21:37.449 18911 18911 I DEBUG   :     401c7988 e1a0c00d e92d00f0 e89c0070 e3a070b4  ......-.p....p..
12-16 06:21:37.449 18911 18911 I DEBUG   :     401c7998 ef000000 e8bd00f0 e1b00000 512fff1e  ............../Q
12-16 06:21:37.449 18911 18911 I DEBUG   :
12-16 06:21:37.449 18911 18911 I DEBUG   : code around lr:
12-16 06:21:37.449 18911 18911 I DEBUG   :     400fde90 6180f44f a801681b f7ff447a a801ee82  O..a.h..zD......
12-16 06:21:37.449 18911 18911 I DEBUG   :     400fdea0 ee84f7ff 4602a901 44784810 f7ff6800  .......F.HxD.h..
12-16 06:21:37.449 18911 18911 I DEBUG   :     400fdeb0 2800ee84 480eda07 f7ff4478 f04fee84  ...(...HxD....O.
12-16 06:21:37.449 18911 18911 I DEBUG   :     400fdec0 f7ff30ff f8ddee86 68231404 d0014299  .0........#h.B..
12-16 06:21:37.449 18911 18911 I DEBUG   :     400fded0 ee84f7ff f50db002 bd106d80 000030b8  .........m...0..
12-16 06:21:37.539 18911 18911 I DEBUG   : crash_level = 0
12-16 06:21:37.569 19454 19454 I DEBUG   : debuggerd: Dec 11 2012 11:24:21
................................
SIGPIPE continue arise in netcfg, ping, show, iptables, sqlite3, vdc, df, ...

[ANALYSIS]
In the logcat, after logcat crash, many SIGPIPE received in several native app cmds.
These cmds are /system/bin/dumpstate used, logcat three times, netcfg, ping three times, show, iptables, sqlite3, vdc, df, lsof, ...
They are with the same root cause.

Notice that
12-16 06:21:18.779   436   459 I ActivityManager: Start proc  for service /.service.CrashMonitorService: pid=19174 uid=10118 gids={1007, 1015, 1028}
................................
12-16 06:21:20.799   436 22830 I ActivityManager: Process com.xxxxxxx.crashmonitor (pid 19174) has died.

In normal case, crashmonitor should not die after CrashMonitorService finishing its intent handle.
Usually, crashmonitor is hidden by ActivityManager, which is something like the following.
12-11 00:42:22.189 I/ActivityManager(  281): No longer want com.xxxxxxx.crashmonitor (pid 17743): hidden #16

CrashmonitorNativeService detects a java app carsh and calls bugreport app to generate a bugreport file.
CrashmonitorNativeService starts dumpstate service and connects socket to dumpstate.
dumpstate runs command logcat(and netcfg, ping, show, iptables, sqlite3, vdc, df, ...) to write data to stdout which is redirected to its unix socket.
If CrashmonitorNativeService is already terminated while dumpstate and his forked children are still writing(including nornal write, sendto, and flush in atexit()) tothe socket, SIGPIPE receives.

NOTE:

In ICS, SIGPIPE is sent once, then continue to working without crash by debuggerd.

But in JB, SIGPIPE re-throw on debugger_signal_handler(). So SIGPIPE is sent twice, then native crash occurred by debuggerd.

In init.rc, dumpstate starts with option -s which redirects stdout to socket.
593service dumpstate /system/bin/dumpstate -s
594    class main
595    socket dumpstate stream 0660 shell log
596    disabled
597    oneshot

In frameworks/base/cmds/bugreport/bugreport.c
Bugreport uses property_set("stl.start", "dumpstate") to start the dumpstate service and connect to dumpstate's socket.
24int main(int argc, char *argv[]) {
25    char buffer[65536];
26    int i, s;
27
28    /* start the dumpstate service */
29    property_set("ctl.start", "dumpstate");
30
31    /* socket will not be available until service starts */
32    for (i = 0; i < 10; i++) {
33        s = socket_local_client("dumpstate",
34                             ANDROID_SOCKET_NAMESPACE_RESERVED,
35                             SOCK_STREAM);
36        if (s >= 0)
37            break;
38        /* try again in 1 second */
39        sleep(1);
40    }
41
42    if (s < 0) {
43        fprintf(stderr, "Failed to connect to dumpstate service\n");
44        exit(1);
45    }
46
47    while (1) {
48        int length = read(s, buffer, sizeof(buffer));
49        if (length <= 0)
50            break;
51        fwrite(buffer, 1, length, stdout);
52    }
53
54    close(s);
55    return 0;
56}

In frameworks/native/cmds/dumpstate/dumpstate.c
Dozens of system native apps are called to dump system and application state.
105    run_command("SYSTEM LOG", 20, "logcat", "-v", "threadtime", "-d", "*:v", NULL);
106    run_command("EVENT LOG", 20, "logcat", "-b", "events", "-v", "threadtime", "-d", "*:v", NULL);
107    run_command("RADIO LOG", 20, "logcat", "-b", "radio", "-v", "threadtime", "-d", "*:v", NULL);
108
145    dump_file("NETWORK DEV INFO", "/proc/net/dev");
146    dump_file("QTAGUID NETWORK INTERFACES INFO", "/proc/net/xt_qtaguid/iface_stat_all");
147    dump_file("QTAGUID NETWORK INTERFACES INFO (xt)", "/proc/net/xt_qtaguid/iface_stat_fmt");
148    dump_file("QTAGUID CTRL INFO", "/proc/net/xt_qtaguid/ctrl");
149    dump_file("QTAGUID STATS INFO", "/proc/net/xt_qtaguid/stats");
150
151    dump_file("NETWORK ROUTES", "/proc/net/route");
152    dump_file("NETWORK ROUTES IPV6", "/proc/net/ipv6_route");
153
154    /* TODO: Make last_kmsg CAP_SYSLOG protected. b/5555691 */
155    dump_file("LAST KMSG", "/proc/last_kmsg");
156    dump_file("LAST PANIC CONSOLE", "/data/dontpanic/apanic_console");
157    dump_file("LAST PANIC THREADS", "/data/dontpanic/apanic_threads");
158
159    if (screenshot_path[0]) {
160        ALOGI("taking screenshot\n");
161        run_command(NULL, 5, SU_PATH, "root", "screenshot", screenshot_path, NULL);
162        ALOGI("wrote screenshot: %s\n", screenshot_path);
163    }
164
165    run_command("SYSTEM SETTINGS", 20, SU_PATH, "root", "sqlite3",
166            "/data/data/com.android.providers.settings/databases/settings.db",
167            "pragma user_version; select * from system; select * from secure;", NULL);
168
169    /* The following have a tendency to get wedged when wifi drivers/fw goes belly-up. */
170    run_command("NETWORK INTERFACES", 10, SU_PATH, "root", "netcfg", NULL);
171    run_command("IP RULES", 10, "ip", "rule", "show", NULL);
172    run_command("IP RULES v6", 10, "ip", "-6", "rule", "show", NULL);
173    run_command("ROUTE TABLE 60", 10, "ip", "route", "show", "table", "60", NULL);
174    run_command("ROUTE TABLE 61 v6", 10, "ip", "-6", "route", "show", "table", "60", NULL);
175    run_command("ROUTE TABLE 61", 10, "ip", "route", "show", "table", "61", NULL);
176    run_command("ROUTE TABLE 61 v6", 10, "ip", "-6", "route", "show", "table", "61", NULL);
177    dump_file("ARP CACHE", "/proc/net/arp");
178    run_command("IPTABLES", 10, SU_PATH, "root", "iptables", "-L", "-nvx", NULL);
179    run_command("IP6TABLES", 10, SU_PATH, "root", "ip6tables", "-L", "-nvx", NULL);
180    run_command("IPTABLE NAT", 10, SU_PATH, "root", "iptables", "-t", "nat", "-L", "-nvx", NULL);
181    /* no ip6 nat */
182    run_command("IPTABLE RAW", 10, SU_PATH, "root", "iptables", "-t", "raw", "-L", "-nvx", NULL);
183    run_command("IP6TABLE RAW", 10, SU_PATH, "root", "ip6tables", "-t", "raw", "-L", "-nvx", NULL);
184
185    run_command("WIFI NETWORKS", 20,
186            SU_PATH, "root", "wpa_cli", "list_networks", NULL);
187
188    property_get("dhcp.wlan0.gateway", network, "");
189    if (network[0])
190        run_command("PING GATEWAY", 10, SU_PATH, "root", "ping", "-c", "3", "-i", ".5", network, NULL);
191    property_get("dhcp.wlan0.dns1", network, "");
192    if (network[0])
193        run_command("PING DNS1", 10, SU_PATH, "root", "ping", "-c", "3", "-i", ".5", network, NULL);
194    property_get("dhcp.wlan0.dns2", network, "");
195    if (network[0])
196        run_command("PING DNS2", 10, SU_PATH, "root", "ping", "-c", "3", "-i", ".5", network, NULL);
197#ifdef FWDUMP_bcm4329
198    run_command("DUMP WIFI STATUS", 20,
199            SU_PATH, "root", "dhdutil", "-i", "wlan0", "dump", NULL);
200    run_command("DUMP WIFI INTERNAL COUNTERS", 20,
201            SU_PATH, "root", "wlutil", "counters", NULL);
202#endif
203
204    print_properties();
205
206    run_command("VOLD DUMP", 10, "vdc", "dump", NULL);
207    run_command("SECURE CONTAINERS", 10, "vdc", "asec", "list", NULL);
208
209    run_command("FILESYSTEMS & FREE SPACE", 10, SU_PATH, "root", "df", NULL);
210
211    run_command("PACKAGE SETTINGS", 20, SU_PATH, "root", "cat", "/data/system/packages.xml", NULL);
212    dump_file("PACKAGE UID ERRORS", "/data/system/uiderrors.txt");
213
214    run_command("LAST RADIO LOG", 10, "parse_radio_log", "/proc/last_radio_log", NULL);

SIGPIPE occurred due to write to socket that is already peer-closed, so Reference solution is to add the following lines
property_set("ctl.stop", "dumpstate");
sleep(1);
to stop dumpstate and its children before bugreport exits occationally.

There are at least two ways to solve the problem for single application:

1. Ignore SIGPIPE for the process before the socket is opened.
signal(SIGPIPE, SIG_IGN);

2. Set MSG_NOSIGNAL flag on the send call
send(fd, buffer, size, MSG_NOSIGNAL);

But the best way is to check the return value of the send socket api to detect the peer-closed socket to avoid the SIGPIPE.  

[Reference]

http://blog.csdn.net/mustanglau/article/details/4485491

服务器程序, 在Linux下测试时, 总是莫名退出. 最后跟踪到是write调用导致退出. 用gdb执行程序, 退出时提示"Broken pipe".

最后问题确定为, 对一个对端已经关闭的socket调用两次write, 第二次将会生成SIGPIPE信号, 该信号默认结束进程.

具体的分析可以结合TCP的"四次握手"关闭. TCP是全双工的信道, 可以看作两条单工信道, TCP连接两端的两个端点各负责一条. 当对端调用close时, 虽然本意是关闭整个两条信道, 但本端只是收到FIN包. 按照TCP协议的语义, 表示对端只是关闭了其所负责的那一条单工信道, 仍然可以继续接收数据. 也就是说, 因为TCP协议的限制, 一个端点无法获知对端的socket是调用了close还是shutdown.

SIGPIPE received in android system native app on Jellybean

对一个已经收到FIN包的socket调用read方法, 如果接收缓冲已空, 则返回0, 这就是常说的表示连接关闭. 但第一次对其调用write方法时, 如果发送缓冲没问题, 会返回正确写入(发送). 但发送的报文会导致对端发送RST报文, 因为对端的socket已经调用了close, 完全关闭, 既不发送, 也不接收数据. 所以, 第二次调用write方法(假设在收到RST之后), 会生成SIGPIPE信号, 导致进程退出.

为了避免进程退出, 可以捕获SIGPIPE信号, 或者忽略它, 给它设置SIG_IGN信号处理函数:

signal(SIGPIPE, SIG_IGN);

这样, 第二次调用write方法时, 会返回-1, 同时errno置为SIGPIPE. 程序便能知道对端已经关闭.

PS: Linux下的SIGALRM似乎会每1秒钟往后偏移1毫秒, 但Windows下经过测试完全准时, 不差1毫秒