tsafe.c 23 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067
  1. /*
  2. * Copyright (c) 2010 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Angus Salkeld <asalkeld@redhat.com>
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <config.h>
  35. #include <unistd.h>
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. #include <math.h>
  39. #include <string.h>
  40. #include <assert.h>
  41. #include <time.h>
  42. #include <sys/types.h>
  43. #include <sys/socket.h>
  44. #include <netinet/in.h>
  45. #include <arpa/inet.h>
  46. #include <grp.h>
  47. #include <pwd.h>
  48. #include <netdb.h>
  49. #include <nl_types.h>
  50. #include <libgen.h>
  51. #include <dlfcn.h>
  52. #ifdef HAVE_UTMPX_H
  53. #include <utmpx.h>
  54. #endif /* HAVE_UTMPX_H */
  55. #include <search.h>
  56. #include <locale.h>
  57. #include <dirent.h>
  58. #include <pthread.h>
  59. #include <tsafe.h>
  60. #ifndef RTLD_NEXT
  61. #define RTLD_NEXT ((void *) -1l)
  62. #endif /* !RTLD_NEXT */
  63. #ifdef COROSYNC_BSD
  64. #define CONST_ON_BSD const
  65. #else
  66. #define CONST_ON_BSD
  67. #endif /* COROSYNC_BSD */
  68. /*
  69. * The point of this file is to prevent people from using functions that are
  70. * known not to be thread safe (see man pthreads).
  71. */
  72. static int tsafe_disabled = 1;
  73. static int tsafe_inited = 0;
  74. static char **coro_environ;
  75. #if defined(HAVE_PTHREAD_SPIN_LOCK)
  76. static pthread_spinlock_t tsafe_enabled_mutex;
  77. #else
  78. static pthread_mutex_t tsafe_enabled_mutex = PTHREAD_MUTEX_INITIALIZER;
  79. #endif
  80. void tsafe_init (char **envp)
  81. {
  82. int i;
  83. int size = 1;
  84. for (i = 0; envp[i] != NULL; i++) {
  85. size++;
  86. }
  87. coro_environ = malloc (sizeof (char*) * size);
  88. for (i = 0; envp[i] != NULL; i++) {
  89. coro_environ[i] = strdup (envp[i]);
  90. }
  91. coro_environ[size-1] = NULL;
  92. #if defined(HAVE_PTHREAD_SPIN_LOCK)
  93. pthread_spin_init (&tsafe_enabled_mutex, 0);
  94. #endif
  95. tsafe_disabled = 1;
  96. tsafe_inited = 1;
  97. }
  98. static void tsafe_lock (void)
  99. {
  100. #if defined(HAVE_PTHREAD_SPIN_LOCK)
  101. pthread_spin_lock (&tsafe_enabled_mutex);
  102. #else
  103. pthread_mutex_lock (&tsafe_enabled_mutex);
  104. #endif
  105. }
  106. static void tsafe_unlock (void)
  107. {
  108. #if defined(HAVE_PTHREAD_SPIN_LOCK)
  109. pthread_spin_unlock (&tsafe_enabled_mutex);
  110. #else
  111. pthread_mutex_unlock (&tsafe_enabled_mutex);
  112. #endif
  113. }
  114. void tsafe_off (void)
  115. {
  116. tsafe_lock ();
  117. tsafe_disabled = 1;
  118. tsafe_unlock ();
  119. }
  120. void tsafe_on (void)
  121. {
  122. tsafe_lock ();
  123. tsafe_disabled = 0;
  124. tsafe_unlock ();
  125. }
  126. static void* _get_real_func_(const char * func_name)
  127. {
  128. void * func = NULL;
  129. #ifdef COROSYNC_BSD
  130. static void *handle;
  131. /*
  132. * On BSD we open the libc and retrive the pointer to "func_name".
  133. */
  134. handle = dlopen("/usr/lib/libc.so", RTLD_LAZY);
  135. func = dlsym (handle, func_name);
  136. #else
  137. /*
  138. * On linux/Sun we can set func to next instance of "func_name",
  139. * which is the original "func_name"
  140. */
  141. func = dlsym (RTLD_NEXT, func_name);
  142. #endif
  143. return func;
  144. }
  145. #ifdef COROSYNC_LINUX
  146. /* we are implementing these functions only to know when to turn tsafe
  147. * on and off.
  148. */
  149. int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
  150. void *(*start_routine) (void *), void *arg)
  151. {
  152. static int (*real_pthread_create)(pthread_t *thread, const pthread_attr_t *attr,
  153. void *(*start_routine) (void *), void *arg) = NULL;
  154. if (tsafe_inited && tsafe_disabled) {
  155. tsafe_on ();
  156. }
  157. if (real_pthread_create == NULL) {
  158. real_pthread_create = _get_real_func_ ("pthread_create");
  159. }
  160. return real_pthread_create (thread, attr, start_routine, arg);
  161. }
  162. pid_t fork(void)
  163. {
  164. static pid_t (*real_fork)(void) = NULL;
  165. pid_t ret;
  166. if (tsafe_inited && !tsafe_disabled) {
  167. tsafe_off ();
  168. }
  169. if (real_fork == NULL) {
  170. real_fork = _get_real_func_ ("fork");
  171. }
  172. ret = real_fork ();
  173. if (ret == 0) {
  174. /* if we have forked corosync then anything goes. */
  175. tsafe_off ();
  176. }
  177. return ret;
  178. }
  179. #endif /* COROSYNC_LINUX */
  180. /*
  181. * we will allow this one as there doesn't seem to be any other option.
  182. * and only used in lcr
  183. * char *dlerror(void)
  184. * {
  185. * }
  186. */
  187. /* the following functions are needed so we are either banning them or
  188. * re-implementing them (depending on tsafe_on).
  189. */
  190. char *getenv(const char *name)
  191. {
  192. static char* (*real_getenv)(const char *name) = NULL;
  193. int entry;
  194. int found = 0;
  195. char *eq;
  196. size_t name_len;
  197. if (!tsafe_inited || tsafe_disabled) {
  198. if (real_getenv == NULL) {
  199. real_getenv = _get_real_func_ ("getenv");
  200. }
  201. return real_getenv (name);
  202. }
  203. for (entry = 0; coro_environ[entry] != NULL; entry++) {
  204. eq = strchr (coro_environ[entry], '=');
  205. name_len = eq - coro_environ[entry];
  206. if (name_len == strlen (name) &&
  207. strncmp(name, coro_environ[entry], name_len) == 0) {
  208. found = 1;
  209. break;
  210. }
  211. }
  212. if (found) {
  213. eq = strchr (coro_environ[entry], '=');
  214. return (eq + 1);
  215. }
  216. return NULL;
  217. }
  218. /* all the following functions are banned and will result in an abort.
  219. */
  220. int setenv(const char *name, const char *value, int overwrite)
  221. {
  222. static int (*real_setenv)(const char *name, const char *value, int overwrite) = NULL;
  223. if (!tsafe_inited || tsafe_disabled) {
  224. if (real_setenv == NULL) {
  225. real_setenv = _get_real_func_ ("setenv");
  226. }
  227. return real_setenv (name, value, overwrite);
  228. }
  229. assert (0);
  230. return 0;
  231. }
  232. int unsetenv(const char *name)
  233. {
  234. static int (*real_unsetenv)(const char *name) = NULL;
  235. if (!tsafe_inited || tsafe_disabled) {
  236. if (real_unsetenv == NULL) {
  237. real_unsetenv = _get_real_func_ ("unsetenv");
  238. }
  239. return real_unsetenv (name);
  240. }
  241. assert (0);
  242. return 0;
  243. }
  244. int putenv(char *string)
  245. {
  246. static int (*real_putenv)(char *string) = NULL;
  247. if (!tsafe_inited || tsafe_disabled) {
  248. if (real_putenv == NULL) {
  249. real_putenv = _get_real_func_ ("putenv");
  250. }
  251. return real_putenv (string);
  252. }
  253. assert (0);
  254. return 0;
  255. }
  256. char *asctime(const struct tm *tm)
  257. {
  258. static char * (*real_asctime)(const struct tm *tm) = NULL;
  259. if (!tsafe_inited || tsafe_disabled) {
  260. if (real_asctime == NULL) {
  261. real_asctime = _get_real_func_ ("asctime");
  262. }
  263. return real_asctime (tm);
  264. }
  265. assert(0);
  266. return NULL;
  267. }
  268. char *basename (CONST_ON_BSD char *path)
  269. {
  270. static char *(*real_basename)(CONST_ON_BSD char *path) = NULL;
  271. if (!tsafe_inited || tsafe_disabled) {
  272. if (real_basename == NULL) {
  273. real_basename = _get_real_func_ ("basename");
  274. }
  275. return real_basename (path);
  276. }
  277. assert(0);
  278. return NULL;
  279. }
  280. char *catgets(nl_catd catalog, int set_number,
  281. int message_number, const char *message)
  282. {
  283. return NULL;
  284. }
  285. #ifdef _XOPEN_SOURCE
  286. char *crypt(const char *key, const char *salt)
  287. {
  288. static char *(*real_crypt)(const char *key, const char *salt) = NULL;
  289. if (!tsafe_inited || tsafe_disabled) {
  290. if (real_crypt == NULL) {
  291. real_crypt = _get_real_func_ ("crypt");
  292. }
  293. return real_crypt (salt);
  294. }
  295. assert(0);
  296. return NULL;
  297. }
  298. #endif /* _XOPEN_SOURCE */
  299. char *ctermid(char *s)
  300. {
  301. static char *(*real_ctermid)(char *s) = NULL;
  302. if (!tsafe_inited || tsafe_disabled) {
  303. if (real_ctermid == NULL) {
  304. real_ctermid = _get_real_func_ ("ctermid");
  305. }
  306. return real_ctermid (s);
  307. }
  308. assert(0);
  309. return NULL;
  310. }
  311. char *ctime(const time_t *timep)
  312. {
  313. static char *(*real_ctime)(const time_t *timep) = NULL;
  314. if (!tsafe_inited || tsafe_disabled) {
  315. if (real_ctime == NULL) {
  316. real_ctime = _get_real_func_ ("ctime");
  317. }
  318. return real_ctime (timep);
  319. }
  320. assert(0);
  321. return NULL;
  322. }
  323. char *dirname(CONST_ON_BSD char *path)
  324. {
  325. static char *(*real_dirname)(CONST_ON_BSD char *path) = NULL;
  326. if (!tsafe_inited || tsafe_disabled) {
  327. if (real_dirname == NULL) {
  328. real_dirname = _get_real_func_ ("dirname");
  329. }
  330. return real_dirname (path);
  331. }
  332. assert(0);
  333. return NULL;
  334. }
  335. double drand48(void)
  336. {
  337. static double (*real_drand48)(void) = NULL;
  338. if (!tsafe_inited || tsafe_disabled) {
  339. if (real_drand48 == NULL) {
  340. real_drand48 = _get_real_func_ ("drand48");
  341. }
  342. return real_drand48 ();
  343. }
  344. assert(0);
  345. return 0;
  346. }
  347. #ifdef _XOPEN_SOURCE
  348. void encrypt(char block[64], int edflag)
  349. {
  350. static void (*real_encrypt)(char block[64], int edflag) = NULL;
  351. if (!tsafe_inited || tsafe_disabled) {
  352. if (real_encrypt == NULL) {
  353. real_encrypt = _get_real_func_ ("encrypt");
  354. }
  355. return real_encrypt (edflag);
  356. }
  357. assert(0);
  358. }
  359. #endif /* _XOPEN_SOURCE */
  360. void endgrent(void)
  361. {
  362. static void (*real_endgrent)(void) = NULL;
  363. if (!tsafe_inited || tsafe_disabled) {
  364. if (real_endgrent == NULL) {
  365. real_endgrent = _get_real_func_ ("endgrent");
  366. }
  367. return real_endgrent ();
  368. }
  369. assert(0);
  370. }
  371. void endpwent(void)
  372. {
  373. static void (*real_endpwent)(void) = NULL;
  374. if (!tsafe_inited || tsafe_disabled) {
  375. if (real_endpwent == NULL) {
  376. real_endpwent = _get_real_func_ ("endpwent");
  377. }
  378. return real_endpwent ();
  379. }
  380. assert(0);
  381. }
  382. #ifdef _XOPEN_SOURCE
  383. struct tm *getdate(const char *string)
  384. {
  385. static struct tm *(*real_getdate)(const char *string) = NULL;
  386. if (!tsafe_inited || tsafe_disabled) {
  387. if (real_getdate == NULL) {
  388. real_getdate = _get_real_func_ ("getdate");
  389. }
  390. return real_getdate (string);
  391. }
  392. assert(0);
  393. return NULL;
  394. }
  395. #endif /* _XOPEN_SOURCE */
  396. struct group *getgrent(void)
  397. {
  398. static struct group *(*real_getgrent)(void) = NULL;
  399. if (!tsafe_inited || tsafe_disabled) {
  400. if (real_getgrent == NULL) {
  401. real_getgrent = _get_real_func_ ("getgrent");
  402. }
  403. return real_getgrent ();
  404. }
  405. assert(0);
  406. return NULL;
  407. }
  408. struct group *getgrgid(gid_t gid)
  409. {
  410. static struct group *(*real_getgrgid)(gid_t gid) = NULL;
  411. if (!tsafe_inited || tsafe_disabled) {
  412. if (real_getgrgid == NULL) {
  413. real_getgrgid = _get_real_func_ ("getgrgid");
  414. }
  415. return real_getgrgid (gid);
  416. }
  417. assert(0);
  418. return NULL;
  419. }
  420. struct group *getgrnam(const char *name)
  421. {
  422. static struct group *(*real_getgrnam)(const char *name) = NULL;
  423. if (!tsafe_inited || tsafe_disabled) {
  424. if (real_getgrnam == NULL) {
  425. real_getgrnam = _get_real_func_ ("getgrnam");
  426. }
  427. return real_getgrnam (name);
  428. }
  429. assert(0);
  430. return NULL;
  431. }
  432. struct hostent *gethostent(void)
  433. {
  434. static struct hostent *(*real_gethostent)(void) = NULL;
  435. if (!tsafe_inited || tsafe_disabled) {
  436. if (real_gethostent == NULL) {
  437. real_gethostent = _get_real_func_ ("gethostent");
  438. }
  439. return real_gethostent ();
  440. }
  441. assert(0);
  442. return NULL;
  443. }
  444. char *getlogin(void)
  445. {
  446. static char *(*real_getlogin)(void) = NULL;
  447. if (!tsafe_inited || tsafe_disabled) {
  448. if (real_getlogin == NULL) {
  449. real_getlogin = _get_real_func_ ("getlogin");
  450. }
  451. return real_getlogin ();
  452. }
  453. assert(0);
  454. return NULL;
  455. }
  456. struct netent *getnetbyaddr(uint32_t net, int type)
  457. {
  458. static struct netent *(*real_getnetbyaddr)(uint32_t net, int type) = NULL;
  459. if (!tsafe_inited || tsafe_disabled) {
  460. if (real_getnetbyaddr == NULL) {
  461. real_getnetbyaddr = _get_real_func_ ("getnetbyaddr");
  462. }
  463. return real_getnetbyaddr (net, type);
  464. }
  465. assert(0);
  466. return NULL;
  467. }
  468. struct netent *getnetbyname(const char *name)
  469. {
  470. static struct netent *(*real_getnetbyname)(const char *name) = NULL;
  471. if (!tsafe_inited || tsafe_disabled) {
  472. if (real_getnetbyname == NULL) {
  473. real_getnetbyname = _get_real_func_ ("getnetbyname");
  474. }
  475. return real_getnetbyname (name);
  476. }
  477. assert(0);
  478. return NULL;
  479. }
  480. struct netent *getnetent(void)
  481. {
  482. static struct netent *(*real_getnetent)(void) = NULL;
  483. if (!tsafe_inited || tsafe_disabled) {
  484. if (real_getnetent == NULL) {
  485. real_getnetent = _get_real_func_ ("getnetent");
  486. }
  487. return real_getnetent ();
  488. }
  489. assert(0);
  490. return NULL;
  491. }
  492. struct protoent *getprotobyname(const char *name)
  493. {
  494. static struct protoent *(*real_getprotobyname)(const char *name) = NULL;
  495. if (!tsafe_inited || tsafe_disabled) {
  496. if (real_getprotobyname == NULL) {
  497. real_getprotobyname = _get_real_func_ ("getprotobyname");
  498. }
  499. return real_getprotobyname (name);
  500. }
  501. assert(0);
  502. return NULL;
  503. }
  504. struct protoent *getprotobynumber(int proto)
  505. {
  506. static struct protoent *(*real_getprotobynumber)(int proto) = NULL;
  507. if (!tsafe_inited || tsafe_disabled) {
  508. if (real_getprotobynumber == NULL) {
  509. real_getprotobynumber = _get_real_func_ ("getprotobynumber");
  510. }
  511. return real_getprotobynumber (proto);
  512. }
  513. assert(0);
  514. return NULL;
  515. }
  516. struct protoent *getprotoent(void)
  517. {
  518. static struct protoent *(*real_getprotoent)(void) = NULL;
  519. if (!tsafe_inited || tsafe_disabled) {
  520. if (real_getprotoent == NULL) {
  521. real_getprotoent = _get_real_func_ ("getprotoent");
  522. }
  523. return real_getprotoent ();
  524. }
  525. assert(0);
  526. return NULL;
  527. }
  528. struct passwd *getpwent(void)
  529. {
  530. static struct passwd *(*real_getpwent)(void) = NULL;
  531. if (!tsafe_inited || tsafe_disabled) {
  532. if (real_getpwent == NULL) {
  533. real_getpwent = _get_real_func_ ("getpwent");
  534. }
  535. return real_getpwent ();
  536. }
  537. assert(0);
  538. return NULL;
  539. }
  540. struct passwd *getpwnam(const char *name)
  541. {
  542. static struct passwd *(*real_getpwnam)(const char *name) = NULL;
  543. if (!tsafe_inited || tsafe_disabled) {
  544. if (real_getpwnam == NULL) {
  545. real_getpwnam = _get_real_func_ ("getpwnam");
  546. }
  547. return real_getpwnam (name);
  548. }
  549. assert(0);
  550. return NULL;
  551. }
  552. struct passwd *getpwuid(uid_t uid)
  553. {
  554. static struct passwd *(*real_getpwuid)(uid_t uid) = NULL;
  555. if (!tsafe_inited || tsafe_disabled) {
  556. if (real_getpwuid == NULL) {
  557. real_getpwuid = _get_real_func_ ("getpwuid");
  558. }
  559. return real_getpwuid (uid);
  560. }
  561. assert(0);
  562. return NULL;
  563. }
  564. struct servent *getservent(void)
  565. {
  566. static struct servent *(*real_getservent)(void) = NULL;
  567. if (!tsafe_inited || tsafe_disabled) {
  568. if (real_getservent == NULL) {
  569. real_getservent = _get_real_func_ ("getservent");
  570. }
  571. return real_getservent ();
  572. }
  573. assert(0);
  574. return NULL;
  575. }
  576. struct servent *getservbyname(const char *name, const char *proto)
  577. {
  578. static struct servent *(*real_getservbyname)(const char *name, const char *proto) = NULL;
  579. if (!tsafe_inited || tsafe_disabled) {
  580. if (real_getservbyname == NULL) {
  581. real_getservbyname = _get_real_func_ ("getservbyname");
  582. }
  583. return real_getservbyname (name, proto);
  584. }
  585. assert(0);
  586. return NULL;
  587. }
  588. struct servent *getservbyport(int port, const char *proto)
  589. {
  590. static struct servent *(*real_getservbyport)(int port, const char *proto) = NULL;
  591. if (!tsafe_inited || tsafe_disabled) {
  592. if (real_getservbyport == NULL) {
  593. real_getservbyport = _get_real_func_ ("getservbyport");
  594. }
  595. return real_getservbyport (port, proto);
  596. }
  597. assert(0);
  598. return NULL;
  599. }
  600. #ifdef HAVE_UTMPX_H
  601. struct utmpx *getutxent(void)
  602. {
  603. static struct utmpx *(*real_getutxent)(void) = NULL;
  604. if (!tsafe_inited || tsafe_disabled) {
  605. if (real_getutxent == NULL) {
  606. real_getutxent = _get_real_func_ ("getutxent");
  607. }
  608. return real_getutxent ();
  609. }
  610. assert(0);
  611. return NULL;
  612. }
  613. struct utmpx *getutxid(const struct utmpx *a)
  614. {
  615. static struct utmpx *(*real_getutxid)(const struct utmpx *a) = NULL;
  616. if (!tsafe_inited || tsafe_disabled) {
  617. if (real_getutxid == NULL) {
  618. real_getutxid = _get_real_func_ ("getutxid");
  619. }
  620. return real_getutxid (a);
  621. }
  622. assert(0);
  623. return NULL;
  624. }
  625. struct utmpx *getutxline(const struct utmpx *a)
  626. {
  627. static struct utmpx *(*real_getutxline)(const struct utmpx *a) = NULL;
  628. if (!tsafe_inited || tsafe_disabled) {
  629. if (real_getutxline == NULL) {
  630. real_getutxline = _get_real_func_ ("getutxline");
  631. }
  632. return real_getutxline (a);
  633. }
  634. assert(0);
  635. return NULL;
  636. }
  637. #endif /* HAVE_UTMPX_H */
  638. struct tm *gmtime(const time_t *timep)
  639. {
  640. static struct tm *(*real_gmtime)(const time_t *timep) = NULL;
  641. if (!tsafe_inited || tsafe_disabled) {
  642. if (real_gmtime == NULL) {
  643. real_gmtime = _get_real_func_ ("gmtime");
  644. }
  645. return real_gmtime (timep);
  646. }
  647. assert(0);
  648. return NULL;
  649. }
  650. int hcreate(size_t nel)
  651. {
  652. static int (*real_hcreate)(size_t nel) = NULL;
  653. if (!tsafe_inited || tsafe_disabled) {
  654. if (real_hcreate == NULL) {
  655. real_hcreate = _get_real_func_ ("hcreate");
  656. }
  657. return real_hcreate (nel);
  658. }
  659. assert(0);
  660. return 0;
  661. }
  662. ENTRY *hsearch(ENTRY item, ACTION action)
  663. {
  664. static ENTRY *(*real_hsearch)(ENTRY item, ACTION action) = NULL;
  665. if (!tsafe_inited || tsafe_disabled) {
  666. if (real_hsearch == NULL) {
  667. real_hsearch = _get_real_func_ ("hsearch");
  668. }
  669. return real_hsearch (item, action);
  670. }
  671. assert(0);
  672. return NULL;
  673. }
  674. void hdestroy(void)
  675. {
  676. static void (*real_hdestroy)(void) = NULL;
  677. if (!tsafe_inited || tsafe_disabled) {
  678. if (real_hdestroy == NULL) {
  679. real_hdestroy = _get_real_func_ ("hdestroy");
  680. }
  681. return real_hdestroy ();
  682. }
  683. assert(0);
  684. }
  685. char *inet_ntoa(struct in_addr in)
  686. {
  687. static char *(*real_inet_ntoa)(struct in_addr in) = NULL;
  688. if (!tsafe_inited || tsafe_disabled) {
  689. if (real_inet_ntoa == NULL) {
  690. real_inet_ntoa = _get_real_func_ ("inet_ntoa");
  691. }
  692. return real_inet_ntoa (in);
  693. }
  694. assert(0);
  695. return NULL;
  696. }
  697. char *l64a(long value)
  698. {
  699. static char *(*real_l64a)(long value) = NULL;
  700. if (!tsafe_inited || tsafe_disabled) {
  701. if (real_l64a == NULL) {
  702. real_l64a = _get_real_func_ ("l64a");
  703. }
  704. return real_l64a (value);
  705. }
  706. assert(0);
  707. return NULL;
  708. }
  709. double lgamma(double x)
  710. {
  711. static double (*real_lgamma)(double x) = NULL;
  712. if (!tsafe_inited || tsafe_disabled) {
  713. if (real_lgamma == NULL) {
  714. real_lgamma = _get_real_func_ ("lgamma");
  715. }
  716. return real_lgamma (x);
  717. }
  718. assert(0);
  719. return 0;
  720. }
  721. float lgammaf(float x)
  722. {
  723. static float (*real_lgammaf)(float x) = NULL;
  724. if (!tsafe_inited || tsafe_disabled) {
  725. if (real_lgammaf == NULL) {
  726. real_lgammaf = _get_real_func_ ("lgammaf");
  727. }
  728. return real_lgammaf (x);
  729. }
  730. assert(0);
  731. return 0;
  732. }
  733. #ifdef COROSYNC_LINUX
  734. long double lgammal(long double x)
  735. {
  736. static long double (*real_lgammal)(long double x) = NULL;
  737. if (!tsafe_inited || tsafe_disabled) {
  738. if (real_lgammal == NULL) {
  739. real_lgammal = _get_real_func_ ("lgammal");
  740. }
  741. return real_lgammal (x);
  742. }
  743. assert(0);
  744. return 0;
  745. }
  746. #endif
  747. struct lconv *localeconv(void)
  748. {
  749. static struct lconv *(*real_localeconv)(void) = NULL;
  750. if (!tsafe_inited || tsafe_disabled) {
  751. if (real_localeconv == NULL) {
  752. real_localeconv = _get_real_func_ ("localeconv");
  753. }
  754. return real_localeconv ();
  755. }
  756. assert(0);
  757. return NULL;
  758. }
  759. struct tm *localtime(const time_t *timep)
  760. {
  761. static struct tm *(*real_localtime)(const time_t *timep) = NULL;
  762. if (!tsafe_inited || tsafe_disabled) {
  763. if (real_localtime == NULL) {
  764. real_localtime = _get_real_func_ ("localtime");
  765. }
  766. return real_localtime (timep);
  767. }
  768. assert(0);
  769. return NULL;
  770. }
  771. long int lrand48(void)
  772. {
  773. static long int (*real_lrand48)(void) = NULL;
  774. if (!tsafe_inited || tsafe_disabled) {
  775. if (real_lrand48 == NULL) {
  776. real_lrand48 = _get_real_func_ ("lrand48");
  777. }
  778. return real_lrand48 ();
  779. }
  780. assert(0);
  781. return 0;
  782. }
  783. long int mrand48(void)
  784. {
  785. static long int (*real_mrand48)(void) = NULL;
  786. if (!tsafe_inited || tsafe_disabled) {
  787. if (real_mrand48 == NULL) {
  788. real_mrand48 = _get_real_func_ ("mrand48");
  789. }
  790. return real_mrand48 ();
  791. }
  792. assert(0);
  793. return 0;
  794. }
  795. #ifdef COROSYNC_LINUX
  796. struct utmpx *pututxline(const struct utmpx *a)
  797. {
  798. static struct utmpx *(*real_pututxline)(const struct utmpx *a) = NULL;
  799. if (!tsafe_inited || tsafe_disabled) {
  800. if (real_pututxline == NULL) {
  801. real_pututxline = _get_real_func_ ("pututxline");
  802. }
  803. return real_pututxline (a);
  804. }
  805. assert(0);
  806. return NULL;
  807. }
  808. #endif
  809. int rand(void)
  810. {
  811. static int (*real_rand)(void) = NULL;
  812. if (!tsafe_inited || tsafe_disabled) {
  813. if (real_rand == NULL) {
  814. real_rand = _get_real_func_ ("rand");
  815. }
  816. return real_rand ();
  817. }
  818. assert(0);
  819. return 0;
  820. }
  821. struct dirent *readdir(DIR *dirp)
  822. {
  823. static struct dirent *(*real_readdir)(DIR *dirp) = NULL;
  824. if (!tsafe_inited || tsafe_disabled) {
  825. if (real_readdir == NULL) {
  826. real_readdir = _get_real_func_ ("readdir");
  827. }
  828. return real_readdir (dirp);
  829. }
  830. assert(0);
  831. return NULL;
  832. }
  833. #ifdef COROSYNC_BSD
  834. int setgrent(void)
  835. {
  836. static int (*real_setgrent)(void) = NULL;
  837. if (!tsafe_inited || tsafe_disabled) {
  838. if (real_setgrent == NULL) {
  839. real_setgrent = _get_real_func_ ("setgrent");
  840. }
  841. return real_setgrent ();
  842. }
  843. assert(0);
  844. return 0;
  845. }
  846. #else
  847. void setgrent(void)
  848. {
  849. static void (*real_setgrent)(void) = NULL;
  850. if (!tsafe_inited || tsafe_disabled) {
  851. if (real_setgrent == NULL) {
  852. real_setgrent = _get_real_func_ ("setgrent");
  853. }
  854. real_setgrent ();
  855. }
  856. assert(0);
  857. }
  858. #endif
  859. #ifdef _XOPEN_SOURCE
  860. void setkey(const char *key)
  861. {
  862. static void (*real_setkey)(const char *key) = NULL;
  863. if (!tsafe_inited || tsafe_disabled) {
  864. if (real_setkey == NULL) {
  865. real_setkey = _get_real_func_ ("setkey");
  866. }
  867. return real_setkey (key);
  868. }
  869. assert(0);
  870. }
  871. #endif /* _XOPEN_SOURCE */
  872. void setpwent(void)
  873. {
  874. static void (*real_setpwent)(void) = NULL;
  875. if (!tsafe_inited || tsafe_disabled) {
  876. if (real_setpwent == NULL) {
  877. real_setpwent = _get_real_func_ ("setpwent");
  878. }
  879. return real_setpwent ();
  880. }
  881. assert(0);
  882. }
  883. void setutxent(void)
  884. {
  885. static void (*real_setutxent)(void) = NULL;
  886. if (!tsafe_inited || tsafe_disabled) {
  887. if (real_setutxent == NULL) {
  888. real_setutxent = _get_real_func_ ("setutxent");
  889. }
  890. return real_setutxent ();
  891. }
  892. assert(0);
  893. }
  894. char *strerror(int errnum)
  895. {
  896. static char *(*real_strerror)(int errnum) = NULL;
  897. if (!tsafe_inited || tsafe_disabled) {
  898. if (real_strerror == NULL) {
  899. real_strerror = _get_real_func_ ("strerror");
  900. }
  901. return real_strerror (errnum);
  902. }
  903. assert(0);
  904. return NULL;
  905. }
  906. char *strsignal(int sig)
  907. {
  908. static char *(*real_strsignal)(int sig) = NULL;
  909. if (!tsafe_inited || tsafe_disabled) {
  910. if (real_strsignal == NULL) {
  911. real_strsignal = _get_real_func_ ("strsignal");
  912. }
  913. return real_strsignal (sig);
  914. }
  915. assert(0);
  916. return NULL;
  917. }
  918. char *strtok(char *str, const char *delim)
  919. {
  920. static char *(*real_strtok)(char *str, const char *delim) = NULL;
  921. if (!tsafe_inited || tsafe_disabled) {
  922. if (real_strtok == NULL) {
  923. real_strtok = _get_real_func_ ("strtok");
  924. }
  925. return real_strtok (str, delim);
  926. }
  927. assert(0);
  928. return NULL;
  929. }
  930. int system(const char *command)
  931. {
  932. static int (*real_system)(const char *command) = NULL;
  933. if (!tsafe_inited || tsafe_disabled) {
  934. if (real_system == NULL) {
  935. real_system = _get_real_func_ ("system");
  936. }
  937. return real_system (command);
  938. }
  939. assert(0);
  940. return 0;
  941. }
  942. char *tmpnam(char *s)
  943. {
  944. static char *(*real_tmpnam)(char *s) = NULL;
  945. if (!tsafe_inited || tsafe_disabled) {
  946. if (real_tmpnam == NULL) {
  947. real_tmpnam = _get_real_func_ ("tmpnam");
  948. }
  949. return real_tmpnam (s);
  950. }
  951. assert(0);
  952. return NULL;
  953. }
  954. char *ttyname(int fd)
  955. {
  956. static char *(*real_ttyname)(int fd) = NULL;
  957. if (!tsafe_inited || tsafe_disabled) {
  958. if (real_ttyname == NULL) {
  959. real_ttyname = _get_real_func_ ("ttyname");
  960. }
  961. return real_ttyname (fd);
  962. }
  963. assert(0);
  964. return NULL;
  965. }