main.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  1. //#define BUILD_DYNAMIC 1
  2. /*
  3. * vi: set autoindent tabstop=4 shiftwidth=4 :
  4. *
  5. * Copyright (c) 2002-2004 MontaVista Software, Inc.
  6. *
  7. * All rights reserved.
  8. *
  9. * Author: Steven Dake (sdake@mvista.com)
  10. *
  11. * This software licensed under BSD license, the text of which follows:
  12. *
  13. * Redistribution and use in source and binary forms, with or without
  14. * modification, are permitted provided that the following conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above copyright notice,
  17. * this list of conditions and the following disclaimer.
  18. * - Redistributions in binary form must reproduce the above copyright notice,
  19. * this list of conditions and the following disclaimer in the documentation
  20. * and/or other materials provided with the distribution.
  21. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  22. * contributors may be used to endorse or promote products derived from this
  23. * software without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  26. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  29. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  30. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  31. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  32. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  33. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  34. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  35. * THE POSSIBILITY OF SUCH DAMAGE.
  36. */
  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/sysinfo.h>
  47. #include <sys/time.h>
  48. #include <sys/resource.h>
  49. #include <netinet/in.h>
  50. #include <arpa/inet.h>
  51. #include <unistd.h>
  52. #include <fcntl.h>
  53. #include <stdlib.h>
  54. #include <stdio.h>
  55. #include <errno.h>
  56. #include <signal.h>
  57. #include <sched.h>
  58. #include <time.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 "amfconfig.h"
  69. #include "totemconfig.h"
  70. #include "main.h"
  71. #include "handlers.h"
  72. #include "sync.h"
  73. #include "evs.h"
  74. #include "clm.h"
  75. #include "amf.h"
  76. #include "ckpt.h"
  77. #include "evt.h"
  78. #include "lck.h"
  79. #include "msg.h"
  80. #include "cfg.h"
  81. #include "swab.h"
  82. #define LOG_SERVICE LOG_SERVICE_MAIN
  83. #include "print.h"
  84. #define SERVER_BACKLOG 5
  85. int ais_uid = 0;
  86. int gid_valid = 0;
  87. /*
  88. * All service handlers in the AIS
  89. */
  90. #ifdef BUILD_DYNAMIC
  91. struct dynamic_service {
  92. char *name;
  93. unsigned int ver;
  94. unsigned int handle;
  95. struct aisexec_iface_ver0 *iface_ver0;
  96. };
  97. /*
  98. * Still need to know the name of the service interface and version number
  99. */
  100. struct dynamic_service dynamic_services[128] = {
  101. {
  102. .name = "openais_evs",
  103. .ver = 0,
  104. .handle = 0,
  105. .iface_ver0 = NULL
  106. },
  107. {
  108. .name = "openais_clm",
  109. .ver = 0,
  110. .handle = 0,
  111. .iface_ver0 = NULL
  112. },
  113. {
  114. .name = "openais_amf",
  115. .ver = 0,
  116. .handle = 0,
  117. .iface_ver0 = NULL
  118. },
  119. {
  120. .name = "openais_ckpt",
  121. .ver = 0,
  122. .handle = 0,
  123. .iface_ver0 = NULL
  124. },
  125. {
  126. .name = "openais_evt",
  127. .ver = 0,
  128. .handle = 0,
  129. .iface_ver0 = NULL
  130. },
  131. {
  132. .name = "openais_lck",
  133. .ver = 0,
  134. .handle = 0,
  135. .iface_ver0 = NULL
  136. },
  137. {
  138. .name = "openais_msg",
  139. .ver = 0,
  140. .handle = 0,
  141. .iface_ver0 = NULL
  142. },
  143. {
  144. .name = "openais_cfg",
  145. .ver = 0,
  146. .handle = 0,
  147. .iface_ver0 = NULL
  148. }
  149. };
  150. #endif /* BUILD_DYNAMIC */
  151. static struct service_handler *ais_service_handlers[32];
  152. /*
  153. unsigned int aisexec_ifact_handle_ver0[32];
  154. static struct aisexec_iface_ver0 *aisexec_iface_ver0[32];
  155. */
  156. static unsigned int service_handlers_count = 32;
  157. SaClmClusterNodeT *(*main_clm_get_by_nodeid) (unsigned int node_id);
  158. /*
  159. * IPC Initializers
  160. */
  161. static int dispatch_init_send_response (struct conn_info *conn_info, void *message);
  162. static int response_init_send_response (struct conn_info *conn_info, void *message);
  163. static int (*ais_init_handlers[]) (struct conn_info *conn_info, void *message) = {
  164. response_init_send_response,
  165. dispatch_init_send_response
  166. };
  167. static int poll_handler_libais_deliver (poll_handle handle, int fd, int revent, void *data, unsigned int *prio);
  168. enum e_ais_done {
  169. AIS_DONE_EXIT = -1,
  170. AIS_DONE_UID_DETERMINE = -2,
  171. AIS_DONE_GID_DETERMINE = -3,
  172. AIS_DONE_MEMPOOL_INIT = -4,
  173. AIS_DONE_FORK = -5,
  174. AIS_DONE_LIBAIS_SOCKET = -6,
  175. AIS_DONE_LIBAIS_BIND = -7,
  176. AIS_DONE_READKEY = -8,
  177. AIS_DONE_MAINCONFIGREAD = -9,
  178. AIS_DONE_LOGSETUP = -10,
  179. AIS_DONE_AMFCONFIGREAD = -11,
  180. };
  181. extern int openais_amf_config_read (char **error_string);
  182. static inline void ais_done (enum e_ais_done err)
  183. {
  184. log_printf (LOG_LEVEL_ERROR, "AIS Executive exiting.\n");
  185. poll_destroy (aisexec_poll_handle);
  186. exit (1);
  187. }
  188. static inline struct conn_info *conn_info_create (int fd) {
  189. struct conn_info *conn_info;
  190. int res;
  191. conn_info = malloc (sizeof (struct conn_info));
  192. if (conn_info == 0) {
  193. return (0);
  194. }
  195. memset (conn_info, 0, sizeof (struct conn_info));
  196. res = queue_init (&conn_info->outq, SIZEQUEUE,
  197. sizeof (struct outq_item));
  198. if (res != 0) {
  199. free (conn_info);
  200. return (0);
  201. }
  202. conn_info->inb = malloc (sizeof (char) * SIZEINB);
  203. if (conn_info->inb == 0) {
  204. queue_free (&conn_info->outq);
  205. free (conn_info);
  206. return (0);
  207. }
  208. conn_info->state = CONN_STATE_ACTIVE;
  209. conn_info->fd = fd;
  210. conn_info->service = SOCKET_SERVICE_INIT;
  211. return (conn_info);
  212. }
  213. #ifdef COMPILE_OUT
  214. static void sigusr2_handler (int num)
  215. {
  216. int i;
  217. for (i = 0; i < AIS_SERVICE_HANDLERS_COUNT; i++) {
  218. if (ais_service_handlers[i]->exec_dump_fn) {
  219. ais_service_handlers[i]->exec_dump_fn ();
  220. }
  221. }
  222. signal (SIGUSR2 ,sigusr2_handler);
  223. return;
  224. }
  225. #endif
  226. struct totem_ip_address *this_ip;
  227. struct totem_ip_address this_non_loopback_ip;
  228. #define LOCALHOST_IP inet_addr("127.0.0.1")
  229. char *socketname = "libais.socket";
  230. totempg_groups_handle openais_group_handle;
  231. struct totempg_group openais_group = {
  232. .group = "a",
  233. .group_len = 1
  234. };
  235. static int libais_connection_active (struct conn_info *conn_info)
  236. {
  237. return (conn_info->state == CONN_STATE_ACTIVE);
  238. }
  239. static void libais_disconnect_delayed (struct conn_info *conn_info)
  240. {
  241. conn_info->state = CONN_STATE_DISCONNECTING_DELAYED;
  242. conn_info->conn_info_partner->state = CONN_STATE_DISCONNECTING_DELAYED;
  243. }
  244. static int libais_disconnect (struct conn_info *conn_info)
  245. {
  246. int res = 0;
  247. struct outq_item *outq_item;
  248. if (conn_info->should_exit_fn &&
  249. ais_service_handlers[conn_info->service]->libais_exit_fn) {
  250. res = ais_service_handlers[conn_info->service]->libais_exit_fn (conn_info);
  251. }
  252. if (conn_info->conn_info_partner &&
  253. conn_info->conn_info_partner->should_exit_fn &&
  254. ais_service_handlers[conn_info->conn_info_partner->service]->libais_exit_fn) {
  255. res = ais_service_handlers[conn_info->conn_info_partner->service]->libais_exit_fn (conn_info->conn_info_partner);
  256. }
  257. /*
  258. * Close the library connection and free its
  259. * data if it hasn't already been freed
  260. */
  261. if (conn_info->state != CONN_STATE_DISCONNECTING) {
  262. conn_info->state = CONN_STATE_DISCONNECTING;
  263. close (conn_info->fd);
  264. /*
  265. * Free the outq queued items
  266. */
  267. while (!queue_is_empty (&conn_info->outq)) {
  268. outq_item = queue_item_get (&conn_info->outq);
  269. free (outq_item->msg);
  270. queue_item_remove (&conn_info->outq);
  271. }
  272. queue_free (&conn_info->outq);
  273. free (conn_info->inb);
  274. }
  275. /*
  276. * Close the library connection and free its
  277. * data if it hasn't already been freed
  278. */
  279. if (conn_info->conn_info_partner &&
  280. conn_info->conn_info_partner->state != CONN_STATE_DISCONNECTING) {
  281. conn_info->conn_info_partner->state = CONN_STATE_DISCONNECTING;
  282. close (conn_info->conn_info_partner->fd);
  283. /*
  284. * Free the outq queued items
  285. */
  286. while (!queue_is_empty (&conn_info->conn_info_partner->outq)) {
  287. outq_item = queue_item_get (&conn_info->conn_info_partner->outq);
  288. free (outq_item->msg);
  289. queue_item_remove (&conn_info->conn_info_partner->outq);
  290. }
  291. queue_free (&conn_info->conn_info_partner->outq);
  292. if (conn_info->conn_info_partner->inb) {
  293. free (conn_info->conn_info_partner->inb);
  294. }
  295. }
  296. /*
  297. * If exit_fn didn't request a retry,
  298. * free the conn_info structure
  299. */
  300. if (res != -1) {
  301. if (conn_info->conn_info_partner) {
  302. poll_dispatch_delete (aisexec_poll_handle,
  303. conn_info->conn_info_partner->fd);
  304. }
  305. poll_dispatch_delete (aisexec_poll_handle, conn_info->fd);
  306. free (conn_info->conn_info_partner);
  307. free (conn_info);
  308. }
  309. /*
  310. * Inverse res from libais exit fn handler
  311. */
  312. return (res != -1 ? -1 : 0);
  313. }
  314. static int cleanup_send_response (struct conn_info *conn_info) {
  315. struct queue *outq;
  316. int res = 0;
  317. struct outq_item *queue_item;
  318. struct msghdr msg_send;
  319. struct iovec iov_send;
  320. char *msg_addr;
  321. if (!libais_connection_active (conn_info)) {
  322. return (-1);
  323. }
  324. outq = &conn_info->outq;
  325. msg_send.msg_iov = &iov_send;
  326. msg_send.msg_name = 0;
  327. msg_send.msg_namelen = 0;
  328. msg_send.msg_iovlen = 1;
  329. msg_send.msg_control = 0;
  330. msg_send.msg_controllen = 0;
  331. msg_send.msg_flags = 0;
  332. while (!queue_is_empty (outq)) {
  333. queue_item = queue_item_get (outq);
  334. msg_addr = (char *)queue_item->msg;
  335. msg_addr = &msg_addr[conn_info->byte_start];
  336. iov_send.iov_base = msg_addr;
  337. iov_send.iov_len = queue_item->mlen - conn_info->byte_start;
  338. retry_sendmsg:
  339. res = sendmsg (conn_info->fd, &msg_send, MSG_DONTWAIT | MSG_NOSIGNAL);
  340. if (res == -1 && errno == EINTR) {
  341. goto retry_sendmsg;
  342. }
  343. if (res == -1 && errno == EAGAIN) {
  344. break; /* outgoing kernel queue full */
  345. }
  346. if (res == -1) {
  347. return (-1); /* message couldn't be sent */
  348. }
  349. if (res + conn_info->byte_start != queue_item->mlen) {
  350. conn_info->byte_start += res;
  351. break;
  352. }
  353. /*
  354. * Message sent, try sending another message
  355. */
  356. queue_item_remove (outq);
  357. conn_info->byte_start = 0;
  358. free (queue_item->msg);
  359. } /* while queue not empty */
  360. if (queue_is_empty (outq)) {
  361. poll_dispatch_modify (aisexec_poll_handle, conn_info->fd,
  362. POLLIN|POLLNVAL, poll_handler_libais_deliver, 0);
  363. }
  364. return (0);
  365. }
  366. extern int libais_send_response (struct conn_info *conn_info,
  367. void *msg, int mlen)
  368. {
  369. struct queue *outq;
  370. char *cmsg;
  371. int res = 0;
  372. int queue_empty;
  373. struct outq_item *queue_item;
  374. struct outq_item queue_item_out;
  375. struct msghdr msg_send;
  376. struct iovec iov_send;
  377. char *msg_addr;
  378. if (!libais_connection_active (conn_info)) {
  379. return (-1);
  380. }
  381. outq = &conn_info->outq;
  382. msg_send.msg_iov = &iov_send;
  383. msg_send.msg_name = 0;
  384. msg_send.msg_namelen = 0;
  385. msg_send.msg_iovlen = 1;
  386. msg_send.msg_control = 0;
  387. msg_send.msg_controllen = 0;
  388. msg_send.msg_flags = 0;
  389. if (queue_is_full (outq)) {
  390. /*
  391. * Start a disconnect if we have not already started one
  392. * and report that the outgoing queue is full
  393. */
  394. log_printf (LOG_LEVEL_ERROR, "Library queue is full, disconnecting library connection.\n");
  395. libais_disconnect_delayed (conn_info);
  396. return (-1);
  397. }
  398. while (!queue_is_empty (outq)) {
  399. queue_item = queue_item_get (outq);
  400. msg_addr = (char *)queue_item->msg;
  401. msg_addr = &msg_addr[conn_info->byte_start];
  402. iov_send.iov_base = msg_addr;
  403. iov_send.iov_len = queue_item->mlen - conn_info->byte_start;
  404. retry_sendmsg:
  405. res = sendmsg (conn_info->fd, &msg_send, MSG_DONTWAIT | MSG_NOSIGNAL);
  406. if (res == -1 && errno == EINTR) {
  407. goto retry_sendmsg;
  408. }
  409. if (res == -1 && errno == EAGAIN) {
  410. break; /* outgoing kernel queue full */
  411. }
  412. if (res == -1) {
  413. break; /* some other error, stop trying to send message */
  414. }
  415. if (res + conn_info->byte_start != queue_item->mlen) {
  416. conn_info->byte_start += res;
  417. break;
  418. }
  419. /*
  420. * Message sent, try sending another message
  421. */
  422. queue_item_remove (outq);
  423. conn_info->byte_start = 0;
  424. free (queue_item->msg);
  425. } /* while queue not empty */
  426. res = -1;
  427. queue_empty = queue_is_empty (outq);
  428. /*
  429. * Send requested message
  430. */
  431. if (queue_empty) {
  432. iov_send.iov_base = msg;
  433. iov_send.iov_len = mlen;
  434. retry_sendmsg_two:
  435. res = sendmsg (conn_info->fd, &msg_send, MSG_DONTWAIT | MSG_NOSIGNAL);
  436. if (res == -1 && errno == EINTR) {
  437. goto retry_sendmsg_two;
  438. }
  439. if (res == -1 && errno == EAGAIN) {
  440. conn_info->byte_start = 0;
  441. poll_dispatch_modify (aisexec_poll_handle, conn_info->fd,
  442. POLLIN|POLLNVAL, poll_handler_libais_deliver, 0);
  443. }
  444. if (res != -1) {
  445. if (res + conn_info->byte_start != mlen) {
  446. conn_info->byte_start += res;
  447. res = -1;
  448. } else {
  449. conn_info->byte_start = 0;
  450. poll_dispatch_modify (aisexec_poll_handle, conn_info->fd,
  451. POLLIN|POLLNVAL, poll_handler_libais_deliver, 0);
  452. }
  453. }
  454. }
  455. /*
  456. * If res == -1 , errrno == EAGAIN which means kernel queue full
  457. */
  458. if (res == -1) {
  459. cmsg = malloc (mlen);
  460. if (cmsg == 0) {
  461. log_printf (LOG_LEVEL_ERROR, "Library queue couldn't allocate a message, disconnecting library connection.\n");
  462. libais_disconnect_delayed (conn_info);
  463. return (-1);
  464. }
  465. queue_item_out.msg = cmsg;
  466. queue_item_out.mlen = mlen;
  467. memcpy (cmsg, msg, mlen);
  468. queue_item_add (outq, &queue_item_out);
  469. poll_dispatch_modify (aisexec_poll_handle, conn_info->fd,
  470. POLLOUT|POLLIN|POLLNVAL, poll_handler_libais_deliver, 0);
  471. }
  472. return (0);
  473. }
  474. static int poll_handler_libais_accept (
  475. poll_handle handle,
  476. int fd,
  477. int revent,
  478. void *data,
  479. unsigned int *prio)
  480. {
  481. socklen_t addrlen;
  482. struct conn_info *conn_info;
  483. struct sockaddr_un un_addr;
  484. int new_fd;
  485. int on = 1;
  486. addrlen = sizeof (struct sockaddr_un);
  487. retry_accept:
  488. new_fd = accept (fd, (struct sockaddr *)&un_addr, &addrlen);
  489. if (new_fd == -1 && errno == EINTR) {
  490. goto retry_accept;
  491. }
  492. if (new_fd == -1) {
  493. log_printf (LOG_LEVEL_ERROR, "ERROR: Could not accept Library connection: %s\n", strerror (errno));
  494. return (0); /* This is an error, but -1 would indicate disconnect from poll loop */
  495. }
  496. /*
  497. * Valid accept
  498. */
  499. /*
  500. * Request credentials of sender provided by kernel
  501. */
  502. setsockopt(new_fd, SOL_SOCKET, SO_PASSCRED, &on, sizeof (on));
  503. log_printf (LOG_LEVEL_DEBUG, "connection received from libais client %d.\n", new_fd);
  504. conn_info = conn_info_create (new_fd);
  505. if (conn_info == 0) {
  506. close (new_fd);
  507. return (0); /* This is an error, but -1 would indicate disconnect from poll */
  508. }
  509. poll_dispatch_add (aisexec_poll_handle, new_fd, POLLIN|POLLNVAL, conn_info,
  510. poll_handler_libais_deliver, 0);
  511. // TODO is this needed, or shouldn't it be in conn_info_create ?
  512. memcpy (&conn_info->ais_ci.un_addr, &un_addr, sizeof (struct sockaddr_un));
  513. return (0);
  514. }
  515. static int dispatch_init_send_response (struct conn_info *conn_info, void *message)
  516. {
  517. SaErrorT error = SA_ERR_ACCESS;
  518. struct req_lib_dispatch_init *req_lib_dispatch_init = (struct req_lib_dispatch_init *)message;
  519. struct res_lib_dispatch_init res_lib_dispatch_init;
  520. struct conn_info *msg_conn_info;
  521. if (conn_info->authenticated) {
  522. conn_info->service = req_lib_dispatch_init->resdis_header.service;
  523. error = SA_OK;
  524. conn_info->conn_info_partner = (struct conn_info *)req_lib_dispatch_init->conn_info;
  525. msg_conn_info = (struct conn_info *)req_lib_dispatch_init->conn_info;
  526. msg_conn_info->conn_info_partner = conn_info;
  527. }
  528. res_lib_dispatch_init.header.size = sizeof (struct res_lib_dispatch_init);
  529. res_lib_dispatch_init.header.id = MESSAGE_RES_INIT;
  530. res_lib_dispatch_init.header.error = error;
  531. libais_send_response (conn_info, &res_lib_dispatch_init,
  532. sizeof (res_lib_dispatch_init));
  533. if (error == SA_ERR_ACCESS) {
  534. return (-1);
  535. }
  536. conn_info->should_exit_fn = 1;
  537. ais_service_handlers[req_lib_dispatch_init->resdis_header.service]->libais_init_two_fn (conn_info);
  538. return (0);
  539. }
  540. static int response_init_send_response (struct conn_info *conn_info, void *message)
  541. {
  542. SaErrorT error = SA_ERR_ACCESS;
  543. struct req_lib_response_init *req_lib_response_init = (struct req_lib_response_init *)message;
  544. struct res_lib_response_init res_lib_response_init;
  545. if (conn_info->authenticated) {
  546. conn_info->service = req_lib_response_init->resdis_header.service;
  547. error = SA_OK;
  548. }
  549. res_lib_response_init.header.size = sizeof (struct res_lib_response_init);
  550. res_lib_response_init.header.id = MESSAGE_RES_INIT;
  551. res_lib_response_init.header.error = error;
  552. res_lib_response_init.conn_info = (unsigned long)conn_info;
  553. libais_send_response (conn_info, &res_lib_response_init,
  554. sizeof (res_lib_response_init));
  555. if (error == SA_ERR_ACCESS) {
  556. return (-1);
  557. }
  558. conn_info->should_exit_fn = 0;
  559. return (0);
  560. }
  561. struct res_overlay {
  562. struct res_header header;
  563. char buf[4096];
  564. };
  565. static int poll_handler_libais_deliver (poll_handle handle, int fd, int revent, void *data, unsigned int *prio)
  566. {
  567. int res;
  568. struct conn_info *conn_info = (struct conn_info *)data;
  569. struct req_header *header;
  570. int service;
  571. struct msghdr msg_recv;
  572. struct iovec iov_recv;
  573. struct cmsghdr *cmsg;
  574. char cmsg_cred[CMSG_SPACE (sizeof (struct ucred))];
  575. struct ucred *cred;
  576. int on = 0;
  577. int send_ok = 0;
  578. int send_ok_joined = 0;
  579. struct iovec send_ok_joined_iovec;
  580. struct res_overlay res_overlay;
  581. if (revent & (POLLERR|POLLHUP)) {
  582. res = libais_disconnect (conn_info);
  583. return (res);
  584. }
  585. /*
  586. * Handle delayed disconnections
  587. */
  588. if (conn_info->state == CONN_STATE_DISCONNECTING_DELAYED) {
  589. res = libais_disconnect (conn_info);
  590. return (res);
  591. }
  592. if (conn_info->state == CONN_STATE_DISCONNECTING) {
  593. return (0);
  594. }
  595. if (revent & POLLOUT) {
  596. cleanup_send_response (conn_info);
  597. }
  598. if ((revent & POLLIN) == 0) {
  599. return (0);
  600. }
  601. msg_recv.msg_iov = &iov_recv;
  602. msg_recv.msg_iovlen = 1;
  603. msg_recv.msg_name = 0;
  604. msg_recv.msg_namelen = 0;
  605. msg_recv.msg_flags = 0;
  606. if (conn_info->authenticated) {
  607. msg_recv.msg_control = 0;
  608. msg_recv.msg_controllen = 0;
  609. } else {
  610. msg_recv.msg_control = (void *)cmsg_cred;
  611. msg_recv.msg_controllen = sizeof (cmsg_cred);
  612. }
  613. iov_recv.iov_base = &conn_info->inb[conn_info->inb_start];
  614. iov_recv.iov_len = (SIZEINB) - conn_info->inb_start;
  615. assert (iov_recv.iov_len != 0);
  616. retry_recv:
  617. res = recvmsg (fd, &msg_recv, MSG_DONTWAIT | MSG_NOSIGNAL);
  618. if (res == -1 && errno == EINTR) {
  619. goto retry_recv;
  620. } else
  621. if (res == -1 && errno != EAGAIN) {
  622. goto error_disconnect;
  623. } else
  624. if (res == 0) {
  625. goto error_disconnect;
  626. return (-1);
  627. }
  628. /*
  629. * Authenticate if this connection has not been authenticated
  630. */
  631. if (conn_info->authenticated == 0) {
  632. cmsg = CMSG_FIRSTHDR (&msg_recv);
  633. cred = (struct ucred *)CMSG_DATA (cmsg);
  634. if (cred) {
  635. if (cred->uid == 0 || cred->gid == gid_valid) {
  636. setsockopt(fd, SOL_SOCKET, SO_PASSCRED, &on, sizeof (on));
  637. conn_info->authenticated = 1;
  638. }
  639. }
  640. if (conn_info->authenticated == 0) {
  641. log_printf (LOG_LEVEL_SECURITY, "Connection not authenticated because gid is %d, expecting %d\n", cred->gid, gid_valid);
  642. }
  643. }
  644. /*
  645. * Dispatch all messages received in recvmsg that can be dispatched
  646. * sizeof (struct req_header) needed at minimum to do any processing
  647. */
  648. conn_info->inb_inuse += res;
  649. conn_info->inb_start += res;
  650. while (conn_info->inb_inuse >= sizeof (struct req_header) && res != -1) {
  651. header = (struct req_header *)&conn_info->inb[conn_info->inb_start - conn_info->inb_inuse];
  652. if (header->size > conn_info->inb_inuse) {
  653. break;
  654. }
  655. service = conn_info->service;
  656. /*
  657. * If this service is in init phase, initialize service
  658. * else handle message using service handlers
  659. */
  660. if (service == SOCKET_SERVICE_INIT) {
  661. res = ais_init_handlers[header->id] (conn_info, header);
  662. // TODO error in init_two_fn needs to be handled
  663. } else {
  664. /*
  665. * Not an init service, but a standard service
  666. */
  667. if (header->id < 0 || header->id > ais_service_handlers[service]->libais_handlers_count) {
  668. log_printf (LOG_LEVEL_SECURITY, "Invalid header id is %d min 0 max %d\n",
  669. header->id, ais_service_handlers[service]->libais_handlers_count);
  670. res = -1;
  671. goto error_disconnect;
  672. }
  673. /*
  674. * If flow control is required of the library handle, determine that
  675. * openais is not in synchronization and that totempg has room available
  676. * to queue a message, otherwise tell the library we are busy and to
  677. * try again later
  678. */
  679. send_ok_joined_iovec.iov_base = header;
  680. send_ok_joined_iovec.iov_len = header->size;
  681. send_ok_joined = totempg_groups_send_ok_joined (openais_group_handle,
  682. &send_ok_joined_iovec, 1);
  683. send_ok =
  684. (ykd_primary() == 1) && (
  685. (ais_service_handlers[service]->libais_handlers[header->id].flow_control == FLOW_CONTROL_NOT_REQUIRED) ||
  686. ((ais_service_handlers[service]->libais_handlers[header->id].flow_control == FLOW_CONTROL_REQUIRED) &&
  687. (send_ok_joined) &&
  688. (sync_in_process() == 0)));
  689. if (send_ok) {
  690. // *prio = 0;
  691. res = ais_service_handlers[service]->libais_handlers[header->id].libais_handler_fn(conn_info, header);
  692. } else {
  693. // *prio = (*prio) + 1;
  694. /*
  695. * Overload, tell library to retry
  696. */
  697. res_overlay.header.size =
  698. ais_service_handlers[service]->libais_handlers[header->id].response_size;
  699. res_overlay.header.id =
  700. ais_service_handlers[service]->libais_handlers[header->id].response_id;
  701. res_overlay.header.error = SA_ERR_TRY_AGAIN;
  702. libais_send_response (conn_info, &res_overlay,
  703. res_overlay.header.size);
  704. }
  705. }
  706. conn_info->inb_inuse -= header->size;
  707. } /* while */
  708. if (conn_info->inb_inuse == 0) {
  709. conn_info->inb_start = 0;
  710. } else
  711. // BUG if (connections[fd].inb_start + connections[fd].inb_inuse >= SIZEINB) {
  712. if (conn_info->inb_start >= SIZEINB) {
  713. /*
  714. * If in buffer is full, move it back to start
  715. */
  716. memmove (conn_info->inb,
  717. &conn_info->inb[conn_info->inb_start - conn_info->inb_inuse],
  718. sizeof (char) * conn_info->inb_inuse);
  719. conn_info->inb_start = conn_info->inb_inuse;
  720. }
  721. return (res);
  722. error_disconnect:
  723. res = libais_disconnect (conn_info);
  724. return (res);
  725. }
  726. void sigintr_handler (int signum)
  727. {
  728. #ifdef DEBUG_MEMPOOL
  729. int stats_inuse[MEMPOOL_GROUP_SIZE];
  730. int stats_avail[MEMPOOL_GROUP_SIZE];
  731. int stats_memoryused[MEMPOOL_GROUP_SIZE];
  732. int i;
  733. mempool_getstats (stats_inuse, stats_avail, stats_memoryused);
  734. log_printf (LOG_LEVEL_DEBUG, "Memory pools:\n");
  735. for (i = 0; i < MEMPOOL_GROUP_SIZE; i++) {
  736. log_printf (LOG_LEVEL_DEBUG, "order %d size %d inuse %d avail %d memory used %d\n",
  737. i, 1<<i, stats_inuse[i], stats_avail[i], stats_memoryused[i]);
  738. }
  739. #endif
  740. totempg_finalize ();
  741. ais_done (AIS_DONE_EXIT);
  742. }
  743. static struct sched_param sched_param = {
  744. sched_priority: 99
  745. };
  746. static int pool_sizes[] = { 0, 0, 0, 0, 0, 4096, 0, 1, 0, /* 256 */
  747. 1024, 0, 1, 4096, 0, 0, 0, 0, /* 65536 */
  748. 1, 1, 1, 1, 1, 1, 1, 1, 1 };
  749. static void openais_sync_completed (void)
  750. {
  751. }
  752. static int openais_sync_callbacks_retrieve (int sync_id,
  753. struct sync_callbacks *callbacks)
  754. {
  755. if (ais_service_handlers[sync_id] == NULL) {
  756. memset (callbacks, 0, sizeof (struct sync_callbacks));
  757. return (-1);
  758. }
  759. callbacks->sync_init = ais_service_handlers[sync_id]->sync_init;
  760. callbacks->sync_process = ais_service_handlers[sync_id]->sync_process;
  761. callbacks->sync_activate = ais_service_handlers[sync_id]->sync_activate;
  762. callbacks->sync_abort = ais_service_handlers[sync_id]->sync_abort;
  763. return (0);
  764. }
  765. char delivery_data[MESSAGE_SIZE_MAX];
  766. static void deliver_fn (
  767. struct totem_ip_address *source_addr,
  768. struct iovec *iovec,
  769. int iov_len,
  770. int endian_conversion_required)
  771. {
  772. struct req_header *header;
  773. int res;
  774. int pos = 0;
  775. int i;
  776. int service;
  777. int fn_id;
  778. /*
  779. * Build buffer without iovecs to make processing easier
  780. * This is only used for messages which are multicast with iovecs
  781. * and self-delivered. All other mechanisms avoid the copy.
  782. */
  783. if (iov_len > 1) {
  784. for (i = 0; i < iov_len; i++) {
  785. memcpy (&delivery_data[pos], iovec[i].iov_base, iovec[i].iov_len);
  786. pos += iovec[i].iov_len;
  787. assert (pos < MESSAGE_SIZE_MAX);
  788. }
  789. header = (struct req_header *)delivery_data;
  790. } else {
  791. header = (struct req_header *)iovec[0].iov_base;
  792. }
  793. if (endian_conversion_required) {
  794. header->id = swab32 (header->id);
  795. header->size = swab32 (header->size);
  796. }
  797. // assert(iovec->iov_len == header->size);
  798. /*
  799. * Call the proper executive handler
  800. */
  801. service = header->id >> 16;
  802. fn_id = header->id & 0xffff;
  803. res = ais_service_handlers[service]->aisexec_handler_fns[fn_id]
  804. (header, source_addr, endian_conversion_required);
  805. }
  806. static struct memb_ring_id aisexec_ring_id;
  807. static void confchg_fn (
  808. enum totem_configuration_type configuration_type,
  809. struct totem_ip_address *member_list, int member_list_entries,
  810. struct totem_ip_address *left_list, int left_list_entries,
  811. struct totem_ip_address *joined_list, int joined_list_entries,
  812. struct memb_ring_id *ring_id)
  813. {
  814. int i;
  815. memcpy (&aisexec_ring_id, ring_id, sizeof (struct memb_ring_id));
  816. if (!totemip_localhost_check(this_ip)) {
  817. totemip_copy(&this_non_loopback_ip, this_ip);
  818. }
  819. /*
  820. * Call configuration change for all services
  821. */
  822. for (i = 0; i < service_handlers_count; i++) {
  823. if (ais_service_handlers[i] && ais_service_handlers[i]->confchg_fn) {
  824. ais_service_handlers[i]->confchg_fn (configuration_type,
  825. member_list, member_list_entries,
  826. left_list, left_list_entries,
  827. joined_list, joined_list_entries, ring_id);
  828. }
  829. }
  830. }
  831. static void aisexec_uid_determine (void)
  832. {
  833. struct passwd *passwd;
  834. passwd = getpwnam("ais");
  835. if (passwd == 0) {
  836. log_printf (LOG_LEVEL_ERROR, "ERROR: The 'ais' user is not found in /etc/passwd, please read the documentation.\n");
  837. ais_done (AIS_DONE_UID_DETERMINE);
  838. }
  839. ais_uid = passwd->pw_uid;
  840. }
  841. static void aisexec_gid_determine (void)
  842. {
  843. struct group *group;
  844. group = getgrnam ("ais");
  845. if (group == 0) {
  846. log_printf (LOG_LEVEL_ERROR, "ERROR: The 'ais' group is not found in /etc/group, please read the documentation.\n");
  847. ais_done (AIS_DONE_GID_DETERMINE);
  848. }
  849. gid_valid = group->gr_gid;
  850. }
  851. static void aisexec_priv_drop (void)
  852. {
  853. return;
  854. setuid (ais_uid);
  855. setegid (ais_uid);
  856. }
  857. static void aisexec_mempool_init (void)
  858. {
  859. int res;
  860. res = mempool_init (pool_sizes);
  861. if (res == ENOMEM) {
  862. log_printf (LOG_LEVEL_ERROR, "Couldn't allocate memory pools, not enough memory");
  863. ais_done (AIS_DONE_MEMPOOL_INIT);
  864. }
  865. }
  866. static void aisexec_tty_detach (void)
  867. {
  868. #define DEBUG
  869. #ifndef DEBUG
  870. /*
  871. * Disconnect from TTY if this is not a debug run
  872. */
  873. switch (fork ()) {
  874. case -1:
  875. ais_done (AIS_DONE_FORK);
  876. break;
  877. case 0:
  878. /*
  879. * child which is disconnected, run this process
  880. */
  881. break;
  882. default:
  883. exit (0);
  884. break;
  885. }
  886. #endif
  887. #undef DEBUG
  888. }
  889. static void aisexec_libais_bind (int *server_fd)
  890. {
  891. int libais_server_fd;
  892. struct sockaddr_un un_addr;
  893. int res;
  894. /*
  895. * Create socket for libais clients, name socket, listen for connections
  896. */
  897. libais_server_fd = socket (PF_UNIX, SOCK_STREAM, 0);
  898. if (libais_server_fd == -1) {
  899. log_printf (LOG_LEVEL_ERROR ,"Cannot create libais client connections socket.\n");
  900. ais_done (AIS_DONE_LIBAIS_SOCKET);
  901. };
  902. memset (&un_addr, 0, sizeof (struct sockaddr_un));
  903. un_addr.sun_family = AF_UNIX;
  904. strcpy (un_addr.sun_path + 1, socketname);
  905. res = bind (libais_server_fd, (struct sockaddr *)&un_addr, sizeof (struct sockaddr_un));
  906. if (res) {
  907. log_printf (LOG_LEVEL_ERROR, "ERROR: Could not bind AF_UNIX: %s.\n", strerror (errno));
  908. ais_done (AIS_DONE_LIBAIS_BIND);
  909. }
  910. listen (libais_server_fd, SERVER_BACKLOG);
  911. *server_fd = libais_server_fd;
  912. }
  913. static void aisexec_setscheduler (void)
  914. {
  915. int res;
  916. return;
  917. res = sched_setscheduler (0, SCHED_RR, &sched_param);
  918. if (res == -1) {
  919. log_printf (LOG_LEVEL_WARNING, "Could not set SCHED_RR at priority 99: %s\n", strerror (errno));
  920. }
  921. }
  922. static void aisexec_mlockall (void)
  923. {
  924. int res;
  925. struct rlimit rlimit;
  926. rlimit.rlim_cur = RLIM_INFINITY;
  927. rlimit.rlim_max = RLIM_INFINITY;
  928. setrlimit (RLIMIT_MEMLOCK, &rlimit);
  929. res = mlockall (MCL_CURRENT | MCL_FUTURE);
  930. if (res == -1) {
  931. log_printf (LOG_LEVEL_WARNING, "Could not lock memory of service to avoid page faults: %s\n", strerror (errno));
  932. };
  933. }
  934. int message_source_is_local(struct message_source *source)
  935. {
  936. int ret = 0;
  937. if ((totemip_localhost_check(&source->addr)
  938. ||(totemip_equal(&source->addr, &this_non_loopback_ip)))) {
  939. ret = 1;
  940. }
  941. return ret;
  942. }
  943. void message_source_set (struct message_source *source, struct conn_info *conn_info)
  944. {
  945. totemip_copy(&source->addr, this_ip);
  946. source->conn_info = conn_info;
  947. }
  948. struct totem_logging_configuration totem_logging_configuration;
  949. int service_handler_register (
  950. struct service_handler *handler,
  951. struct openais_config *config)
  952. {
  953. assert (ais_service_handlers[handler->id] == NULL);
  954. log_printf (LOG_LEVEL_NOTICE, "Registering service handler '%s'\n", handler->name);
  955. ais_service_handlers[handler->id] = handler;
  956. if (ais_service_handlers[handler->id]->exec_init_fn) {
  957. ais_service_handlers[handler->id]->exec_init_fn (config);
  958. }
  959. }
  960. void default_services_register (struct openais_config *openais_config)
  961. {
  962. #ifdef BUILD_DYNAMIC
  963. int i;
  964. for (i = 0; i < 8; i++) {
  965. lcr_ifact_reference (
  966. &dynamic_services[i].handle,
  967. dynamic_services[i].name,
  968. dynamic_services[i].ver,
  969. (void **)&dynamic_services[i].iface_ver0,
  970. (void *)0);
  971. service_handler_register (dynamic_services[i].iface_ver0->get_handler_ver0(), openais_config);
  972. }
  973. #else /* NOT BUILD_DYNAMIC */
  974. /*
  975. * link everything together - better for debugging - smaller memory footprint
  976. */
  977. service_handler_register (&evs_service_handler, openais_config);
  978. service_handler_register (&clm_service_handler, openais_config);
  979. service_handler_register (&amf_service_handler, openais_config);
  980. service_handler_register (&ckpt_service_handler, openais_config);
  981. service_handler_register (&evt_service_handler, openais_config);
  982. service_handler_register (&lck_service_handler, openais_config);
  983. service_handler_register (&msg_service_handler, openais_config);
  984. service_handler_register (&cfg_service_handler, openais_config);
  985. #endif /* BUILD_DYNAMIC */
  986. }
  987. int main (int argc, char **argv)
  988. {
  989. int libais_server_fd;
  990. int res;
  991. char *error_string;
  992. struct openais_config openais_config;
  993. memset(&this_non_loopback_ip, 0, sizeof(struct totem_ip_address));
  994. totemip_localhost(AF_INET, &this_non_loopback_ip);
  995. aisexec_uid_determine ();
  996. aisexec_gid_determine ();
  997. aisexec_poll_handle = poll_create ();
  998. //TODO signal (SIGUSR2, sigusr2_handler);
  999. /*
  1000. * if totempg_initialize doesn't have root priveleges, it cannot
  1001. * bind to a specific interface. This only matters if
  1002. * there is more then one interface in a system, so
  1003. * in this case, only a warning is printed
  1004. */
  1005. res = openais_main_config_read (&error_string, &openais_config, 1);
  1006. if (res == -1) {
  1007. log_printf (LOG_LEVEL_NOTICE, "AIS Executive Service: Copyright (C) 2002-2004 MontaVista Software, Inc and contributors.\n");
  1008. log_printf (LOG_LEVEL_ERROR, error_string);
  1009. ais_done (AIS_DONE_MAINCONFIGREAD);
  1010. }
  1011. res = openais_amf_config_read (&error_string);
  1012. if (res == -1) {
  1013. log_printf (LOG_LEVEL_ERROR, error_string);
  1014. ais_done (AIS_DONE_AMFCONFIGREAD);
  1015. }
  1016. res = totem_config_read (&openais_config.totem_config, &error_string, 1);
  1017. if (res == -1) {
  1018. log_printf (LOG_LEVEL_NOTICE, "AIS Executive Service: Copyright (C) 2002-2004 MontaVista Software, Inc and contributors.\n");
  1019. log_printf (LOG_LEVEL_ERROR, error_string);
  1020. ais_done (AIS_DONE_MAINCONFIGREAD);
  1021. }
  1022. res = totem_config_keyread ("/etc/ais/authkey", &openais_config.totem_config, &error_string);
  1023. if (res == -1) {
  1024. log_printf (LOG_LEVEL_ERROR, error_string);
  1025. ais_done (AIS_DONE_MAINCONFIGREAD);
  1026. }
  1027. res = totem_config_validate (&openais_config.totem_config, &error_string);
  1028. if (res == -1) {
  1029. log_printf (LOG_LEVEL_ERROR, error_string);
  1030. ais_done (AIS_DONE_MAINCONFIGREAD);
  1031. }
  1032. res = log_setup (&error_string, openais_config.logmode, openais_config.logfile);
  1033. if (res == -1) {
  1034. log_printf (LOG_LEVEL_ERROR, error_string);
  1035. ais_done (AIS_DONE_LOGSETUP);
  1036. }
  1037. log_printf (LOG_LEVEL_NOTICE, "AIS Executive Service: Copyright (C) 2002-2004 MontaVista Software, Inc. and contributors.\n");
  1038. /*
  1039. * Set round robin realtime scheduling with priority 99
  1040. * Lock all memory to avoid page faults which may interrupt
  1041. * application healthchecking
  1042. */
  1043. aisexec_setscheduler ();
  1044. aisexec_mlockall ();
  1045. openais_config.totem_config.totem_logging_configuration = totem_logging_configuration;
  1046. openais_config.totem_config.totem_logging_configuration.log_level_security = mklog (LOG_LEVEL_SECURITY, LOG_SERVICE_GMI);
  1047. openais_config.totem_config.totem_logging_configuration.log_level_error = mklog (LOG_LEVEL_ERROR, LOG_SERVICE_GMI);
  1048. openais_config.totem_config.totem_logging_configuration.log_level_warning = mklog (LOG_LEVEL_WARNING, LOG_SERVICE_GMI);
  1049. openais_config.totem_config.totem_logging_configuration.log_level_notice = mklog (LOG_LEVEL_NOTICE, LOG_SERVICE_GMI);
  1050. openais_config.totem_config.totem_logging_configuration.log_level_debug = mklog (LOG_LEVEL_DEBUG, LOG_SERVICE_GMI);
  1051. openais_config.totem_config.totem_logging_configuration.log_printf = internal_log_printf;
  1052. totempg_initialize (
  1053. aisexec_poll_handle,
  1054. &openais_config.totem_config);
  1055. totempg_groups_initialize (
  1056. &openais_group_handle,
  1057. deliver_fn,
  1058. confchg_fn);
  1059. totempg_groups_join (
  1060. openais_group_handle,
  1061. &openais_group,
  1062. 1);
  1063. this_ip = &openais_config.totem_config.interfaces[0].boundto;
  1064. default_services_register(&openais_config);
  1065. sync_register (openais_sync_callbacks_retrieve, openais_sync_completed);
  1066. /*
  1067. * Drop root privleges to user 'ais'
  1068. * TODO: Don't really need full root capabilities;
  1069. * needed capabilities are:
  1070. * CAP_NET_RAW (bindtodevice)
  1071. * CAP_SYS_NICE (setscheduler)
  1072. * CAP_IPC_LOCK (mlockall)
  1073. */
  1074. aisexec_priv_drop ();
  1075. aisexec_mempool_init ();
  1076. signal (SIGINT, sigintr_handler);
  1077. aisexec_libais_bind (&libais_server_fd);
  1078. aisexec_tty_detach ();
  1079. log_printf (LOG_LEVEL_NOTICE, "AIS Executive Service: started and ready to receive connections.\n");
  1080. /*
  1081. * Setup libais connection dispatch routine
  1082. */
  1083. poll_dispatch_add (aisexec_poll_handle, libais_server_fd,
  1084. POLLIN, 0, poll_handler_libais_accept, 0);
  1085. /*
  1086. * Join multicast group and setup delivery
  1087. * and configuration change functions
  1088. */
  1089. /*
  1090. * Start main processing loop
  1091. */
  1092. poll_run (aisexec_poll_handle);
  1093. return (0);
  1094. }