main.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  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. NULL,
  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. hdb_handle_t corosync_poll_handle;
  97. static void sigusr2_handler (int num)
  98. {
  99. int i;
  100. for (i = 0; ais_service[i]; i++) {
  101. if (ais_service[i]->exec_dump_fn) {
  102. ais_service[i]->exec_dump_fn ();
  103. }
  104. }
  105. }
  106. static void *corosync_exit (void *arg)
  107. {
  108. if (api) {
  109. corosync_service_unlink_all (api);
  110. }
  111. #ifdef DEBUG_MEMPOOL
  112. int stats_inuse[MEMPOOL_GROUP_SIZE];
  113. int stats_avail[MEMPOOL_GROUP_SIZE];
  114. int stats_memoryused[MEMPOOL_GROUP_SIZE];
  115. int i;
  116. mempool_getstats (stats_inuse, stats_avail, stats_memoryused);
  117. log_printf (LOG_LEVEL_DEBUG, "Memory pools:\n");
  118. for (i = 0; i < MEMPOOL_GROUP_SIZE; i++) {
  119. log_printf (LOG_LEVEL_DEBUG, "order %d size %d inuse %d avail %d memory used %d\n",
  120. i, 1<<i, stats_inuse[i], stats_avail[i], stats_memoryused[i]);
  121. }
  122. #endif
  123. poll_stop (0);
  124. totempg_finalize ();
  125. cs_ipc_exit ();
  126. corosync_exit_error (AIS_DONE_EXIT);
  127. /* never reached */
  128. return NULL;
  129. }
  130. pthread_t corosync_exit_thread;
  131. static void init_shutdown(void *data)
  132. {
  133. pthread_create (&corosync_exit_thread, NULL, corosync_exit, NULL);
  134. }
  135. static poll_timer_handle shutdown_handle;
  136. static void sigquit_handler (int num)
  137. {
  138. /* avoid creating threads from within the interrupt context */
  139. poll_timer_add (corosync_poll_handle, 500, NULL, init_shutdown, &shutdown_handle);
  140. }
  141. static void sigsegv_handler (int num)
  142. {
  143. (void)signal (SIGSEGV, SIG_DFL);
  144. logsys_atsegv();
  145. logsys_log_rec_store (LOCALSTATEDIR "/lib/corosync/fdata");
  146. raise (SIGSEGV);
  147. }
  148. static void sigabrt_handler (int num)
  149. {
  150. (void)signal (SIGABRT, SIG_DFL);
  151. logsys_atsegv();
  152. logsys_log_rec_store (LOCALSTATEDIR "/lib/corosync/fdata");
  153. raise (SIGABRT);
  154. }
  155. #define LOCALHOST_IP inet_addr("127.0.0.1")
  156. hdb_handle_t corosync_group_handle;
  157. struct totempg_group corosync_group = {
  158. .group = "a",
  159. .group_len = 1
  160. };
  161. void sigintr_handler (int signum)
  162. {
  163. poll_timer_add (corosync_poll_handle, 500, NULL, init_shutdown, &shutdown_handle);
  164. }
  165. static int pool_sizes[] = { 0, 0, 0, 0, 0, 4096, 0, 1, 0, /* 256 */
  166. 1024, 0, 1, 4096, 0, 0, 0, 0, /* 65536 */
  167. 1, 1, 1, 1, 1, 1, 1, 1, 1 };
  168. void serialize_mutex_lock (void)
  169. {
  170. pthread_mutex_lock (&serialize_mutex);
  171. }
  172. void serialize_mutex_unlock (void)
  173. {
  174. pthread_mutex_unlock (&serialize_mutex);
  175. }
  176. static void corosync_sync_completed (void)
  177. {
  178. }
  179. static int corosync_sync_callbacks_retrieve (int sync_id,
  180. struct sync_callbacks *callbacks)
  181. {
  182. unsigned int ais_service_index;
  183. unsigned int ais_services_found = 0;
  184. for (ais_service_index = 0;
  185. ais_service_index < SERVICE_HANDLER_MAXIMUM_COUNT;
  186. ais_service_index++) {
  187. if (ais_service[ais_service_index] != NULL) {
  188. if (ais_services_found == sync_id) {
  189. break;
  190. }
  191. ais_services_found += 1;
  192. }
  193. }
  194. if (ais_service_index == SERVICE_HANDLER_MAXIMUM_COUNT) {
  195. memset (callbacks, 0, sizeof (struct sync_callbacks));
  196. return (-1);
  197. }
  198. callbacks->name = ais_service[ais_service_index]->name;
  199. callbacks->sync_init = ais_service[ais_service_index]->sync_init;
  200. callbacks->sync_process = ais_service[ais_service_index]->sync_process;
  201. callbacks->sync_activate = ais_service[ais_service_index]->sync_activate;
  202. callbacks->sync_abort = ais_service[ais_service_index]->sync_abort;
  203. return (0);
  204. }
  205. static struct memb_ring_id corosync_ring_id;
  206. static void confchg_fn (
  207. enum totem_configuration_type configuration_type,
  208. unsigned int *member_list, int member_list_entries,
  209. unsigned int *left_list, int left_list_entries,
  210. unsigned int *joined_list, int joined_list_entries,
  211. struct memb_ring_id *ring_id)
  212. {
  213. int i;
  214. memcpy (&corosync_ring_id, ring_id, sizeof (struct memb_ring_id));
  215. /*
  216. * Call configuration change for all services
  217. */
  218. for (i = 0; i < service_count; i++) {
  219. if (ais_service[i] && ais_service[i]->confchg_fn) {
  220. ais_service[i]->confchg_fn (configuration_type,
  221. member_list, member_list_entries,
  222. left_list, left_list_entries,
  223. joined_list, joined_list_entries, ring_id);
  224. }
  225. }
  226. }
  227. static void priv_drop (struct main_config *main_config)
  228. {
  229. return; /* TODO: we are still not dropping privs */
  230. setuid (main_config->uid);
  231. setegid (main_config->gid);
  232. }
  233. static void corosync_mempool_init (void)
  234. {
  235. int res;
  236. res = mempool_init (pool_sizes);
  237. if (res == ENOMEM) {
  238. log_printf (LOG_LEVEL_ERROR, "Couldn't allocate memory pools, not enough memory");
  239. corosync_exit_error (AIS_DONE_MEMPOOL_INIT);
  240. }
  241. }
  242. static void corosync_tty_detach (void)
  243. {
  244. int fd;
  245. /*
  246. * Disconnect from TTY if this is not a debug run
  247. */
  248. switch (fork ()) {
  249. case -1:
  250. corosync_exit_error (AIS_DONE_FORK);
  251. break;
  252. case 0:
  253. /*
  254. * child which is disconnected, run this process
  255. */
  256. /* setset();
  257. close (0);
  258. close (1);
  259. close (2);
  260. */
  261. break;
  262. default:
  263. exit (0);
  264. break;
  265. }
  266. /* Create new session */
  267. (void)setsid();
  268. /*
  269. * Map stdin/out/err to /dev/null.
  270. */
  271. fd = open("/dev/null", O_RDWR);
  272. if (fd >= 0) {
  273. /* dup2 to 0 / 1 / 2 (stdin / stdout / stderr) */
  274. dup2(fd, STDIN_FILENO); /* 0 */
  275. dup2(fd, STDOUT_FILENO); /* 1 */
  276. dup2(fd, STDERR_FILENO); /* 2 */
  277. /* Should be 0, but just in case it isn't... */
  278. if (fd > 2)
  279. close(fd);
  280. }
  281. }
  282. static void corosync_setscheduler (void)
  283. {
  284. #if ! defined(TS_CLASS) && (defined(COROSYNC_BSD) || defined(COROSYNC_LINUX) || defined(COROSYNC_SOLARIS))
  285. struct sched_param sched_param;
  286. int res;
  287. res = sched_get_priority_max (SCHED_RR);
  288. if (res != -1) {
  289. sched_param.sched_priority = 1;//res;
  290. res = sched_setscheduler (0, SCHED_RR, &sched_param);
  291. if (res == -1) {
  292. log_printf (LOG_LEVEL_WARNING, "Could not set SCHED_RR at priority %d: %s\n",
  293. sched_param.sched_priority, strerror (errno));
  294. }
  295. } else
  296. log_printf (LOG_LEVEL_WARNING, "Could not get maximum scheduler priority: %s\n", strerror (errno));
  297. #else
  298. log_printf(LOG_LEVEL_WARNING, "Scheduler priority left to default value (no OS support)\n");
  299. #endif
  300. }
  301. static void corosync_mlockall (void)
  302. {
  303. #if !defined(COROSYNC_BSD)
  304. int res;
  305. #endif
  306. struct rlimit rlimit;
  307. rlimit.rlim_cur = RLIM_INFINITY;
  308. rlimit.rlim_max = RLIM_INFINITY;
  309. #ifndef COROSYNC_SOLARIS
  310. setrlimit (RLIMIT_MEMLOCK, &rlimit);
  311. #else
  312. setrlimit (RLIMIT_VMEM, &rlimit);
  313. #endif
  314. #if defined(COROSYNC_BSD)
  315. /* under FreeBSD a process with locked page cannot call dlopen
  316. * code disabled until FreeBSD bug i386/93396 was solved
  317. */
  318. log_printf (LOG_LEVEL_WARNING, "Could not lock memory of service to avoid page faults\n");
  319. #else
  320. res = mlockall (MCL_CURRENT | MCL_FUTURE);
  321. if (res == -1) {
  322. log_printf (LOG_LEVEL_WARNING, "Could not lock memory of service to avoid page faults: %s\n", strerror (errno));
  323. };
  324. #endif
  325. }
  326. static void deliver_fn (
  327. unsigned int nodeid,
  328. struct iovec *iovec,
  329. int iov_len,
  330. int endian_conversion_required)
  331. {
  332. mar_req_header_t *header;
  333. int pos = 0;
  334. int i;
  335. int service;
  336. int fn_id;
  337. /*
  338. * Build buffer without iovecs to make processing easier
  339. * This is only used for messages which are multicast with iovecs
  340. * and self-delivered. All other mechanisms avoid the copy.
  341. */
  342. if (iov_len > 1) {
  343. for (i = 0; i < iov_len; i++) {
  344. memcpy (&delivery_data[pos], iovec[i].iov_base, iovec[i].iov_len);
  345. pos += iovec[i].iov_len;
  346. assert (pos < MESSAGE_SIZE_MAX);
  347. }
  348. header = (mar_req_header_t *)delivery_data;
  349. } else {
  350. header = (mar_req_header_t *)iovec[0].iov_base;
  351. }
  352. if (endian_conversion_required) {
  353. header->id = swab32 (header->id);
  354. header->size = swab32 (header->size);
  355. }
  356. // assert(iovec->iov_len == header->size);
  357. /*
  358. * Call the proper executive handler
  359. */
  360. service = header->id >> 16;
  361. fn_id = header->id & 0xffff;
  362. if (!ais_service[service])
  363. return;
  364. if (endian_conversion_required) {
  365. assert(ais_service[service]->exec_engine[fn_id].exec_endian_convert_fn != NULL);
  366. ais_service[service]->exec_engine[fn_id].exec_endian_convert_fn
  367. (header);
  368. }
  369. ais_service[service]->exec_engine[fn_id].exec_handler_fn
  370. (header, nodeid);
  371. }
  372. void main_get_config_modules(struct config_iface_ver0 ***modules, int *num)
  373. {
  374. *modules = config_modules;
  375. *num = num_config_modules;
  376. }
  377. int main_mcast (
  378. struct iovec *iovec,
  379. int iov_len,
  380. unsigned int guarantee)
  381. {
  382. return (totempg_groups_mcast_joined (corosync_group_handle, iovec, iov_len, guarantee));
  383. }
  384. int main (int argc, char **argv)
  385. {
  386. const char *error_string;
  387. struct main_config main_config;
  388. struct totem_config totem_config;
  389. hdb_handle_t objdb_handle;
  390. hdb_handle_t config_handle;
  391. unsigned int config_version = 0;
  392. void *objdb_p;
  393. struct config_iface_ver0 *config;
  394. void *config_p;
  395. const char *config_iface;
  396. char *iface;
  397. int res, ch;
  398. int background, setprio;
  399. /* default configuration
  400. */
  401. background = 1;
  402. setprio = 1;
  403. while ((ch = getopt (argc, argv, "fp")) != EOF) {
  404. switch (ch) {
  405. case 'f':
  406. background = 0;
  407. logsys_config_mode_set (LOG_MODE_OUTPUT_STDERR|LOG_MODE_THREADED|LOG_MODE_FORK);
  408. break;
  409. case 'p':
  410. setprio = 0;
  411. break;
  412. default:
  413. fprintf(stderr, \
  414. "usage:\n"\
  415. " -f : Start application in foreground.\n"\
  416. " -p : Do not set process priority. \n");
  417. return EXIT_FAILURE;
  418. }
  419. }
  420. if (background)
  421. corosync_tty_detach ();
  422. log_printf (LOG_LEVEL_NOTICE, "Corosync Executive Service RELEASE '%s'\n", RELEASE_VERSION);
  423. log_printf (LOG_LEVEL_NOTICE, "Copyright (C) 2002-2006 MontaVista Software, Inc and contributors.\n");
  424. log_printf (LOG_LEVEL_NOTICE, "Copyright (C) 2006-2008 Red Hat, Inc.\n");
  425. (void)signal (SIGINT, sigintr_handler);
  426. (void)signal (SIGUSR2, sigusr2_handler);
  427. (void)signal (SIGSEGV, sigsegv_handler);
  428. (void)signal (SIGABRT, sigabrt_handler);
  429. (void)signal (SIGQUIT, sigquit_handler);
  430. corosync_timer_init (
  431. serialize_mutex_lock,
  432. serialize_mutex_unlock);
  433. log_printf (LOG_LEVEL_NOTICE, "Corosync Executive Service: started and ready to provide service.\n");
  434. corosync_poll_handle = poll_create (
  435. serialize_mutex_lock,
  436. serialize_mutex_unlock);
  437. /*
  438. * Load the object database interface
  439. */
  440. res = lcr_ifact_reference (
  441. &objdb_handle,
  442. "objdb",
  443. 0,
  444. &objdb_p,
  445. 0);
  446. if (res == -1) {
  447. log_printf (LOG_LEVEL_ERROR, "Corosync Executive couldn't open configuration object database component.\n");
  448. corosync_exit_error (AIS_DONE_OBJDB);
  449. }
  450. objdb = (struct objdb_iface_ver0 *)objdb_p;
  451. objdb->objdb_init ();
  452. /*
  453. * Initialize the corosync_api_v1 definition
  454. */
  455. apidef_init (objdb);
  456. api = apidef_get ();
  457. num_config_modules = 0;
  458. /*
  459. * Bootstrap in the default configuration parser or use
  460. * the corosync default built in parser if the configuration parser
  461. * isn't overridden
  462. */
  463. config_iface = getenv("COROSYNC_DEFAULT_CONFIG_IFACE");
  464. if (!config_iface) {
  465. config_iface = "corosync_parser";
  466. }
  467. /* Make a copy so we can deface it with strtok */
  468. config_iface = strdup(config_iface);
  469. iface = strtok(config_iface, ":");
  470. while (iface)
  471. {
  472. res = lcr_ifact_reference (
  473. &config_handle,
  474. iface,
  475. config_version,
  476. &config_p,
  477. 0);
  478. config = (struct config_iface_ver0 *)config_p;
  479. if (res == -1) {
  480. log_printf (LOG_LEVEL_ERROR, "Corosync Executive couldn't open configuration component '%s'\n", iface);
  481. corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
  482. }
  483. res = config->config_readconfig(objdb, &error_string);
  484. if (res == -1) {
  485. log_printf (LOG_LEVEL_ERROR, "%s", error_string);
  486. corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
  487. }
  488. log_printf (LOG_LEVEL_NOTICE, "%s", error_string);
  489. config_modules[num_config_modules++] = config;
  490. iface = strtok(NULL, ":");
  491. }
  492. if (config_iface)
  493. free(config_iface);
  494. res = corosync_main_config_read (objdb, &error_string, &main_config);
  495. if (res == -1) {
  496. log_printf (LOG_LEVEL_ERROR, "%s", error_string);
  497. corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
  498. }
  499. res = totem_config_read (objdb, &totem_config, &error_string);
  500. if (res == -1) {
  501. log_printf (LOG_LEVEL_ERROR, "%s", error_string);
  502. corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
  503. }
  504. res = totem_config_keyread (objdb, &totem_config, &error_string);
  505. if (res == -1) {
  506. log_printf (LOG_LEVEL_ERROR, "%s", error_string);
  507. corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
  508. }
  509. res = totem_config_validate (&totem_config, &error_string);
  510. if (res == -1) {
  511. log_printf (LOG_LEVEL_ERROR, "%s", error_string);
  512. corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
  513. }
  514. /*
  515. * Set round robin realtime scheduling with priority 99
  516. * Lock all memory to avoid page faults which may interrupt
  517. * application healthchecking
  518. */
  519. if (setprio)
  520. corosync_setscheduler ();
  521. corosync_mlockall ();
  522. totem_config.totem_logging_configuration = totem_logging_configuration;
  523. totem_config.totem_logging_configuration.log_subsys_id =
  524. _logsys_subsys_create ("TOTEM", LOG_INFO);
  525. totem_config.totem_logging_configuration.log_level_security = LOG_LEVEL_SECURITY;
  526. totem_config.totem_logging_configuration.log_level_error = LOG_LEVEL_ERROR;
  527. totem_config.totem_logging_configuration.log_level_warning = LOG_LEVEL_WARNING;
  528. totem_config.totem_logging_configuration.log_level_notice = LOG_LEVEL_NOTICE;
  529. totem_config.totem_logging_configuration.log_level_debug = LOG_LEVEL_DEBUG;
  530. totem_config.totem_logging_configuration.log_printf = _logsys_log_printf;
  531. /*
  532. * Sleep for a while to let other nodes in the cluster
  533. * understand that this node has been away (if it was
  534. * an corosync restart).
  535. */
  536. // TODO what is this hack for? usleep(totem_config.token_timeout * 2000);
  537. /*
  538. * if totempg_initialize doesn't have root priveleges, it cannot
  539. * bind to a specific interface. This only matters if
  540. * there is more then one interface in a system, so
  541. * in this case, only a warning is printed
  542. */
  543. /*
  544. * Join multicast group and setup delivery
  545. * and configuration change functions
  546. */
  547. totempg_initialize (
  548. corosync_poll_handle,
  549. &totem_config);
  550. totempg_groups_initialize (
  551. &corosync_group_handle,
  552. deliver_fn,
  553. confchg_fn);
  554. totempg_groups_join (
  555. corosync_group_handle,
  556. &corosync_group,
  557. 1);
  558. /*
  559. * This must occur after totempg is initialized because "this_ip" must be set
  560. */
  561. res = corosync_service_defaults_link_and_init (api);
  562. if (res == -1) {
  563. log_printf (LOG_LEVEL_ERROR, "Could not initialize default services\n");
  564. corosync_exit_error (AIS_DONE_INIT_SERVICES);
  565. }
  566. sync_register (corosync_sync_callbacks_retrieve, corosync_sync_completed);
  567. /*
  568. * Drop root privleges to user 'ais'
  569. * TODO: Don't really need full root capabilities;
  570. * needed capabilities are:
  571. * CAP_NET_RAW (bindtodevice)
  572. * CAP_SYS_NICE (setscheduler)
  573. * CAP_IPC_LOCK (mlockall)
  574. */
  575. priv_drop (&main_config);
  576. corosync_mempool_init ();
  577. cs_ipc_init (main_config.gid,
  578. serialize_mutex_lock,
  579. serialize_mutex_unlock);
  580. /*
  581. * Start main processing loop
  582. */
  583. poll_run (corosync_poll_handle);
  584. return EXIT_SUCCESS;
  585. }