Advertisement
Guest User

Untitled

a guest
Dec 10th, 2014
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.77 KB | None | 0 0
  1. From 8cd1352b963badfc876002c108c4ff32dadfbb2f Mon Sep 17 00:00:00 2001
  2. From: "Erich E. Hoover" <erich.e.hoover@gmail.com>
  3. Date: Wed, 10 Dec 2014 14:55:01 -0700
  4. Subject: Make sure that the constructor has been called when the loader chose
  5. to load another constructor first.
  6.  
  7. ---
  8. src/libfaketime.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
  9. 1 file changed, 104 insertions(+)
  10.  
  11. diff --git a/src/libfaketime.c b/src/libfaketime.c
  12. index eb78548..c8c44ab 100644
  13. --- a/src/libfaketime.c
  14. +++ b/src/libfaketime.c
  15. @@ -152,7 +152,10 @@ static int apple_clock_gettime (clockid_t clk_id, struct timespec *
  16. static clock_serv_t clock_serv_real;
  17. #endif
  18.  
  19. +static int initialized = 0;
  20. +
  21. /* prototypes */
  22. +void ftpl_init(void);
  23. time_t fake_time(time_t *time_tptr);
  24. int fake_gettimeofday(struct timeval *tv);
  25. int fake_clock_gettime(clockid_t clk_id, struct timespec *tp);
  26. @@ -500,6 +503,10 @@ static inline void fake_stat64buf (struct stat64 *buf) {
  27. /* Contributed by Philipp Hachtmann in version 0.6 */
  28. int __xstat (int ver, const char *path, struct stat *buf)
  29. {
  30. + if (!initialized)
  31. + {
  32. + ftpl_init();
  33. + }
  34. if (NULL == real_stat)
  35. { /* dlsym() failed */
  36. #ifdef DEBUG
  37. @@ -529,6 +536,10 @@ int __xstat (int ver, const char *path, struct stat *buf)
  38. /* Contributed by Philipp Hachtmann in version 0.6 */
  39. int __fxstat (int ver, int fildes, struct stat *buf)
  40. {
  41. + if (!initialized)
  42. + {
  43. + ftpl_init();
  44. + }
  45. if (NULL == real_fstat)
  46. { /* dlsym() failed */
  47. #ifdef DEBUG
  48. @@ -558,6 +569,10 @@ int __fxstat (int ver, int fildes, struct stat *buf)
  49. #ifndef NO_ATFILE
  50. int __fxstatat(int ver, int fildes, const char *filename, struct stat *buf, int flag)
  51. {
  52. + if (!initialized)
  53. + {
  54. + ftpl_init();
  55. + }
  56. if (NULL == real_fstatat)
  57. { /* dlsym() failed */
  58. #ifdef DEBUG
  59. @@ -587,6 +602,10 @@ int __fxstatat(int ver, int fildes, const char *filename, struct stat *buf, int
  60. /* Contributed by Philipp Hachtmann in version 0.6 */
  61. int __lxstat (int ver, const char *path, struct stat *buf)
  62. {
  63. + if (!initialized)
  64. + {
  65. + ftpl_init();
  66. + }
  67. if (NULL == real_lstat)
  68. { /* dlsym() failed */
  69. #ifdef DEBUG
  70. @@ -615,6 +634,10 @@ int __lxstat (int ver, const char *path, struct stat *buf)
  71. /* Contributed by Philipp Hachtmann in version 0.6 */
  72. int __xstat64 (int ver, const char *path, struct stat64 *buf)
  73. {
  74. + if (!initialized)
  75. + {
  76. + ftpl_init();
  77. + }
  78. if (NULL == real_stat64)
  79. { /* dlsym() failed */
  80. #ifdef DEBUG
  81. @@ -643,6 +666,10 @@ int __xstat64 (int ver, const char *path, struct stat64 *buf)
  82. /* Contributed by Philipp Hachtmann in version 0.6 */
  83. int __fxstat64 (int ver, int fildes, struct stat64 *buf)
  84. {
  85. + if (!initialized)
  86. + {
  87. + ftpl_init();
  88. + }
  89. if (NULL == real_fstat64)
  90. { /* dlsym() failed */
  91. #ifdef DEBUG
  92. @@ -672,6 +699,10 @@ int __fxstat64 (int ver, int fildes, struct stat64 *buf)
  93. #ifndef NO_ATFILE
  94. int __fxstatat64 (int ver, int fildes, const char *filename, struct stat64 *buf, int flag)
  95. {
  96. + if (!initialized)
  97. + {
  98. + ftpl_init();
  99. + }
  100. if (NULL == real_fstatat64)
  101. { /* dlsym() failed */
  102. #ifdef DEBUG
  103. @@ -701,6 +732,10 @@ int __fxstatat64 (int ver, int fildes, const char *filename, struct stat64 *buf,
  104. /* Contributed by Philipp Hachtmann in version 0.6 */
  105. int __lxstat64 (int ver, const char *path, struct stat64 *buf)
  106. {
  107. + if (!initialized)
  108. + {
  109. + ftpl_init();
  110. + }
  111. if (NULL == real_lstat64)
  112. { /* dlsym() failed */
  113. #ifdef DEBUG
  114. @@ -743,6 +778,10 @@ int nanosleep(const struct timespec *req, struct timespec *rem)
  115. int result;
  116. struct timespec real_req;
  117.  
  118. + if (!initialized)
  119. + {
  120. + ftpl_init();
  121. + }
  122. if (real_nanosleep == NULL)
  123. {
  124. return -1;
  125. @@ -787,6 +826,11 @@ int nanosleep(const struct timespec *req, struct timespec *rem)
  126. int usleep(useconds_t usec)
  127. {
  128. int result;
  129. +
  130. + if (!initialized)
  131. + {
  132. + ftpl_init();
  133. + }
  134. if (user_rate_set && !dont_fake)
  135. {
  136. struct timespec real_req;
  137. @@ -819,6 +863,10 @@ int usleep(useconds_t usec)
  138. */
  139. unsigned int sleep(unsigned int seconds)
  140. {
  141. + if (!initialized)
  142. + {
  143. + ftpl_init();
  144. + }
  145. if (user_rate_set && !dont_fake)
  146. {
  147. if (real_nanosleep == NULL)
  148. @@ -870,6 +918,11 @@ unsigned int alarm(unsigned int seconds)
  149. {
  150. unsigned int ret;
  151. unsigned int seconds_real = (user_rate_set && !dont_fake)?((1.0 / user_rate) * seconds):seconds;
  152. +
  153. + if (!initialized)
  154. + {
  155. + ftpl_init();
  156. + }
  157. if (real_alarm == NULL)
  158. {
  159. return -1;
  160. @@ -888,6 +941,10 @@ int ppoll(struct pollfd *fds, nfds_t nfds,
  161. struct timespec real_timeout, *real_timeout_pt;
  162. int ret;
  163.  
  164. + if (!initialized)
  165. + {
  166. + ftpl_init();
  167. + }
  168. if (real_ppoll == NULL)
  169. {
  170. return -1;
  171. @@ -920,6 +977,11 @@ int ppoll(struct pollfd *fds, nfds_t nfds,
  172. int poll(struct pollfd *fds, nfds_t nfds, int timeout)
  173. {
  174. int ret, timeout_real = (user_rate_set && !dont_fake && (timeout > 0))?(timeout / user_rate):timeout;
  175. +
  176. + if (!initialized)
  177. + {
  178. + ftpl_init();
  179. + }
  180. if (real_poll == NULL)
  181. {
  182. return -1;
  183. @@ -958,6 +1020,10 @@ timer_settime_common(timer_t_or_int timerid, int flags,
  184. struct itimerspec new_real;
  185. struct itimerspec *new_real_pt = &new_real;
  186.  
  187. + if (!initialized)
  188. + {
  189. + ftpl_init();
  190. + }
  191. if (new_value == NULL)
  192. {
  193. new_real_pt = NULL;
  194. @@ -1062,6 +1128,10 @@ int timer_settime_22(int timerid, int flags,
  195. const struct itimerspec *new_value,
  196. struct itimerspec *old_value)
  197. {
  198. + if (!initialized)
  199. + {
  200. + ftpl_init();
  201. + }
  202. if (real_timer_settime_22 == NULL)
  203. {
  204. return -1;
  205. @@ -1080,6 +1150,10 @@ int timer_settime_233(timer_t timerid, int flags,
  206. const struct itimerspec *new_value,
  207. struct itimerspec *old_value)
  208. {
  209. + if (!initialized)
  210. + {
  211. + ftpl_init();
  212. + }
  213. if (real_timer_settime_233 == NULL)
  214. {
  215. return -1;
  216. @@ -1099,6 +1173,10 @@ int timer_gettime_common(timer_t_or_int timerid, struct itimerspec *curr_value,
  217. {
  218. int result;
  219.  
  220. + if (!initialized)
  221. + {
  222. + ftpl_init();
  223. + }
  224. if (real_timer_gettime_233 == NULL)
  225. {
  226. return -1;
  227. @@ -1140,6 +1218,10 @@ int timer_gettime_common(timer_t_or_int timerid, struct itimerspec *curr_value,
  228. */
  229. int timer_gettime_22(timer_t timerid, struct itimerspec *curr_value)
  230. {
  231. + if (!initialized)
  232. + {
  233. + ftpl_init();
  234. + }
  235. if (real_timer_gettime_22 == NULL)
  236. {
  237. return -1;
  238. @@ -1156,6 +1238,10 @@ int timer_gettime_22(timer_t timerid, struct itimerspec *curr_value)
  239. */
  240. int timer_gettime_233(timer_t timerid, struct itimerspec *curr_value)
  241. {
  242. + if (!initialized)
  243. + {
  244. + ftpl_init();
  245. + }
  246. if (real_timer_gettime_233 == NULL)
  247. {
  248. return -1;
  249. @@ -1191,6 +1277,10 @@ time_t time(time_t *time_tptr)
  250. struct timespec tp;
  251. time_t result;
  252.  
  253. + if (!initialized)
  254. + {
  255. + ftpl_init();
  256. + }
  257. DONT_FAKE_TIME(result = (*real_clock_gettime)(CLOCK_REALTIME, &tp));
  258. if (result == -1) return -1;
  259.  
  260. @@ -1209,6 +1299,10 @@ int ftime(struct timeb *tb)
  261. struct timespec tp;
  262. int result;
  263.  
  264. + if (!initialized)
  265. + {
  266. + ftpl_init();
  267. + }
  268. /* sanity check */
  269. if (tb == NULL)
  270. return 0; /* ftime() always returns 0, see manpage */
  271. @@ -1246,6 +1340,10 @@ int gettimeofday(struct timeval *tv, void *tz)
  272. {
  273. int result;
  274.  
  275. + if (!initialized)
  276. + {
  277. + ftpl_init();
  278. + }
  279. /* sanity check */
  280. if (tv == NULL)
  281. {
  282. @@ -1276,6 +1374,10 @@ int clock_gettime(clockid_t clk_id, struct timespec *tp)
  283. {
  284. int result;
  285.  
  286. + if (!initialized)
  287. + {
  288. + ftpl_init();
  289. + }
  290. /* sanity check */
  291. if (tp == NULL)
  292. {
  293. @@ -1652,6 +1754,8 @@ void __attribute__ ((constructor)) ftpl_init(void)
  294. parse_config_file = false;
  295. parse_ft_string(tmp_env);
  296. }
  297. +
  298. + initialized = 1;
  299. }
  300.  
  301.  
  302. --
  303. 1.9.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement