@ -8,11 +8,11 @@ import subprocess 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					import  time  
					 
					 
					 
					import  time  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					import  glob  
					 
					 
					 
					import  glob  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					from  raven  import  Client  
					 
					 
					 
					import  sentry_sdk  
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					from  raven . transport . http  import  HTTPTransport  
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					from  common . params  import  Params  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					from  common . file_helpers  import  mkdirs_exists_ok  
					 
					 
					 
					from  common . file_helpers  import  mkdirs_exists_ok  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					from  selfdrive . hardware  import  TICI  
					 
					 
					 
					from  selfdrive . hardware  import  TICI ,  HARDWARE  
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					from  selfdrive . loggerd . config  import  ROOT  
					 
					 
					 
					from  selfdrive . loggerd . config  import  ROOT  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					from  selfdrive . swaglog  import  cloudlog  
					 
					 
					 
					from  selfdrive . swaglog  import  cloudlog  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					from  selfdrive . version  import  branch ,  commit ,  dirty ,  origin ,  version  
					 
					 
					 
					from  selfdrive . version  import  branch ,  commit ,  dirty ,  origin ,  version  
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -31,16 +31,15 @@ def safe_fn(s): 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  return  " " . join ( c  for  c  in  s  if  c . isalnum ( )  or  c  in  extra ) . rstrip ( )   
					 
					 
					 
					  return  " " . join ( c  for  c  in  s  if  c . isalnum ( )  or  c  in  extra ) . rstrip ( )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					def  sentry_report ( client ,  fn ,  message ,  contents ) :  
					 
					 
					 
					def  sentry_report ( fn ,  message ,  contents ) :  
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					  cloudlog . error ( { ' tombstone ' :  message } )   
					 
					 
					 
					  cloudlog . error ( { ' tombstone ' :  message } )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  client . captureMessage (   
					 
					 
					 
					
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    message = message ,   
					 
					 
					 
					  with  sentry_sdk . configure_scope ( )  as  scope :   
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    sdk = { ' name ' :  ' tombstoned ' ,  ' version ' :  ' 0 ' } ,   
					 
					 
					 
					      scope . set_extra ( " tombstone_fn " ,  fn )   
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    extra = {   
					 
					 
					 
					      scope . set_extra ( " tombstone " ,  contents )   
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					      ' tombstone_fn ' :  fn ,   
					 
					 
					 
					      sentry_sdk . capture_message ( message = message )   
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					      ' tombstone ' :  contents   
					 
					 
					 
					      sentry_sdk . flush ( )   
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    } ,   
					 
					 
					 
					
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					  )   
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					def  clear_apport_folder ( ) :  
					 
					 
					 
					def  clear_apport_folder ( ) :  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  for  f  in  glob . glob ( APPORT_DIR  +  ' * ' ) :   
					 
					 
					 
					  for  f  in  glob . glob ( APPORT_DIR  +  ' * ' ) :   
				
			 
			
		
	
	
		
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
					 
					@ -77,7 +76,7 @@ def get_tombstones(): 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  return  files   
					 
					 
					 
					  return  files   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					def  report_tombstone_android ( fn ,  client ) :  
					 
					 
					 
					def  report_tombstone_android ( fn ) :  
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					  f_size  =  os . path . getsize ( fn )   
					 
					 
					 
					  f_size  =  os . path . getsize ( fn )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  if  f_size  >  MAX_SIZE :   
					 
					 
					 
					  if  f_size  >  MAX_SIZE :   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    cloudlog . error ( f " Tombstone  { fn }  too big,  { f_size } . Skipping... " )   
					 
					 
					 
					    cloudlog . error ( f " Tombstone  { fn }  too big,  { f_size } . Skipping... " )   
				
			 
			
		
	
	
		
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
					 
					@ -104,7 +103,7 @@ def report_tombstone_android(fn, client): 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  if  fault_idx  > =  0 :   
					 
					 
					 
					  if  fault_idx  > =  0 :   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    message  =  message [ : fault_idx ]   
					 
					 
					 
					    message  =  message [ : fault_idx ]   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  sentry_report ( client ,  fn ,  message ,  contents )   
					 
					 
					 
					  sentry_report ( fn ,  message ,  contents )   
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  # Copy crashlog to upload folder   
					 
					 
					 
					  # Copy crashlog to upload folder   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  clean_path  =  executable . replace ( ' ./ ' ,  ' ' ) . replace ( ' / ' ,  ' _ ' )   
					 
					 
					 
					  clean_path  =  executable . replace ( ' ./ ' ,  ' ' ) . replace ( ' / ' ,  ' _ ' )   
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -118,7 +117,7 @@ def report_tombstone_android(fn, client): 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  shutil . copy ( fn ,  os . path . join ( crashlog_dir ,  new_fn ) )   
					 
					 
					 
					  shutil . copy ( fn ,  os . path . join ( crashlog_dir ,  new_fn ) )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					def  report_tombstone_apport ( fn ,  client ) :  
					 
					 
					 
					def  report_tombstone_apport ( fn ) :  
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					  f_size  =  os . path . getsize ( fn )   
					 
					 
					 
					  f_size  =  os . path . getsize ( fn )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  if  f_size  >  MAX_SIZE :   
					 
					 
					 
					  if  f_size  >  MAX_SIZE :   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    cloudlog . error ( f " Tombstone  { fn }  too big,  { f_size } . Skipping... " )   
					 
					 
					 
					    cloudlog . error ( f " Tombstone  { fn }  too big,  { f_size } . Skipping... " )   
				
			 
			
		
	
	
		
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
					 
					@ -178,7 +177,7 @@ def report_tombstone_apport(fn, client): 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  contents  =  stacktrace  +  " \n \n "  +  contents   
					 
					 
					 
					  contents  =  stacktrace  +  " \n \n "  +  contents   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  message  =  message  +  "  -  "  +  crash_function   
					 
					 
					 
					  message  =  message  +  "  -  "  +  crash_function   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  sentry_report ( client ,  fn ,  message ,  contents )   
					 
					 
					 
					  sentry_report ( fn ,  message ,  contents )   
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  # Copy crashlog to upload folder   
					 
					 
					 
					  # Copy crashlog to upload folder   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  clean_path  =  path . replace ( ' / ' ,  ' _ ' )   
					 
					 
					 
					  clean_path  =  path . replace ( ' / ' ,  ' _ ' )   
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -202,15 +201,18 @@ def main(): 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  clear_apport_folder ( )   # Clear apport folder on start, otherwise duplicate crashes won't register   
					 
					 
					 
					  clear_apport_folder ( )   # Clear apport folder on start, otherwise duplicate crashes won't register   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  initial_tombstones  =  set ( get_tombstones ( ) )   
					 
					 
					 
					  initial_tombstones  =  set ( get_tombstones ( ) )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  tags  =  {   
					 
					 
					 
					  sentry_sdk . utils . MAX_STRING_LENGTH  =  8192   
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    ' dirty ' :  dirty ,   
					 
					 
					 
					  sentry_sdk . init ( " https://a40f22e13cbc4261873333c125fc9d38@o33823.ingest.sentry.io/157615 " ,   
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    ' origin ' :  origin ,   
					 
					 
					 
					                  default_integrations = False ,  release = version )   
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					    ' branch ' :  branch   
					 
					 
					 
					
 
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					  }   
					 
					 
					 
					  dongle_id  =  Params ( ) . get ( " DongleId " ,  encoding = ' utf-8 ' )   
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					  client  =  Client ( ' https://a40f22e13cbc4261873333c125fc9d38:dd57b2dc8113415093f8d9c017df092b@o33823.ingest.sentry.io/157615 ' ,   
					 
					 
					 
					  sentry_sdk . set_user ( { " id " :  dongle_id } )   
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					                  install_sys_hook = False ,  transport = HTTPTransport ,  release = version ,  tags = tags ,  string_max_length = 10000 )   
					 
					 
					 
					  sentry_sdk . set_tag ( " dirty " ,  dirty )   
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					  sentry_sdk . set_tag ( " origin " ,  origin )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					  sentry_sdk . set_tag ( " branch " ,  branch )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					  sentry_sdk . set_tag ( " commit " ,  commit )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					  sentry_sdk . set_tag ( " device " ,  HARDWARE . get_device_type ( ) )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  client . user_context ( { ' id ' :  os . environ . get ( ' DONGLE_ID ' ) } )   
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					  while  True :   
					 
					 
					 
					  while  True :   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					    now_tombstones  =  set ( get_tombstones ( ) )   
					 
					 
					 
					    now_tombstones  =  set ( get_tombstones ( ) )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -218,9 +220,9 @@ def main(): 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					      try :   
					 
					 
					 
					      try :   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        cloudlog . info ( f " reporting new tombstone  { fn } " )   
					 
					 
					 
					        cloudlog . info ( f " reporting new tombstone  { fn } " )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        if  fn . endswith ( " .crash " ) :   
					 
					 
					 
					        if  fn . endswith ( " .crash " ) :   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          report_tombstone_apport ( fn ,  client )   
					 
					 
					 
					          report_tombstone_apport ( fn )   
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					        else :   
					 
					 
					 
					        else :   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					          report_tombstone_android ( fn ,  client )   
					 
					 
					 
					          report_tombstone_android ( fn )   
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					      except  Exception :   
					 
					 
					 
					      except  Exception :   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					        cloudlog . exception ( f " Error reporting tombstone  { fn } " )   
					 
					 
					 
					        cloudlog . exception ( f " Error reporting tombstone  { fn } " )