main.c 18 KB

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