Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2017
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #define _GNU_SOURCE
  2. #include <dlfcn.h>
  3. #include <semaphore.h>
  4. #include <stdio.h>
  5. #include <time.h>
  6. #include <unistd.h>
  7.  
  8. static int (*_realSemTimedWait)() = NULL;
  9.  
  10. int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout)
  11. {
  12. if (abs_timeout->tv_nsec >= 1000000000)
  13. {
  14. //fprintf(stderr, "to: %lu:%lu\n", abs_timeout->tv_sec, abs_timeout->tv_nsec);
  15. ((struct timespec *)abs_timeout)->tv_nsec -= 1000000000;
  16. ((struct timespec *)abs_timeout)->tv_sec++;
  17. }
  18. _realSemTimedWait(sem, abs_timeout);
  19. }
  20.  
  21. __attribute__((constructor)) int init(void)
  22. {
  23. _realSemTimedWait = dlsym(RTLD_NEXT, "sem_timedwait");
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement