main.c 19 KB

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