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