testamf1.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. /*
  2. * Copyright (c) 2002-2003 MontaVista Software, Inc.
  3. * Copyright (c) 2006 Ericsson AB.
  4. * Copyright (c) 2006 Sun Microsystems, Inc.
  5. *
  6. * All rights reserved.
  7. *
  8. * Author: Steven Dake (sdake@mvista.com)
  9. * Hans Feldt
  10. *
  11. * This software licensed under BSD license, the text of which follows:
  12. *
  13. * Redistribution and use in source and binary forms, with or without
  14. * modification, are permitted provided that the following conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above copyright notice,
  17. * this list of conditions and the following disclaimer.
  18. * - Redistributions in binary form must reproduce the above copyright notice,
  19. * this list of conditions and the following disclaimer in the documentation
  20. * and/or other materials provided with the distribution.
  21. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  22. * contributors may be used to endorse or promote products derived from this
  23. * software without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  26. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  29. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  30. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  31. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  32. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  33. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  34. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  35. * THE POSSIBILITY OF SUCH DAMAGE.
  36. */
  37. #include <stdio.h>
  38. #include <stdlib.h>
  39. #include <string.h>
  40. #include <errno.h>
  41. #include <signal.h>
  42. #include <unistd.h>
  43. #include <sys/types.h>
  44. #include <sys/socket.h>
  45. #include <sys/un.h>
  46. #include <sched.h>
  47. #include <sys/stat.h>
  48. #include <fcntl.h>
  49. #include <stdarg.h>
  50. #include "saAis.h"
  51. #include "saAmf.h"
  52. SaAmfHandleT handle;
  53. SaAmfHealthcheckKeyT keyAmfInvoked = {
  54. .key = "amfInvoked",
  55. .keyLen = 10
  56. };
  57. SaAmfHealthcheckKeyT keyCompInvoked = {
  58. .key = "compInvoked",
  59. .keyLen = 11
  60. };
  61. SaNameT compNameGlobal;
  62. int good_health = 0;
  63. int good_health_limit = 0;
  64. enum {
  65. FINALIZE = 0,
  66. UNREGISTER,
  67. ERROR_REPORT
  68. };
  69. #define die(format, args...) _die (__FILE__, __LINE__, format, ##args)
  70. static void _die (char *file, int line, char *format, ...) __attribute__((format(printf, 3, 4)));
  71. static void _die (char *file, int line, char *format, ...)
  72. {
  73. char buf[1024];
  74. va_list ap;
  75. sprintf (buf, "%d - %s:#%d - Error: '%s', exiting...\n",
  76. (int)getpid(), file, line, format);
  77. va_start (ap, format);
  78. vfprintf (stderr, buf, ap);
  79. va_end(ap);
  80. exit (-1);
  81. }
  82. static void response (
  83. SaAmfHandleT handle, SaInvocationT invocation, SaAisErrorT error)
  84. {
  85. SaAisErrorT result;
  86. do {
  87. result = saAmfResponse (handle, invocation, error);
  88. if (result == SA_AIS_ERR_TRY_AGAIN) {
  89. fprintf(stderr, "%d: TRY_AGAIN received\n", (int)getpid());
  90. usleep (100000);
  91. }
  92. } while (result == SA_AIS_ERR_TRY_AGAIN);
  93. if (result != SA_AIS_OK) {
  94. die ("saAmfResponse failed %d", result);
  95. }
  96. }
  97. void printSaNameT (SaNameT *name)
  98. {
  99. int i;
  100. for (i = 0; i < name->length; i++) {
  101. printf ("%c", name->value[i]);
  102. }
  103. }
  104. void setSanameT (SaNameT *name, char *str) {
  105. name->length = strlen (str);
  106. memcpy (name->value, str, name->length);
  107. }
  108. static unsigned int healthcheck_no = 0;
  109. int stop = 0;
  110. void HealthcheckCallback (SaInvocationT invocation,
  111. const SaNameT *compName,
  112. SaAmfHealthcheckKeyT *healthcheckKey)
  113. {
  114. SaAisErrorT res;
  115. if( !good_health && healthcheck_no++);
  116. if (healthcheck_no == good_health_limit ) {
  117. response (handle, invocation, SA_AIS_OK);
  118. res = saAmfHealthcheckStop (handle,
  119. &compNameGlobal,
  120. &keyAmfInvoked);
  121. printf ("healthcheck stop result %d (should be %d)\n", res, SA_AIS_OK);
  122. printf ("COMPONENT REPORTING ERROR %s\n", compNameGlobal.value);
  123. saAmfComponentErrorReport (handle, compName, 0, SA_AMF_COMPONENT_RESTART, 0);
  124. printf ("COMPONENT DONE REPORTING ERROR\n");
  125. } else {
  126. response (handle, invocation, SA_AIS_OK);
  127. }
  128. }
  129. void ComponentTerminateCallback (
  130. SaInvocationT invocation,
  131. const SaNameT *compName)
  132. {
  133. printf ("ComponentTerminateCallback\n");
  134. response (handle, invocation, SA_AIS_OK);
  135. exit (0);
  136. }
  137. #if 0
  138. #include <sys/time.h>
  139. #define TRU "%d"
  140. #define TRS "%s"
  141. #define TR(format,x) do { \
  142. struct timeval t;\
  143. gettimeofday(&t,NULL); \
  144. printf("%s:%d: %s : %d : %u: %u :%s : " format "\n",\
  145. __FILE__,__LINE__,__FUNCTION__, \
  146. (int)getpid(),(int)t.tv_sec, (int)t.tv_usec,#x,x); \
  147. }while(0)
  148. #else
  149. #define TRU "%d"
  150. #define TRS "%s"
  151. #define TR(format,x)
  152. #endif
  153. void CSISetCallback (
  154. SaInvocationT invocation,
  155. const SaNameT *compName,
  156. SaAmfHAStateT haState,
  157. SaAmfCSIDescriptorT *csiDescriptor)
  158. {
  159. SaAmfHAStateT state;
  160. int res;
  161. int i;
  162. switch (haState) {
  163. case SA_AMF_HA_ACTIVE:
  164. printf ("PID %d: Component '%s' requested to enter hastate SA_AMF_ACTIVE"
  165. " for \n\tCSI '%s'\n",
  166. (int)getpid(), compName->value, csiDescriptor->csiName.value);
  167. response (handle, invocation, SA_AIS_OK);
  168. res = saAmfHAStateGet (handle, compName, &csiDescriptor->csiName, &state);
  169. if (res != SA_AIS_OK || haState != state) {
  170. fprintf (stderr, "saAmfHAStateGet failed: %d\n", res);
  171. exit (-1);
  172. }
  173. TR(TRU, csiDescriptor->csiAttr.number);
  174. for(i=0; i<csiDescriptor->csiAttr.number; i++) {
  175. if( strcmp((char*)csiDescriptor->csiAttr.attr[i].attrName, "good_health_limit") == 0){
  176. good_health = strcmp((char*)csiDescriptor->csiAttr.attr[i].attrValue, "0") ? 0 : 1;
  177. good_health_limit = atoi((char*)csiDescriptor->csiAttr.attr[i].attrValue);
  178. }
  179. #if 0
  180. TR(TRS,csiDescriptor->csiAttr.attr[i].attrName);
  181. TR(TRS, csiDescriptor->csiAttr.attr[i].attrValue);
  182. #endif
  183. }
  184. TR(TRU, csiDescriptor->csiFlags);
  185. printSaNameT((SaNameT*) &csiDescriptor->csiStateDescriptor.activeDescriptor.activeCompName);
  186. TR(TRU, csiDescriptor->csiStateDescriptor.activeDescriptor.transitionDescriptor);
  187. break;
  188. case SA_AMF_HA_STANDBY:
  189. printf ("PID %d: Component '%s' requested to enter hastate SA_AMF_STANDBY "
  190. "for \n\tCSI '%s'\n",
  191. (int)getpid(), compName->value, csiDescriptor->csiName.value);
  192. response (handle, invocation, SA_AIS_OK);
  193. TR(TRU,csiDescriptor->csiAttr.number);
  194. for(i=0; i<csiDescriptor->csiAttr.number; i++) {
  195. if(!strcmp((char*)csiDescriptor->csiAttr.attr[i].attrName, "good_health") &&
  196. !strcmp((char*)csiDescriptor->csiAttr.attr[i].attrValue, "true")){
  197. good_health = 1;
  198. }
  199. TR(TRS,csiDescriptor->csiAttr.attr[i].attrName);
  200. TR(TRS,csiDescriptor->csiAttr.attr[i].attrValue);
  201. }
  202. TR(TRU,csiDescriptor->csiFlags);
  203. printSaNameT((SaNameT*) &csiDescriptor->csiStateDescriptor.standbyDescriptor.activeCompName);
  204. TR(TRU,csiDescriptor->csiStateDescriptor.standbyDescriptor.standbyRank);
  205. break;
  206. case SA_AMF_HA_QUIESCED:
  207. printf ("%d: Component '%s' requested to enter hastate SA_AMF_HA_QUIESCED "
  208. "for \n\tCSI '%s'\n",
  209. (int)getpid(), compName->value, csiDescriptor->csiName.value);
  210. response (handle, invocation, SA_AIS_OK);
  211. break;
  212. case SA_AMF_HA_QUIESCING:
  213. break;
  214. default:
  215. break;
  216. }
  217. }
  218. void CSIRemoveCallback (
  219. SaInvocationT invocation,
  220. const SaNameT *compName,
  221. const SaNameT *csiName,
  222. SaAmfCSIFlagsT csiFlags)
  223. {
  224. printf ("CSIRemoveCallback for component '");
  225. printSaNameT ((SaNameT *)compName);
  226. printf ("' in CSI '");
  227. printSaNameT ((SaNameT *)csiName);
  228. printf ("'\n");
  229. response (handle, invocation, SA_AIS_OK);
  230. }
  231. #ifdef COMPILE_OUT
  232. void ProtectionGroupTrackCallback (
  233. const SaNameT *csiName,
  234. SaAmfProtectionGroupNotificationT *notificationBuffer,
  235. SaUint32T numberOfItems,
  236. SaUint32T numberOfMembers,
  237. SaAisErrorT error)
  238. {
  239. int i;
  240. printf ("ProtectionGroupTrackCallback items %d members %d\n", (int)numberOfItems, (int)numberOfMembers);
  241. printf ("buffer is %p\n", notificationBuffer);
  242. for (i = 0; i < numberOfItems; i++) {
  243. printf ("component name");
  244. printSaNameT (&notificationBuffer[i].member.compName);
  245. printf ("\n");
  246. printf ("\treadiness state is %d\n", notificationBuffer[i].member.readinessState);
  247. printf ("\thastate %d\n", notificationBuffer[i].member.haState);
  248. printf ("\tchange is %d\n", notificationBuffer[i].change);
  249. }
  250. }
  251. #endif
  252. SaAmfCallbacksT amfCallbacks = {
  253. .saAmfHealthcheckCallback = HealthcheckCallback,
  254. .saAmfComponentTerminateCallback = ComponentTerminateCallback,
  255. .saAmfCSISetCallback = CSISetCallback,
  256. .saAmfCSIRemoveCallback = CSIRemoveCallback,
  257. };
  258. SaAmfCallbacksT amfCallbacks;
  259. SaVersionT version = { 'B', 1, 1 };
  260. #if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS))
  261. static struct sched_param sched_param;
  262. #endif
  263. void sigintr_handler (int signum) {
  264. stop = FINALIZE;
  265. }
  266. void sigusr1_handler (int signum) {
  267. stop = UNREGISTER;
  268. }
  269. void sigusr2_handler (int signum) {
  270. stop = ERROR_REPORT;
  271. }
  272. void write_pid (void) {
  273. char pid[256];
  274. char filename[256];
  275. int fd;
  276. int res;
  277. sprintf (filename, "/var/run/openais_cleanup_%s", compNameGlobal.value);
  278. fd = open (filename, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU);
  279. if (fd == -1) {
  280. printf("%d: Failed using /var/run for pid file, using /tmp\n", (int)getpid());
  281. sprintf (filename, "/tmp/openais_cleanup_%s", compNameGlobal.value);
  282. fd = open (filename, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU);
  283. }
  284. sprintf (pid, "%d", (int)getpid());
  285. res = write (fd, pid, strlen (pid));
  286. close (fd);
  287. }
  288. static SaSelectionObjectT comp_init ()
  289. {
  290. char *name;
  291. char *env;
  292. int result;
  293. SaSelectionObjectT select_fd;
  294. SaAmfPmErrorsT pmErrors = (SA_AMF_PM_ZERO_EXIT |
  295. SA_AMF_PM_NON_ZERO_EXIT |
  296. SA_AMF_PM_ABNORMAL_END);
  297. name = getenv ("SA_AMF_COMPONENT_NAME");
  298. if (name == NULL) {
  299. die ("SA_AMF_COMPONENT_NAME missing");
  300. }
  301. if (strstr (name, "safComp=") == NULL ||
  302. strstr (name, "safSu=") == NULL ||
  303. strstr (name, "safSg=") == NULL ||
  304. strstr (name, "safApp=") == NULL) {
  305. die ("SA_AMF_COMPONENT_NAME value wrong");
  306. }
  307. printf("%d: Hello world from %s\n", (int)getpid(), name);
  308. env = getenv ("var1");
  309. if (env == NULL) {
  310. die ("var1 missing");
  311. }
  312. if (strcmp (env, "val1") != 0) {
  313. die ("var1 value wrong");
  314. }
  315. env = getenv ("var2");
  316. if (env == NULL) {
  317. die ("var2 wrong");
  318. }
  319. if (strcmp (env, "val2") != 0) {
  320. die ("var2 value wrong");
  321. }
  322. signal (SIGINT, sigintr_handler);
  323. signal (SIGUSR1, sigusr1_handler);
  324. signal (SIGUSR2, sigusr2_handler);
  325. #if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS))
  326. sched_param.sched_priority = sched_get_priority_max(SCHED_RR);
  327. if (sched_param.sched_priority == -1) {
  328. fprintf (stderr, "%d: couldn't retrieve the maximum scheduling " \
  329. "priority supported by the Round-Robin class (%s)\n",
  330. (int)getpid(), strerror(errno));
  331. } else {
  332. result = sched_setscheduler (0, SCHED_RR, &sched_param);
  333. if (result == -1) {
  334. fprintf (stderr, "%d: couldn't set sched priority (%s)\n",
  335. (int)getpid(), strerror(errno));
  336. }
  337. }
  338. #endif
  339. do {
  340. result = saAmfInitialize (&handle, &amfCallbacks, &version);
  341. if (result == SA_AIS_ERR_TRY_AGAIN) {
  342. printf("%d: TRY_AGAIN received\n", (int)getpid());
  343. usleep (100000);
  344. }
  345. } while (result == SA_AIS_ERR_TRY_AGAIN);
  346. if (result != SA_AIS_OK) {
  347. die ("saAmfInitialize result is %d", result);
  348. }
  349. do {
  350. result = saAmfSelectionObjectGet (handle, &select_fd);
  351. if (result == SA_AIS_ERR_TRY_AGAIN) {
  352. printf("%d: TRY_AGAIN received\n", (int)getpid());
  353. usleep (100000);
  354. }
  355. } while (result == SA_AIS_ERR_TRY_AGAIN);
  356. if (result != SA_AIS_OK) {
  357. die ("saAmfSelectionObjectGet failed %d", result);
  358. }
  359. do {
  360. result = saAmfComponentNameGet (handle, &compNameGlobal);
  361. if (result == SA_AIS_ERR_TRY_AGAIN) {
  362. printf("%d: TRY_AGAIN received\n", (int)getpid());
  363. usleep (100000);
  364. }
  365. } while (result == SA_AIS_ERR_TRY_AGAIN);
  366. if (result != SA_AIS_OK) {
  367. die ("saAmfComponentNameGet failed %d", result);
  368. }
  369. write_pid ();
  370. do {
  371. result = saAmfHealthcheckStart (handle,
  372. &compNameGlobal,
  373. &keyAmfInvoked,
  374. SA_AMF_HEALTHCHECK_AMF_INVOKED,
  375. SA_AMF_COMPONENT_FAILOVER);
  376. if (result == SA_AIS_ERR_TRY_AGAIN) {
  377. printf("%d: TRY_AGAIN received\n", (int)getpid());
  378. usleep (100000);
  379. }
  380. } while (result == SA_AIS_ERR_TRY_AGAIN);
  381. if (result != SA_AIS_OK) {
  382. die ("saAmfHealthcheckStart failed %d", result);
  383. }
  384. do {
  385. result = saAmfHealthcheckStart (handle,
  386. &compNameGlobal,
  387. &keyCompInvoked,
  388. SA_AMF_HEALTHCHECK_COMPONENT_INVOKED,
  389. SA_AMF_COMPONENT_FAILOVER);
  390. if (result == SA_AIS_ERR_TRY_AGAIN) {
  391. printf("%d: TRY_AGAIN received\n", (int)getpid());
  392. usleep (100000);
  393. }
  394. } while (result == SA_AIS_ERR_TRY_AGAIN);
  395. if (result != SA_AIS_OK) {
  396. die ("saAmfHealthcheckStart failed %d", result);
  397. }
  398. {
  399. SaNameT badname;
  400. strcpy ((char*)badname.value, "badname");
  401. badname.length = 7;
  402. do {
  403. result = saAmfComponentRegister (handle, &badname, NULL);
  404. if (result == SA_AIS_ERR_TRY_AGAIN) {
  405. printf("%d: TRY_AGAIN received\n", (int)getpid());
  406. usleep (100000);
  407. }
  408. } while (result == SA_AIS_ERR_TRY_AGAIN);
  409. if (result != SA_AIS_ERR_INVALID_PARAM) {
  410. die ("saAmfComponentRegister failed %d", result);
  411. }
  412. }
  413. do {
  414. result = saAmfComponentRegister (handle, &compNameGlobal, NULL);
  415. if (result == SA_AIS_ERR_TRY_AGAIN) {
  416. printf("%d: TRY_AGAIN received\n", (int)getpid());
  417. usleep (100000);
  418. }
  419. } while (result == SA_AIS_ERR_TRY_AGAIN);
  420. if (result != SA_AIS_OK) {
  421. die ("saAmfComponentRegister failed %d", result);
  422. }
  423. /*
  424. * startup passive monitoring
  425. */
  426. do {
  427. result = saAmfPmStart (handle,
  428. &compNameGlobal, getpid(), 1,
  429. pmErrors,
  430. SA_AMF_COMPONENT_FAILOVER);
  431. if (result == SA_AIS_ERR_TRY_AGAIN) {
  432. printf("%d: TRY_AGAIN received\n", (int)getpid());
  433. usleep (100000);
  434. }
  435. } while (result == SA_AIS_ERR_TRY_AGAIN);
  436. /*
  437. * Test already started healthcheck
  438. */
  439. do {
  440. result = saAmfHealthcheckStart (handle,
  441. &compNameGlobal,
  442. &keyAmfInvoked,
  443. SA_AMF_HEALTHCHECK_AMF_INVOKED,
  444. SA_AMF_COMPONENT_FAILOVER);
  445. if (result == SA_AIS_ERR_TRY_AGAIN) {
  446. printf("%d: TRY_AGAIN received\n", (int)getpid());
  447. usleep (100000);
  448. }
  449. } while (result == SA_AIS_ERR_TRY_AGAIN);
  450. if (result != SA_AIS_ERR_EXIST) {
  451. die ("saAmfHealthcheckStart failed %d", result);
  452. }
  453. return select_fd;
  454. }
  455. static void handle_intr (void)
  456. {
  457. SaAisErrorT result;
  458. switch (stop) {
  459. case FINALIZE:
  460. result = saAmfFinalize (handle);
  461. if (result != SA_AIS_OK) {
  462. die ("saAmfFinalize failed %d", result);
  463. }
  464. fprintf(stderr, "%d: %s exiting\n",
  465. (int)getpid(), compNameGlobal.value);
  466. exit (EXIT_SUCCESS);
  467. break;
  468. case UNREGISTER:
  469. fprintf(stderr, "%d: %s unregistering\n",
  470. (int)getpid(), compNameGlobal.value);
  471. result = saAmfComponentUnregister (
  472. handle, &compNameGlobal, NULL);
  473. if (result != SA_AIS_OK) {
  474. die ("saAmfComponentUnregister failed %d", result);
  475. }
  476. fprintf(stderr, "%d: waiting after unregister\n", (int)getpid());
  477. while (1) {
  478. sleep (100000000);
  479. }
  480. break;
  481. case ERROR_REPORT:
  482. fprintf(stderr, "%d: %s error reporting\n",
  483. (int)getpid(), compNameGlobal.value);
  484. result = saAmfComponentErrorReport (
  485. handle, &compNameGlobal, 0, SA_AMF_COMPONENT_RESTART, 0);
  486. if (result != SA_AIS_OK) {
  487. die ("saAmfComponentErrorReport failed %d", result);
  488. }
  489. fprintf(stderr, "%d: waiting after error report\n", (int)getpid());
  490. while (1) {
  491. sleep (100000000);
  492. }
  493. break;
  494. default:
  495. die ("unknown %d", stop);
  496. break;
  497. }
  498. }
  499. int main (int argc, char **argv)
  500. {
  501. int result;
  502. SaSelectionObjectT select_fd;
  503. fd_set read_fds;
  504. struct timeval tv;
  505. select_fd = comp_init();
  506. FD_ZERO (&read_fds);
  507. do {
  508. tv.tv_sec = 2; /* related to value in amf.conf! */
  509. tv.tv_usec = 0;
  510. FD_SET (select_fd, &read_fds);
  511. result = select (select_fd + 1, &read_fds, 0, 0, &tv);
  512. if (result == -1) {
  513. if (errno == EINTR) {
  514. handle_intr ();
  515. } else {
  516. die ("select failed - %s", strerror (errno));
  517. }
  518. } else if (result > 0) {
  519. do {
  520. result = saAmfDispatch (handle, SA_DISPATCH_ALL);
  521. if (result == SA_AIS_ERR_TRY_AGAIN) {
  522. fprintf(stderr, "%d: TRY_AGAIN received\n", (int)getpid());
  523. usleep (100000);
  524. }
  525. } while (result == SA_AIS_ERR_TRY_AGAIN);
  526. if (result != SA_AIS_OK) {
  527. die ("saAmfDispatch failed %d", result);
  528. }
  529. } else {
  530. /* timeout */
  531. do {
  532. result = saAmfHealthcheckConfirm (handle, &compNameGlobal,
  533. &keyCompInvoked, SA_AIS_OK);
  534. if (result == SA_AIS_ERR_TRY_AGAIN) {
  535. fprintf(stderr, "%d: TRY_AGAIN received\n", (int)getpid());
  536. usleep (100000);
  537. }
  538. } while (result == SA_AIS_ERR_TRY_AGAIN);
  539. if (result != SA_AIS_OK) {
  540. die ("saAmfHealthcheckConfirm failed %d", result);
  541. }
  542. }
  543. } while (stop == 0);
  544. fprintf(stderr, "%d: exiting...\n", (int)getpid());
  545. exit (EXIT_SUCCESS);
  546. }