main.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. /*
  2. * Copyright (c) 2002-2006 MontaVista Software, Inc.
  3. * Copyright (c) 2006 Red Hat, Inc.
  4. * Copyright (c) 2006 Sun Microsystems, Inc.
  5. *
  6. * All rights reserved.
  7. *
  8. * Author: Steven Dake (sdake@redhat.com)
  9. *
  10. * This software licensed under BSD license, the text of which follows:
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * - Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  21. * contributors may be used to endorse or promote products derived from this
  22. * software without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  28. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  30. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  31. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  32. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  33. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  34. * THE POSSIBILITY OF SUCH DAMAGE.
  35. */
  36. #include <pthread.h>
  37. #include <assert.h>
  38. #include <pwd.h>
  39. #include <grp.h>
  40. #include <sys/types.h>
  41. #include <sys/poll.h>
  42. #include <sys/uio.h>
  43. #include <sys/mman.h>
  44. #include <sys/socket.h>
  45. #include <sys/un.h>
  46. #include <sys/time.h>
  47. #include <sys/resource.h>
  48. #include <netinet/in.h>
  49. #include <arpa/inet.h>
  50. #include <unistd.h>
  51. #include <fcntl.h>
  52. #include <stdlib.h>
  53. #include <stdio.h>
  54. #include <errno.h>
  55. #include <signal.h>
  56. #include <sched.h>
  57. #include <time.h>
  58. #include "swab.h"
  59. #include "../include/saAis.h"
  60. #include "../include/list.h"
  61. #include "../include/queue.h"
  62. #include "../lcr/lcr_ifact.h"
  63. #include "poll.h"
  64. #include "totempg.h"
  65. #include "totemsrp.h"
  66. #include "mempool.h"
  67. #include "mainconfig.h"
  68. #include "totemconfig.h"
  69. #include "main.h"
  70. #include "service.h"
  71. #include "sync.h"
  72. #include "swab.h"
  73. #include "objdb.h"
  74. #include "config.h"
  75. #include "tlist.h"
  76. #include "flow.h"
  77. #include "ipc.h"
  78. #include "timer.h"
  79. #include "logsys.h"
  80. #include "util.h"
  81. #include "flow.h"
  82. #include "version.h"
  83. LOGSYS_DECLARE_SYSTEM ("openais",
  84. LOG_MODE_OUTPUT_STDERR | LOG_MODE_OUTPUT_SYSLOG_THREADED | LOG_MODE_DISPLAY_DEBUG | LOG_MODE_BUFFER_BEFORE_CONFIG,
  85. NULL,
  86. LOG_DAEMON);
  87. LOGSYS_DECLARE_SUBSYS ("MAIN", LOG_INFO);
  88. #define SERVER_BACKLOG 5
  89. static int ais_uid = 0;
  90. static int gid_valid = 0;
  91. static unsigned int service_count = 32;
  92. static pthread_mutex_t serialize_mutex = PTHREAD_MUTEX_INITIALIZER;
  93. static struct totem_logging_configuration totem_logging_configuration;
  94. static char delivery_data[MESSAGE_SIZE_MAX];
  95. static int num_config_modules;
  96. static struct config_iface_ver0 *config_modules[MAX_DYNAMIC_SERVICES];
  97. static struct objdb_iface_ver0 *objdb = NULL;
  98. SaClmClusterNodeT *(*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(objdb) {
  111. openais_service_unlink_all (objdb);
  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 lpc, fd;
  266. struct rlimit oflimits;
  267. /*
  268. * Disconnect from TTY if this is not a debug run
  269. */
  270. switch (fork ()) {
  271. case -1:
  272. openais_exit_error (AIS_DONE_FORK);
  273. break;
  274. case 0:
  275. /*
  276. * child which is disconnected, run this process
  277. */
  278. /* setset(); */
  279. close (0);
  280. close (1);
  281. close (2);
  282. break;
  283. default:
  284. exit (0);
  285. break;
  286. }
  287. /* Create new session */
  288. setsid();
  289. /*
  290. * Map stdin/out/err to /dev/null.
  291. */
  292. fd = open("/dev/null", O_RDWR);
  293. if (fd >= 0) {
  294. /* dup2 to 0 / 1 / 2 (stdin / stdout / stderr) */
  295. dup2(fd, STDIN_FILENO); /* 0 */
  296. dup2(fd, STDOUT_FILENO); /* 1 */
  297. dup2(fd, STDERR_FILENO); /* 2 */
  298. /* Should be 0, but just in case it isn't... */
  299. if (fd > 2)
  300. close(fd);
  301. }
  302. }
  303. static void aisexec_setscheduler (void)
  304. {
  305. #if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS))
  306. struct sched_param sched_param;
  307. int res;
  308. res = sched_get_priority_max (SCHED_RR);
  309. if (res != -1) {
  310. sched_param.sched_priority = 1;//res;
  311. res = sched_setscheduler (0, SCHED_RR, &sched_param);
  312. if (res == -1) {
  313. log_printf (LOG_LEVEL_WARNING, "Could not set SCHED_RR at priority %d: %s\n",
  314. sched_param.sched_priority, strerror (errno));
  315. }
  316. } else
  317. log_printf (LOG_LEVEL_WARNING, "Could not get maximum scheduler priority: %s\n", strerror (errno));
  318. #else
  319. log_printf(LOG_LEVEL_WARNING, "Scheduler priority left to default value (no OS support)\n");
  320. #endif
  321. }
  322. static void aisexec_mlockall (void)
  323. {
  324. #if !defined(OPENAIS_BSD)
  325. int res;
  326. #endif
  327. struct rlimit rlimit;
  328. rlimit.rlim_cur = RLIM_INFINITY;
  329. rlimit.rlim_max = RLIM_INFINITY;
  330. #ifndef OPENAIS_SOLARIS
  331. setrlimit (RLIMIT_MEMLOCK, &rlimit);
  332. #else
  333. setrlimit (RLIMIT_VMEM, &rlimit);
  334. #endif
  335. #if defined(OPENAIS_BSD)
  336. /* under FreeBSD a process with locked page cannot call dlopen
  337. * code disabled until FreeBSD bug i386/93396 was solved
  338. */
  339. log_printf (LOG_LEVEL_WARNING, "Could not lock memory of service to avoid page faults\n");
  340. #else
  341. res = mlockall (MCL_CURRENT | MCL_FUTURE);
  342. if (res == -1) {
  343. log_printf (LOG_LEVEL_WARNING, "Could not lock memory of service to avoid page faults: %s\n", strerror (errno));
  344. };
  345. #endif
  346. }
  347. static void deliver_fn (
  348. unsigned int nodeid,
  349. struct iovec *iovec,
  350. int iov_len,
  351. int endian_conversion_required)
  352. {
  353. mar_req_header_t *header;
  354. int pos = 0;
  355. int i;
  356. int service;
  357. int fn_id;
  358. /*
  359. * Build buffer without iovecs to make processing easier
  360. * This is only used for messages which are multicast with iovecs
  361. * and self-delivered. All other mechanisms avoid the copy.
  362. */
  363. if (iov_len > 1) {
  364. for (i = 0; i < iov_len; i++) {
  365. memcpy (&delivery_data[pos], iovec[i].iov_base, iovec[i].iov_len);
  366. pos += iovec[i].iov_len;
  367. assert (pos < MESSAGE_SIZE_MAX);
  368. }
  369. header = (mar_req_header_t *)delivery_data;
  370. } else {
  371. header = (mar_req_header_t *)iovec[0].iov_base;
  372. }
  373. if (endian_conversion_required) {
  374. header->id = swab32 (header->id);
  375. header->size = swab32 (header->size);
  376. }
  377. // assert(iovec->iov_len == header->size);
  378. /*
  379. * Call the proper executive handler
  380. */
  381. service = header->id >> 16;
  382. fn_id = header->id & 0xffff;
  383. if (endian_conversion_required) {
  384. assert(ais_service[service]->exec_service[fn_id].exec_endian_convert_fn != NULL);
  385. ais_service[service]->exec_service[fn_id].exec_endian_convert_fn
  386. (header);
  387. }
  388. ais_service[service]->exec_service[fn_id].exec_handler_fn
  389. (header, nodeid);
  390. }
  391. void main_get_config_modules(struct config_iface_ver0 ***modules, int *num)
  392. {
  393. *modules = config_modules;
  394. *num = num_config_modules;
  395. }
  396. int main (int argc, char **argv)
  397. {
  398. char *error_string;
  399. struct main_config main_config;
  400. struct totem_config totem_config;
  401. unsigned int objdb_handle;
  402. unsigned int config_handle;
  403. unsigned int config_version = 0;
  404. void *objdb_p;
  405. struct config_iface_ver0 *config;
  406. void *config_p;
  407. char *config_iface;
  408. char *iface;
  409. int res, ch;
  410. int background, setprio;
  411. int totem_log_service;
  412. /* default configuration
  413. */
  414. background = 1;
  415. setprio = 1;
  416. while ((ch = getopt (argc, argv, "fp")) != EOF) {
  417. switch (ch) {
  418. case 'f':
  419. background = 0;
  420. logsys_config_mode_set (LOG_MODE_OUTPUT_STDERR|LOG_MODE_FLUSH_AFTER_CONFIG);
  421. break;
  422. case 'p':
  423. setprio = 0;
  424. break;
  425. default:
  426. fprintf(stderr, \
  427. "usage:\n"\
  428. " -f : Start application in foreground.\n"\
  429. " -p : Do not set process priority. \n");
  430. return EXIT_FAILURE;
  431. }
  432. }
  433. if (background)
  434. aisexec_tty_detach ();
  435. log_printf (LOG_LEVEL_NOTICE, "AIS Executive Service RELEASE '%s'\n", RELEASE_VERSION);
  436. log_printf (LOG_LEVEL_NOTICE, "Copyright (C) 2002-2006 MontaVista Software, Inc and contributors.\n");
  437. log_printf (LOG_LEVEL_NOTICE, "Copyright (C) 2006-2007 Red Hat, Inc.\n");
  438. signal (SIGINT, sigintr_handler);
  439. signal (SIGUSR2, sigusr2_handler);
  440. signal (SIGSEGV, sigsegv_handler);
  441. signal (SIGABRT, sigabrt_handler);
  442. signal (SIGQUIT, sigquit_handler);
  443. openais_timer_init (
  444. serialize_mutex_lock,
  445. serialize_mutex_unlock);
  446. log_printf (LOG_LEVEL_NOTICE, "AIS Executive Service: started and ready to provide service.\n");
  447. aisexec_poll_handle = poll_create (
  448. serialize_mutex_lock,
  449. serialize_mutex_unlock);
  450. /*
  451. * Load the object database interface
  452. */
  453. res = lcr_ifact_reference (
  454. &objdb_handle,
  455. "objdb",
  456. 0,
  457. &objdb_p,
  458. 0);
  459. if (res == -1) {
  460. log_printf (LOG_LEVEL_ERROR, "AIS Executive couldn't open configuration object database component.\n");
  461. openais_exit_error (AIS_DONE_OBJDB);
  462. }
  463. objdb = (struct objdb_iface_ver0 *)objdb_p;
  464. objdb->objdb_init ();
  465. num_config_modules = 0;
  466. /*
  467. * Bootstrap in the default configuration parser or use
  468. * the openais default built in parser if the configuration parser
  469. * isn't overridden
  470. */
  471. config_iface = getenv("OPENAIS_DEFAULT_CONFIG_IFACE");
  472. if (!config_iface) {
  473. config_iface = "aisparser";
  474. }
  475. /* Make a copy so we can deface it with strtok */
  476. config_iface = strdup(config_iface);
  477. iface = strtok(config_iface, ":");
  478. while (iface)
  479. {
  480. res = lcr_ifact_reference (
  481. &config_handle,
  482. iface,
  483. config_version,
  484. &config_p,
  485. 0);
  486. config = (struct config_iface_ver0 *)config_p;
  487. if (res == -1) {
  488. log_printf (LOG_LEVEL_ERROR, "AIS Executive couldn't open configuration component '%s'\n", iface);
  489. openais_exit_error (AIS_DONE_MAINCONFIGREAD);
  490. }
  491. res = config->config_readconfig(objdb, &error_string);
  492. if (res == -1) {
  493. log_printf (LOG_LEVEL_ERROR, error_string);
  494. openais_exit_error (AIS_DONE_MAINCONFIGREAD);
  495. }
  496. log_printf (LOG_LEVEL_NOTICE, error_string);
  497. config_modules[num_config_modules++] = config;
  498. iface = strtok(NULL, ":");
  499. }
  500. if (config_iface)
  501. free(config_iface);
  502. res = openais_main_config_read (objdb, &error_string, &main_config);
  503. if (res == -1) {
  504. log_printf (LOG_LEVEL_ERROR, error_string);
  505. openais_exit_error (AIS_DONE_MAINCONFIGREAD);
  506. }
  507. res = totem_config_read (objdb, &totem_config, &error_string);
  508. if (res == -1) {
  509. log_printf (LOG_LEVEL_ERROR, error_string);
  510. openais_exit_error (AIS_DONE_MAINCONFIGREAD);
  511. }
  512. res = totem_config_keyread (objdb, &totem_config, &error_string);
  513. if (res == -1) {
  514. log_printf (LOG_LEVEL_ERROR, error_string);
  515. openais_exit_error (AIS_DONE_MAINCONFIGREAD);
  516. }
  517. res = totem_config_validate (&totem_config, &error_string);
  518. if (res == -1) {
  519. log_printf (LOG_LEVEL_ERROR, error_string);
  520. openais_exit_error (AIS_DONE_MAINCONFIGREAD);
  521. }
  522. logsys_config_facility_set ("openais", main_config.syslog_facility);
  523. logsys_config_mode_set (main_config.logmode);
  524. logsys_config_file_set (&error_string, main_config.logfile);
  525. aisexec_uid_determine (&main_config);
  526. aisexec_gid_determine (&main_config);
  527. /*
  528. * Set round robin realtime scheduling with priority 99
  529. * Lock all memory to avoid page faults which may interrupt
  530. * application healthchecking
  531. */
  532. if (setprio)
  533. aisexec_setscheduler ();
  534. aisexec_mlockall ();
  535. totem_config.totem_logging_configuration = totem_logging_configuration;
  536. totem_log_service = _logsys_subsys_create ("TOTEM", LOG_INFO);
  537. totem_config.totem_logging_configuration.log_level_security = logsys_mkpri (LOG_LEVEL_SECURITY, totem_log_service);
  538. totem_config.totem_logging_configuration.log_level_error = logsys_mkpri (LOG_LEVEL_ERROR, totem_log_service);
  539. totem_config.totem_logging_configuration.log_level_warning = logsys_mkpri (LOG_LEVEL_WARNING, totem_log_service);
  540. totem_config.totem_logging_configuration.log_level_notice = logsys_mkpri (LOG_LEVEL_NOTICE, totem_log_service);
  541. totem_config.totem_logging_configuration.log_level_debug = logsys_mkpri (LOG_LEVEL_DEBUG, totem_log_service);
  542. totem_config.totem_logging_configuration.log_printf = logsys_log_printf;
  543. /*
  544. * Sleep for a while to let other nodes in the cluster
  545. * understand that this node has been away (if it was
  546. * an aisexec restart).
  547. */
  548. // TODO what is this hack for? usleep(totem_config.token_timeout * 2000);
  549. /*
  550. * if totempg_initialize doesn't have root priveleges, it cannot
  551. * bind to a specific interface. This only matters if
  552. * there is more then one interface in a system, so
  553. * in this case, only a warning is printed
  554. */
  555. /*
  556. * Join multicast group and setup delivery
  557. * and configuration change functions
  558. */
  559. totempg_initialize (
  560. aisexec_poll_handle,
  561. &totem_config);
  562. totempg_groups_initialize (
  563. &openais_group_handle,
  564. deliver_fn,
  565. confchg_fn);
  566. totempg_groups_join (
  567. openais_group_handle,
  568. &openais_group,
  569. 1);
  570. /*
  571. * This must occur after totempg is initialized because "this_ip" must be set
  572. */
  573. res = openais_service_defaults_link_and_init (objdb);
  574. if (res == -1) {
  575. log_printf (LOG_LEVEL_ERROR, "Could not initialize default services\n");
  576. openais_exit_error (AIS_DONE_INIT_SERVICES);
  577. }
  578. sync_register (openais_sync_callbacks_retrieve, openais_sync_completed,
  579. totem_config.vsf_type);
  580. res = openais_flow_control_initialize ();
  581. /*
  582. * Drop root privleges to user 'ais'
  583. * TODO: Don't really need full root capabilities;
  584. * needed capabilities are:
  585. * CAP_NET_RAW (bindtodevice)
  586. * CAP_SYS_NICE (setscheduler)
  587. * CAP_IPC_LOCK (mlockall)
  588. */
  589. aisexec_priv_drop ();
  590. aisexec_mempool_init ();
  591. openais_ipc_init (
  592. serialize_mutex_lock,
  593. serialize_mutex_unlock,
  594. gid_valid);
  595. /*
  596. * Start main processing loop
  597. */
  598. poll_run (aisexec_poll_handle);
  599. return EXIT_SUCCESS;
  600. }