main.c 19 KB

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