main.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. /*
  2. * Copyright (c) 2002-2006 MontaVista Software, Inc.
  3. * Copyright (c) 2006-2008 Red Hat, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Author: Steven Dake (sdake@redhat.com)
  8. *
  9. * This software licensed under BSD license, the text of which follows:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. * - Redistributions in binary form must reproduce the above copyright notice,
  17. * this list of conditions and the following disclaimer in the documentation
  18. * and/or other materials provided with the distribution.
  19. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  33. * THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #include <pthread.h>
  36. #include <assert.h>
  37. #include <pwd.h>
  38. #include <grp.h>
  39. #include <sys/types.h>
  40. #include <sys/poll.h>
  41. #include <sys/uio.h>
  42. #include <sys/mman.h>
  43. #include <sys/socket.h>
  44. #include <sys/un.h>
  45. #include <sys/time.h>
  46. #include <sys/resource.h>
  47. #include <netinet/in.h>
  48. #include <arpa/inet.h>
  49. #include <unistd.h>
  50. #include <fcntl.h>
  51. #include <stdlib.h>
  52. #include <stdio.h>
  53. #include <errno.h>
  54. #include <signal.h>
  55. #include <sched.h>
  56. #include <time.h>
  57. #include <corosync/swab.h>
  58. #include <corosync/corotypes.h>
  59. #include <corosync/list.h>
  60. #include <corosync/queue.h>
  61. #include <corosync/lcr/lcr_ifact.h>
  62. #include <corosync/totem/coropoll.h>
  63. #include <corosync/totem/totempg.h>
  64. #include <corosync/engine/objdb.h>
  65. #include <corosync/engine/config.h>
  66. #include <corosync/engine/logsys.h>
  67. #include "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_THREADED | LOG_MODE_FORK,
  84. NULL,
  85. LOG_DAEMON,
  86. "[%6s] %b",
  87. 1000000);
  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. corosync_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. corosync_exit_error (AIS_DONE_EXIT);
  129. /* never reached */
  130. return NULL;
  131. }
  132. pthread_t aisexec_exit_thread;
  133. static void init_shutdown(void *data)
  134. {
  135. pthread_create (&aisexec_exit_thread, NULL, aisexec_exit, NULL);
  136. }
  137. static poll_timer_handle shutdown_handle;
  138. static void sigquit_handler (int num)
  139. {
  140. /* avoid creating threads from within the interrupt context */
  141. poll_timer_add (aisexec_poll_handle, 500, NULL, init_shutdown, &shutdown_handle);
  142. }
  143. static void sigsegv_handler (int num)
  144. {
  145. signal (SIGSEGV, SIG_DFL);
  146. logsys_atsegv();
  147. logsys_log_rec_store ("/var/lib/corosync/fdata");
  148. raise (SIGSEGV);
  149. }
  150. static void sigabrt_handler (int num)
  151. {
  152. signal (SIGABRT, SIG_DFL);
  153. logsys_atsegv();
  154. logsys_log_rec_store ("/var/lib/corosync/fdata");
  155. raise (SIGABRT);
  156. }
  157. #define LOCALHOST_IP inet_addr("127.0.0.1")
  158. totempg_groups_handle corosync_group_handle;
  159. struct totempg_group corosync_group = {
  160. .group = "a",
  161. .group_len = 1
  162. };
  163. void sigintr_handler (int signum)
  164. {
  165. poll_timer_add (aisexec_poll_handle, 500, NULL, init_shutdown, &shutdown_handle);
  166. }
  167. static int pool_sizes[] = { 0, 0, 0, 0, 0, 4096, 0, 1, 0, /* 256 */
  168. 1024, 0, 1, 4096, 0, 0, 0, 0, /* 65536 */
  169. 1, 1, 1, 1, 1, 1, 1, 1, 1 };
  170. void serialize_mutex_lock (void)
  171. {
  172. pthread_mutex_lock (&serialize_mutex);
  173. }
  174. void serialize_mutex_unlock (void)
  175. {
  176. pthread_mutex_unlock (&serialize_mutex);
  177. }
  178. static void corosync_sync_completed (void)
  179. {
  180. }
  181. static int corosync_sync_callbacks_retrieve (int sync_id,
  182. struct sync_callbacks *callbacks)
  183. {
  184. unsigned int ais_service_index;
  185. unsigned int ais_services_found = 0;
  186. for (ais_service_index = 0;
  187. ais_service_index < SERVICE_HANDLER_MAXIMUM_COUNT;
  188. ais_service_index++) {
  189. if (ais_service[ais_service_index] != NULL) {
  190. if (ais_services_found == sync_id) {
  191. break;
  192. }
  193. ais_services_found += 1;
  194. }
  195. }
  196. if (ais_service_index == SERVICE_HANDLER_MAXIMUM_COUNT) {
  197. memset (callbacks, 0, sizeof (struct sync_callbacks));
  198. return (-1);
  199. }
  200. callbacks->name = ais_service[ais_service_index]->name;
  201. callbacks->sync_init = ais_service[ais_service_index]->sync_init;
  202. callbacks->sync_process = ais_service[ais_service_index]->sync_process;
  203. callbacks->sync_activate = ais_service[ais_service_index]->sync_activate;
  204. callbacks->sync_abort = ais_service[ais_service_index]->sync_abort;
  205. return (0);
  206. }
  207. static struct memb_ring_id aisexec_ring_id;
  208. static void confchg_fn (
  209. enum totem_configuration_type configuration_type,
  210. unsigned int *member_list, int member_list_entries,
  211. unsigned int *left_list, int left_list_entries,
  212. unsigned int *joined_list, int joined_list_entries,
  213. struct memb_ring_id *ring_id)
  214. {
  215. int i;
  216. memcpy (&aisexec_ring_id, ring_id, sizeof (struct memb_ring_id));
  217. /*
  218. * Call configuration change for all services
  219. */
  220. for (i = 0; i < service_count; i++) {
  221. if (ais_service[i] && ais_service[i]->confchg_fn) {
  222. ais_service[i]->confchg_fn (configuration_type,
  223. member_list, member_list_entries,
  224. left_list, left_list_entries,
  225. joined_list, joined_list_entries, ring_id);
  226. }
  227. }
  228. }
  229. static void aisexec_uid_determine (struct main_config *main_config)
  230. {
  231. struct passwd *passwd;
  232. passwd = getpwnam(main_config->user);
  233. if (passwd == 0) {
  234. log_printf (LOG_LEVEL_ERROR, "ERROR: The '%s' user is not found in /etc/passwd, please read the documentation.\n", main_config->user);
  235. corosync_exit_error (AIS_DONE_UID_DETERMINE);
  236. }
  237. ais_uid = passwd->pw_uid;
  238. endpwent ();
  239. }
  240. static void aisexec_gid_determine (struct main_config *main_config)
  241. {
  242. struct group *group;
  243. group = getgrnam (main_config->group);
  244. if (group == 0) {
  245. log_printf (LOG_LEVEL_ERROR, "ERROR: The '%s' group is not found in /etc/group, please read the documentation.\n", group->gr_name);
  246. corosync_exit_error (AIS_DONE_GID_DETERMINE);
  247. }
  248. gid_valid = group->gr_gid;
  249. endgrent ();
  250. }
  251. static void aisexec_priv_drop (void)
  252. {
  253. return;
  254. setuid (ais_uid);
  255. setegid (ais_uid);
  256. }
  257. static void aisexec_mempool_init (void)
  258. {
  259. int res;
  260. res = mempool_init (pool_sizes);
  261. if (res == ENOMEM) {
  262. log_printf (LOG_LEVEL_ERROR, "Couldn't allocate memory pools, not enough memory");
  263. corosync_exit_error (AIS_DONE_MEMPOOL_INIT);
  264. }
  265. }
  266. static void aisexec_tty_detach (void)
  267. {
  268. int fd;
  269. /*
  270. * Disconnect from TTY if this is not a debug run
  271. */
  272. switch (fork ()) {
  273. case -1:
  274. corosync_exit_error (AIS_DONE_FORK);
  275. break;
  276. case 0:
  277. /*
  278. * child which is disconnected, run this process
  279. */
  280. /* setset(); */
  281. close (0);
  282. close (1);
  283. close (2);
  284. break;
  285. default:
  286. exit (0);
  287. break;
  288. }
  289. /* Create new session */
  290. setsid();
  291. /*
  292. * Map stdin/out/err to /dev/null.
  293. */
  294. fd = open("/dev/null", O_RDWR);
  295. if (fd >= 0) {
  296. /* dup2 to 0 / 1 / 2 (stdin / stdout / stderr) */
  297. dup2(fd, STDIN_FILENO); /* 0 */
  298. dup2(fd, STDOUT_FILENO); /* 1 */
  299. dup2(fd, STDERR_FILENO); /* 2 */
  300. /* Should be 0, but just in case it isn't... */
  301. if (fd > 2)
  302. close(fd);
  303. }
  304. }
  305. static void aisexec_setscheduler (void)
  306. {
  307. #if ! defined(TS_CLASS) && (defined(COROSYNC_BSD) || defined(COROSYNC_LINUX) || defined(COROSYNC_SOLARIS))
  308. struct sched_param sched_param;
  309. int res;
  310. res = sched_get_priority_max (SCHED_RR);
  311. if (res != -1) {
  312. sched_param.sched_priority = 1;//res;
  313. res = sched_setscheduler (0, SCHED_RR, &sched_param);
  314. if (res == -1) {
  315. log_printf (LOG_LEVEL_WARNING, "Could not set SCHED_RR at priority %d: %s\n",
  316. sched_param.sched_priority, strerror (errno));
  317. }
  318. } else
  319. log_printf (LOG_LEVEL_WARNING, "Could not get maximum scheduler priority: %s\n", strerror (errno));
  320. #else
  321. log_printf(LOG_LEVEL_WARNING, "Scheduler priority left to default value (no OS support)\n");
  322. #endif
  323. }
  324. static void aisexec_mlockall (void)
  325. {
  326. #if !defined(COROSYNC_BSD)
  327. int res;
  328. #endif
  329. struct rlimit rlimit;
  330. rlimit.rlim_cur = RLIM_INFINITY;
  331. rlimit.rlim_max = RLIM_INFINITY;
  332. #ifndef COROSYNC_SOLARIS
  333. setrlimit (RLIMIT_MEMLOCK, &rlimit);
  334. #else
  335. setrlimit (RLIMIT_VMEM, &rlimit);
  336. #endif
  337. #if defined(COROSYNC_BSD)
  338. /* under FreeBSD a process with locked page cannot call dlopen
  339. * code disabled until FreeBSD bug i386/93396 was solved
  340. */
  341. log_printf (LOG_LEVEL_WARNING, "Could not lock memory of service to avoid page faults\n");
  342. #else
  343. res = mlockall (MCL_CURRENT | MCL_FUTURE);
  344. if (res == -1) {
  345. log_printf (LOG_LEVEL_WARNING, "Could not lock memory of service to avoid page faults: %s\n", strerror (errno));
  346. };
  347. #endif
  348. }
  349. static void deliver_fn (
  350. unsigned int nodeid,
  351. struct iovec *iovec,
  352. int iov_len,
  353. int endian_conversion_required)
  354. {
  355. mar_req_header_t *header;
  356. int pos = 0;
  357. int i;
  358. int service;
  359. int fn_id;
  360. /*
  361. * Build buffer without iovecs to make processing easier
  362. * This is only used for messages which are multicast with iovecs
  363. * and self-delivered. All other mechanisms avoid the copy.
  364. */
  365. if (iov_len > 1) {
  366. for (i = 0; i < iov_len; i++) {
  367. memcpy (&delivery_data[pos], iovec[i].iov_base, iovec[i].iov_len);
  368. pos += iovec[i].iov_len;
  369. assert (pos < MESSAGE_SIZE_MAX);
  370. }
  371. header = (mar_req_header_t *)delivery_data;
  372. } else {
  373. header = (mar_req_header_t *)iovec[0].iov_base;
  374. }
  375. if (endian_conversion_required) {
  376. header->id = swab32 (header->id);
  377. header->size = swab32 (header->size);
  378. }
  379. // assert(iovec->iov_len == header->size);
  380. /*
  381. * Call the proper executive handler
  382. */
  383. service = header->id >> 16;
  384. fn_id = header->id & 0xffff;
  385. if (endian_conversion_required) {
  386. assert(ais_service[service]->exec_engine[fn_id].exec_endian_convert_fn != NULL);
  387. ais_service[service]->exec_engine[fn_id].exec_endian_convert_fn
  388. (header);
  389. }
  390. ais_service[service]->exec_engine[fn_id].exec_handler_fn
  391. (header, nodeid);
  392. }
  393. void main_get_config_modules(struct config_iface_ver0 ***modules, int *num)
  394. {
  395. *modules = config_modules;
  396. *num = num_config_modules;
  397. }
  398. int main_mcast (
  399. struct iovec *iovec,
  400. int iov_len,
  401. unsigned int guarantee)
  402. {
  403. return (totempg_groups_mcast_joined (corosync_group_handle, iovec, iov_len, guarantee));
  404. }
  405. extern int main_send_ok (
  406. struct iovec *iovec,
  407. int iov_len)
  408. {
  409. return (totempg_groups_send_ok_joined (corosync_group_handle, iovec, iov_len));
  410. }
  411. int main (int argc, char **argv)
  412. {
  413. char *error_string;
  414. struct main_config main_config;
  415. struct totem_config totem_config;
  416. unsigned int objdb_handle;
  417. unsigned int config_handle;
  418. unsigned int config_version = 0;
  419. void *objdb_p;
  420. struct config_iface_ver0 *config;
  421. void *config_p;
  422. char *config_iface;
  423. char *iface;
  424. int res, ch;
  425. int background, setprio;
  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_THREADED|LOG_MODE_FORK);
  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. corosync_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. corosync_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 corosync 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. corosync_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. corosync_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 = corosync_main_config_read (objdb, &error_string, &main_config);
  522. if (res == -1) {
  523. log_printf (LOG_LEVEL_ERROR, error_string);
  524. corosync_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. corosync_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. corosync_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. corosync_exit_error (AIS_DONE_MAINCONFIGREAD);
  540. }
  541. logsys_config_facility_set ("corosync", main_config.syslog_facility);
  542. logsys_config_mode_set (main_config.logmode);
  543. logsys_config_file_set (&error_string, main_config.logfile);
  544. logsys_fork_completed ();
  545. aisexec_uid_determine (&main_config);
  546. aisexec_gid_determine (&main_config);
  547. /*
  548. * Set round robin realtime scheduling with priority 99
  549. * Lock all memory to avoid page faults which may interrupt
  550. * application healthchecking
  551. */
  552. if (setprio)
  553. aisexec_setscheduler ();
  554. aisexec_mlockall ();
  555. totem_config.totem_logging_configuration = totem_logging_configuration;
  556. totem_config.totem_logging_configuration.log_subsys_id =
  557. _logsys_subsys_create ("TOTEM", LOG_INFO);
  558. totem_config.totem_logging_configuration.log_level_security = LOG_LEVEL_SECURITY;
  559. totem_config.totem_logging_configuration.log_level_error = LOG_LEVEL_ERROR;
  560. totem_config.totem_logging_configuration.log_level_warning = LOG_LEVEL_WARNING;
  561. totem_config.totem_logging_configuration.log_level_notice = LOG_LEVEL_NOTICE;
  562. totem_config.totem_logging_configuration.log_level_debug = LOG_LEVEL_DEBUG;
  563. totem_config.totem_logging_configuration.log_printf = _logsys_log_printf;
  564. /*
  565. * Sleep for a while to let other nodes in the cluster
  566. * understand that this node has been away (if it was
  567. * an aisexec restart).
  568. */
  569. // TODO what is this hack for? usleep(totem_config.token_timeout * 2000);
  570. /*
  571. * if totempg_initialize doesn't have root priveleges, it cannot
  572. * bind to a specific interface. This only matters if
  573. * there is more then one interface in a system, so
  574. * in this case, only a warning is printed
  575. */
  576. /*
  577. * Join multicast group and setup delivery
  578. * and configuration change functions
  579. */
  580. totempg_initialize (
  581. aisexec_poll_handle,
  582. &totem_config);
  583. totempg_groups_initialize (
  584. &corosync_group_handle,
  585. deliver_fn,
  586. confchg_fn);
  587. totempg_groups_join (
  588. corosync_group_handle,
  589. &corosync_group,
  590. 1);
  591. /*
  592. * This must occur after totempg is initialized because "this_ip" must be set
  593. */
  594. res = corosync_service_defaults_link_and_init (api);
  595. if (res == -1) {
  596. log_printf (LOG_LEVEL_ERROR, "Could not initialize default services\n");
  597. corosync_exit_error (AIS_DONE_INIT_SERVICES);
  598. }
  599. sync_register (corosync_sync_callbacks_retrieve, corosync_sync_completed,
  600. totem_config.vsf_type);
  601. res = cs_flow_control_initialize ();
  602. /*
  603. * Drop root privleges to user 'ais'
  604. * TODO: Don't really need full root capabilities;
  605. * needed capabilities are:
  606. * CAP_NET_RAW (bindtodevice)
  607. * CAP_SYS_NICE (setscheduler)
  608. * CAP_IPC_LOCK (mlockall)
  609. */
  610. aisexec_priv_drop ();
  611. aisexec_mempool_init ();
  612. cs_ipc_init (
  613. serialize_mutex_lock,
  614. serialize_mutex_unlock,
  615. gid_valid);
  616. /*
  617. * Start main processing loop
  618. */
  619. poll_run (aisexec_poll_handle);
  620. return EXIT_SUCCESS;
  621. }