main.c 19 KB

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