evt.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866
  1. /*
  2. * Copyright (c) 2004-2005 Mark Haverkamp
  3. * Copyright (c) 2004-2005 Open Source Development Lab
  4. *
  5. * All rights reserved.
  6. *
  7. * This software licensed under BSD license, the text of which follows:
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions are met:
  11. *
  12. * - Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. * - Redistributions in binary form must reproduce the above copyright notice,
  15. * this list of conditions and the following disclaimer in the documentation
  16. * and/or other materials provided with the distribution.
  17. * - Neither the name of the Open Source Developement Lab nor the names of its
  18. * contributors may be used to endorse or promote products derived from this
  19. * software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  25. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  26. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  27. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  28. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  29. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  30. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  31. * THE POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. #include <sys/types.h>
  34. #include <errno.h>
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include <string.h>
  38. #include <unistd.h>
  39. #include <sys/time.h>
  40. #include <sys/socket.h>
  41. #include "../include/ipc_evt.h"
  42. #include "util.h"
  43. #include "../exec/totempg.h"
  44. static void evtHandleInstanceDestructor(void *instance);
  45. static void chanHandleInstanceDestructor(void *instance);
  46. static void eventHandleInstanceDestructor(void *instance);
  47. /*
  48. * Versions of the SAF AIS specification supported by this library
  49. */
  50. static SaVersionT supported_versions[] = {
  51. {'B', 0x01, 0x01},
  52. {'b', 0x01, 0x01}
  53. };
  54. static struct saVersionDatabase evt_version_database = {
  55. sizeof(supported_versions) / sizeof(SaVersionT),
  56. supported_versions
  57. };
  58. /*
  59. * Event instance data
  60. */
  61. struct saHandleDatabase evt_instance_handle_db = {
  62. .handleCount = 0,
  63. .handles = 0,
  64. .mutex = PTHREAD_MUTEX_INITIALIZER,
  65. .handleInstanceDestructor = evtHandleInstanceDestructor
  66. };
  67. /*
  68. * Channel instance data
  69. */
  70. struct saHandleDatabase channel_handle_db = {
  71. .handleCount = 0,
  72. .handles = 0,
  73. .mutex = PTHREAD_MUTEX_INITIALIZER,
  74. .handleInstanceDestructor = chanHandleInstanceDestructor
  75. };
  76. /*
  77. * Event instance data
  78. */
  79. struct saHandleDatabase event_handle_db = {
  80. .handleCount = 0,
  81. .handles = 0,
  82. .mutex = PTHREAD_MUTEX_INITIALIZER,
  83. .handleInstanceDestructor = eventHandleInstanceDestructor
  84. };
  85. struct message_overlay {
  86. struct res_header header;
  87. char data[0];
  88. };
  89. /*
  90. * data required to support events for a given initialization
  91. *
  92. * ei_fd: fd received from the evtInitialize call.
  93. * ei_callback: callback function.
  94. * ei_version: version sent to the evtInitialize call.
  95. * ei_node_id: our node id.
  96. * ei_node_name: our node name.
  97. * ei_finalize: instance in finalize flag
  98. * ei_queue: queue for async messages while doing sync commands
  99. * ei_mutex: instance mutex
  100. *
  101. */
  102. struct event_instance {
  103. int ei_fd;
  104. SaEvtCallbacksT ei_callback;
  105. SaVersionT ei_version;
  106. SaClmNodeIdT ei_node_id;
  107. SaNameT ei_node_name;
  108. int ei_finalize;
  109. struct queue ei_inq;
  110. char ei_message[MESSAGE_SIZE_MAX];
  111. pthread_mutex_t ei_mutex;
  112. };
  113. /*
  114. * Data associated with an opened channel
  115. *
  116. * eci_channel_name: name of channel
  117. * eci_open_flags: channel open flags
  118. * eci_svr_channel_handle: channel handle returned from server
  119. * eci_closing: channel in process of being closed
  120. * eci_mutex: channel mutex
  121. *
  122. */
  123. struct event_channel_instance {
  124. SaNameT eci_channel_name;
  125. SaEvtChannelOpenFlagsT eci_open_flags;
  126. uint32_t eci_svr_channel_handle;
  127. SaEvtHandleT eci_instance_handle;
  128. int eci_closing;
  129. pthread_mutex_t eci_mutex;
  130. };
  131. /*
  132. * Event data.
  133. *
  134. * Store event data from saEvtEventAllocate function.
  135. * Store event data from received events.
  136. *
  137. * edi_channel_handle: handle (local) of assocated channel
  138. * edi_patterns: event patterns
  139. * edi_priority: event priority
  140. * edi_retention_time: event's retention time
  141. * edi_pub_name: event's publisher name
  142. * edi_pub_node: event's publisher node
  143. * edi_pub_time: event's publish time
  144. * edi_event_id: event's Id
  145. * edi_event_data: event's data
  146. * edi_event_data_size: size of edi_event_data
  147. * edi_freeing: event is being freed
  148. * edi_mutex: event data mutex
  149. *
  150. */
  151. struct event_data_instance {
  152. SaEvtChannelHandleT edi_channel_handle;
  153. SaEvtEventPatternArrayT edi_patterns;
  154. SaUint8T edi_priority;
  155. SaTimeT edi_retention_time;
  156. SaNameT edi_pub_name;
  157. SaClmNodeIdT edi_pub_node;
  158. SaTimeT edi_pub_time;
  159. SaEvtEventIdT edi_event_id;
  160. void *edi_event_data;
  161. SaSizeT edi_event_data_size;
  162. int edi_freeing;
  163. pthread_mutex_t edi_mutex;
  164. };
  165. #define PUB_SLEEP_NSEC 0L;
  166. #define PUB_SLEEP_SEC 1
  167. #define PUB_SLEEP_TRYS 20
  168. #define min(a,b) ((a) < (b) ? (a) : (b))
  169. /*
  170. * Clean up function for an evt instance (saEvtInitialize) handle
  171. */
  172. static void evtHandleInstanceDestructor(void *instance)
  173. {
  174. struct event_instance *evti = instance;
  175. void **msg;
  176. int empty;
  177. /*
  178. * Empty out the queue if there are any pending messages
  179. */
  180. while ((saQueueIsEmpty(&evti->ei_inq, &empty) == SA_AIS_OK) && !empty) {
  181. saQueueItemGet(&evti->ei_inq, (void *)&msg);
  182. saQueueItemRemove(&evti->ei_inq);
  183. free(*msg);
  184. }
  185. /*
  186. * clean up the queue itself
  187. */
  188. if (evti->ei_inq.items) {
  189. free(evti->ei_inq.items);
  190. }
  191. /*
  192. * Disconnect from the server
  193. */
  194. if (evti->ei_fd != -1) {
  195. shutdown(evti->ei_fd, 0);
  196. close(evti->ei_fd);
  197. }
  198. }
  199. /*
  200. * Clean up function for an open channel handle
  201. */
  202. static void chanHandleInstanceDestructor(void *instance)
  203. {
  204. }
  205. /*
  206. * Clean up function for an event handle
  207. */
  208. static void eventHandleInstanceDestructor(void *instance)
  209. {
  210. struct event_data_instance *edi = instance;
  211. int i;
  212. for (i = 0; i < edi->edi_patterns.patternsNumber; i++) {
  213. free(edi->edi_patterns.patterns[i].pattern);
  214. }
  215. if (edi->edi_patterns.patterns) {
  216. free(edi->edi_patterns.patterns);
  217. }
  218. if (edi->edi_event_data) {
  219. free(edi->edi_event_data);
  220. }
  221. }
  222. /*
  223. * The saEvtInitialize() function initializes the Event Service for the
  224. * invoking process. A user of the Event Service must invoke this function
  225. * before it invokes any other function of the Event Service API. Each
  226. * initialization returns a different callback handle that the process
  227. * can use to communicate with that library instance.
  228. */
  229. SaAisErrorT
  230. saEvtInitialize(
  231. SaEvtHandleT *evt_handle,
  232. const SaEvtCallbacksT *callbacks,
  233. SaVersionT *version)
  234. {
  235. SaAisErrorT error = SA_AIS_OK;
  236. struct event_instance *evti;
  237. /*
  238. * validate the requested version with what we support
  239. */
  240. error = saVersionVerify(&evt_version_database, version);
  241. if (error != SA_AIS_OK) {
  242. goto error_nofree;
  243. }
  244. /*
  245. * Allocate instance data, allocate unique handle for instance,
  246. * assign instance data to unique handle
  247. */
  248. error = saHandleCreate(&evt_instance_handle_db, sizeof(*evti),
  249. (void*)evt_handle);
  250. if (error != SA_AIS_OK) {
  251. goto error_nofree;
  252. }
  253. error = saHandleInstanceGet(&evt_instance_handle_db, *evt_handle,
  254. (void*)&evti);
  255. if (error != SA_AIS_OK) {
  256. goto error_handle_free;
  257. }
  258. memset(evti, 0, sizeof(*evti));
  259. /*
  260. * Save the version so we can check with the event server
  261. * and see if it supports this version.
  262. */
  263. evti->ei_version = *version;
  264. /*
  265. * An inq is needed to store async messages while waiting for a
  266. * sync response
  267. */
  268. error = saQueueInit(&evti->ei_inq, 1024, sizeof(void *));
  269. if (error != SA_AIS_OK) {
  270. goto error_handle_put;
  271. }
  272. /*
  273. * Set up communication with the event server
  274. */
  275. error = saServiceConnect(&evti->ei_fd, MESSAGE_REQ_EVT_INIT);
  276. if (error != SA_AIS_OK) {
  277. goto error_handle_put;
  278. }
  279. /*
  280. * The callback function is saved in the event instance for
  281. * saEvtDispatch() to use.
  282. */
  283. if (callbacks) {
  284. memcpy(&evti->ei_callback, callbacks,
  285. sizeof(evti->ei_callback));
  286. }
  287. pthread_mutex_init(&evti->ei_mutex, NULL);
  288. saHandleInstancePut(&evt_instance_handle_db, *evt_handle);
  289. return SA_AIS_OK;
  290. error_handle_put:
  291. saHandleInstancePut(&evt_instance_handle_db, *evt_handle);
  292. error_handle_free:
  293. (void)saHandleDestroy(&evt_instance_handle_db, *evt_handle);
  294. error_nofree:
  295. return error;
  296. }
  297. /*
  298. * The saEvtSelectionObjectGet() function returns the operating system
  299. * handle selection_object, associated with the handle evt_handle, allowing
  300. * the invoking process to ascertain when callbacks are pending. This
  301. * function allows a process to avoid repeated invoking saEvtDispatch() to
  302. * see if there is a new event, thus, needlessly consuming CPU time. In a
  303. * POSIX environment the system handle could be a file descriptor that is
  304. * used with the poll() or select() system calls to detect incoming callbacks.
  305. */
  306. SaAisErrorT
  307. saEvtSelectionObjectGet(
  308. SaEvtHandleT evt_handle,
  309. SaSelectionObjectT *selection_object)
  310. {
  311. struct event_instance *evti;
  312. SaAisErrorT error;
  313. error = saHandleInstanceGet(&evt_instance_handle_db, evt_handle,
  314. (void *)&evti);
  315. if (error != SA_AIS_OK) {
  316. return error;
  317. }
  318. *selection_object = evti->ei_fd;
  319. saHandleInstancePut(&evt_instance_handle_db, evt_handle);
  320. return SA_AIS_OK;
  321. }
  322. /*
  323. * Alocate an event data structure and associated handle to be
  324. * used to supply event data to a call back function.
  325. */
  326. static SaAisErrorT make_event(SaEvtEventHandleT *event_handle,
  327. struct lib_event_data *evt)
  328. {
  329. struct event_data_instance *edi;
  330. SaEvtEventPatternT *pat;
  331. SaUint8T *str;
  332. SaAisErrorT error;
  333. int i;
  334. error = saHandleCreate(&event_handle_db, sizeof(*edi),
  335. (void*)event_handle);
  336. if (error != SA_AIS_OK) {
  337. goto make_evt_done;
  338. }
  339. error = saHandleInstanceGet(&event_handle_db, *event_handle,
  340. (void*)&edi);
  341. if (error != SA_AIS_OK) {
  342. goto make_evt_done;
  343. }
  344. memset(edi, 0, sizeof(*edi));
  345. pthread_mutex_init(&edi->edi_mutex, NULL);
  346. edi->edi_freeing = 0;
  347. edi->edi_channel_handle = evt->led_lib_channel_handle;
  348. edi->edi_priority = evt->led_priority;
  349. edi->edi_retention_time = evt->led_retention_time;
  350. edi->edi_pub_node = evt->led_publisher_node_id;
  351. edi->edi_pub_time = evt->led_publish_time;
  352. edi->edi_event_data_size = evt->led_user_data_size;
  353. edi->edi_event_id = evt->led_event_id;
  354. edi->edi_pub_name = evt->led_publisher_name;
  355. if (edi->edi_event_data_size) {
  356. edi->edi_event_data = malloc(edi->edi_event_data_size);
  357. memcpy(edi->edi_event_data,
  358. evt->led_body + evt->led_user_data_offset,
  359. edi->edi_event_data_size);
  360. }
  361. /*
  362. * Move the pattern bits into the SaEvtEventPatternArrayT
  363. */
  364. edi->edi_patterns.patternsNumber = evt->led_patterns_number;
  365. edi->edi_patterns.patterns = malloc(sizeof(SaEvtEventPatternT) *
  366. edi->edi_patterns.patternsNumber);
  367. pat = (SaEvtEventPatternT *)evt->led_body;
  368. str = evt->led_body + sizeof(SaEvtEventPatternT) *
  369. edi->edi_patterns.patternsNumber;
  370. for (i = 0; i < evt->led_patterns_number; i++) {
  371. edi->edi_patterns.patterns[i].patternSize = pat->patternSize;
  372. edi->edi_patterns.patterns[i].pattern = malloc(pat->patternSize);
  373. if (!edi->edi_patterns.patterns[i].pattern) {
  374. printf("make_event: couldn't alloc %d bytes\n", pat->patternSize);
  375. error = SA_AIS_ERR_NO_MEMORY;
  376. break;
  377. }
  378. memcpy(edi->edi_patterns.patterns[i].pattern,
  379. str, pat->patternSize);
  380. str += pat->patternSize;
  381. pat++;
  382. }
  383. saHandleInstancePut (&event_handle_db, *event_handle);
  384. make_evt_done:
  385. return error;
  386. }
  387. /*
  388. * The saEvtDispatch() function invokes, in the context of the calling
  389. * thread, one or all of the pending callbacks for the handle evt_handle.
  390. */
  391. SaAisErrorT
  392. saEvtDispatch(
  393. SaEvtHandleT evt_handle,
  394. SaDispatchFlagsT dispatch_flags)
  395. {
  396. struct pollfd ufds;
  397. int timeout = -1;
  398. SaAisErrorT error;
  399. int dispatch_avail;
  400. struct event_instance *evti;
  401. SaEvtEventHandleT event_handle;
  402. SaEvtCallbacksT callbacks;
  403. struct res_header **queue_msg;
  404. struct res_header *msg = 0;
  405. int empty;
  406. int ignore_dispatch = 0;
  407. int cont = 1; /* always continue do loop except when set to 0 */
  408. int poll_fd;
  409. struct message_overlay *dispatch_data;
  410. struct lib_event_data *evt;
  411. struct res_evt_event_data res;
  412. error = saHandleInstanceGet(&evt_instance_handle_db, evt_handle,
  413. (void *)&evti);
  414. if (error != SA_AIS_OK) {
  415. return error;
  416. }
  417. /*
  418. * Timeout instantly for SA_DISPATCH_ALL
  419. */
  420. if (dispatch_flags == SA_DISPATCH_ALL) {
  421. timeout = 0;
  422. }
  423. do {
  424. poll_fd = evti->ei_fd;
  425. ufds.fd = poll_fd;
  426. ufds.events = POLLIN;
  427. ufds.revents = 0;
  428. pthread_mutex_lock(&evti->ei_mutex);
  429. saQueueIsEmpty(&evti->ei_inq, &empty);
  430. /*
  431. * Read from the socket if there is nothing in
  432. * our queue.
  433. */
  434. if (empty == 1) {
  435. pthread_mutex_unlock(&evti->ei_mutex);
  436. error = saPollRetry(&ufds, 1, timeout);
  437. if (error != SA_AIS_OK) {
  438. goto error_nounlock;
  439. }
  440. pthread_mutex_lock(&evti->ei_mutex);
  441. }
  442. /*
  443. * Handle has been finalized in another thread
  444. */
  445. if (evti->ei_finalize == 1) {
  446. error = SA_AIS_OK;
  447. pthread_mutex_unlock(&evti->ei_mutex);
  448. goto error_unlock;
  449. }
  450. dispatch_avail = (ufds.revents & POLLIN) | (empty == 0);
  451. if (dispatch_avail == 0 && dispatch_flags == SA_DISPATCH_ALL) {
  452. pthread_mutex_unlock(&evti->ei_mutex);
  453. break; /* exit do while cont is 1 loop */
  454. } else
  455. if (dispatch_avail == 0) {
  456. pthread_mutex_unlock(&evti->ei_mutex);
  457. continue; /* next poll */
  458. }
  459. saQueueIsEmpty(&evti->ei_inq, &empty);
  460. if (empty == 0) {
  461. /*
  462. * Queue is not empty, read data from queue
  463. */
  464. saQueueItemGet(&evti->ei_inq, (void *)&queue_msg);
  465. msg = *queue_msg;
  466. dispatch_data = (struct message_overlay *)msg;
  467. saQueueItemRemove(&evti->ei_inq);
  468. } else {
  469. /*
  470. * Queue empty, read response from socket
  471. */
  472. dispatch_data = (struct message_overlay *)&evti->ei_message;
  473. error = saRecvRetry(evti->ei_fd, &dispatch_data->header,
  474. sizeof(struct res_header), MSG_WAITALL | MSG_NOSIGNAL);
  475. if (error != SA_AIS_OK) {
  476. pthread_mutex_unlock(&evti->ei_mutex);
  477. goto error_unlock;
  478. }
  479. if (dispatch_data->header.size > sizeof(struct res_header)) {
  480. error = saRecvRetry(evti->ei_fd, dispatch_data->data,
  481. dispatch_data->header.size - sizeof(struct res_header),
  482. MSG_WAITALL | MSG_NOSIGNAL);
  483. if (error != SA_AIS_OK) {
  484. pthread_mutex_unlock(&evti->ei_mutex);
  485. goto error_unlock;
  486. }
  487. }
  488. }
  489. /*
  490. * Make copy of callbacks, message data, unlock instance,
  491. * and call callback. A risk of this dispatch method is that
  492. * the callback routines may operate at the same time that
  493. * EvtFinalize has been called in another thread.
  494. */
  495. memcpy(&callbacks, &evti->ei_callback, sizeof(evti->ei_callback));
  496. pthread_mutex_unlock(&evti->ei_mutex);
  497. /*
  498. * Dispatch incoming response
  499. */
  500. switch (dispatch_data->header.id) {
  501. case MESSAGE_RES_LIB_ACTIVATEPOLL:
  502. /*
  503. * This is a do nothing message which the node
  504. * executive sends to activate the file evt_handle
  505. * in poll when the library has queued a message into
  506. * evti->ei_inq. The dispatch is ignored for the
  507. * following two cases:
  508. * 1) setting of timeout to zero for the
  509. * DISPATCH_ALL case
  510. * 2) expiration of the do loop for the
  511. * DISPATCH_ONE case
  512. */
  513. ignore_dispatch = 1;
  514. break;
  515. case MESSAGE_RES_EVT_AVAILABLE:
  516. /*
  517. * There are events available. Send a request for one and then
  518. * dispatch it.
  519. */
  520. evt = (struct lib_event_data *)&evti->ei_message;
  521. res.evd_head.id = MESSAGE_REQ_EVT_EVENT_DATA;
  522. res.evd_head.size = sizeof(res);
  523. error = saSendRetry(evti->ei_fd, &res, sizeof(res), MSG_NOSIGNAL);
  524. if (error != SA_AIS_OK) {
  525. printf("MESSAGE_RES_EVT_AVAILABLE: send failed: %d\n", error);
  526. break;
  527. }
  528. error = saRecvQueue(evti->ei_fd, evt, &evti->ei_inq,
  529. MESSAGE_RES_EVT_EVENT_DATA);
  530. if (error != SA_AIS_OK) {
  531. printf("MESSAGE_RES_EVT_AVAILABLE: receive failed: %d\n",
  532. error);
  533. break;
  534. }
  535. /*
  536. * No data available. This is OK.
  537. */
  538. if (evt->led_head.error == SA_AIS_ERR_NOT_EXIST) {
  539. // printf("MESSAGE_RES_EVT_AVAILABLE: No event data\n");
  540. error = SA_AIS_OK;
  541. break;
  542. }
  543. if (evt->led_head.error != SA_AIS_OK) {
  544. error = evt->led_head.error;
  545. printf("MESSAGE_RES_EVT_AVAILABLE: Error returned: %d\n",
  546. error);
  547. break;
  548. }
  549. error = make_event(&event_handle, evt);
  550. if (error != SA_AIS_OK) {
  551. break;
  552. }
  553. callbacks.saEvtEventDeliverCallback(evt->led_sub_id, event_handle,
  554. evt->led_user_data_size);
  555. break;
  556. case MESSAGE_RES_EVT_CHAN_OPEN_CALLBACK:
  557. {
  558. struct res_evt_open_chan_async *resa =
  559. (struct res_evt_open_chan_async *)dispatch_data;
  560. struct event_channel_instance *eci;
  561. /*
  562. * Check for errors. If there are none, then
  563. * look up the local channel via the handle that we
  564. * got from the callback request. All we need to do
  565. * is place in the handle from the server side and then
  566. * we can call the callback.
  567. */
  568. error = resa->ica_head.error;
  569. if (error == SA_AIS_OK) {
  570. error = saHandleInstanceGet(&channel_handle_db,
  571. resa->ica_c_handle, (void*)&eci);
  572. if (error == SA_AIS_OK) {
  573. eci->eci_svr_channel_handle = resa->ica_channel_handle;
  574. saHandleInstancePut (&channel_handle_db,
  575. resa->ica_c_handle);
  576. }
  577. }
  578. callbacks.saEvtChannelOpenCallback(resa->ica_invocation,
  579. resa->ica_c_handle, error);
  580. }
  581. break;
  582. default:
  583. printf("Dispatch: Bad message type 0x%x\n",
  584. dispatch_data->header.id);
  585. error = SA_AIS_ERR_LIBRARY;
  586. goto error_nounlock;
  587. break;
  588. }
  589. /*
  590. * If empty is zero it means the we got the
  591. * message from the queue and we are responsible
  592. * for freeing it.
  593. */
  594. if (empty == 0) {
  595. free(msg);
  596. }
  597. /*
  598. * Determine if more messages should be processed
  599. */
  600. switch (dispatch_flags) {
  601. case SA_DISPATCH_ONE:
  602. if (ignore_dispatch) {
  603. ignore_dispatch = 0;
  604. } else {
  605. cont = 0;
  606. }
  607. break;
  608. case SA_DISPATCH_ALL:
  609. if (ignore_dispatch) {
  610. ignore_dispatch = 0;
  611. }
  612. break;
  613. case SA_DISPATCH_BLOCKING:
  614. break;
  615. }
  616. } while (cont);
  617. error_unlock:
  618. saHandleInstancePut(&evt_instance_handle_db, evt_handle);
  619. error_nounlock:
  620. return error;
  621. }
  622. /*
  623. * The saEvtFinalize() function closes the association, represented by the
  624. * evt_handle parameter, between the process and the Event Service. It may
  625. * free up resources.
  626. * This function cannot be invoked before the process has invoked the
  627. * corresponding saEvtInitialize() function for the Event Service. After
  628. * this function is invoked, the selection object is no longer valid.
  629. * Moreover, the Event Service is unavailable for further use unless it is
  630. * reinitialized using the saEvtInitialize() function.
  631. */
  632. SaAisErrorT
  633. saEvtFinalize(SaEvtHandleT evt_handle)
  634. {
  635. struct event_instance *evti;
  636. SaAisErrorT error;
  637. error = saHandleInstanceGet(&evt_instance_handle_db, evt_handle,
  638. (void *)&evti);
  639. if (error != SA_AIS_OK) {
  640. return error;
  641. }
  642. pthread_mutex_lock(&evti->ei_mutex);
  643. /*
  644. * Another thread has already started finalizing
  645. */
  646. if (evti->ei_finalize) {
  647. pthread_mutex_unlock(&evti->ei_mutex);
  648. saHandleInstancePut(&evt_instance_handle_db, evt_handle);
  649. return SA_AIS_ERR_BAD_HANDLE;
  650. }
  651. evti->ei_finalize = 1;
  652. saActivatePoll(evti->ei_fd);
  653. pthread_mutex_unlock(&evti->ei_mutex);
  654. saHandleDestroy(&evt_instance_handle_db, evt_handle);
  655. saHandleInstancePut(&evt_instance_handle_db, evt_handle);
  656. return error;
  657. }
  658. /*
  659. * The saEvtChannelOpen() function creates a new event channel or open an
  660. * existing channel. The saEvtChannelOpen() function is a blocking operation
  661. * and returns a new event channel handle. An event channel may be opened
  662. * multiple times by the same or different processes for publishing, and
  663. * subscribing to, events. If a process opens an event channel multiple
  664. * times, it is possible to receive the same event multiple times. However,
  665. * a process shall never receive an event more than once on a particular
  666. * event channel handle. If a process opens a channel twice and an event is
  667. * matched on both open channels, the Event Service performs two
  668. * callbacks -- one for each opened channel.
  669. */
  670. SaAisErrorT
  671. saEvtChannelOpen(
  672. SaEvtHandleT evt_handle,
  673. const SaNameT *channel_name,
  674. SaEvtChannelOpenFlagsT channel_open_flags,
  675. SaTimeT timeout,
  676. SaEvtChannelHandleT *channel_handle)
  677. {
  678. struct event_instance *evti;
  679. struct req_evt_channel_open req;
  680. struct res_evt_channel_open res;
  681. struct event_channel_instance *eci;
  682. SaAisErrorT error;
  683. error = saHandleInstanceGet(&evt_instance_handle_db, evt_handle,
  684. (void*)&evti);
  685. if (error != SA_AIS_OK) {
  686. goto chan_open_done;
  687. }
  688. /*
  689. * create a handle for this open channel
  690. */
  691. error = saHandleCreate(&channel_handle_db, sizeof(*eci),
  692. (void*)channel_handle);
  693. if (error != SA_AIS_OK) {
  694. goto chan_open_put;
  695. }
  696. error = saHandleInstanceGet(&channel_handle_db, *channel_handle,
  697. (void*)&eci);
  698. if (error != SA_AIS_OK) {
  699. saHandleDestroy(&channel_handle_db, *channel_handle);
  700. goto chan_open_put;
  701. }
  702. /*
  703. * Send the request to the server and wait for a response
  704. */
  705. req.ico_head.size = sizeof(req);
  706. req.ico_head.id = MESSAGE_REQ_EVT_OPEN_CHANNEL;
  707. req.ico_c_handle = *channel_handle;
  708. req.ico_timeout = timeout;
  709. req.ico_open_flag = channel_open_flags;
  710. req.ico_channel_name = *channel_name;
  711. pthread_mutex_lock(&evti->ei_mutex);
  712. error = saSendRetry(evti->ei_fd, &req, sizeof(req), MSG_NOSIGNAL);
  713. if (error != SA_AIS_OK) {
  714. pthread_mutex_unlock (&evti->ei_mutex);
  715. goto chan_open_free;
  716. }
  717. error = saRecvQueue(evti->ei_fd, &res, &evti->ei_inq,
  718. MESSAGE_RES_EVT_OPEN_CHANNEL);
  719. pthread_mutex_unlock (&evti->ei_mutex);
  720. if (error != SA_AIS_OK) {
  721. goto chan_open_free;
  722. }
  723. error = res.ico_head.error;
  724. if (error != SA_AIS_OK) {
  725. goto chan_open_free;
  726. }
  727. eci->eci_svr_channel_handle = res.ico_channel_handle;
  728. eci->eci_channel_name = *channel_name;
  729. eci->eci_open_flags = channel_open_flags;
  730. eci->eci_instance_handle = evt_handle;
  731. eci->eci_closing = 0;
  732. pthread_mutex_init(&eci->eci_mutex, NULL);
  733. saHandleInstancePut (&evt_instance_handle_db, evt_handle);
  734. saHandleInstancePut (&channel_handle_db, *channel_handle);
  735. return SA_AIS_OK;
  736. chan_open_free:
  737. saHandleDestroy(&channel_handle_db, *channel_handle);
  738. saHandleInstancePut (&channel_handle_db, *channel_handle);
  739. chan_open_put:
  740. saHandleInstancePut (&evt_instance_handle_db, evt_handle);
  741. chan_open_done:
  742. return error;
  743. }
  744. /*
  745. * The saEvtChannelClose() function closes an event channel and frees
  746. * resources allo-cated for that event channel in the invoking process. If
  747. * the event channel is not refer-enced by any process and does not hold
  748. * any events with non-zero retention time, the Event Service automatically
  749. * deletes the event channel from the cluster namespace.
  750. */
  751. SaAisErrorT
  752. saEvtChannelClose(SaEvtChannelHandleT channel_handle)
  753. {
  754. SaAisErrorT error;
  755. struct event_instance *evti;
  756. struct event_channel_instance *eci;
  757. struct req_evt_channel_close req;
  758. struct res_evt_channel_close res;
  759. error = saHandleInstanceGet(&channel_handle_db, channel_handle,
  760. (void*)&eci);
  761. if (error != SA_AIS_OK) {
  762. goto chan_close_done;
  763. }
  764. /*
  765. * get the evt handle for the fd
  766. */
  767. error = saHandleInstanceGet(&evt_instance_handle_db,
  768. eci->eci_instance_handle, (void*)&evti);
  769. if (error != SA_AIS_OK) {
  770. goto chan_close_put1;
  771. }
  772. /*
  773. * Make sure that the channel isn't being closed elsewhere
  774. */
  775. pthread_mutex_lock(&eci->eci_mutex);
  776. if (eci->eci_closing) {
  777. pthread_mutex_unlock(&eci->eci_mutex);
  778. saHandleInstancePut(&channel_handle_db, channel_handle);
  779. return SA_AIS_ERR_BAD_HANDLE;
  780. }
  781. eci->eci_closing = 1;
  782. saActivatePoll(evti->ei_fd);
  783. pthread_mutex_unlock(&eci->eci_mutex);
  784. /*
  785. * Send the request to the server and wait for a response
  786. */
  787. req.icc_head.size = sizeof(req);
  788. req.icc_head.id = MESSAGE_REQ_EVT_CLOSE_CHANNEL;
  789. req.icc_channel_handle = eci->eci_svr_channel_handle;
  790. pthread_mutex_lock(&evti->ei_mutex);
  791. error = saSendRetry(evti->ei_fd, &req, sizeof(req), MSG_NOSIGNAL);
  792. if (error != SA_AIS_OK) {
  793. pthread_mutex_unlock(&evti->ei_mutex);
  794. eci->eci_closing = 0;
  795. goto chan_close_put2;
  796. }
  797. error = saRecvQueue(evti->ei_fd, &res, &evti->ei_inq,
  798. MESSAGE_RES_EVT_CLOSE_CHANNEL);
  799. pthread_mutex_unlock(&evti->ei_mutex);
  800. if (error != SA_AIS_OK) {
  801. eci->eci_closing = 0;
  802. goto chan_close_put2;
  803. }
  804. error = res.icc_head.error;
  805. saHandleInstancePut(&evt_instance_handle_db,
  806. eci->eci_instance_handle);
  807. saHandleDestroy(&channel_handle_db, channel_handle);
  808. saHandleInstancePut(&channel_handle_db, channel_handle);
  809. return error;
  810. chan_close_put2:
  811. saHandleInstancePut(&evt_instance_handle_db,
  812. eci->eci_instance_handle);
  813. chan_close_put1:
  814. saHandleInstancePut(&channel_handle_db, channel_handle);
  815. chan_close_done:
  816. return error;
  817. }
  818. /*
  819. * The saEvtChannelOpenAsync() function creates a new event channel or open an
  820. * existing channel. The saEvtChannelOpenAsync() function is a non-blocking
  821. * operation. A new event channel handle is returned in the channel open
  822. * callback function (SaEvtChannelOpenCallbackT).
  823. */
  824. SaAisErrorT
  825. saEvtChannelOpenAsync(SaEvtHandleT evt_handle,
  826. SaInvocationT invocation,
  827. const SaNameT *channel_name,
  828. SaEvtChannelOpenFlagsT channel_open_flags)
  829. {
  830. struct event_instance *evti;
  831. struct req_evt_channel_open req;
  832. struct res_evt_channel_open res;
  833. struct event_channel_instance *eci;
  834. SaEvtChannelHandleT channel_handle;
  835. SaAisErrorT error;
  836. error = saHandleInstanceGet(&evt_instance_handle_db, evt_handle,
  837. (void*)&evti);
  838. if (error != SA_AIS_OK) {
  839. goto chan_open_done;
  840. }
  841. /*
  842. * create a handle for this open channel
  843. */
  844. error = saHandleCreate(&channel_handle_db, sizeof(*eci),
  845. &channel_handle);
  846. if (error != SA_AIS_OK) {
  847. goto chan_open_put;
  848. }
  849. error = saHandleInstanceGet(&channel_handle_db, channel_handle,
  850. (void*)&eci);
  851. if (error != SA_AIS_OK) {
  852. saHandleDestroy(&channel_handle_db, channel_handle);
  853. goto chan_open_put;
  854. }
  855. /*
  856. * Send the request to the server. The response isn't the open channel,
  857. * just an ack. The open channel will be returned when the channel open
  858. * callback is called.
  859. */
  860. req.ico_head.size = sizeof(req);
  861. req.ico_head.id = MESSAGE_REQ_EVT_OPEN_CHANNEL_ASYNC;
  862. req.ico_c_handle = channel_handle;
  863. req.ico_timeout = 0;
  864. req.ico_invocation = invocation;
  865. req.ico_open_flag = channel_open_flags;
  866. req.ico_channel_name = *channel_name;
  867. pthread_mutex_lock(&evti->ei_mutex);
  868. error = saSendRetry(evti->ei_fd, &req, sizeof(req), MSG_NOSIGNAL);
  869. if (error != SA_AIS_OK) {
  870. pthread_mutex_unlock (&evti->ei_mutex);
  871. goto chan_open_free;
  872. }
  873. error = saRecvQueue(evti->ei_fd, &res, &evti->ei_inq,
  874. MESSAGE_RES_EVT_OPEN_CHANNEL);
  875. pthread_mutex_unlock (&evti->ei_mutex);
  876. if (error != SA_AIS_OK) {
  877. goto chan_open_free;
  878. }
  879. error = res.ico_head.error;
  880. if (error != SA_AIS_OK) {
  881. goto chan_open_free;
  882. }
  883. eci->eci_svr_channel_handle = 0; /* filled in by callback */
  884. eci->eci_channel_name = *channel_name;
  885. eci->eci_open_flags = channel_open_flags;
  886. eci->eci_instance_handle = evt_handle;
  887. eci->eci_closing = 0;
  888. pthread_mutex_init(&eci->eci_mutex, NULL);
  889. saHandleInstancePut (&evt_instance_handle_db, evt_handle);
  890. saHandleInstancePut (&channel_handle_db, channel_handle);
  891. return SA_AIS_OK;
  892. chan_open_free:
  893. saHandleDestroy(&channel_handle_db, channel_handle);
  894. saHandleInstancePut (&channel_handle_db, channel_handle);
  895. chan_open_put:
  896. saHandleInstancePut (&evt_instance_handle_db, evt_handle);
  897. chan_open_done:
  898. return error;
  899. }
  900. SaAisErrorT
  901. SaEvtChannelUnlink(
  902. SaEvtHandleT evtHandle,
  903. const SaNameT *channelName)
  904. {
  905. /*
  906. * TODO: Fill in code
  907. */
  908. return SA_AIS_ERR_LIBRARY;
  909. }
  910. /*
  911. * The saEvtEventAllocate() function allocates memory for the event, but not
  912. * for the eventHandle, and initializes all event attributes to default values.
  913. * The event allocated by saEvtEventAllocate() is freed by invoking
  914. * saEvtEventFree().
  915. * The memory associated with the eventHandle is not deallocated by the
  916. * saEvtEventAllocate() function or the saEvtEventFree() function. It is the
  917. * responsibility of the invoking process to deallocate the memory for the
  918. * eventHandle when the process has published the event and has freed the
  919. * event by invoking saEvtEventFree().
  920. */
  921. SaAisErrorT
  922. saEvtEventAllocate(
  923. const SaEvtChannelHandleT channel_handle,
  924. SaEvtEventHandleT *event_handle)
  925. {
  926. SaAisErrorT error;
  927. struct event_data_instance *edi;
  928. struct event_instance *evti;
  929. struct event_channel_instance *eci;
  930. error = saHandleInstanceGet(&channel_handle_db, channel_handle,
  931. (void*)&eci);
  932. if (error != SA_AIS_OK) {
  933. goto alloc_done;
  934. }
  935. error = saHandleInstanceGet(&evt_instance_handle_db,
  936. eci->eci_instance_handle, (void*)&evti);
  937. if (error != SA_AIS_OK) {
  938. goto alloc_put1;
  939. }
  940. error = saHandleCreate(&event_handle_db, sizeof(*edi),
  941. (void*)event_handle);
  942. if (error != SA_AIS_OK) {
  943. goto alloc_put2;
  944. }
  945. error = saHandleInstanceGet(&event_handle_db, *event_handle,
  946. (void*)&edi);
  947. if (error != SA_AIS_OK) {
  948. goto alloc_put2;
  949. }
  950. memset(edi, 0, sizeof(*edi));
  951. pthread_mutex_init(&edi->edi_mutex, NULL);
  952. edi->edi_freeing = 0;
  953. edi->edi_channel_handle = channel_handle;
  954. edi->edi_pub_node = evti->ei_node_id;
  955. edi->edi_priority = SA_EVT_LOWEST_PRIORITY;
  956. saHandleInstancePut (&event_handle_db, *event_handle);
  957. alloc_put2:
  958. saHandleInstancePut (&evt_instance_handle_db, eci->eci_instance_handle);
  959. alloc_put1:
  960. saHandleInstancePut (&channel_handle_db, edi->edi_channel_handle);
  961. alloc_done:
  962. return error;
  963. }
  964. /*
  965. * The saEvtEventFree() function gives the Event Service premission to
  966. * deallocate the memory that contains the attributes of the event that is
  967. * associated with eventHandle. The function is used to free events allocated
  968. * by saEvtEventAllocate() and by saEvtEventDeliverCallback().
  969. */
  970. SaAisErrorT
  971. saEvtEventFree(SaEvtEventHandleT event_handle)
  972. {
  973. SaAisErrorT error;
  974. struct event_data_instance *edi;
  975. error = saHandleInstanceGet(&event_handle_db, event_handle,
  976. (void*)&edi);
  977. if (error != SA_AIS_OK) {
  978. goto evt_free_done;
  979. }
  980. /*
  981. * Make sure that the event isn't being freed elsewhere
  982. */
  983. pthread_mutex_lock(&edi->edi_mutex);
  984. if (edi->edi_freeing) {
  985. pthread_mutex_unlock(&edi->edi_mutex);
  986. saHandleInstancePut(&event_handle_db, event_handle);
  987. return SA_AIS_ERR_BAD_HANDLE;
  988. }
  989. edi->edi_freeing = 1;
  990. pthread_mutex_unlock(&edi->edi_mutex);
  991. saHandleDestroy(&event_handle_db, event_handle);
  992. saHandleInstancePut(&event_handle_db, event_handle);
  993. evt_free_done:
  994. return error;
  995. }
  996. /*
  997. * This function may be used to assign writeable event attributes. It takes
  998. * as arguments an event handle event_handle and the attribute to be set in
  999. * the event structure of the event with that handle. Note: The only
  1000. * attributes that a process can set are the pattern_array, priority,
  1001. * retention_time and publisher_name attributes.
  1002. */
  1003. SaAisErrorT
  1004. saEvtEventAttributesSet(
  1005. const SaEvtEventHandleT event_handle,
  1006. const SaEvtEventPatternArrayT *pattern_array,
  1007. SaEvtEventPriorityT priority,
  1008. SaTimeT retention_time,
  1009. const SaNameT *publisher_name)
  1010. {
  1011. SaEvtEventPatternT *oldpatterns;
  1012. SaSizeT oldnumber;
  1013. SaAisErrorT error;
  1014. struct event_data_instance *edi;
  1015. int i;
  1016. error = saHandleInstanceGet(&event_handle_db, event_handle,
  1017. (void*)&edi);
  1018. if (error != SA_AIS_OK) {
  1019. goto attr_set_done;
  1020. }
  1021. pthread_mutex_lock(&edi->edi_mutex);
  1022. edi->edi_priority = priority;
  1023. edi->edi_retention_time = retention_time;
  1024. /*
  1025. * publisher_name or pattern_array not allowed to be NULL
  1026. */
  1027. if (!publisher_name || !pattern_array) {
  1028. error = SA_AIS_ERR_INVALID_PARAM;
  1029. goto attr_set_unlock;
  1030. }
  1031. edi->edi_pub_name = *publisher_name;
  1032. oldpatterns = edi->edi_patterns.patterns;
  1033. oldnumber = edi->edi_patterns.patternsNumber;
  1034. edi->edi_patterns.patterns = 0;
  1035. edi->edi_patterns.patterns = malloc(sizeof(SaEvtEventPatternT) *
  1036. pattern_array->patternsNumber);
  1037. if (!edi->edi_patterns.patterns) {
  1038. error = SA_AIS_ERR_NO_MEMORY;
  1039. goto attr_set_done_reset;
  1040. }
  1041. edi->edi_patterns.patternsNumber = pattern_array->patternsNumber;
  1042. /*
  1043. * copy the patterns from the caller. allocating memory for
  1044. * of all the strings.
  1045. */
  1046. for (i = 0; i < pattern_array->patternsNumber; i++) {
  1047. edi->edi_patterns.patterns[i].pattern =
  1048. malloc(pattern_array->patterns[i].patternSize);
  1049. if (!edi->edi_patterns.patterns[i].pattern) {
  1050. int j;
  1051. for (j = 0; j < i; j++) {
  1052. free(edi->edi_patterns.patterns[j].pattern);
  1053. }
  1054. free(edi->edi_patterns.patterns);
  1055. error = SA_AIS_ERR_NO_MEMORY;
  1056. goto attr_set_done_reset;
  1057. }
  1058. memcpy(edi->edi_patterns.patterns[i].pattern,
  1059. pattern_array->patterns[i].pattern,
  1060. pattern_array->patterns[i].patternSize);
  1061. edi->edi_patterns.patterns[i].patternSize =
  1062. pattern_array->patterns[i].patternSize;
  1063. }
  1064. /*
  1065. * free up the old pattern memory
  1066. */
  1067. if (oldpatterns) {
  1068. for (i = 0; i < oldnumber; i++) {
  1069. if (oldpatterns[i].pattern) {
  1070. free(oldpatterns[i].pattern);
  1071. }
  1072. }
  1073. free (oldpatterns);
  1074. }
  1075. goto attr_set_unlock;
  1076. attr_set_done_reset:
  1077. edi->edi_patterns.patterns = oldpatterns;
  1078. edi->edi_patterns.patternsNumber = oldnumber;
  1079. attr_set_unlock:
  1080. pthread_mutex_unlock(&edi->edi_mutex);
  1081. saHandleInstancePut(&event_handle_db, event_handle);
  1082. attr_set_done:
  1083. return error;
  1084. }
  1085. /*
  1086. * This function takes as parameters an event handle eventHandle and the
  1087. * attributes of the event with that handle. The function retrieves the
  1088. * value of the attributes for the event and stores them at the address
  1089. * provided for the out parameters.
  1090. * It is the responsibility of the invoking process to allocate memory for
  1091. * the out parameters before it invokes this function. The Event Service
  1092. * assigns the out values into that memory. For each of the out, or in/out,
  1093. * parameters, if the invoking process provides a NULL reference, the
  1094. * Availability Management Framework does not return the out value.
  1095. * Similarly, it is the responsibility of the invoking process to allocate
  1096. * memory for the pattern_array.
  1097. */
  1098. SaAisErrorT
  1099. saEvtEventAttributesGet(
  1100. SaEvtEventHandleT event_handle,
  1101. SaEvtEventPatternArrayT *pattern_array,
  1102. SaEvtEventPriorityT *priority,
  1103. SaTimeT *retention_time,
  1104. SaNameT *publisher_name,
  1105. SaTimeT *publish_time,
  1106. SaEvtEventIdT *event_id)
  1107. {
  1108. SaAisErrorT error;
  1109. struct event_data_instance *edi;
  1110. SaSizeT npats;
  1111. int i;
  1112. error = saHandleInstanceGet(&event_handle_db, event_handle,
  1113. (void*)&edi);
  1114. if (error != SA_AIS_OK) {
  1115. goto attr_get_done;
  1116. }
  1117. pthread_mutex_lock(&edi->edi_mutex);
  1118. /*
  1119. * Go through the args and send back information if the pointer
  1120. * isn't NULL
  1121. */
  1122. if (event_id) {
  1123. *event_id = edi->edi_event_id;
  1124. }
  1125. if (publish_time) {
  1126. *publish_time = edi->edi_pub_time;
  1127. }
  1128. if (publisher_name) {
  1129. *publisher_name = edi->edi_pub_name;
  1130. }
  1131. if (retention_time) {
  1132. *retention_time = edi->edi_retention_time;
  1133. }
  1134. if (priority) {
  1135. *priority = edi->edi_priority;
  1136. }
  1137. if (!pattern_array) {
  1138. goto attr_get_unlock;
  1139. }
  1140. npats = min(pattern_array->patternsNumber,
  1141. edi->edi_patterns.patternsNumber);
  1142. /*
  1143. * We set the returned number of patterns to the actual
  1144. * pattern count of the event. This way the caller can tell
  1145. * if it got all the possible patterns. If the returned number
  1146. * is more that the number supplied, then some available patterns
  1147. * were not returned.
  1148. *
  1149. * The same thing happens when copying the pattern strings.
  1150. */
  1151. pattern_array->patternsNumber = edi->edi_patterns.patternsNumber;
  1152. for (i = 0; i < npats; i++) {
  1153. memcpy(pattern_array->patterns[i].pattern,
  1154. edi->edi_patterns.patterns[i].pattern,
  1155. min(pattern_array->patterns[i].patternSize,
  1156. edi->edi_patterns.patterns[i].patternSize));
  1157. pattern_array->patterns[i].patternSize =
  1158. edi->edi_patterns.patterns[i].patternSize;
  1159. }
  1160. attr_get_unlock:
  1161. pthread_mutex_unlock(&edi->edi_mutex);
  1162. saHandleInstancePut(&event_handle_db, event_handle);
  1163. attr_get_done:
  1164. return error;
  1165. }
  1166. /*
  1167. * The saEvtEventDataGet() function allows a process to retrieve the data
  1168. * associated with an event previously delivered by
  1169. * saEvtEventDeliverCallback().
  1170. */
  1171. SaAisErrorT
  1172. saEvtEventDataGet(
  1173. const SaEvtEventHandleT event_handle,
  1174. void *event_data,
  1175. SaSizeT *event_data_size)
  1176. {
  1177. SaAisErrorT error = SA_AIS_OK;
  1178. struct event_data_instance *edi;
  1179. SaSizeT xfsize;
  1180. if (!event_data || !event_data_size) {
  1181. goto data_get_done;
  1182. }
  1183. error = saHandleInstanceGet(&event_handle_db, event_handle,
  1184. (void*)&edi);
  1185. if (error != SA_AIS_OK) {
  1186. goto data_get_done;
  1187. }
  1188. pthread_mutex_lock(&edi->edi_mutex);
  1189. if (edi->edi_event_data && edi->edi_event_data_size) {
  1190. xfsize = min(*event_data_size, edi->edi_event_data_size);
  1191. *event_data_size = edi->edi_event_data_size;
  1192. memcpy(event_data, edi->edi_event_data, xfsize);
  1193. } else {
  1194. *event_data_size = 0;
  1195. }
  1196. pthread_mutex_unlock(&edi->edi_mutex);
  1197. saHandleInstancePut(&event_handle_db, event_handle);
  1198. data_get_done:
  1199. return error;
  1200. }
  1201. /*
  1202. * Calculate the size in bytes for patterns
  1203. */
  1204. static size_t patt_size(const SaEvtEventPatternArrayT *patterns)
  1205. {
  1206. int i;
  1207. size_t size = sizeof(SaEvtEventPatternArrayT);
  1208. for (i = 0; i < patterns->patternsNumber; i++) {
  1209. size += sizeof(SaEvtEventPatternT);
  1210. size += patterns->patterns[i].patternSize;
  1211. }
  1212. return size;
  1213. }
  1214. /*
  1215. * copy patterns to a form for sending to the server
  1216. */
  1217. static uint32_t aispatt_to_evt_patt(const SaEvtEventPatternArrayT *patterns,
  1218. void *data)
  1219. {
  1220. int i;
  1221. SaEvtEventPatternT *pats = data;
  1222. SaUint8T *str = (SaUint8T *)pats +
  1223. (patterns->patternsNumber * sizeof(*pats));
  1224. /*
  1225. * Pointers are replaced with offsets into the data array. These
  1226. * will be later converted back into pointers when received as events.
  1227. */
  1228. for (i = 0; i < patterns->patternsNumber; i++) {
  1229. memcpy(str, patterns->patterns[i].pattern,
  1230. patterns->patterns[i].patternSize);
  1231. pats->patternSize = patterns->patterns[i].patternSize;
  1232. pats->pattern = (SaUint8T *)((void *)str - data);
  1233. str += patterns->patterns[i].patternSize;
  1234. pats++;
  1235. }
  1236. return patterns->patternsNumber;
  1237. }
  1238. /*
  1239. * Calculate the size in bytes for filters
  1240. */
  1241. static size_t filt_size(const SaEvtEventFilterArrayT *filters)
  1242. {
  1243. int i;
  1244. size_t size = sizeof(SaEvtEventFilterArrayT);
  1245. for (i = 0; i < filters->filtersNumber; i++) {
  1246. size += sizeof(SaEvtEventFilterT);
  1247. size += filters->filters[i].filter.patternSize;
  1248. }
  1249. return size;
  1250. }
  1251. /*
  1252. * Convert the Sa filters to a form that can be sent over the network
  1253. * i.e. replace pointers with offsets. The pointers will be reconstituted
  1254. * by the receiver.
  1255. */
  1256. static uint32_t aisfilt_to_evt_filt(const SaEvtEventFilterArrayT *filters,
  1257. void *data)
  1258. {
  1259. int i;
  1260. SaEvtEventFilterArrayT *filta = data;
  1261. SaEvtEventFilterT *filts = data + sizeof(SaEvtEventFilterArrayT);
  1262. SaUint8T *str = (SaUint8T *)filts +
  1263. (filters->filtersNumber * sizeof(*filts));
  1264. /*
  1265. * Pointers are replaced with offsets into the data array. These
  1266. * will be later converted back into pointers by the evt server.
  1267. */
  1268. filta->filters = (SaEvtEventFilterT *)((void *)filts - data);
  1269. filta->filtersNumber = filters->filtersNumber;
  1270. for (i = 0; i < filters->filtersNumber; i++) {
  1271. filts->filterType = filters->filters[i].filterType;
  1272. filts->filter.patternSize =
  1273. filters->filters[i].filter.patternSize;
  1274. memcpy(str,
  1275. filters->filters[i].filter.pattern,
  1276. filters->filters[i].filter.patternSize);
  1277. filts->filter.pattern = (SaUint8T *)((void *)str - data);
  1278. str += filters->filters[i].filter.patternSize;
  1279. filts++;
  1280. }
  1281. return filters->filtersNumber;
  1282. }
  1283. /*
  1284. * The saEvtEventPublish() function publishes an event on the channel
  1285. * designated by channel_handle. The event to be published consists of a
  1286. * standard set of attributes (the event header) and an optional data part.
  1287. * Before an event can be published, the publisher process must invoke the
  1288. * saEvtEventPatternArraySet() function to set the event patterns. The event
  1289. * is delivered to subscribers whose subscription filter matches the event
  1290. * patterns.
  1291. * When the Event Service publishes an event, it automatically sets
  1292. * the following readonly event attributes:
  1293. * - Event attribute time
  1294. * - Event publisher identifier
  1295. * - Event publisher node identifier
  1296. * - Event identifier
  1297. * In addition to the event attributes, a process can supply values for the
  1298. * eventData and eventDataSize parameters for publication as part of the
  1299. * event. The data portion of the event may be at most SA_EVT_DATA_MAX_LEN
  1300. * bytes in length.
  1301. * The process may assume that the invocation of saEvtEventPublish() copies
  1302. * all pertinent parameters, including the memory associated with the
  1303. * eventHandle and eventData parameters, to its own local memory. However,
  1304. * the invocation does not automatically deallocate memory associated with
  1305. * the eventHandle and eventData parameters. It is the responsibility of the
  1306. * invoking process to deallocate the memory for those parameters after
  1307. * saEvtEventPublish() returns.
  1308. */
  1309. SaAisErrorT
  1310. saEvtEventPublish(
  1311. const SaEvtEventHandleT event_handle,
  1312. const void *event_data,
  1313. SaSizeT event_data_size,
  1314. SaEvtEventIdT *eventid)
  1315. {
  1316. SaAisErrorT error;
  1317. struct event_data_instance *edi;
  1318. struct event_instance *evti;
  1319. struct event_channel_instance *eci;
  1320. struct lib_event_data *req;
  1321. struct res_evt_event_publish res;
  1322. size_t pattern_size;
  1323. struct event_pattern *patterns;
  1324. void *data_start;
  1325. int pub_sleep_trys = PUB_SLEEP_TRYS;
  1326. if (event_data_size > SA_EVT_DATA_MAX_LEN) {
  1327. error = SA_AIS_ERR_INVALID_PARAM;
  1328. goto pub_done;
  1329. }
  1330. error = saHandleInstanceGet(&event_handle_db, event_handle,
  1331. (void*)&edi);
  1332. if (error != SA_AIS_OK) {
  1333. goto pub_done;
  1334. }
  1335. pthread_mutex_lock(&edi->edi_mutex);
  1336. /*
  1337. * See if patterns have been set for this event. If not, we
  1338. * can't publish.
  1339. */
  1340. if (!edi->edi_patterns.patterns) {
  1341. error = SA_AIS_ERR_INVALID_PARAM;
  1342. goto pub_put1;
  1343. }
  1344. error = saHandleInstanceGet(&channel_handle_db, edi->edi_channel_handle,
  1345. (void*)&eci);
  1346. if (error != SA_AIS_OK) {
  1347. goto pub_put1;
  1348. }
  1349. /*
  1350. * See if we can publish to this channel
  1351. */
  1352. if (!(eci->eci_open_flags & SA_EVT_CHANNEL_PUBLISHER)) {
  1353. error = SA_AIS_ERR_ACCESS;
  1354. goto pub_put2;
  1355. }
  1356. error = saHandleInstanceGet(&evt_instance_handle_db,
  1357. eci->eci_instance_handle, (void*)&evti);
  1358. if (error != SA_AIS_OK) {
  1359. goto pub_put2;
  1360. }
  1361. /*
  1362. * Figure out how much memory we need for the patterns and data
  1363. */
  1364. pattern_size = patt_size(&edi->edi_patterns);
  1365. req = malloc(sizeof(*req) + event_data_size + pattern_size);
  1366. patterns = (struct event_pattern *)req->led_body;
  1367. data_start = (void *)req->led_body + pattern_size;
  1368. if (!req) {
  1369. error = SA_AIS_ERR_NO_MEMORY;
  1370. goto pub_put3;
  1371. }
  1372. /*
  1373. * copy everything to the request structure
  1374. */
  1375. aispatt_to_evt_patt(&edi->edi_patterns, patterns);
  1376. req->led_patterns_number = edi->edi_patterns.patternsNumber;
  1377. req->led_user_data_offset = pattern_size;
  1378. if (event_data && event_data_size) {
  1379. memcpy(data_start, event_data, event_data_size);
  1380. req->led_user_data_size = event_data_size;
  1381. } else {
  1382. req->led_user_data_size = 0;
  1383. }
  1384. req->led_head.id = MESSAGE_REQ_EVT_PUBLISH;
  1385. req->led_head.size = sizeof(*req) + pattern_size + event_data_size;
  1386. req->led_svr_channel_handle = eci->eci_svr_channel_handle;
  1387. req->led_retention_time = edi->edi_retention_time;
  1388. req->led_publish_time = clustTimeNow();
  1389. req->led_priority = edi->edi_priority;
  1390. req->led_publisher_name = edi->edi_pub_name;
  1391. while (--pub_sleep_trys) {
  1392. pthread_mutex_lock(&evti->ei_mutex);
  1393. error = saSendRetry(evti->ei_fd, req, req->led_head.size, MSG_NOSIGNAL);
  1394. if (error != SA_AIS_OK) {
  1395. pthread_mutex_unlock (&evti->ei_mutex);
  1396. goto pub_put3_free;
  1397. }
  1398. error = saRecvQueue(evti->ei_fd, &res, &evti->ei_inq,
  1399. MESSAGE_RES_EVT_PUBLISH);
  1400. pthread_mutex_unlock (&evti->ei_mutex);
  1401. if (error != SA_AIS_OK) {
  1402. goto pub_put3_free;
  1403. }
  1404. error = res.iep_head.error;
  1405. if (error == SA_AIS_ERR_TRY_AGAIN) {
  1406. struct timespec ts;
  1407. struct timespec rem;
  1408. ts.tv_sec = PUB_SLEEP_SEC;
  1409. ts.tv_nsec = PUB_SLEEP_NSEC;
  1410. pub_sleep:
  1411. if (nanosleep(&ts, &rem) < 0) {
  1412. if (errno == EINTR) {
  1413. ts = rem;
  1414. goto pub_sleep;
  1415. }
  1416. error = SA_AIS_ERR_TIMEOUT;
  1417. goto pub_put3_free;
  1418. }
  1419. continue;
  1420. }
  1421. *eventid = res.iep_event_id;
  1422. break;
  1423. }
  1424. if (error == SA_AIS_ERR_TRY_AGAIN) {
  1425. error = SA_AIS_ERR_TIMEOUT;
  1426. }
  1427. pub_put3_free:
  1428. free(req);
  1429. pub_put3:
  1430. saHandleInstancePut (&evt_instance_handle_db, eci->eci_instance_handle);
  1431. pub_put2:
  1432. saHandleInstancePut (&channel_handle_db, edi->edi_channel_handle);
  1433. pub_put1:
  1434. pthread_mutex_unlock(&edi->edi_mutex);
  1435. saHandleInstancePut(&event_handle_db, event_handle);
  1436. pub_done:
  1437. return error;
  1438. }
  1439. /*
  1440. * The saEvtEventSubscribe() function enables a process to subscribe for
  1441. * events on an event channel by registering one or more filters on that
  1442. * event channel. The process must have opened the event channel, designated
  1443. * by channel_handle, with the SA_EVT_CHANNEL_SUBSCRIBER flag set for an
  1444. * invocation of this function to be successful.
  1445. * The memory associated with the filters is not deallocated by the
  1446. * saEvtEventSubscribe() function. It is the responsibility of the invoking
  1447. * process to deallocate the memory when the saEvtEventSubscribe() function
  1448. * returns.
  1449. * For a given subscription, the filters parameter cannot be modified. To
  1450. * change the filters parameter without losing events, a process must
  1451. * establish a new subscription with the new filters parameter. After the new
  1452. * subscription is established, the old subscription can be removed by
  1453. * invoking the saEvtEventUnsubscribe() function.
  1454. */
  1455. SaAisErrorT
  1456. saEvtEventSubscribe(
  1457. const SaEvtChannelHandleT channel_handle,
  1458. const SaEvtEventFilterArrayT *filters,
  1459. SaEvtSubscriptionIdT subscription_id)
  1460. {
  1461. SaAisErrorT error;
  1462. struct event_instance *evti;
  1463. struct event_channel_instance *eci;
  1464. struct req_evt_event_subscribe *req;
  1465. struct res_evt_event_subscribe res;
  1466. int sz;
  1467. error = saHandleInstanceGet(&channel_handle_db, channel_handle,
  1468. (void*)&eci);
  1469. if (error != SA_AIS_OK) {
  1470. goto subscribe_done;
  1471. }
  1472. /*
  1473. * get the evt handle for the fd
  1474. */
  1475. error = saHandleInstanceGet(&evt_instance_handle_db,
  1476. eci->eci_instance_handle, (void*)&evti);
  1477. if (error != SA_AIS_OK) {
  1478. goto subscribe_put1;
  1479. }
  1480. /*
  1481. * See if we can subscribe to this channel
  1482. */
  1483. if (!(eci->eci_open_flags & SA_EVT_CHANNEL_SUBSCRIBER)) {
  1484. error = SA_AIS_ERR_INVALID_PARAM;
  1485. goto subscribe_put2;
  1486. }
  1487. /*
  1488. * calculate size needed to store the filters
  1489. */
  1490. sz = filt_size(filters);
  1491. req = malloc(sizeof(*req) + sz);
  1492. if (!req) {
  1493. error = SA_AIS_ERR_NO_MEMORY;
  1494. goto subscribe_put2;
  1495. }
  1496. /*
  1497. * Copy the supplied filters to the request
  1498. */
  1499. req->ics_filter_count = aisfilt_to_evt_filt(filters,
  1500. req->ics_filter_data);
  1501. req->ics_head.id = MESSAGE_REQ_EVT_SUBSCRIBE;
  1502. req->ics_head.size = sizeof(*req) + sz;
  1503. req->ics_channel_handle = eci->eci_svr_channel_handle;
  1504. req->ics_sub_id = subscription_id;
  1505. req->ics_filter_size = sz;
  1506. pthread_mutex_lock(&evti->ei_mutex);
  1507. error = saSendRetry(evti->ei_fd, req, req->ics_head.size, MSG_NOSIGNAL);
  1508. free(req);
  1509. if (error != SA_AIS_OK) {
  1510. pthread_mutex_unlock (&evti->ei_mutex);
  1511. goto subscribe_put2;
  1512. }
  1513. error = saRecvQueue(evti->ei_fd, &res, &evti->ei_inq,
  1514. MESSAGE_RES_EVT_SUBSCRIBE);
  1515. pthread_mutex_unlock (&evti->ei_mutex);
  1516. if (error != SA_AIS_OK) {
  1517. goto subscribe_put2;
  1518. }
  1519. error = res.ics_head.error;
  1520. subscribe_put2:
  1521. saHandleInstancePut(&evt_instance_handle_db,
  1522. eci->eci_instance_handle);
  1523. subscribe_put1:
  1524. saHandleInstancePut(&channel_handle_db, channel_handle);
  1525. subscribe_done:
  1526. return error;
  1527. }
  1528. /*
  1529. * The saEvtEventUnsubscribe() function allows a process to stop receiving
  1530. * events for a particular subscription on an event channel by removing the
  1531. * subscription. The saEvtEventUnsubscribe() operation is successful if the
  1532. * subscriptionId parameter matches a previously registered subscription.
  1533. * Pending events that no longer match any subscription, because the
  1534. * saEvtEventUnsubscribe() operation had been invoked, are purged. a process
  1535. * that wishes to modify a subscription without losing any events must
  1536. * establish the new subscription before removing the existing subscription.
  1537. */
  1538. SaAisErrorT
  1539. saEvtEventUnsubscribe(
  1540. const SaEvtChannelHandleT channel_handle,
  1541. SaEvtSubscriptionIdT subscription_id)
  1542. {
  1543. SaAisErrorT error;
  1544. struct event_instance *evti;
  1545. struct event_channel_instance *eci;
  1546. struct req_evt_event_unsubscribe req;
  1547. struct res_evt_event_unsubscribe res;
  1548. error = saHandleInstanceGet(&channel_handle_db, channel_handle,
  1549. (void*)&eci);
  1550. if (error != SA_AIS_OK) {
  1551. goto unsubscribe_done;
  1552. }
  1553. error = saHandleInstanceGet(&evt_instance_handle_db,
  1554. eci->eci_instance_handle, (void*)&evti);
  1555. if (error != SA_AIS_OK) {
  1556. goto unsubscribe_put1;
  1557. }
  1558. req.icu_head.id = MESSAGE_REQ_EVT_UNSUBSCRIBE;
  1559. req.icu_head.size = sizeof(req);
  1560. req.icu_channel_handle = eci->eci_svr_channel_handle;
  1561. req.icu_sub_id = subscription_id;
  1562. pthread_mutex_lock(&evti->ei_mutex);
  1563. error = saSendRetry(evti->ei_fd, &req, sizeof(req), MSG_NOSIGNAL);
  1564. if (error != SA_AIS_OK) {
  1565. pthread_mutex_unlock (&evti->ei_mutex);
  1566. goto unsubscribe_put2;
  1567. }
  1568. error = saRecvQueue(evti->ei_fd, &res, &evti->ei_inq,
  1569. MESSAGE_RES_EVT_UNSUBSCRIBE);
  1570. pthread_mutex_unlock (&evti->ei_mutex);
  1571. if (error != SA_AIS_OK) {
  1572. goto unsubscribe_put2;
  1573. }
  1574. error = res.icu_head.error;
  1575. unsubscribe_put2:
  1576. saHandleInstancePut(&evt_instance_handle_db,
  1577. eci->eci_instance_handle);
  1578. unsubscribe_put1:
  1579. saHandleInstancePut(&channel_handle_db, channel_handle);
  1580. unsubscribe_done:
  1581. return error;
  1582. }
  1583. /*
  1584. * The saEvtEventRetentionTimeClear() function is used to clear the retention
  1585. * time of a published event. It indicates to the Event Service that it does
  1586. * not need to keep the event any longer for potential new subscribers. Once
  1587. * the value of the retention time is reset to 0, the event is no longer
  1588. * available for new subscribers. The event is held until all old subscribers
  1589. * in the system process the event and free the event using saEvtEventFree().
  1590. */
  1591. SaAisErrorT
  1592. saEvtEventRetentionTimeClear(
  1593. const SaEvtChannelHandleT channel_handle,
  1594. const SaEvtEventIdT event_id)
  1595. {
  1596. SaAisErrorT error;
  1597. struct event_instance *evti;
  1598. struct event_channel_instance *eci;
  1599. struct req_evt_event_clear_retentiontime req;
  1600. struct res_evt_event_clear_retentiontime res;
  1601. error = saHandleInstanceGet(&channel_handle_db, channel_handle,
  1602. (void*)&eci);
  1603. if (error != SA_AIS_OK) {
  1604. goto ret_time_done;
  1605. }
  1606. error = saHandleInstanceGet(&evt_instance_handle_db,
  1607. eci->eci_instance_handle, (void*)&evti);
  1608. if (error != SA_AIS_OK) {
  1609. goto ret_time_put1;
  1610. }
  1611. req.iec_head.id = MESSAGE_REQ_EVT_CLEAR_RETENTIONTIME;
  1612. req.iec_head.size = sizeof(req);
  1613. req.iec_channel_handle = eci->eci_svr_channel_handle;
  1614. req.iec_event_id = event_id;
  1615. pthread_mutex_lock(&evti->ei_mutex);
  1616. error = saSendRetry(evti->ei_fd, &req, sizeof(req), MSG_NOSIGNAL);
  1617. if (error != SA_AIS_OK) {
  1618. pthread_mutex_unlock (&evti->ei_mutex);
  1619. goto ret_time_put2;
  1620. }
  1621. error = saRecvQueue(evti->ei_fd, &res, &evti->ei_inq,
  1622. MESSAGE_RES_EVT_CLEAR_RETENTIONTIME);
  1623. pthread_mutex_unlock (&evti->ei_mutex);
  1624. if (error != SA_AIS_OK) {
  1625. goto ret_time_put2;
  1626. }
  1627. error = res.iec_head.error;
  1628. ret_time_put2:
  1629. saHandleInstancePut(&evt_instance_handle_db,
  1630. eci->eci_instance_handle);
  1631. ret_time_put1:
  1632. saHandleInstancePut(&channel_handle_db, channel_handle);
  1633. ret_time_done:
  1634. return error;
  1635. }
  1636. /*
  1637. * vi: set autoindent tabstop=4 shiftwidth=4 :
  1638. */