main.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  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 "flow.h"
  74. #include "ipc.h"
  75. #include "timer.h"
  76. #include "util.h"
  77. #include "flow.h"
  78. #include "apidef.h"
  79. #include "service.h"
  80. #include "version.h"
  81. LOGSYS_DECLARE_SYSTEM ("corosync",
  82. LOG_MODE_OUTPUT_STDERR | LOG_MODE_THREADED | LOG_MODE_FORK,
  83. NULL,
  84. LOG_DAEMON,
  85. "[%6s] %b",
  86. 1000000);
  87. LOGSYS_DECLARE_SUBSYS ("MAIN", LOG_INFO);
  88. #define SERVER_BACKLOG 5
  89. static unsigned int service_count = 32;
  90. static pthread_mutex_t serialize_mutex = PTHREAD_MUTEX_INITIALIZER;
  91. static struct totem_logging_configuration totem_logging_configuration;
  92. static char delivery_data[MESSAGE_SIZE_MAX];
  93. static int num_config_modules;
  94. static struct config_iface_ver0 *config_modules[MAX_DYNAMIC_SERVICES];
  95. static struct objdb_iface_ver0 *objdb = NULL;
  96. static struct corosync_api_v1 *api = NULL;
  97. unsigned long long *(*main_clm_get_by_nodeid) (unsigned int node_id);
  98. static void sigusr2_handler (int num)
  99. {
  100. int i;
  101. for (i = 0; ais_service[i]; i++) {
  102. if (ais_service[i]->exec_dump_fn) {
  103. ais_service[i]->exec_dump_fn ();
  104. }
  105. }
  106. }
  107. static void *aisexec_exit (void *arg)
  108. {
  109. if (api) {
  110. corosync_service_unlink_all (api);
  111. }
  112. #ifdef DEBUG_MEMPOOL
  113. int stats_inuse[MEMPOOL_GROUP_SIZE];
  114. int stats_avail[MEMPOOL_GROUP_SIZE];
  115. int stats_memoryused[MEMPOOL_GROUP_SIZE];
  116. int i;
  117. mempool_getstats (stats_inuse, stats_avail, stats_memoryused);
  118. log_printf (LOG_LEVEL_DEBUG, "Memory pools:\n");
  119. for (i = 0; i < MEMPOOL_GROUP_SIZE; i++) {
  120. log_printf (LOG_LEVEL_DEBUG, "order %d size %d inuse %d avail %d memory used %d\n",
  121. i, 1<<i, stats_inuse[i], stats_avail[i], stats_memoryused[i]);
  122. }
  123. #endif
  124. totempg_finalize ();
  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. break;
  260. default:
  261. exit (0);
  262. break;
  263. }
  264. /* Create new session */
  265. (void)setsid();
  266. /*
  267. * Map stdin/out/err to /dev/null.
  268. */
  269. fd = open("/dev/null", O_RDWR);
  270. if (fd >= 0) {
  271. /* dup2 to 0 / 1 / 2 (stdin / stdout / stderr) */
  272. dup2(fd, STDIN_FILENO); /* 0 */
  273. dup2(fd, STDOUT_FILENO); /* 1 */
  274. dup2(fd, STDERR_FILENO); /* 2 */
  275. /* Should be 0, but just in case it isn't... */
  276. if (fd > 2)
  277. close(fd);
  278. }
  279. }
  280. static void aisexec_setscheduler (void)
  281. {
  282. #if ! defined(TS_CLASS) && (defined(COROSYNC_BSD) || defined(COROSYNC_LINUX) || defined(COROSYNC_SOLARIS))
  283. struct sched_param sched_param;
  284. int res;
  285. res = sched_get_priority_max (SCHED_RR);
  286. if (res != -1) {
  287. sched_param.sched_priority = 1;//res;
  288. res = sched_setscheduler (0, SCHED_RR, &sched_param);
  289. if (res == -1) {
  290. log_printf (LOG_LEVEL_WARNING, "Could not set SCHED_RR at priority %d: %s\n",
  291. sched_param.sched_priority, strerror (errno));
  292. }
  293. } else
  294. log_printf (LOG_LEVEL_WARNING, "Could not get maximum scheduler priority: %s\n", strerror (errno));
  295. #else
  296. log_printf(LOG_LEVEL_WARNING, "Scheduler priority left to default value (no OS support)\n");
  297. #endif
  298. }
  299. static void aisexec_mlockall (void)
  300. {
  301. #if !defined(COROSYNC_BSD)
  302. int res;
  303. #endif
  304. struct rlimit rlimit;
  305. rlimit.rlim_cur = RLIM_INFINITY;
  306. rlimit.rlim_max = RLIM_INFINITY;
  307. #ifndef COROSYNC_SOLARIS
  308. setrlimit (RLIMIT_MEMLOCK, &rlimit);
  309. #else
  310. setrlimit (RLIMIT_VMEM, &rlimit);
  311. #endif
  312. #if defined(COROSYNC_BSD)
  313. /* under FreeBSD a process with locked page cannot call dlopen
  314. * code disabled until FreeBSD bug i386/93396 was solved
  315. */
  316. log_printf (LOG_LEVEL_WARNING, "Could not lock memory of service to avoid page faults\n");
  317. #else
  318. res = mlockall (MCL_CURRENT | MCL_FUTURE);
  319. if (res == -1) {
  320. log_printf (LOG_LEVEL_WARNING, "Could not lock memory of service to avoid page faults: %s\n", strerror (errno));
  321. };
  322. #endif
  323. }
  324. static void deliver_fn (
  325. unsigned int nodeid,
  326. struct iovec *iovec,
  327. int iov_len,
  328. int endian_conversion_required)
  329. {
  330. mar_req_header_t *header;
  331. int pos = 0;
  332. int i;
  333. int service;
  334. int fn_id;
  335. /*
  336. * Build buffer without iovecs to make processing easier
  337. * This is only used for messages which are multicast with iovecs
  338. * and self-delivered. All other mechanisms avoid the copy.
  339. */
  340. if (iov_len > 1) {
  341. for (i = 0; i < iov_len; i++) {
  342. memcpy (&delivery_data[pos], iovec[i].iov_base, iovec[i].iov_len);
  343. pos += iovec[i].iov_len;
  344. assert (pos < MESSAGE_SIZE_MAX);
  345. }
  346. header = (mar_req_header_t *)delivery_data;
  347. } else {
  348. header = (mar_req_header_t *)iovec[0].iov_base;
  349. }
  350. if (endian_conversion_required) {
  351. header->id = swab32 (header->id);
  352. header->size = swab32 (header->size);
  353. }
  354. // assert(iovec->iov_len == header->size);
  355. /*
  356. * Call the proper executive handler
  357. */
  358. service = header->id >> 16;
  359. fn_id = header->id & 0xffff;
  360. if (!ais_service[service])
  361. return;
  362. if (endian_conversion_required) {
  363. assert(ais_service[service]->exec_engine[fn_id].exec_endian_convert_fn != NULL);
  364. ais_service[service]->exec_engine[fn_id].exec_endian_convert_fn
  365. (header);
  366. }
  367. ais_service[service]->exec_engine[fn_id].exec_handler_fn
  368. (header, nodeid);
  369. }
  370. void main_get_config_modules(struct config_iface_ver0 ***modules, int *num)
  371. {
  372. *modules = config_modules;
  373. *num = num_config_modules;
  374. }
  375. int main_mcast (
  376. struct iovec *iovec,
  377. int iov_len,
  378. unsigned int guarantee)
  379. {
  380. return (totempg_groups_mcast_joined (corosync_group_handle, iovec, iov_len, guarantee));
  381. }
  382. extern int main_send_ok (
  383. struct iovec *iovec,
  384. int iov_len)
  385. {
  386. return (totempg_groups_send_ok_joined (corosync_group_handle, iovec, iov_len));
  387. }
  388. int main (int argc, char **argv)
  389. {
  390. char *error_string;
  391. struct main_config main_config;
  392. struct totem_config totem_config;
  393. unsigned int objdb_handle;
  394. unsigned int config_handle;
  395. unsigned int config_version = 0;
  396. void *objdb_p;
  397. struct config_iface_ver0 *config;
  398. void *config_p;
  399. char *config_iface;
  400. char *iface;
  401. int res, ch;
  402. int background, setprio;
  403. /* default configuration
  404. */
  405. background = 1;
  406. setprio = 1;
  407. while ((ch = getopt (argc, argv, "fp")) != EOF) {
  408. switch (ch) {
  409. case 'f':
  410. background = 0;
  411. logsys_config_mode_set (LOG_MODE_OUTPUT_STDERR|LOG_MODE_THREADED|LOG_MODE_FORK);
  412. break;
  413. case 'p':
  414. setprio = 0;
  415. break;
  416. default:
  417. fprintf(stderr, \
  418. "usage:\n"\
  419. " -f : Start application in foreground.\n"\
  420. " -p : Do not set process priority. \n");
  421. return EXIT_FAILURE;
  422. }
  423. }
  424. if (background)
  425. aisexec_tty_detach ();
  426. log_printf (LOG_LEVEL_NOTICE, "Corosync Executive Service RELEASE '%s'\n", RELEASE_VERSION);
  427. log_printf (LOG_LEVEL_NOTICE, "Copyright (C) 2002-2006 MontaVista Software, Inc and contributors.\n");
  428. log_printf (LOG_LEVEL_NOTICE, "Copyright (C) 2006-2008 Red Hat, Inc.\n");
  429. (void)signal (SIGINT, sigintr_handler);
  430. (void)signal (SIGUSR2, sigusr2_handler);
  431. (void)signal (SIGSEGV, sigsegv_handler);
  432. (void)signal (SIGABRT, sigabrt_handler);
  433. (void)signal (SIGQUIT, sigquit_handler);
  434. corosync_timer_init (
  435. serialize_mutex_lock,
  436. serialize_mutex_unlock);
  437. log_printf (LOG_LEVEL_NOTICE, "Corosync Executive Service: started and ready to provide service.\n");
  438. aisexec_poll_handle = poll_create (
  439. serialize_mutex_lock,
  440. serialize_mutex_unlock);
  441. /*
  442. * Load the object database interface
  443. */
  444. res = lcr_ifact_reference (
  445. &objdb_handle,
  446. "objdb",
  447. 0,
  448. &objdb_p,
  449. 0);
  450. if (res == -1) {
  451. log_printf (LOG_LEVEL_ERROR, "Corosync Executive couldn't open configuration object database component.\n");
  452. corosync_exit_error (AIS_DONE_OBJDB);
  453. }
  454. objdb = (struct objdb_iface_ver0 *)objdb_p;
  455. objdb->objdb_init ();
  456. /*
  457. * Initialize the corosync_api_v1 definition
  458. */
  459. apidef_init (objdb);
  460. api = apidef_get ();
  461. num_config_modules = 0;
  462. /*
  463. * Bootstrap in the default configuration parser or use
  464. * the corosync default built in parser if the configuration parser
  465. * isn't overridden
  466. */
  467. config_iface = getenv("COROSYNC_DEFAULT_CONFIG_IFACE");
  468. if (!config_iface) {
  469. config_iface = "corosync_parser";
  470. }
  471. /* Make a copy so we can deface it with strtok */
  472. config_iface = strdup(config_iface);
  473. iface = strtok(config_iface, ":");
  474. while (iface)
  475. {
  476. res = lcr_ifact_reference (
  477. &config_handle,
  478. iface,
  479. config_version,
  480. &config_p,
  481. 0);
  482. config = (struct config_iface_ver0 *)config_p;
  483. if (res == -1) {
  484. log_printf (LOG_LEVEL_ERROR, "Corosync Executive couldn't open configuration component '%s'\n", iface);
  485. corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
  486. }
  487. res = config->config_readconfig(objdb, &error_string);
  488. if (res == -1) {
  489. log_printf (LOG_LEVEL_ERROR, error_string);
  490. corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
  491. }
  492. log_printf (LOG_LEVEL_NOTICE, error_string);
  493. config_modules[num_config_modules++] = config;
  494. iface = strtok(NULL, ":");
  495. }
  496. if (config_iface)
  497. free(config_iface);
  498. res = corosync_main_config_read (objdb, &error_string, &main_config);
  499. if (res == -1) {
  500. log_printf (LOG_LEVEL_ERROR, error_string);
  501. corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
  502. }
  503. res = totem_config_read (objdb, &totem_config, &error_string);
  504. if (res == -1) {
  505. log_printf (LOG_LEVEL_ERROR, error_string);
  506. corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
  507. }
  508. res = totem_config_keyread (objdb, &totem_config, &error_string);
  509. if (res == -1) {
  510. log_printf (LOG_LEVEL_ERROR, error_string);
  511. corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
  512. }
  513. res = totem_config_validate (&totem_config, &error_string);
  514. if (res == -1) {
  515. log_printf (LOG_LEVEL_ERROR, error_string);
  516. corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
  517. }
  518. /*
  519. * Set round robin realtime scheduling with priority 99
  520. * Lock all memory to avoid page faults which may interrupt
  521. * application healthchecking
  522. */
  523. if (setprio)
  524. aisexec_setscheduler ();
  525. aisexec_mlockall ();
  526. totem_config.totem_logging_configuration = totem_logging_configuration;
  527. totem_config.totem_logging_configuration.log_subsys_id =
  528. _logsys_subsys_create ("TOTEM", LOG_INFO);
  529. totem_config.totem_logging_configuration.log_level_security = LOG_LEVEL_SECURITY;
  530. totem_config.totem_logging_configuration.log_level_error = LOG_LEVEL_ERROR;
  531. totem_config.totem_logging_configuration.log_level_warning = LOG_LEVEL_WARNING;
  532. totem_config.totem_logging_configuration.log_level_notice = LOG_LEVEL_NOTICE;
  533. totem_config.totem_logging_configuration.log_level_debug = LOG_LEVEL_DEBUG;
  534. totem_config.totem_logging_configuration.log_printf = _logsys_log_printf;
  535. /*
  536. * Sleep for a while to let other nodes in the cluster
  537. * understand that this node has been away (if it was
  538. * an aisexec restart).
  539. */
  540. // TODO what is this hack for? usleep(totem_config.token_timeout * 2000);
  541. /*
  542. * if totempg_initialize doesn't have root priveleges, it cannot
  543. * bind to a specific interface. This only matters if
  544. * there is more then one interface in a system, so
  545. * in this case, only a warning is printed
  546. */
  547. /*
  548. * Join multicast group and setup delivery
  549. * and configuration change functions
  550. */
  551. totempg_initialize (
  552. aisexec_poll_handle,
  553. &totem_config);
  554. totempg_groups_initialize (
  555. &corosync_group_handle,
  556. deliver_fn,
  557. confchg_fn);
  558. totempg_groups_join (
  559. corosync_group_handle,
  560. &corosync_group,
  561. 1);
  562. /*
  563. * This must occur after totempg is initialized because "this_ip" must be set
  564. */
  565. res = corosync_service_defaults_link_and_init (api);
  566. if (res == -1) {
  567. log_printf (LOG_LEVEL_ERROR, "Could not initialize default services\n");
  568. corosync_exit_error (AIS_DONE_INIT_SERVICES);
  569. }
  570. sync_register (corosync_sync_callbacks_retrieve, corosync_sync_completed);
  571. res = cs_flow_control_initialize ();
  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 (
  583. serialize_mutex_lock,
  584. serialize_mutex_unlock,
  585. main_config.gid);
  586. /*
  587. * Start main processing loop
  588. */
  589. poll_run (aisexec_poll_handle);
  590. return EXIT_SUCCESS;
  591. }