threadMain.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260
  1. #ident "ldclt @(#)threadMain.c 1.40 01/05/04"
  2. /** BEGIN COPYRIGHT BLOCK
  3. * This Program is free software; you can redistribute it and/or modify it under
  4. * the terms of the GNU General Public License as published by the Free Software
  5. * Foundation; version 2 of the License.
  6. *
  7. * This Program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  10. *
  11. * You should have received a copy of the GNU General Public License along with
  12. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  13. * Place, Suite 330, Boston, MA 02111-1307 USA.
  14. *
  15. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  16. * right to link the code of this Program with code not covered under the GNU
  17. * General Public License ("Non-GPL Code") and to distribute linked combinations
  18. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  19. * permitted under this exception must only link to the code of this Program
  20. * through those well defined interfaces identified in the file named EXCEPTION
  21. * found in the source code files (the "Approved Interfaces"). The files of
  22. * Non-GPL Code may instantiate templates or use macros or inline functions from
  23. * the Approved Interfaces without causing the resulting work to be covered by
  24. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  25. * additions to the list of Approved Interfaces. You must obey the GNU General
  26. * Public License in all respects for all of the Program code and other code used
  27. * in conjunction with the Program except the Non-GPL Code covered by this
  28. * exception. If you modify this file, you may extend this exception to your
  29. * version of the file, but you are not obligated to do so. If you do not wish to
  30. * provide this exception without modification, you must delete this exception
  31. * statement from your version and license this file solely under the GPL without
  32. * exception.
  33. *
  34. *
  35. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  36. * Copyright (C) 2006 Red Hat, Inc.
  37. * All rights reserved.
  38. * END COPYRIGHT BLOCK **/
  39. #ifdef HAVE_CONFIG_H
  40. # include <config.h>
  41. #endif
  42. /*
  43. FILE : threadMain.c
  44. AUTHOR : Jean-Luc SCHWING
  45. VERSION : 1.0
  46. DATE : 04 December 1998
  47. DESCRIPTION :
  48. This file implements the main/core part of the
  49. threads. The ldap part is in another source file.
  50. LOCAL : None.
  51. HISTORY :
  52. ---------+--------------+------------------------------------------------------
  53. dd/mm/yy | Author | Comments
  54. ---------+--------------+------------------------------------------------------
  55. 04/12/98 | JL Schwing | Creation
  56. ---------+--------------+------------------------------------------------------
  57. 10/12/98 | JL Schwing | 1.2 : Add nb of errors statistics.
  58. ---------+--------------+------------------------------------------------------
  59. 10/12/98 | JL Schwing | 1.3 : Implement asynchronous mode.
  60. ---------+--------------+------------------------------------------------------
  61. 11/12/98 | JL Schwing | 1.4 : Implement max errors threshold.
  62. | fflush(stdout) after each printf.
  63. ---------+--------------+------------------------------------------------------
  64. 14/12/98 | JL Schwing | 1.5 : Implement "-e close".
  65. | Add "thread is dead" message.
  66. ---------+--------------+------------------------------------------------------
  67. 16/12/98 | JL Schwing | 1.6 : Implement "-e add" and "-e delete".
  68. ---------+--------------+------------------------------------------------------
  69. 23/12/98 | JL Schwing | 1.7 : bug fix - crash in msgIdDel().
  70. ---------+--------------+------------------------------------------------------
  71. 28/12/98 | JL Schwing | 1.8 : Add tag asyncHit.
  72. ---------+--------------+------------------------------------------------------
  73. 13/01/99 | JL Schwing | 1.9 : Implement "-e string".
  74. ---------+--------------+------------------------------------------------------
  75. 18/01/99 | JL Schwing | 1.10: Implement "-e randombase".
  76. ---------+--------------+------------------------------------------------------
  77. 21/01/99 | JL Schwing | 1.11: Implement "-e ascii".
  78. ---------+--------------+------------------------------------------------------
  79. 26/02/99 | JL Schwing | 1.12: Improve strict ascii: reject more characters.
  80. ---------+--------------+------------------------------------------------------
  81. 26/02/99 | JL Schwing | 1.13: Quote (aka \) characters rather than reject.
  82. ---------+--------------+------------------------------------------------------
  83. 04/05/99 | JL Schwing | 1.14: Modify msgId*() to memorize attribs as well.
  84. ---------+--------------+------------------------------------------------------
  85. 19/05/99 | JL Schwing | 1.15: Implement "-e rename".
  86. | Exit the thread if status==DEAD
  87. ---------+--------------+------------------------------------------------------
  88. 28/05/99 | JL Schwing | 1.16: Add new option -W (wait).
  89. ---------+--------------+------------------------------------------------------
  90. 06/03/00 | JL Schwing | 1.17: Test malloc() return value.
  91. ---------+--------------+------------------------------------------------------
  92. 18/08/00 | JL Schwing | 1.18: Print begin and end dates.
  93. ---------+--------------+------------------------------------------------------
  94. 25/08/00 | JL Schwing | 1.19: Implement consistent exit status...
  95. | Fix some old legacy code.
  96. ---------+--------------+------------------------------------------------------
  97. 14/11/00 | JL Schwing | 1.20: Will now use utils.c functions.
  98. ---------+--------------+------------------------------------------------------
  99. 17/11/00 | JL Schwing | 1.21: Implement "-e smoothshutdown".
  100. | Add new functions setThreadStatus() getThreadStatus().
  101. ---------+--------------+------------------------------------------------------
  102. 21/11/00 | JL Schwing | 1.22: Implement "-e attreplace=name:mask"
  103. ---------+--------------+------------------------------------------------------
  104. 29/11/00 | JL Schwing | 1.23: Port on NT 4.
  105. ---------+--------------+------------------------------------------------------
  106. 01/12/00 | JL Schwing | 1.24: Port on Linux.
  107. ---------+--------------+------------------------------------------------------
  108. 15/12/00 | JL Schwing | 1.25: Add more trace in VERY_VERBOSE mode.
  109. ---------+--------------+------------------------------------------------------
  110. 18/12/00 | JL Schwing | 1.26: Add new exit status EXIT_INIT.
  111. ---------+--------------+------------------------------------------------------
  112. 05/01/01 | JL Schwing | 1.27: Implement "-e randombinddn" and associated
  113. | "-e randombinddnlow/high"
  114. ---------+--------------+------------------------------------------------------
  115. 08/01/01 | JL Schwing | 1.28: Implement "-e scalab01".
  116. ---------+--------------+------------------------------------------------------
  117. 12/01/01 | JL Schwing | 1.29: Include scalab01.h
  118. ---------+--------------+------------------------------------------------------
  119. 05/03/01 | JL Schwing | 1.30: Bug fix - crash SIGSEGV if no binDN provided.
  120. ---------+--------------+------------------------------------------------------
  121. 14/03/01 | JL Schwing | 1.31: Implement "-e commoncounter"
  122. | Add new function incrementCommonCounter().
  123. ---------+--------------+------------------------------------------------------
  124. 14/03/01 | JL Schwing | 1.32: Implement "-e dontsleeponserverdown".
  125. ---------+--------------+------------------------------------------------------
  126. 15/03/01 | JL Schwing | 1.33: Implement "-e randomattrlist=name:name:name"
  127. | Add new function selectRandomAttrList().
  128. ---------+--------------+------------------------------------------------------
  129. 19/03/01 | JL Schwing | 1.34: Implement "-e genldif=filename"
  130. ---------+--------------+------------------------------------------------------
  131. 23/03/01 | JL Schwing | 1.35: Implements "-e rdn=value".
  132. ---------+--------------+------------------------------------------------------
  133. 28/03/01 | JL Schwing | 1.36: Support -e commoncounter with -e rdn/object
  134. | Add new function incrementCommonCounterObject().
  135. ---------+--------------+------------------------------------------------------
  136. 02/04/01 | JL Schwing | 1.37: Bug fix : large files support for -e genldif.
  137. ---------+--------------+------------------------------------------------------
  138. 11/04/01 | JL Schwing | 1.38: Implement [INCRFROMFILE<NOLOOP>(myfile)]
  139. ---------+--------------+------------------------------------------------------
  140. 03/05/01 | JL Schwing | 1.39: Implement -e randombinddnfromfile=filename.
  141. ---------+--------------+------------------------------------------------------
  142. 04/05/01 | JL Schwing | 1.40: Implement -e bindonly.
  143. ---------+--------------+------------------------------------------------------
  144. */
  145. #include <stdio.h> /* printf(), etc... */
  146. #include <string.h> /* strerror(), etc... */
  147. #include <stdlib.h> /* exit(), etc... */
  148. #include <ctype.h> /* isascii(), etc... */
  149. #include <errno.h> /* errno, etc... */ /*JLS 06-03-00*/
  150. #include <lber.h> /* ldap C-API BER declarations */
  151. #include <ldap.h> /* ldap C-API declarations */
  152. #ifndef _WIN32 /*JLS 29-11-00*/
  153. #include <unistd.h> /* close(), etc... */
  154. #include <pthread.h> /* pthreads(), etc... */
  155. #include <signal.h> /* sigfillset(), etc... */
  156. #endif /*JLS 29-11-00*/
  157. #include "port.h" /* Portability definitions */ /*JLS 29-11-00*/
  158. #include "ldclt.h" /* This tool's include file */
  159. #include "utils.h" /* Utilities functions */ /*JLS 14-11-00*/
  160. #include "scalab01.h" /* Scalab01 specific */ /*JLS 12-01-01*/
  161. /* New */ /*JLS 15-03-01*/
  162. /* ****************************************************************************
  163. FUNCTION : selectRandomAttrList
  164. PURPOSE : Select a random attr list.
  165. INPUT : tttctx = this thread context
  166. OUTPUT : None.
  167. RETURN : The random list.
  168. DESCRIPTION :
  169. *****************************************************************************/
  170. char **
  171. selectRandomAttrList (
  172. thread_context *tttctx)
  173. {
  174. tttctx->attrlist[0] = mctx.attrlist[rndlim(0,mctx.attrlistNb-1)];
  175. return (tttctx->attrlist);
  176. }
  177. /* ****************************************************************************
  178. FUNCTION : randomString
  179. PURPOSE : Return a random string, of length nbDigits.
  180. The string is returned in tttctx->buf2.
  181. INPUT : tttctx = thread context.
  182. nbDigits = number of digits required.
  183. OUTPUT : None.
  184. RETURN : -1 if error, 0 else.
  185. DESCRIPTION :
  186. *****************************************************************************/
  187. int
  188. randomString (
  189. thread_context *tttctx,
  190. int nbDigits)
  191. {
  192. rndstr (tttctx->buf2, nbDigits); /*JLS 14-11-00*/
  193. return (0);
  194. }
  195. /* New */ /*JLS 28-03-01*/
  196. /* ****************************************************************************
  197. FUNCTION : incrementCommonCounterObject
  198. PURPOSE : Purpose of the fct
  199. INPUT : tttctx = thread context
  200. field = field to process
  201. OUTPUT : None.
  202. RETURN : -1 if error or end of loop (no_loop), new value else.
  203. DESCRIPTION :
  204. *****************************************************************************/
  205. int
  206. incrementCommonCounterObject (
  207. thread_context *tttctx,
  208. vers_field *field)
  209. {
  210. int ret; /* Return value */
  211. int val; /* New value */
  212. /*
  213. * Get mutex
  214. */
  215. if ((ret = ldclt_mutex_lock (&(field->cnt_mutex))) != 0)
  216. {
  217. fprintf (stderr, "ldclt[%d]: %s: cannot mutex_lock(field->cnt_mutex), error=%d (%s)\n",
  218. mctx.pid, tttctx->thrdId, ret, strerror (ret));
  219. fflush (stderr);
  220. return (-1);
  221. }
  222. /*
  223. * Compute next value
  224. */
  225. switch (field->how)
  226. {
  227. case HOW_INCR_FROM_FILE:
  228. case HOW_INCR_NB:
  229. if (field->cnt <= field->high) /* Limit not reached */
  230. {
  231. val = field->cnt;
  232. field->cnt++;
  233. }
  234. else
  235. {
  236. val = field->low;
  237. field->cnt = field->low + 1;
  238. }
  239. break;
  240. case HOW_INCR_FROM_FILE_NL:
  241. case HOW_INCR_NB_NOLOOP:
  242. if (field->cnt <= field->high) /* Limit not reached */
  243. {
  244. val = field->cnt;
  245. field->cnt++;
  246. }
  247. else
  248. val = -1; /* Exit thread */
  249. break;
  250. default:
  251. printf ("ldclt[%d]: %s: Illegal how=%d in incrementCommonCounterObject()\n",
  252. mctx.pid, tttctx->thrdId, field->how);
  253. val = -1;
  254. break;
  255. }
  256. /*
  257. * Free mutex
  258. */
  259. if ((ret = ldclt_mutex_unlock (&(field->cnt_mutex))) != 0)
  260. {
  261. fprintf(stderr,"ldclt[%d]: %s: cannot mutex_unlock(field->cnt_mutex), error=%d (%s)\n",
  262. mctx.pid, tttctx->thrdId, ret, strerror (ret));
  263. fflush (stderr);
  264. return (-1);
  265. }
  266. /*
  267. * Maybe a message to print ?
  268. */
  269. if (val < 0)
  270. printf ("ldclt[%d]: %s: Hit top incrementeal value\n", mctx.pid, tttctx->thrdId);
  271. return (val);
  272. }
  273. /* New */ /*JLS 14-03-01*/
  274. /* ****************************************************************************
  275. FUNCTION : incrementCommonCounter
  276. PURPOSE : Purpose of the fct
  277. INPUT : tttctx = thread context
  278. OUTPUT : None.
  279. RETURN : -1 if error or end of loop (no_loop), new value else.
  280. DESCRIPTION :
  281. *****************************************************************************/
  282. int
  283. incrementCommonCounter (
  284. thread_context *tttctx)
  285. {
  286. int ret; /* Return value */
  287. int val; /* New value */
  288. /*
  289. * Get mutex
  290. */
  291. if ((ret = ldclt_mutex_lock (&(mctx.lastVal_mutex))) != 0)
  292. {
  293. fprintf (stderr, "ldclt[%d]: T%03d: cannot mutex_lock(lastVal_mutex), error=%d (%s)\n",
  294. mctx.pid, tttctx->thrdNum, ret, strerror (ret));
  295. fflush (stderr);
  296. return (-1);
  297. }
  298. /*
  299. * Compute next value
  300. */
  301. if ((mctx.mode & NOLOOP) && (mctx.lastVal == mctx.randomHigh))
  302. val = -1;
  303. else
  304. {
  305. mctx.lastVal++;
  306. if (mctx.lastVal > mctx.randomHigh)
  307. {
  308. if (mctx.mode & NOLOOP)
  309. val = -1;
  310. else
  311. mctx.lastVal = mctx.randomLow;
  312. }
  313. val = mctx.lastVal;
  314. }
  315. /*
  316. * Free mutex
  317. */
  318. if ((ret = ldclt_mutex_unlock (&(mctx.lastVal_mutex))) != 0)
  319. {
  320. fprintf(stderr,"ldclt[%d]: T%03d: cannot mutex_unlock(lastVal_mutex), error=%d (%s)\n",
  321. mctx.pid, tttctx->thrdNum, ret, strerror (ret));
  322. fflush (stderr);
  323. return (-1);
  324. }
  325. /*
  326. * Maybe a message to print ?
  327. */
  328. if (val < 0)
  329. printf ("ldclt[%d]: T%03d: Hit top incrementeal value\n", mctx.pid, tttctx->thrdNum);
  330. return (val);
  331. }
  332. /* ****************************************************************************
  333. FUNCTION : incrementNbOpers
  334. PURPOSE : Increment the counters tttctx->nbOpers and
  335. tttctx->totOpers of the given thread.
  336. INPUT : tttctx = thread context.
  337. OUTPUT : None.
  338. RETURN : -1 if error, 0 else.
  339. DESCRIPTION :
  340. *****************************************************************************/
  341. int
  342. incrementNbOpers (
  343. thread_context *tttctx)
  344. {
  345. int ret; /* Return value */
  346. /*
  347. * Get mutex
  348. */
  349. if ((ret = ldclt_mutex_lock (&(tttctx->nbOpers_mutex))) != 0)
  350. {
  351. fprintf (stderr, "ldclt[%d]: T%03d: cannot mutex_lock(), error=%d (%s)\n",
  352. mctx.pid, tttctx->thrdNum, ret, strerror (ret));
  353. fflush (stderr);
  354. return (-1);
  355. }
  356. /*
  357. * Increment counter
  358. */
  359. tttctx->nbOpers++;
  360. /*
  361. * Free mutex
  362. */
  363. if ((ret = ldclt_mutex_unlock (&(tttctx->nbOpers_mutex))) != 0)
  364. {
  365. fprintf (stderr, "ldclt[%d]: T%03d: cannot mutex_unlock(), error=%d (%s)\n",
  366. mctx.pid, tttctx->thrdNum, ret, strerror (ret));
  367. fflush (stderr);
  368. return (-1);
  369. }
  370. /*
  371. * Increment total and check if max value reached
  372. */
  373. tttctx->totOpers++;
  374. if(tttctx->totalReq > -1) {
  375. if (tttctx->totOpers >= tttctx->totalReq) {
  376. if (setThreadStatus(tttctx, MUST_SHUTDOWN) < 0) {
  377. tttctx->status = DEAD; /* Force thread to die! */
  378. }
  379. }
  380. }
  381. return (0);
  382. }
  383. /* ****************************************************************************
  384. FUNCTION : ignoreError
  385. PURPOSE : Returns true or false depending on the given error
  386. should be ignored or not (option -I).
  387. We will sleep() if an error about server down is to be
  388. ignored.
  389. INPUT : err = error number
  390. OUTPUT : None.
  391. RETURN : 1 if should be ignored, 0 else.
  392. DESCRIPTION :
  393. *****************************************************************************/
  394. int
  395. ignoreError (
  396. int err)
  397. {
  398. int i;
  399. for (i=0 ; i<mctx.ignErrNb ; i++)
  400. if (mctx.ignErr[i] == err)
  401. { /*JLS 14-03-01*/
  402. if ((!(mctx.mode & DONT_SLEEP_DOWN)) && /*JLS 14-03-01*/
  403. ((err == LDAP_SERVER_DOWN) || /*JLS 14-03-01*/
  404. (err == LDAP_CONNECT_ERROR))) /*JLS 14-03-01*/
  405. ldclt_sleep (1); /*JLS 14-03-01*/
  406. return (1);
  407. } /*JLS 14-03-01*/
  408. return (0);
  409. }
  410. /* ****************************************************************************
  411. FUNCTION : addErrorStat
  412. PURPOSE : Add the given error number to the statistics.
  413. INPUT : err = error number
  414. OUTPUT : None.
  415. RETURN : -1 if error, 0 else.
  416. DESCRIPTION :
  417. *****************************************************************************/
  418. int
  419. addErrorStat (
  420. int err)
  421. {
  422. int ret; /* Return value */
  423. /*
  424. * Get mutex
  425. */
  426. if ((ret = ldclt_mutex_lock (&(mctx.errors_mutex))) != 0)
  427. {
  428. fprintf (stderr,
  429. "ldclt[%d]: Cannot mutex_lock(errors_mutex), error=%d (%s)\n",
  430. mctx.pid, ret, strerror (ret));
  431. fflush (stderr);
  432. return (-1);
  433. }
  434. /*
  435. * Update the counters
  436. */
  437. if ((err <= 0) || (err >= MAX_ERROR_NB))
  438. {
  439. fprintf (stderr, "ldclt[%d]: Illegal error number %d\n", mctx.pid, err);
  440. fflush (stderr);
  441. mctx.errorsBad++;
  442. }
  443. else
  444. mctx.errors[err]++;
  445. /*
  446. * Release the mutex
  447. */
  448. if ((ret = ldclt_mutex_unlock (&(mctx.errors_mutex))) != 0)
  449. {
  450. fprintf (stderr,
  451. "ldclt[%d]: Cannot mutex_unlock(errors_mutex), error=%d (%s)\n",
  452. mctx.pid, ret, strerror (ret));
  453. fflush (stderr);
  454. return (-1);
  455. }
  456. /*
  457. * Maybe we should ignore this error ?
  458. */
  459. if (!(ignoreError (err)))
  460. {
  461. /*
  462. * Ok, we should not ignore this error...
  463. * Maybe the limit is reached ?
  464. */
  465. if ((err <= 0) || (err >= MAX_ERROR_NB))
  466. {
  467. if (mctx.errorsBad > mctx.maxErrors)
  468. {
  469. printf ("ldclt[%d]: Max error limit reached - exiting.\n", mctx.pid);
  470. (void) printGlobalStatistics(); /*JLS 25-08-00*/
  471. fflush (stdout);
  472. ldclt_sleep (5);
  473. ldcltExit (EXIT_MAX_ERRORS); /*JLS 25-08-00*/
  474. }
  475. }
  476. else
  477. if (mctx.errors[err] > mctx.maxErrors)
  478. {
  479. printf ("ldclt[%d]: Max error limit reached - exiting.\n", mctx.pid);
  480. (void) printGlobalStatistics(); /*JLS 25-08-00*/
  481. fflush (stdout);
  482. ldclt_sleep (5);
  483. ldcltExit (EXIT_MAX_ERRORS); /*JLS 25-08-00*/
  484. }
  485. }
  486. /*
  487. * Normal end
  488. */
  489. return (0);
  490. }
  491. /* ****************************************************************************
  492. FUNCTION : msgIdAdd
  493. PURPOSE : Add a new message id to the pending ones.
  494. INPUT : tttctx = thread's context.
  495. msgid = message id.
  496. str = free string.
  497. dn = dn of the entry
  498. attribs = attributes
  499. OUTPUT : None.
  500. RETURN : -1 if error, 0 else.
  501. DESCRIPTION :
  502. *****************************************************************************/
  503. int
  504. msgIdAdd (
  505. thread_context *tttctx,
  506. int msgid,
  507. char *str,
  508. char *dn,
  509. LDAPMod **attribs)
  510. {
  511. if (mctx.mode & VERY_VERBOSE)
  512. printf ("ldclt[%d]: T%03d: msgIdAdd (%d, %s)\n", mctx.pid, tttctx->thrdNum, msgid, str);
  513. /*
  514. * Add the new cell
  515. */
  516. if (tttctx->firstMsgId == NULL)
  517. {
  518. tttctx->firstMsgId = (msgid_cell *) malloc (sizeof (msgid_cell));
  519. if (tttctx->firstMsgId == NULL) /*JLS 06-03-00*/
  520. { /*JLS 06-03-00*/
  521. printf ("ldclt[%d]: T%03d: cannot malloc(tttctx->firstMsgId), error=%d (%s)\n",
  522. mctx.pid, tttctx->thrdNum, errno, strerror (errno));
  523. return (-1); /*JLS 06-03-00*/
  524. } /*JLS 06-03-00*/
  525. tttctx->lastMsgId = tttctx->firstMsgId;
  526. }
  527. else
  528. {
  529. tttctx->lastMsgId->next = (msgid_cell *) malloc (sizeof (msgid_cell));
  530. if (tttctx->lastMsgId->next == NULL) /*JLS 06-03-00*/
  531. { /*JLS 06-03-00*/
  532. printf ("ldclt[%d]: T%03d: cannot malloc(tttctx->lastMsgId->next), error=%d (%s)\n",
  533. mctx.pid, tttctx->thrdNum, errno, strerror (errno));
  534. return (-1); /*JLS 06-03-00*/
  535. } /*JLS 06-03-00*/
  536. tttctx->lastMsgId = tttctx->lastMsgId->next;
  537. }
  538. /*
  539. * Memorize the information
  540. */
  541. tttctx->lastMsgId->next = NULL;
  542. tttctx->lastMsgId->msgid = msgid;
  543. strcpy (tttctx->lastMsgId->str, str);
  544. strcpy (tttctx->lastMsgId->dn, dn);
  545. tttctx->lastMsgId->attribs = attribs;
  546. return (0);
  547. }
  548. /* ****************************************************************************
  549. FUNCTION : msgIdAttribs
  550. PURPOSE : Found the requested message id in the pending list.
  551. INPUT : tttctx = thread's context
  552. msgid = message id
  553. OUTPUT : None
  554. RETURN : The associated attributes, or NULL.
  555. DESCRIPTION :
  556. *****************************************************************************/
  557. LDAPMod **
  558. msgIdAttribs (
  559. thread_context *tttctx,
  560. int msgid)
  561. {
  562. msgid_cell *pt;
  563. if (mctx.mode & VERY_VERBOSE)
  564. printf ("ldclt[%d]: T%03d: msgIdAttribs (%d)\n", mctx.pid, tttctx->thrdNum, msgid);
  565. for (pt = tttctx->firstMsgId ; pt != NULL ; pt = pt->next)
  566. if (pt->msgid == msgid)
  567. return (pt->attribs);
  568. return (NULL);
  569. }
  570. /* ****************************************************************************
  571. FUNCTION : msgIdDN
  572. PURPOSE : Found the requested message id in the pending list.
  573. INPUT : tttctx = thread's context
  574. msgid = message id
  575. OUTPUT : None
  576. RETURN : The associated DN, or NULL.
  577. DESCRIPTION :
  578. *****************************************************************************/
  579. char *
  580. msgIdDN (
  581. thread_context *tttctx,
  582. int msgid)
  583. {
  584. msgid_cell *pt;
  585. if (mctx.mode & VERY_VERBOSE)
  586. printf ("ldclt[%d]: T%03d: msgIdDN (%d)\n", mctx.pid, tttctx->thrdNum, msgid);
  587. for (pt = tttctx->firstMsgId ; pt != NULL ; pt = pt->next)
  588. if (pt->msgid == msgid)
  589. return (pt->dn);
  590. return (NULL);
  591. }
  592. /* ****************************************************************************
  593. FUNCTION : msgIdStr
  594. PURPOSE : Found the requested message id in the pending list.
  595. INPUT : tttctx = thread's context
  596. msgid = message id
  597. OUTPUT : None
  598. RETURN : The associated str, or an error message string.
  599. DESCRIPTION :
  600. *****************************************************************************/
  601. char *
  602. msgIdStr (
  603. thread_context *tttctx,
  604. int msgid)
  605. {
  606. msgid_cell *pt;
  607. if (mctx.mode & VERY_VERBOSE)
  608. printf ("ldclt[%d]: T%03d: msgIdStr (%d)\n", mctx.pid, tttctx->thrdNum, msgid);
  609. for (pt = tttctx->firstMsgId ; pt != NULL ; pt = pt->next)
  610. if (pt->msgid == msgid)
  611. return (pt->str);
  612. return ("Error: msgid not found");
  613. }
  614. /* ****************************************************************************
  615. FUNCTION : msgIdDel
  616. PURPOSE : Delete a message id from the pending ones.
  617. INPUT : tttctx = thread's context
  618. msgid = message id.
  619. freeAttr= true or false depending on freing the attribs
  620. OUTPUT : None.
  621. RETURN : -1 if not found, 0 else.
  622. DESCRIPTION :
  623. *****************************************************************************/
  624. int
  625. msgIdDel (
  626. thread_context *tttctx,
  627. int msgid,
  628. int freeAttr)
  629. {
  630. msgid_cell *pt; /* For the loop */
  631. msgid_cell *ptToFree; /* The cell to free */
  632. if (mctx.mode & VERY_VERBOSE)
  633. printf ("ldclt[%d]: T%03d: msgIdDel (%d)\n", mctx.pid, tttctx->thrdNum, msgid);
  634. /*
  635. * Make sure there is a list !
  636. */
  637. if (tttctx->firstMsgId != NULL)
  638. {
  639. /*
  640. * Maybe it is the first one ?
  641. */
  642. if (tttctx->firstMsgId->msgid == msgid)
  643. {
  644. ptToFree = tttctx->firstMsgId;
  645. tttctx->firstMsgId = tttctx->firstMsgId->next;
  646. if (tttctx->firstMsgId == NULL)
  647. tttctx->lastMsgId = NULL;
  648. free (ptToFree);
  649. return (0);
  650. }
  651. /*
  652. * Let's go through the whole list
  653. */
  654. for (pt = tttctx->firstMsgId ; pt->next != NULL ; pt = pt->next)
  655. if (pt->next->msgid == msgid)
  656. {
  657. /*
  658. * Be carrefull if it is the last element of the list
  659. */
  660. if (pt->next->next == NULL)
  661. tttctx->lastMsgId = pt;
  662. ptToFree = pt->next;
  663. pt->next = ptToFree->next;
  664. if (freeAttr)
  665. if (freeAttrib (ptToFree->attribs) < 0)
  666. return (-1);
  667. /*
  668. * Free the pointer itself
  669. */
  670. free (ptToFree);
  671. return (0);
  672. }
  673. }
  674. /*
  675. * Not found
  676. */
  677. printf ("ldclt[%d]: T%03d: message %d not found.\n", mctx.pid, tttctx->thrdNum, msgid);
  678. fflush (stdout);
  679. return (-1);
  680. }
  681. /* New function */ /*JLS 17-11-00*/
  682. /* ****************************************************************************
  683. FUNCTION : getThreadStatus
  684. PURPOSE : Get the value of a given thread's status.
  685. INPUT : tttctx = thread context
  686. OUTPUT : status = the thread's status
  687. RETURN : -1 if error, 0 else.
  688. DESCRIPTION :
  689. *****************************************************************************/
  690. int
  691. getThreadStatus (
  692. thread_context *tttctx,
  693. int *status)
  694. {
  695. int ret; /* Return code */
  696. if ((ret = ldclt_mutex_lock (&(tttctx->status_mutex))) != 0)
  697. {
  698. fprintf (stderr,
  699. "ldclt[%d]: Cannot mutex_lock(T%03d), error=%d (%s)\n",
  700. mctx.pid, tttctx->thrdNum, ret, strerror (ret));
  701. fprintf (stderr, "ldclt[%d]: Problem in getThreadStatus()\n", mctx.pid);
  702. fflush (stderr);
  703. return (-1);
  704. }
  705. *status = tttctx->status;
  706. if ((ret = ldclt_mutex_unlock (&(tttctx->status_mutex))) != 0)
  707. {
  708. fprintf (stderr,
  709. "ldclt[%d]: Cannot mutex_unlock(T%03d), error=%d (%s)\n",
  710. mctx.pid, tttctx->thrdNum, ret, strerror (ret));
  711. fprintf (stderr, "ldclt[%d]: Problem in getThreadStatus()\n", mctx.pid);
  712. fflush (stderr);
  713. return (-1);
  714. }
  715. return (0);
  716. }
  717. /* New function */ /*JLS 17-11-00*/
  718. /* ****************************************************************************
  719. FUNCTION : setThreadStatus
  720. PURPOSE : Set the value of a given thread's status.
  721. INPUT : tttctx = thread context
  722. status = new status
  723. OUTPUT : None.
  724. RETURN : -1 if error, 0 else.
  725. DESCRIPTION :
  726. *****************************************************************************/
  727. int
  728. setThreadStatus (
  729. thread_context *tttctx,
  730. int status)
  731. {
  732. int ret; /* Return code */
  733. if ((ret = ldclt_mutex_lock (&(tttctx->status_mutex))) != 0)
  734. {
  735. fprintf (stderr,
  736. "ldclt[%d]: Cannot mutex_lock(T%03d), error=%d (%s)\n",
  737. mctx.pid, tttctx->thrdNum, ret, strerror (ret));
  738. fprintf (stderr, "ldclt[%d]: Problem in setThreadStatus()\n", mctx.pid);
  739. fflush (stderr);
  740. return (-1);
  741. }
  742. tttctx->status = status;
  743. if ((ret = ldclt_mutex_unlock (&(tttctx->status_mutex))) != 0)
  744. {
  745. fprintf (stderr,
  746. "ldclt[%d]: Cannot mutex_unlock(T%03d), error=%d (%s)\n",
  747. mctx.pid, tttctx->thrdNum, ret, strerror (ret));
  748. fprintf (stderr, "ldclt[%d]: Problem in setThreadStatus()\n", mctx.pid);
  749. fflush (stderr);
  750. return (-1);
  751. }
  752. return (0);
  753. }
  754. /* ****************************************************************************
  755. FUNCTION : threadMain
  756. PURPOSE : This function is the main function of the client threads
  757. part of this tool.
  758. INPUT : arg = this thread's thread_context
  759. OUTPUT : None.
  760. RETURN : None.
  761. DESCRIPTION :
  762. *****************************************************************************/
  763. void *
  764. threadMain (
  765. void *arg)
  766. {
  767. thread_context *tttctx; /* This thread's context */
  768. int go = 1; /* Thread must continue */
  769. int status; /* Thread's status */ /*JLS 17-11-00*/
  770. /*
  771. * Initialization
  772. */
  773. tttctx = (thread_context *) arg;
  774. if (setThreadStatus (tttctx, CREATED) < 0) /*JLS 17-11-00*/
  775. { /*JLS 17-11-00*/
  776. tttctx->status = DEAD; /*JLS 17-11-00*/
  777. return NULL; /*JLS 17-11-00*/
  778. } /*JLS 17-11-00*/
  779. tttctx->asyncHit = 0;
  780. tttctx->binded = 0;
  781. tttctx->fd = -1;
  782. tttctx->lastVal = mctx.randomLow-1;
  783. tttctx->ldapCtx = NULL;
  784. tttctx->matcheddnp = NULL; /*JLS 15-12-00*/
  785. tttctx->nbOpers = 0;
  786. tttctx->totOpers = 0;
  787. tttctx->pendingNb = 0;
  788. tttctx->firstMsgId = NULL;
  789. tttctx->lastMsgId = NULL;
  790. /*
  791. * Don't forget the buffers !!
  792. * This should save time while redoing random values
  793. */
  794. if ((mctx.mode & NEED_FILTER) || (mctx.mod2 & (M2_GENLDIF|M2_NEED_FILTER))) /*JLS 19-03-01*/
  795. {
  796. if (mctx.mod2 & M2_RDN_VALUE) /*JLS 23-03-01*/
  797. tttctx->bufFilter = (char *) malloc (MAX_FILTER); /*JLS 23-03-01*/
  798. else /*JLS 23-03-01*/
  799. { /*JLS 23-03-01*/
  800. /*
  801. * Variable filter ?
  802. */
  803. tttctx->bufFilter = (char *) malloc (strlen (mctx.filter) + 1);
  804. if (tttctx->bufFilter == NULL) /*JLS 06-03-00*/
  805. { /*JLS 06-03-00*/
  806. printf ("ldclt[%d]: %s: cannot malloc(tttctx->bufFilter), error=%d (%s)\n",
  807. mctx.pid, tttctx->thrdId, errno, strerror (errno));
  808. ldcltExit (EXIT_INIT); /*JLS 18-12-00*/
  809. } /*JLS 06-03-00*/
  810. if (!(mctx.mode & (RANDOM | INCREMENTAL)))
  811. strcpy (tttctx->bufFilter, mctx.filter);
  812. else
  813. {
  814. tttctx->startRandom = strlen (mctx.randomHead);
  815. strcpy (tttctx->bufFilter, mctx.randomHead);
  816. strcpy (&(tttctx->bufFilter[tttctx->startRandom+mctx.randomNbDigit]),
  817. mctx.randomTail);
  818. if (mctx.mode & VERY_VERBOSE)
  819. {
  820. printf ("ldclt[%d]: %s: startRandom = %d\n",
  821. mctx.pid, tttctx->thrdId, tttctx->startRandom);
  822. printf ("ldclt[%d]: %s: randomHead = \"%s\", randomTail = \"%s\"\n",
  823. mctx.pid, tttctx->thrdId, mctx.randomHead, mctx.randomTail);
  824. }
  825. }
  826. } /*JLS 23-03-01*/
  827. /*
  828. * Variable base DN ?
  829. */
  830. tttctx->bufBaseDN = (char *) malloc (strlen (mctx.baseDN) + 1);
  831. if (tttctx->bufBaseDN == NULL) /*JLS 06-03-00*/
  832. { /*JLS 06-03-00*/
  833. printf ("ldclt[%d]: T%03d: cannot malloc(tttctx->bufBaseDN), error=%d (%s)\n",
  834. mctx.pid, tttctx->thrdNum, errno, strerror (errno));
  835. ldcltExit (EXIT_INIT); /*JLS 18-12-00*/
  836. } /*JLS 06-03-00*/
  837. if (!(mctx.mode & RANDOM_BASE))
  838. strcpy (tttctx->bufBaseDN, mctx.baseDN);
  839. else
  840. {
  841. tttctx->startBaseDN = strlen (mctx.baseDNHead);
  842. strcpy (tttctx->bufBaseDN, mctx.baseDNHead);
  843. strcpy (&(tttctx->bufBaseDN[tttctx->startBaseDN+mctx.baseDNNbDigit]),
  844. mctx.baseDNTail);
  845. }
  846. /*
  847. * Variable bind DN ?
  848. * Do not forget the random bind password below that is activated
  849. * at the same time as the random bind DN.
  850. */
  851. if (mctx.bindDN != NULL) /*JLS 05-03-01*/
  852. { /*JLS 05-03-01*/
  853. tttctx->bufBindDN = (char *) malloc (strlen (mctx.bindDN) + 1);
  854. if (tttctx->bufBindDN == NULL)
  855. {
  856. printf ("ldclt[%d]: T%03d: cannot malloc(tttctx->bufBindDN), error=%d (%s)\n",
  857. mctx.pid, tttctx->thrdNum, errno, strerror (errno));
  858. ldcltExit (EXIT_INIT);
  859. }
  860. if (!(mctx.mode & RANDOM_BINDDN))
  861. strcpy (tttctx->bufBindDN, mctx.bindDN);
  862. else
  863. {
  864. tttctx->startBindDN = strlen (mctx.bindDNHead);
  865. strcpy (tttctx->bufBindDN, mctx.bindDNHead);
  866. strcpy (&(tttctx->bufBindDN[tttctx->startBindDN+mctx.bindDNNbDigit]),
  867. mctx.bindDNTail);
  868. }
  869. } /*JLS 05-03-01*/
  870. /*
  871. * Variable bind password ?
  872. * Remember that the random bind password feature is activated
  873. * by the same option as the random bind DN, but has here its own
  874. * code section for the ease of coding.
  875. */
  876. if (mctx.passwd != NULL) /*JLS 05-03-01*/
  877. { /*JLS 05-03-01*/
  878. tttctx->bufPasswd = (char *) malloc (strlen (mctx.passwd) + 1);
  879. if (tttctx->bufPasswd == NULL)
  880. {
  881. printf ("ldclt[%d]: T%03d: cannot malloc(tttctx->bufPasswd), error=%d (%s)\n",
  882. mctx.pid, tttctx->thrdNum, errno, strerror (errno));
  883. ldcltExit (EXIT_INIT);
  884. }
  885. if (!(mctx.mode & RANDOM_BINDDN))
  886. strcpy (tttctx->bufPasswd, mctx.passwd);
  887. else
  888. {
  889. tttctx->startPasswd = strlen (mctx.passwdHead);
  890. strcpy (tttctx->bufPasswd, mctx.passwdHead);
  891. strcpy (&(tttctx->bufPasswd[tttctx->startPasswd+mctx.passwdNbDigit]),
  892. mctx.passwdTail);
  893. }
  894. }
  895. } /*JLS 05-03-01*/
  896. /*
  897. * Bind DN from a file ?
  898. * The trick (mctx.passwd = "foo bar"; ) is needed to
  899. * simplify the code, because in many places we check
  900. * if mctx.passwd exist before sending password.
  901. */
  902. if (mctx.mod2 & M2_RNDBINDFILE) /*JLS 03-05-01*/
  903. { /*JLS 03-05-01*/
  904. tttctx->bufBindDN = (char *) malloc (MAX_DN_LENGTH); /*JLS 03-05-01*/
  905. tttctx->bufPasswd = (char *) malloc (MAX_DN_LENGTH); /*JLS 03-05-01*/
  906. mctx.passwd = "foo bar"; /* trick... */ /*JLS 03-05-01*/
  907. } /*JLS 03-05-01*/
  908. /*
  909. * Variable Authid ?
  910. */
  911. if (mctx.sasl_authid != NULL)
  912. {
  913. tttctx->bufSaslAuthid = (char *) malloc (strlen (mctx.sasl_authid) + 1);
  914. if (tttctx->bufSaslAuthid == NULL)
  915. {
  916. printf ("ldclt[%d]: T%03d: cannot malloc(tttctx->bufSaslAuthid), error=%d (%s)\n",
  917. mctx.pid, tttctx->thrdNum, errno, strerror (errno));
  918. ldcltExit (EXIT_INIT);
  919. }
  920. if (!(mctx.mod2 & M2_RANDOM_SASLAUTHID))
  921. strcpy (tttctx->bufSaslAuthid, mctx.sasl_authid);
  922. else
  923. {
  924. tttctx->startSaslAuthid = strlen (mctx.sasl_authid_head);
  925. strcpy (tttctx->bufSaslAuthid, mctx.sasl_authid_head);
  926. strcpy (&(tttctx->bufSaslAuthid[tttctx->startSaslAuthid+mctx.sasl_authid_nbdigit]),
  927. mctx.sasl_authid_tail);
  928. }
  929. }
  930. /*
  931. * Initiates the attribute replace buffers
  932. */
  933. if (mctx.mode & ATTR_REPLACE) /* New */ /*JLS 21-11-00*/
  934. {
  935. tttctx->bufAttrpl = (char *) malloc (strlen (mctx.attrpl) + 1);
  936. if (tttctx->bufAttrpl == NULL)
  937. {
  938. printf ("ldclt[%d]: T%03d: cannot malloc(tttctx->bufAttrpl), error=%d (%s)\n",
  939. mctx.pid, tttctx->thrdNum, errno, strerror (errno));
  940. ldcltExit (EXIT_INIT); /*JLS 18-12-00*/
  941. }
  942. tttctx->startAttrpl = strlen (mctx.attrplHead);
  943. strcpy (tttctx->bufAttrpl, mctx.attrplHead);
  944. strcpy (&(tttctx->bufAttrpl[tttctx->startAttrpl+mctx.attrplNbDigit]),
  945. mctx.attrplTail);
  946. }
  947. /*
  948. * Initiates the attribute replace buffers attrplName
  949. */
  950. if ( mctx.mod2 & M2_ATTR_REPLACE_FILE )
  951. {
  952. /* bufAttrpl should point to the same memory location that mctx.attrplFileContent points to */
  953. tttctx->bufAttrpl = mctx.attrplFileContent;
  954. if (tttctx->bufAttrpl == NULL)
  955. {
  956. printf ("ldclt[%d]: T%03d: cannot malloc(tttctx->bufAttrpl), error=%d (%s), can we read file [%s]\n",
  957. mctx.pid, tttctx->thrdNum, errno, strerror (errno), mctx.attrplFile);
  958. ldcltExit (EXIT_INIT); /*JLS 18-12-00*/
  959. }
  960. }
  961. /*
  962. * We are ready to go !
  963. */
  964. status = RUNNING; /*JLS 17-11-00*/
  965. if (setThreadStatus (tttctx, RUNNING) < 0) /*JLS 17-11-00*/
  966. status = DEAD; /*JLS 17-11-00*/
  967. /*
  968. * Let's go !
  969. */
  970. while (go && (status != DEAD) && (status != MUST_SHUTDOWN)) /*JLS 17-11-00*/
  971. {
  972. if (mctx.waitSec > 0)
  973. { /*JLS 17-11-00*/
  974. ldclt_sleep (mctx.waitSec);
  975. /*
  976. * Maybe we should shutdown ?
  977. */
  978. if (getThreadStatus (tttctx, &status) < 0) /*JLS 17-11-00*/
  979. break; /*JLS 17-11-00*/
  980. if (status == MUST_SHUTDOWN) /*JLS 17-11-00*/
  981. break; /*JLS 17-11-00*/
  982. } /*JLS 17-11-00*/
  983. /*
  984. * Do a LDAP request
  985. */
  986. if (tttctx->mode & ADD_ENTRIES)
  987. if (doAddEntry (tttctx) < 0)
  988. {
  989. go = 0;
  990. continue;
  991. }
  992. if (tttctx->mode & ATTR_REPLACE) /*JLS 21-11-00*/
  993. if (doAttrReplace (tttctx) < 0) /*JLS 21-11-00*/
  994. { /*JLS 21-11-00*/
  995. go = 0; /*JLS 21-11-00*/
  996. continue; /*JLS 21-11-00*/
  997. } /*JLS 21-11-00*/
  998. if (mctx.mod2 & M2_ATTR_REPLACE_FILE )
  999. if (doAttrFileReplace (tttctx) < 0)
  1000. {
  1001. go = 0;
  1002. continue;
  1003. }
  1004. if (tttctx->mode & DELETE_ENTRIES)
  1005. if (doDeleteEntry (tttctx) < 0)
  1006. {
  1007. go = 0;
  1008. continue;
  1009. }
  1010. if (mctx.mod2 & M2_BINDONLY) /*JLS 04-05-01*/
  1011. if (doBindOnly (tttctx) < 0) /*JLS 04-05-01*/
  1012. { /*JLS 04-05-01*/
  1013. go = 0; /*JLS 04-05-01*/
  1014. continue; /*JLS 04-05-01*/
  1015. } /*JLS 04-05-01*/
  1016. if (tttctx->mode & EXACT_SEARCH)
  1017. if (doExactSearch (tttctx) < 0)
  1018. {
  1019. go = 0;
  1020. continue;
  1021. }
  1022. if (tttctx->mode & RENAME_ENTRIES)
  1023. if (doRename (tttctx) < 0)
  1024. {
  1025. go = 0;
  1026. continue;
  1027. }
  1028. /*
  1029. * Maybe a specific scenario ?
  1030. */
  1031. if (tttctx->mode & SCALAB01) /*JLS 08-01-01*/
  1032. if (doScalab01 (tttctx) < 0) /*JLS 08-01-01*/
  1033. { /*JLS 08-01-01*/
  1034. go = 0; /*JLS 08-01-01*/
  1035. continue; /*JLS 08-01-01*/
  1036. } /*JLS 08-01-01*/
  1037. /*
  1038. * Maybe genldif mode ?
  1039. */
  1040. if (mctx.mod2 & M2_GENLDIF) /*JLS 19-03-01*/
  1041. if (doGenldif (tttctx) < 0) /*JLS 19-03-01*/
  1042. { /*JLS 19-03-01*/
  1043. ldclt_flush_genldif(); /*JLS 02-04-01*/
  1044. go = 0; /*JLS 19-03-01*/
  1045. continue; /*JLS 19-03-01*/
  1046. } /*JLS 19-03-01*/
  1047. if (mctx.mod2 & M2_ABANDON)
  1048. {
  1049. if (doAbandon (tttctx) < 0)
  1050. {
  1051. go = 0;
  1052. continue;
  1053. }
  1054. }
  1055. /*
  1056. * Check the thread's status
  1057. */
  1058. if (getThreadStatus (tttctx, &status) < 0) /*JLS 17-11-00*/
  1059. break; /*JLS 17-11-00*/
  1060. }
  1061. /*
  1062. * End of thread
  1063. */
  1064. /* [156984] once setting "DEAD", nothing should be done in the context */
  1065. /* moved the dead message above setThreadStatus(DEAD) */
  1066. printf ("ldclt[%d]: T%03d: thread is dead.\n", mctx.pid, tttctx->thrdNum);
  1067. fflush (stdout);
  1068. if (setThreadStatus (tttctx, DEAD) < 0) /*JLS 17-11-00*/
  1069. { /*JLS 17-11-00*/
  1070. ldclt_sleep (1); /*JLS 17-11-00*/
  1071. tttctx->status = DEAD; /* Force it !!! */ /*JLS 17-11-00*/
  1072. } /*JLS 17-11-00*/
  1073. return (arg);
  1074. }
  1075. /* End of file */