gmtime_r.c 767 B

12345678910111213141516171819202122232425
  1. #include <stdio.h>
  2. #include <dlfcn.h>
  3. #include <time.h>
  4. #include <sys/time.h>
  5. extern int MotorFd;
  6. extern struct timeval MotorLastMovedTime;
  7. static struct tm *(*original_gmtime_r)(const time_t *timep, struct tm *result);
  8. static void __attribute ((constructor)) gmtime_r_hook_init(void) {
  9. original_gmtime_r = dlsym(dlopen ("/lib/libc.so.0", RTLD_LAZY), "gmtime_r");
  10. }
  11. struct tm *gmtime_r(const time_t *timep, struct tm *result) {
  12. original_gmtime_r(timep, result);
  13. // While the camera is moving, the AI process is disabled by returning a day of the week that does not exist when motion is detected.
  14. struct timeval tv;
  15. gettimeofday(&tv, NULL);
  16. timersub(&tv, &MotorLastMovedTime, &tv);
  17. if(MotorFd || !tv.tv_sec) result->tm_wday = 8;
  18. return result;
  19. }