void run_callback()

in scripts/inotify/inotify.c [68:94]


void run_callback(char** callback, struct timespec *last, bool always) {
  if (!always) {
    struct timespec tp;
    int ret = clock_gettime(CLOCK_MONOTONIC, &tp);
    if (ret != 0) {
      perror("clock_gettime");
      exit(EXIT_FAILURE);
    }

    int diff_milliseconds = (tp.tv_sec - last->tv_sec) * 1000 \
                   + (tp.tv_nsec - last->tv_nsec) / 1000000;
    if (diff_milliseconds < kPollTimeout) {
      return;
    }

    printf("inotify: calling %s after %dms since the last run\n",
           callback[0], diff_milliseconds);
  }

  run_callback_internal(callback);

  int ret = clock_gettime(CLOCK_MONOTONIC, last);
  if (ret != 0) {
    perror("clock_gettime");
    exit(EXIT_FAILURE);
  }
}