tsafe.c 23 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073
  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 (key, 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 (block, 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. #ifdef HAVE_UTMPX_H
  886. void setutxent(void)
  887. {
  888. static void (*real_setutxent)(void) = NULL;
  889. if (!tsafe_inited || tsafe_disabled) {
  890. if (real_setutxent == NULL) {
  891. real_setutxent = _get_real_func_ ("setutxent");
  892. }
  893. return real_setutxent ();
  894. }
  895. assert(0);
  896. }
  897. #endif
  898. char *strerror(int errnum)
  899. {
  900. static char *(*real_strerror)(int errnum) = NULL;
  901. if (!tsafe_inited || tsafe_disabled) {
  902. if (real_strerror == NULL) {
  903. real_strerror = _get_real_func_ ("strerror");
  904. }
  905. return real_strerror (errnum);
  906. }
  907. assert(0);
  908. return NULL;
  909. }
  910. char *strsignal(int sig)
  911. {
  912. static char *(*real_strsignal)(int sig) = NULL;
  913. if (!tsafe_inited || tsafe_disabled) {
  914. if (real_strsignal == NULL) {
  915. real_strsignal = _get_real_func_ ("strsignal");
  916. }
  917. return real_strsignal (sig);
  918. }
  919. assert(0);
  920. return NULL;
  921. }
  922. char *strtok(char *str, const char *delim)
  923. {
  924. static char *(*real_strtok)(char *str, const char *delim) = NULL;
  925. if (!tsafe_inited || tsafe_disabled) {
  926. if (real_strtok == NULL) {
  927. real_strtok = _get_real_func_ ("strtok");
  928. }
  929. return real_strtok (str, delim);
  930. }
  931. assert(0);
  932. return NULL;
  933. }
  934. int system(const char *command)
  935. {
  936. static int (*real_system)(const char *command) = NULL;
  937. if (!tsafe_inited || tsafe_disabled) {
  938. if (real_system == NULL) {
  939. real_system = _get_real_func_ ("system");
  940. }
  941. return real_system (command);
  942. }
  943. assert(0);
  944. return 0;
  945. }
  946. char *tmpnam(char *s)
  947. {
  948. static char *(*real_tmpnam)(char *s) = NULL;
  949. if (!tsafe_inited || tsafe_disabled) {
  950. if (real_tmpnam == NULL) {
  951. real_tmpnam = _get_real_func_ ("tmpnam");
  952. }
  953. return real_tmpnam (s);
  954. }
  955. assert(0);
  956. return NULL;
  957. }
  958. char *ttyname(int fd)
  959. {
  960. static char *(*real_ttyname)(int fd) = NULL;
  961. if (!tsafe_inited || tsafe_disabled) {
  962. if (real_ttyname == NULL) {
  963. real_ttyname = _get_real_func_ ("ttyname");
  964. }
  965. return real_ttyname (fd);
  966. }
  967. assert(0);
  968. return NULL;
  969. }