watchdog_kick: non-allocating (#22892)
	
		
	
				
					
				
			* non-allocating
* unpack
* call kick every second
* cleanup include
old-commit-hash: ca88a8769b
			
			
				vw-mqb-aeb
			
			
		
							parent
							
								
									688b55c8e0
								
							
						
					
					
						commit
						84097b29df
					
				
				 3 changed files with 8 additions and 12 deletions
			
			
		@ -1,19 +1,12 @@ | 
				
			|||||||
#include "selfdrive/common/watchdog.h" | 
					#include "selfdrive/common/watchdog.h" | 
				
			||||||
 | 
					 | 
				
			||||||
#include <unistd.h> | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include <cstdint> | 
					 | 
				
			||||||
#include <string> | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "selfdrive/common/timing.h" | 
					#include "selfdrive/common/timing.h" | 
				
			||||||
#include "selfdrive/common/util.h" | 
					#include "selfdrive/common/util.h" | 
				
			||||||
 | 
					
 | 
				
			||||||
const std::string watchdog_fn_prefix = "/dev/shm/wd_";  // + <pid>
 | 
					const std::string watchdog_fn_prefix = "/dev/shm/wd_";  // + <pid>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool watchdog_kick() { | 
					bool watchdog_kick() { | 
				
			||||||
  std::string fn = watchdog_fn_prefix + std::to_string(getpid()); | 
					  static std::string fn = watchdog_fn_prefix + std::to_string(getpid()); | 
				
			||||||
  std::string cur_t = std::to_string(nanos_since_boot()); | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  int r = util::write_file(fn.c_str(), cur_t.data(), cur_t.length(), O_WRONLY | O_CREAT); | 
					  uint64_t ts = nanos_since_boot(); | 
				
			||||||
  return r == 0; | 
					  return util::write_file(fn.c_str(), &ts, sizeof(ts), O_WRONLY | O_CREAT) > 0; | 
				
			||||||
} | 
					} | 
				
			||||||
 | 
				
			|||||||
					Loading…
					
					
				
		Reference in new issue