Files
StarPilot/selfdrive/common/watchdog.cc
T
Dean Lee 7534abdd50 util.cc: reduce two read_file functions into one (#20655)
* no need to malloc one extra byte

* combine two read_file into a faster one

* cleanup #include

* use resize

* apply suggestions from review

* space

* rebase master
old-commit-hash: fe2f63849ae467fee70c72d18fa52a184c056331
2021-04-13 11:43:43 -07:00

18 lines
464 B
C++

#include <string>
#include <cstdint>
#include <unistd.h>
#include "common/timing.h"
#include "common/util.h"
#include "common/watchdog.h"
const std::string watchdog_fn_prefix = "/dev/shm/wd_"; // + <pid>
bool watchdog_kick(){
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);
return r == 0;
}