tsafe.c 23 KB

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