main.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. /*
  2. * Copyright (c) 2002-2006 MontaVista Software, Inc.
  3. * Copyright (c) 2006-2008 Red Hat, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Author: Steven Dake (sdake@redhat.com)
  8. *
  9. * This software licensed under BSD license, the text of which follows:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. * - Redistributions in binary form must reproduce the above copyright notice,
  17. * this list of conditions and the following disclaimer in the documentation
  18. * and/or other materials provided with the distribution.
  19. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  33. * THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #include <pthread.h>
  36. #include <assert.h>
  37. #include <sys/types.h>
  38. #include <sys/poll.h>
  39. #include <sys/uio.h>
  40. #include <sys/mman.h>
  41. #include <sys/socket.h>
  42. #include <sys/un.h>
  43. #include <sys/time.h>
  44. #include <sys/resource.h>
  45. #include <netinet/in.h>
  46. #include <arpa/inet.h>
  47. #include <unistd.h>
  48. #include <fcntl.h>
  49. #include <stdlib.h>
  50. #include <stdio.h>
  51. #include <errno.h>
  52. #include <signal.h>
  53. #include <sched.h>
  54. #include <time.h>
  55. #include <corosync/swab.h>
  56. #include <corosync/corotypes.h>
  57. #include <corosync/list.h>
  58. #include <corosync/queue.h>
  59. #include <corosync/lcr/lcr_ifact.h>
  60. #include <corosync/totem/coropoll.h>
  61. #include <corosync/totem/totempg.h>
  62. #include <corosync/engine/objdb.h>
  63. #include <corosync/engine/config.h>
  64. #include <corosync/engine/logsys.h>
  65. #include "quorum.h"
  66. #include "totemsrp.h"
  67. #include "mempool.h"
  68. #include "mainconfig.h"
  69. #include "totemconfig.h"
  70. #include "main.h"
  71. #include "sync.h"
  72. #include "tlist.h"
  73. #include "ipc.h"
  74. #include "timer.h"
  75. #include "util.h"
  76. #include "apidef.h"
  77. #include "service.h"
  78. #include "version.h"
  79. LOGSYS_DECLARE_SYSTEM ("corosync",
  80. LOG_MODE_OUTPUT_STDERR | LOG_MODE_THREADED | LOG_MODE_FORK,
  81. NULL,
  82. LOG_DAEMON,
  83. "[%6s] %b",
  84. 1000000);
  85. LOGSYS_DECLARE_SUBSYS ("MAIN", LOG_INFO);
  86. #define SERVER_BACKLOG 5
  87. static unsigned int service_count = 32;
  88. static pthread_mutex_t serialize_mutex = PTHREAD_MUTEX_INITIALIZER;
  89. static struct totem_logging_configuration totem_logging_configuration;
  90. static char delivery_data[MESSAGE_SIZE_MAX];
  91. static int num_config_modules;
  92. static struct config_iface_ver0 *config_modules[MAX_DYNAMIC_SERVICES];
  93. static struct objdb_iface_ver0 *objdb = NULL;
  94. static struct corosync_api_v1 *api = NULL;
  95. unsigned long long *(*main_clm_get_by_nodeid) (unsigned int node_id);
  96. static void sigusr2_handler (int num)
  97. {
  98. int i;
  99. for (i = 0; ais_service[i]; i++) {
  100. if (ais_service[i]->exec_dump_fn) {
  101. ais_service[i]->exec_dump_fn ();
  102. }
  103. }
  104. }
  105. static void *aisexec_exit (void *arg)
  106. {
  107. if (api) {
  108. corosync_service_unlink_all (api);
  109. }
  110. #ifdef DEBUG_MEMPOOL
  111. int stats_inuse[MEMPOOL_GROUP_SIZE];
  112. int stats_avail[MEMPOOL_GROUP_SIZE];
  113. int stats_memoryused[MEMPOOL_GROUP_SIZE];
  114. int i;
  115. mempool_getstats (stats_inuse, stats_avail, stats_memoryused);
  116. log_printf (LOG_LEVEL_DEBUG, "Memory pools:\n");
  117. for (i = 0; i < MEMPOOL_GROUP_SIZE; i++) {
  118. log_printf (LOG_LEVEL_DEBUG, "order %d size %d inuse %d avail %d memory used %d\n",
  119. i, 1<<i, stats_inuse[i], stats_avail[i], stats_memoryused[i]);
  120. }
  121. #endif
  122. poll_stop (0);
  123. totempg_finalize ();
  124. cs_ipc_exit ();
  125. corosync_exit_error (AIS_DONE_EXIT);
  126. /* never reached */
  127. return NULL;
  128. }
  129. pthread_t aisexec_exit_thread;
  130. static void init_shutdown(void *data)
  131. {
  132. pthread_create (&aisexec_exit_thread, NULL, aisexec_exit, NULL);
  133. }
  134. static poll_timer_handle shutdown_handle;
  135. static void sigquit_handler (int num)
  136. {
  137. /* avoid creating threads from within the interrupt context */
  138. poll_timer_add (aisexec_poll_handle, 500, NULL, init_shutdown, &shutdown_handle);
  139. }
  140. static void sigsegv_handler (int num)
  141. {
  142. (void)signal (SIGSEGV, SIG_DFL);
  143. logsys_atsegv();
  144. logsys_log_rec_store ("/var/lib/corosync/fdata");
  145. raise (SIGSEGV);
  146. }
  147. static void sigabrt_handler (int num)
  148. {
  149. (void)signal (SIGABRT, SIG_DFL);
  150. logsys_atsegv();
  151. logsys_log_rec_store ("/var/lib/corosync/fdata");
  152. raise (SIGABRT);
  153. }
  154. #define LOCALHOST_IP inet_addr("127.0.0.1")
  155. totempg_groups_handle corosync_group_handle;
  156. struct totempg_group corosync_group = {
  157. .group = "a",
  158. .group_len = 1
  159. };
  160. void sigintr_handler (int signum)
  161. {
  162. poll_timer_add (aisexec_poll_handle, 500, NULL, init_shutdown, &shutdown_handle);
  163. }
  164. static int pool_sizes[] = { 0, 0, 0, 0, 0, 4096, 0, 1, 0, /* 256 */
  165. 1024, 0, 1, 4096, 0, 0, 0, 0, /* 65536 */
  166. 1, 1, 1, 1, 1, 1, 1, 1, 1 };
  167. void serialize_mutex_lock (void)
  168. {
  169. pthread_mutex_lock (&serialize_mutex);
  170. }
  171. void serialize_mutex_unlock (void)
  172. {
  173. pthread_mutex_unlock (&serialize_mutex);
  174. }
  175. static void corosync_sync_completed (void)
  176. {
  177. }
  178. static int corosync_sync_callbacks_retrieve (int sync_id,
  179. struct sync_callbacks *callbacks)
  180. {
  181. unsigned int ais_service_index;
  182. unsigned int ais_services_found = 0;
  183. for (ais_service_index = 0;
  184. ais_service_index < SERVICE_HANDLER_MAXIMUM_COUNT;
  185. ais_service_index++) {
  186. if (ais_service[ais_service_index] != NULL) {
  187. if (ais_services_found == sync_id) {
  188. break;
  189. }
  190. ais_services_found += 1;
  191. }
  192. }
  193. if (ais_service_index == SERVICE_HANDLER_MAXIMUM_COUNT) {
  194. memset (callbacks, 0, sizeof (struct sync_callbacks));
  195. return (-1);
  196. }
  197. callbacks->name = ais_service[ais_service_index]->name;
  198. callbacks->sync_init = ais_service[ais_service_index]->sync_init;
  199. callbacks->sync_process = ais_service[ais_service_index]->sync_process;
  200. callbacks->sync_activate = ais_service[ais_service_index]->sync_activate;
  201. callbacks->sync_abort = ais_service[ais_service_index]->sync_abort;
  202. return (0);
  203. }
  204. static struct memb_ring_id aisexec_ring_id;
  205. static void confchg_fn (
  206. enum totem_configuration_type configuration_type,
  207. unsigned int *member_list, int member_list_entries,
  208. unsigned int *left_list, int left_list_entries,
  209. unsigned int *joined_list, int joined_list_entries,
  210. struct memb_ring_id *ring_id)
  211. {
  212. int i;
  213. memcpy (&aisexec_ring_id, ring_id, sizeof (struct memb_ring_id));
  214. /*
  215. * Call configuration change for all services
  216. */
  217. for (i = 0; i < service_count; i++) {
  218. if (ais_service[i] && ais_service[i]->confchg_fn) {
  219. ais_service[i]->confchg_fn (configuration_type,
  220. member_list, member_list_entries,
  221. left_list, left_list_entries,
  222. joined_list, joined_list_entries, ring_id);
  223. }
  224. }
  225. }
  226. static void priv_drop (struct main_config *main_config)
  227. {
  228. return; /* TODO: we are still not dropping privs */
  229. setuid (main_config->uid);
  230. setegid (main_config->gid);
  231. }
  232. static void aisexec_mempool_init (void)
  233. {
  234. int res;
  235. res = mempool_init (pool_sizes);
  236. if (res == ENOMEM) {
  237. log_printf (LOG_LEVEL_ERROR, "Couldn't allocate memory pools, not enough memory");
  238. corosync_exit_error (AIS_DONE_MEMPOOL_INIT);
  239. }
  240. }
  241. static void aisexec_tty_detach (void)
  242. {
  243. int fd;
  244. /*
  245. * Disconnect from TTY if this is not a debug run
  246. */
  247. switch (fork ()) {
  248. case -1:
  249. corosync_exit_error (AIS_DONE_FORK);
  250. break;
  251. case 0:
  252. /*
  253. * child which is disconnected, run this process
  254. */
  255. /* setset();
  256. close (0);
  257. close (1);
  258. close (2);
  259. */
  260. break;
  261. default:
  262. exit (0);
  263. break;
  264. }
  265. /* Create new session */
  266. (void)setsid();
  267. /*
  268. * Map stdin/out/err to /dev/null.
  269. */
  270. fd = open("/dev/null", O_RDWR);
  271. if (fd >= 0) {
  272. /* dup2 to 0 / 1 / 2 (stdin / stdout / stderr) */
  273. dup2(fd, STDIN_FILENO); /* 0 */
  274. dup2(fd, STDOUT_FILENO); /* 1 */
  275. dup2(fd, STDERR_FILENO); /* 2 */
  276. /* Should be 0, but just in case it isn't... */
  277. if (fd > 2)
  278. close(fd);
  279. }
  280. }
  281. static void aisexec_setscheduler (void)
  282. {
  283. #if ! defined(TS_CLASS) && (defined(COROSYNC_BSD) || defined(COROSYNC_LINUX) || defined(COROSYNC_SOLARIS))
  284. struct sched_param sched_param;
  285. int res;
  286. res = sched_get_priority_max (SCHED_RR);
  287. if (res != -1) {
  288. sched_param.sched_priority = 1;//res;
  289. res = sched_setscheduler (0, SCHED_RR, &sched_param);
  290. if (res == -1) {
  291. log_printf (LOG_LEVEL_WARNING, "Could not set SCHED_RR at priority %d: %s\n",
  292. sched_param.sched_priority, strerror (errno));
  293. }
  294. } else
  295. log_printf (LOG_LEVEL_WARNING, "Could not get maximum scheduler priority: %s\n", strerror (errno));
  296. #else
  297. log_printf(LOG_LEVEL_WARNING, "Scheduler priority left to default value (no OS support)\n");
  298. #endif
  299. }
  300. static void aisexec_mlockall (void)
  301. {
  302. #if !defined(COROSYNC_BSD)
  303. int res;
  304. #endif
  305. struct rlimit rlimit;
  306. rlimit.rlim_cur = RLIM_INFINITY;
  307. rlimit.rlim_max = RLIM_INFINITY;
  308. #ifndef COROSYNC_SOLARIS
  309. setrlimit (RLIMIT_MEMLOCK, &rlimit);
  310. #else
  311. setrlimit (RLIMIT_VMEM, &rlimit);
  312. #endif
  313. #if defined(COROSYNC_BSD)
  314. /* under FreeBSD a process with locked page cannot call dlopen
  315. * code disabled until FreeBSD bug i386/93396 was solved
  316. */
  317. log_printf (LOG_LEVEL_WARNING, "Could not lock memory of service to avoid page faults\n");
  318. #else
  319. res = mlockall (MCL_CURRENT | MCL_FUTURE);
  320. if (res == -1) {
  321. log_printf (LOG_LEVEL_WARNING, "Could not lock memory of service to avoid page faults: %s\n", strerror (errno));
  322. };
  323. #endif
  324. }
  325. static void deliver_fn (
  326. unsigned int nodeid,
  327. struct iovec *iovec,
  328. int iov_len,
  329. int endian_conversion_required)
  330. {
  331. mar_req_header_t *header;
  332. int pos = 0;
  333. int i;
  334. int service;
  335. int fn_id;
  336. /*
  337. * Build buffer without iovecs to make processing easier
  338. * This is only used for messages which are multicast with iovecs
  339. * and self-delivered. All other mechanisms avoid the copy.
  340. */
  341. if (iov_len > 1) {
  342. for (i = 0; i < iov_len; i++) {
  343. memcpy (&delivery_data[pos], iovec[i].iov_base, iovec[i].iov_len);
  344. pos += iovec[i].iov_len;
  345. assert (pos < MESSAGE_SIZE_MAX);
  346. }
  347. header = (mar_req_header_t *)delivery_data;
  348. } else {
  349. header = (mar_req_header_t *)iovec[0].iov_base;
  350. }
  351. if (endian_conversion_required) {
  352. header->id = swab32 (header->id);
  353. header->size = swab32 (header->size);
  354. }
  355. // assert(iovec->iov_len == header->size);
  356. /*
  357. * Call the proper executive handler
  358. */
  359. service = header->id >> 16;
  360. fn_id = header->id & 0xffff;
  361. if (!ais_service[service])
  362. return;
  363. if (endian_conversion_required) {
  364. assert(ais_service[service]->exec_engine[fn_id].exec_endian_convert_fn != NULL);
  365. ais_service[service]->exec_engine[fn_id].exec_endian_convert_fn
  366. (header);
  367. }
  368. ais_service[service]->exec_engine[fn_id].exec_handler_fn
  369. (header, nodeid);
  370. }
  371. void main_get_config_modules(struct config_iface_ver0 ***modules, int *num)
  372. {
  373. *modules = config_modules;
  374. *num = num_config_modules;
  375. }
  376. int main_mcast (
  377. struct iovec *iovec,
  378. int iov_len,
  379. unsigned int guarantee)
  380. {
  381. return (totempg_groups_mcast_joined (corosync_group_handle, iovec, iov_len, guarantee));
  382. }
  383. extern int main_send_ok (
  384. struct iovec *iovec,
  385. int iov_len)
  386. {
  387. return (totempg_groups_send_ok_joined (corosync_group_handle, iovec, iov_len));
  388. }
  389. int main (int argc, char **argv)
  390. {
  391. char *error_string;
  392. struct main_config main_config;
  393. struct totem_config totem_config;
  394. unsigned int objdb_handle;
  395. unsigned int config_handle;
  396. unsigned int config_version = 0;
  397. void *objdb_p;
  398. struct config_iface_ver0 *config;
  399. void *config_p;
  400. char *config_iface;
  401. char *iface;
  402. int res, ch;
  403. int background, setprio;
  404. /* default configuration
  405. */
  406. background = 1;
  407. setprio = 1;
  408. while ((ch = getopt (argc, argv, "fp")) != EOF) {
  409. switch (ch) {
  410. case 'f':
  411. background = 0;
  412. logsys_config_mode_set (LOG_MODE_OUTPUT_STDERR|LOG_MODE_THREADED|LOG_MODE_FORK);
  413. break;
  414. case 'p':
  415. setprio = 0;
  416. break;
  417. default:
  418. fprintf(stderr, \
  419. "usage:\n"\
  420. " -f : Start application in foreground.\n"\
  421. " -p : Do not set process priority. \n");
  422. return EXIT_FAILURE;
  423. }
  424. }
  425. if (background)
  426. aisexec_tty_detach ();
  427. log_printf (LOG_LEVEL_NOTICE, "Corosync Executive Service RELEASE '%s'\n", RELEASE_VERSION);
  428. log_printf (LOG_LEVEL_NOTICE, "Copyright (C) 2002-2006 MontaVista Software, Inc and contributors.\n");
  429. log_printf (LOG_LEVEL_NOTICE, "Copyright (C) 2006-2008 Red Hat, Inc.\n");
  430. (void)signal (SIGINT, sigintr_handler);
  431. (void)signal (SIGUSR2, sigusr2_handler);
  432. (void)signal (SIGSEGV, sigsegv_handler);
  433. (void)signal (SIGABRT, sigabrt_handler);
  434. (void)signal (SIGQUIT, sigquit_handler);
  435. corosync_timer_init (
  436. serialize_mutex_lock,
  437. serialize_mutex_unlock);
  438. log_printf (LOG_LEVEL_NOTICE, "Corosync Executive Service: started and ready to provide service.\n");
  439. aisexec_poll_handle = poll_create (
  440. serialize_mutex_lock,
  441. serialize_mutex_unlock);
  442. /*
  443. * Load the object database interface
  444. */
  445. res = lcr_ifact_reference (
  446. &objdb_handle,
  447. "objdb",
  448. 0,
  449. &objdb_p,
  450. 0);
  451. if (res == -1) {
  452. log_printf (LOG_LEVEL_ERROR, "Corosync Executive couldn't open configuration object database component.\n");
  453. corosync_exit_error (AIS_DONE_OBJDB);
  454. }
  455. objdb = (struct objdb_iface_ver0 *)objdb_p;
  456. objdb->objdb_init ();
  457. /*
  458. * Initialize the corosync_api_v1 definition
  459. */
  460. apidef_init (objdb);
  461. api = apidef_get ();
  462. num_config_modules = 0;
  463. /*
  464. * Bootstrap in the default configuration parser or use
  465. * the corosync default built in parser if the configuration parser
  466. * isn't overridden
  467. */
  468. config_iface = getenv("COROSYNC_DEFAULT_CONFIG_IFACE");
  469. if (!config_iface) {
  470. config_iface = "corosync_parser";
  471. }
  472. /* Make a copy so we can deface it with strtok */
  473. config_iface = strdup(config_iface);
  474. iface = strtok(config_iface, ":");
  475. while (iface)
  476. {
  477. res = lcr_ifact_reference (
  478. &config_handle,
  479. iface,
  480. config_version,
  481. &config_p,
  482. 0);
  483. config = (struct config_iface_ver0 *)config_p;
  484. if (res == -1) {
  485. log_printf (LOG_LEVEL_ERROR, "Corosync Executive couldn't open configuration component '%s'\n", iface);
  486. corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
  487. }
  488. res = config->config_readconfig(objdb, &error_string);
  489. if (res == -1) {
  490. log_printf (LOG_LEVEL_ERROR, error_string);
  491. corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
  492. }
  493. log_printf (LOG_LEVEL_NOTICE, error_string);
  494. config_modules[num_config_modules++] = config;
  495. iface = strtok(NULL, ":");
  496. }
  497. if (config_iface)
  498. free(config_iface);
  499. res = corosync_main_config_read (objdb, &error_string, &main_config);
  500. if (res == -1) {
  501. log_printf (LOG_LEVEL_ERROR, error_string);
  502. corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
  503. }
  504. res = totem_config_read (objdb, &totem_config, &error_string);
  505. if (res == -1) {
  506. log_printf (LOG_LEVEL_ERROR, error_string);
  507. corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
  508. }
  509. res = totem_config_keyread (objdb, &totem_config, &error_string);
  510. if (res == -1) {
  511. log_printf (LOG_LEVEL_ERROR, error_string);
  512. corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
  513. }
  514. res = totem_config_validate (&totem_config, &error_string);
  515. if (res == -1) {
  516. log_printf (LOG_LEVEL_ERROR, error_string);
  517. corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
  518. }
  519. /*
  520. * Set round robin realtime scheduling with priority 99
  521. * Lock all memory to avoid page faults which may interrupt
  522. * application healthchecking
  523. */
  524. if (setprio)
  525. aisexec_setscheduler ();
  526. aisexec_mlockall ();
  527. totem_config.totem_logging_configuration = totem_logging_configuration;
  528. totem_config.totem_logging_configuration.log_subsys_id =
  529. _logsys_subsys_create ("TOTEM", LOG_INFO);
  530. totem_config.totem_logging_configuration.log_level_security = LOG_LEVEL_SECURITY;
  531. totem_config.totem_logging_configuration.log_level_error = LOG_LEVEL_ERROR;
  532. totem_config.totem_logging_configuration.log_level_warning = LOG_LEVEL_WARNING;
  533. totem_config.totem_logging_configuration.log_level_notice = LOG_LEVEL_NOTICE;
  534. totem_config.totem_logging_configuration.log_level_debug = LOG_LEVEL_DEBUG;
  535. totem_config.totem_logging_configuration.log_printf = _logsys_log_printf;
  536. /*
  537. * Sleep for a while to let other nodes in the cluster
  538. * understand that this node has been away (if it was
  539. * an aisexec restart).
  540. */
  541. // TODO what is this hack for? usleep(totem_config.token_timeout * 2000);
  542. /*
  543. * if totempg_initialize doesn't have root priveleges, it cannot
  544. * bind to a specific interface. This only matters if
  545. * there is more then one interface in a system, so
  546. * in this case, only a warning is printed
  547. */
  548. /*
  549. * Join multicast group and setup delivery
  550. * and configuration change functions
  551. */
  552. totempg_initialize (
  553. aisexec_poll_handle,
  554. &totem_config);
  555. totempg_groups_initialize (
  556. &corosync_group_handle,
  557. deliver_fn,
  558. confchg_fn);
  559. totempg_groups_join (
  560. corosync_group_handle,
  561. &corosync_group,
  562. 1);
  563. /*
  564. * This must occur after totempg is initialized because "this_ip" must be set
  565. */
  566. res = corosync_service_defaults_link_and_init (api);
  567. if (res == -1) {
  568. log_printf (LOG_LEVEL_ERROR, "Could not initialize default services\n");
  569. corosync_exit_error (AIS_DONE_INIT_SERVICES);
  570. }
  571. sync_register (corosync_sync_callbacks_retrieve, corosync_sync_completed);
  572. /*
  573. * Drop root privleges to user 'ais'
  574. * TODO: Don't really need full root capabilities;
  575. * needed capabilities are:
  576. * CAP_NET_RAW (bindtodevice)
  577. * CAP_SYS_NICE (setscheduler)
  578. * CAP_IPC_LOCK (mlockall)
  579. */
  580. priv_drop (&main_config);
  581. aisexec_mempool_init ();
  582. cs_ipc_init (main_config.gid);
  583. /*
  584. * Start main processing loop
  585. */
  586. poll_run (aisexec_poll_handle);
  587. return EXIT_SUCCESS;
  588. }