tsafe.c 23 KB

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