main.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292
  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 "ykd.h"
  82. #include "swab.h"
  83. #define LOG_SERVICE LOG_SERVICE_MAIN
  84. #include "print.h"
  85. #define SERVER_BACKLOG 5
  86. int ais_uid = 0;
  87. int gid_valid = 0;
  88. /*
  89. * All service handlers in the AIS
  90. */
  91. #ifdef BUILD_DYNAMIC
  92. struct dynamic_service {
  93. char *name;
  94. unsigned int ver;
  95. unsigned int handle;
  96. struct openais_service_handler_iface_ver0 *iface_ver0;
  97. };
  98. /*
  99. * Still need to know the name of the service interface and version number
  100. */
  101. struct dynamic_service dynamic_services[128] = {
  102. {
  103. .name = "openais_evs",
  104. .ver = 0,
  105. .handle = 0,
  106. .iface_ver0 = NULL
  107. },
  108. {
  109. .name = "openais_clm",
  110. .ver = 0,
  111. .handle = 0,
  112. .iface_ver0 = NULL
  113. },
  114. {
  115. .name = "openais_amf",
  116. .ver = 0,
  117. .handle = 0,
  118. .iface_ver0 = NULL
  119. },
  120. {
  121. .name = "openais_ckpt",
  122. .ver = 0,
  123. .handle = 0,
  124. .iface_ver0 = NULL
  125. },
  126. {
  127. .name = "openais_evt",
  128. .ver = 0,
  129. .handle = 0,
  130. .iface_ver0 = NULL
  131. },
  132. {
  133. .name = "openais_lck",
  134. .ver = 0,
  135. .handle = 0,
  136. .iface_ver0 = NULL
  137. },
  138. {
  139. .name = "openais_msg",
  140. .ver = 0,
  141. .handle = 0,
  142. .iface_ver0 = NULL
  143. },
  144. {
  145. .name = "openais_cfg",
  146. .ver = 0,
  147. .handle = 0,
  148. .iface_ver0 = NULL
  149. }
  150. };
  151. #endif /* BUILD_DYNAMIC */
  152. static struct openais_service_handler *ais_service_handlers[32];
  153. static unsigned int service_handlers_count = 32;
  154. SaClmClusterNodeT *(*main_clm_get_by_nodeid) (unsigned int node_id);
  155. /*
  156. * IPC Initializers
  157. */
  158. static int dispatch_init_send_response (struct conn_info *conn_info, void *message);
  159. static int response_init_send_response (struct conn_info *conn_info, void *message);
  160. static int (*ais_init_handlers[]) (struct conn_info *conn_info, void *message) = {
  161. response_init_send_response,
  162. dispatch_init_send_response
  163. };
  164. static int poll_handler_libais_deliver (poll_handle handle, int fd, int revent, void *data, unsigned int *prio);
  165. enum e_ais_done {
  166. AIS_DONE_EXIT = -1,
  167. AIS_DONE_UID_DETERMINE = -2,
  168. AIS_DONE_GID_DETERMINE = -3,
  169. AIS_DONE_MEMPOOL_INIT = -4,
  170. AIS_DONE_FORK = -5,
  171. AIS_DONE_LIBAIS_SOCKET = -6,
  172. AIS_DONE_LIBAIS_BIND = -7,
  173. AIS_DONE_READKEY = -8,
  174. AIS_DONE_MAINCONFIGREAD = -9,
  175. AIS_DONE_LOGSETUP = -10,
  176. AIS_DONE_AMFCONFIGREAD = -11,
  177. };
  178. extern int openais_amf_config_read (char **error_string);
  179. static inline void ais_done (enum e_ais_done err)
  180. {
  181. log_printf (LOG_LEVEL_ERROR, "AIS Executive exiting.\n");
  182. poll_destroy (aisexec_poll_handle);
  183. exit (1);
  184. }
  185. static inline struct conn_info *conn_info_create (int fd) {
  186. struct conn_info *conn_info;
  187. int res;
  188. conn_info = malloc (sizeof (struct conn_info));
  189. if (conn_info == 0) {
  190. return (0);
  191. }
  192. memset (conn_info, 0, sizeof (struct conn_info));
  193. res = queue_init (&conn_info->outq, SIZEQUEUE,
  194. sizeof (struct outq_item));
  195. if (res != 0) {
  196. free (conn_info);
  197. return (0);
  198. }
  199. conn_info->inb = malloc (sizeof (char) * SIZEINB);
  200. if (conn_info->inb == 0) {
  201. queue_free (&conn_info->outq);
  202. free (conn_info);
  203. return (0);
  204. }
  205. conn_info->state = CONN_STATE_ACTIVE;
  206. conn_info->fd = fd;
  207. conn_info->service = SOCKET_SERVICE_INIT;
  208. return (conn_info);
  209. }
  210. #ifdef COMPILE_OUT
  211. static void sigusr2_handler (int num)
  212. {
  213. int i;
  214. for (i = 0; i < AIS_SERVICE_HANDLERS_COUNT; i++) {
  215. if (ais_service_handlers[i]->exec_dump_fn) {
  216. ais_service_handlers[i]->exec_dump_fn ();
  217. }
  218. }
  219. signal (SIGUSR2 ,sigusr2_handler);
  220. return;
  221. }
  222. #endif
  223. struct totem_ip_address *this_ip;
  224. struct totem_ip_address this_non_loopback_ip;
  225. #define LOCALHOST_IP inet_addr("127.0.0.1")
  226. char *socketname = "libais.socket";
  227. totempg_groups_handle openais_group_handle;
  228. struct totempg_group openais_group = {
  229. .group = "a",
  230. .group_len = 1
  231. };
  232. static int libais_connection_active (struct conn_info *conn_info)
  233. {
  234. return (conn_info->state == CONN_STATE_ACTIVE);
  235. }
  236. static void libais_disconnect_delayed (struct conn_info *conn_info)
  237. {
  238. conn_info->state = CONN_STATE_DISCONNECTING_DELAYED;
  239. conn_info->conn_info_partner->state = CONN_STATE_DISCONNECTING_DELAYED;
  240. }
  241. static int libais_disconnect (struct conn_info *conn_info)
  242. {
  243. int res = 0;
  244. struct outq_item *outq_item;
  245. if (conn_info->should_exit_fn &&
  246. ais_service_handlers[conn_info->service]->lib_exit_fn) {
  247. res = ais_service_handlers[conn_info->service]->lib_exit_fn (conn_info);
  248. }
  249. if (conn_info->conn_info_partner &&
  250. conn_info->conn_info_partner->should_exit_fn &&
  251. ais_service_handlers[conn_info->conn_info_partner->service]->lib_exit_fn) {
  252. res = ais_service_handlers[conn_info->conn_info_partner->service]->lib_exit_fn (conn_info->conn_info_partner);
  253. }
  254. /*
  255. * Close the library connection and free its
  256. * data if it hasn't already been freed
  257. */
  258. if (conn_info->state != CONN_STATE_DISCONNECTING) {
  259. conn_info->state = CONN_STATE_DISCONNECTING;
  260. close (conn_info->fd);
  261. /*
  262. * Free the outq queued items
  263. */
  264. while (!queue_is_empty (&conn_info->outq)) {
  265. outq_item = queue_item_get (&conn_info->outq);
  266. free (outq_item->msg);
  267. queue_item_remove (&conn_info->outq);
  268. }
  269. queue_free (&conn_info->outq);
  270. free (conn_info->inb);
  271. }
  272. /*
  273. * Close the library connection and free its
  274. * data if it hasn't already been freed
  275. */
  276. if (conn_info->conn_info_partner &&
  277. conn_info->conn_info_partner->state != CONN_STATE_DISCONNECTING) {
  278. conn_info->conn_info_partner->state = CONN_STATE_DISCONNECTING;
  279. close (conn_info->conn_info_partner->fd);
  280. /*
  281. * Free the outq queued items
  282. */
  283. while (!queue_is_empty (&conn_info->conn_info_partner->outq)) {
  284. outq_item = queue_item_get (&conn_info->conn_info_partner->outq);
  285. free (outq_item->msg);
  286. queue_item_remove (&conn_info->conn_info_partner->outq);
  287. }
  288. queue_free (&conn_info->conn_info_partner->outq);
  289. if (conn_info->conn_info_partner->inb) {
  290. free (conn_info->conn_info_partner->inb);
  291. }
  292. }
  293. /*
  294. * If exit_fn didn't request a retry,
  295. * free the conn_info structure
  296. */
  297. if (res != -1) {
  298. if (conn_info->conn_info_partner) {
  299. poll_dispatch_delete (aisexec_poll_handle,
  300. conn_info->conn_info_partner->fd);
  301. }
  302. poll_dispatch_delete (aisexec_poll_handle, conn_info->fd);
  303. free (conn_info->conn_info_partner);
  304. free (conn_info);
  305. }
  306. /*
  307. * Inverse res from libais exit fn handler
  308. */
  309. return (res != -1 ? -1 : 0);
  310. }
  311. static int cleanup_send_response (struct conn_info *conn_info) {
  312. struct queue *outq;
  313. int res = 0;
  314. struct outq_item *queue_item;
  315. struct msghdr msg_send;
  316. struct iovec iov_send;
  317. char *msg_addr;
  318. if (!libais_connection_active (conn_info)) {
  319. return (-1);
  320. }
  321. outq = &conn_info->outq;
  322. msg_send.msg_iov = &iov_send;
  323. msg_send.msg_name = 0;
  324. msg_send.msg_namelen = 0;
  325. msg_send.msg_iovlen = 1;
  326. msg_send.msg_control = 0;
  327. msg_send.msg_controllen = 0;
  328. msg_send.msg_flags = 0;
  329. while (!queue_is_empty (outq)) {
  330. queue_item = queue_item_get (outq);
  331. msg_addr = (char *)queue_item->msg;
  332. msg_addr = &msg_addr[conn_info->byte_start];
  333. iov_send.iov_base = msg_addr;
  334. iov_send.iov_len = queue_item->mlen - conn_info->byte_start;
  335. retry_sendmsg:
  336. res = sendmsg (conn_info->fd, &msg_send, MSG_DONTWAIT | MSG_NOSIGNAL);
  337. if (res == -1 && errno == EINTR) {
  338. goto retry_sendmsg;
  339. }
  340. if (res == -1 && errno == EAGAIN) {
  341. break; /* outgoing kernel queue full */
  342. }
  343. if (res == -1) {
  344. return (-1); /* message couldn't be sent */
  345. }
  346. if (res + conn_info->byte_start != queue_item->mlen) {
  347. conn_info->byte_start += res;
  348. break;
  349. }
  350. /*
  351. * Message sent, try sending another message
  352. */
  353. queue_item_remove (outq);
  354. conn_info->byte_start = 0;
  355. free (queue_item->msg);
  356. } /* while queue not empty */
  357. if (queue_is_empty (outq)) {
  358. poll_dispatch_modify (aisexec_poll_handle, conn_info->fd,
  359. POLLIN|POLLNVAL, poll_handler_libais_deliver, 0);
  360. }
  361. return (0);
  362. }
  363. extern int libais_send_response (struct conn_info *conn_info,
  364. void *msg, int mlen)
  365. {
  366. struct queue *outq;
  367. char *cmsg;
  368. int res = 0;
  369. int queue_empty;
  370. struct outq_item *queue_item;
  371. struct outq_item queue_item_out;
  372. struct msghdr msg_send;
  373. struct iovec iov_send;
  374. char *msg_addr;
  375. if (!libais_connection_active (conn_info)) {
  376. return (-1);
  377. }
  378. outq = &conn_info->outq;
  379. msg_send.msg_iov = &iov_send;
  380. msg_send.msg_name = 0;
  381. msg_send.msg_namelen = 0;
  382. msg_send.msg_iovlen = 1;
  383. msg_send.msg_control = 0;
  384. msg_send.msg_controllen = 0;
  385. msg_send.msg_flags = 0;
  386. if (queue_is_full (outq)) {
  387. /*
  388. * Start a disconnect if we have not already started one
  389. * and report that the outgoing queue is full
  390. */
  391. log_printf (LOG_LEVEL_ERROR, "Library queue is full, disconnecting library connection.\n");
  392. libais_disconnect_delayed (conn_info);
  393. return (-1);
  394. }
  395. while (!queue_is_empty (outq)) {
  396. queue_item = queue_item_get (outq);
  397. msg_addr = (char *)queue_item->msg;
  398. msg_addr = &msg_addr[conn_info->byte_start];
  399. iov_send.iov_base = msg_addr;
  400. iov_send.iov_len = queue_item->mlen - conn_info->byte_start;
  401. retry_sendmsg:
  402. res = sendmsg (conn_info->fd, &msg_send, MSG_DONTWAIT | MSG_NOSIGNAL);
  403. if (res == -1 && errno == EINTR) {
  404. goto retry_sendmsg;
  405. }
  406. if (res == -1 && errno == EAGAIN) {
  407. break; /* outgoing kernel queue full */
  408. }
  409. if (res == -1) {
  410. break; /* some other error, stop trying to send message */
  411. }
  412. if (res + conn_info->byte_start != queue_item->mlen) {
  413. conn_info->byte_start += res;
  414. break;
  415. }
  416. /*
  417. * Message sent, try sending another message
  418. */
  419. queue_item_remove (outq);
  420. conn_info->byte_start = 0;
  421. free (queue_item->msg);
  422. } /* while queue not empty */
  423. res = -1;
  424. queue_empty = queue_is_empty (outq);
  425. /*
  426. * Send requested message
  427. */
  428. if (queue_empty) {
  429. iov_send.iov_base = msg;
  430. iov_send.iov_len = mlen;
  431. retry_sendmsg_two:
  432. res = sendmsg (conn_info->fd, &msg_send, MSG_DONTWAIT | MSG_NOSIGNAL);
  433. if (res == -1 && errno == EINTR) {
  434. goto retry_sendmsg_two;
  435. }
  436. if (res == -1 && errno == EAGAIN) {
  437. conn_info->byte_start = 0;
  438. poll_dispatch_modify (aisexec_poll_handle, conn_info->fd,
  439. POLLIN|POLLNVAL, poll_handler_libais_deliver, 0);
  440. }
  441. if (res != -1) {
  442. if (res + conn_info->byte_start != mlen) {
  443. conn_info->byte_start += res;
  444. res = -1;
  445. } else {
  446. conn_info->byte_start = 0;
  447. poll_dispatch_modify (aisexec_poll_handle, conn_info->fd,
  448. POLLIN|POLLNVAL, poll_handler_libais_deliver, 0);
  449. }
  450. }
  451. }
  452. /*
  453. * If res == -1 , errrno == EAGAIN which means kernel queue full
  454. */
  455. if (res == -1) {
  456. cmsg = malloc (mlen);
  457. if (cmsg == 0) {
  458. log_printf (LOG_LEVEL_ERROR, "Library queue couldn't allocate a message, disconnecting library connection.\n");
  459. libais_disconnect_delayed (conn_info);
  460. return (-1);
  461. }
  462. queue_item_out.msg = cmsg;
  463. queue_item_out.mlen = mlen;
  464. memcpy (cmsg, msg, mlen);
  465. queue_item_add (outq, &queue_item_out);
  466. poll_dispatch_modify (aisexec_poll_handle, conn_info->fd,
  467. POLLOUT|POLLIN|POLLNVAL, poll_handler_libais_deliver, 0);
  468. }
  469. return (0);
  470. }
  471. static int poll_handler_libais_accept (
  472. poll_handle handle,
  473. int fd,
  474. int revent,
  475. void *data,
  476. unsigned int *prio)
  477. {
  478. socklen_t addrlen;
  479. struct conn_info *conn_info;
  480. struct sockaddr_un un_addr;
  481. int new_fd;
  482. int on = 1;
  483. addrlen = sizeof (struct sockaddr_un);
  484. retry_accept:
  485. new_fd = accept (fd, (struct sockaddr *)&un_addr, &addrlen);
  486. if (new_fd == -1 && errno == EINTR) {
  487. goto retry_accept;
  488. }
  489. if (new_fd == -1) {
  490. log_printf (LOG_LEVEL_ERROR, "ERROR: Could not accept Library connection: %s\n", strerror (errno));
  491. return (0); /* This is an error, but -1 would indicate disconnect from poll loop */
  492. }
  493. /*
  494. * Valid accept
  495. */
  496. /*
  497. * Request credentials of sender provided by kernel
  498. */
  499. setsockopt(new_fd, SOL_SOCKET, SO_PASSCRED, &on, sizeof (on));
  500. log_printf (LOG_LEVEL_DEBUG, "connection received from libais client %d.\n", new_fd);
  501. conn_info = conn_info_create (new_fd);
  502. if (conn_info == 0) {
  503. close (new_fd);
  504. return (0); /* This is an error, but -1 would indicate disconnect from poll */
  505. }
  506. poll_dispatch_add (aisexec_poll_handle, new_fd, POLLIN|POLLNVAL, conn_info,
  507. poll_handler_libais_deliver, 0);
  508. // TODO is this needed, or shouldn't it be in conn_info_create ?
  509. memcpy (&conn_info->ais_ci.un_addr, &un_addr, sizeof (struct sockaddr_un));
  510. return (0);
  511. }
  512. static int dispatch_init_send_response (struct conn_info *conn_info, void *message)
  513. {
  514. SaAisErrorT error = SA_AIS_ERR_ACCESS;
  515. struct req_lib_dispatch_init *req_lib_dispatch_init = (struct req_lib_dispatch_init *)message;
  516. struct res_lib_dispatch_init res_lib_dispatch_init;
  517. struct conn_info *msg_conn_info;
  518. if (conn_info->authenticated) {
  519. conn_info->service = req_lib_dispatch_init->resdis_header.service;
  520. error = SA_AIS_OK;
  521. conn_info->conn_info_partner = (struct conn_info *)req_lib_dispatch_init->conn_info;
  522. msg_conn_info = (struct conn_info *)req_lib_dispatch_init->conn_info;
  523. msg_conn_info->conn_info_partner = conn_info;
  524. }
  525. res_lib_dispatch_init.header.size = sizeof (struct res_lib_dispatch_init);
  526. res_lib_dispatch_init.header.id = MESSAGE_RES_INIT;
  527. res_lib_dispatch_init.header.error = error;
  528. libais_send_response (conn_info, &res_lib_dispatch_init,
  529. sizeof (res_lib_dispatch_init));
  530. if (error == SA_AIS_ERR_ACCESS) {
  531. return (-1);
  532. }
  533. conn_info->should_exit_fn = 1;
  534. ais_service_handlers[req_lib_dispatch_init->resdis_header.service]->lib_init_fn (conn_info);
  535. return (0);
  536. }
  537. static int response_init_send_response (struct conn_info *conn_info, void *message)
  538. {
  539. SaAisErrorT error = SA_AIS_ERR_ACCESS;
  540. struct req_lib_response_init *req_lib_response_init = (struct req_lib_response_init *)message;
  541. struct res_lib_response_init res_lib_response_init;
  542. if (conn_info->authenticated) {
  543. conn_info->service = req_lib_response_init->resdis_header.service;
  544. error = SA_AIS_OK;
  545. }
  546. res_lib_response_init.header.size = sizeof (struct res_lib_response_init);
  547. res_lib_response_init.header.id = MESSAGE_RES_INIT;
  548. res_lib_response_init.header.error = error;
  549. res_lib_response_init.conn_info = (unsigned long)conn_info;
  550. libais_send_response (conn_info, &res_lib_response_init,
  551. sizeof (res_lib_response_init));
  552. if (error == SA_AIS_ERR_ACCESS) {
  553. return (-1);
  554. }
  555. conn_info->should_exit_fn = 0;
  556. return (0);
  557. }
  558. struct res_overlay {
  559. struct res_header header;
  560. char buf[4096];
  561. };
  562. static int poll_handler_libais_deliver (poll_handle handle, int fd, int revent, void *data, unsigned int *prio)
  563. {
  564. int res;
  565. struct conn_info *conn_info = (struct conn_info *)data;
  566. struct req_header *header;
  567. int service;
  568. struct msghdr msg_recv;
  569. struct iovec iov_recv;
  570. struct cmsghdr *cmsg;
  571. char cmsg_cred[CMSG_SPACE (sizeof (struct ucred))];
  572. struct ucred *cred;
  573. int on = 0;
  574. int send_ok = 0;
  575. int send_ok_joined = 0;
  576. struct iovec send_ok_joined_iovec;
  577. struct res_overlay res_overlay;
  578. if (revent & (POLLERR|POLLHUP)) {
  579. res = libais_disconnect (conn_info);
  580. return (res);
  581. }
  582. /*
  583. * Handle delayed disconnections
  584. */
  585. if (conn_info->state == CONN_STATE_DISCONNECTING_DELAYED) {
  586. res = libais_disconnect (conn_info);
  587. return (res);
  588. }
  589. if (conn_info->state == CONN_STATE_DISCONNECTING) {
  590. return (0);
  591. }
  592. if (revent & POLLOUT) {
  593. cleanup_send_response (conn_info);
  594. }
  595. if ((revent & POLLIN) == 0) {
  596. return (0);
  597. }
  598. msg_recv.msg_iov = &iov_recv;
  599. msg_recv.msg_iovlen = 1;
  600. msg_recv.msg_name = 0;
  601. msg_recv.msg_namelen = 0;
  602. msg_recv.msg_flags = 0;
  603. if (conn_info->authenticated) {
  604. msg_recv.msg_control = 0;
  605. msg_recv.msg_controllen = 0;
  606. } else {
  607. msg_recv.msg_control = (void *)cmsg_cred;
  608. msg_recv.msg_controllen = sizeof (cmsg_cred);
  609. }
  610. iov_recv.iov_base = &conn_info->inb[conn_info->inb_start];
  611. iov_recv.iov_len = (SIZEINB) - conn_info->inb_start;
  612. assert (iov_recv.iov_len != 0);
  613. retry_recv:
  614. res = recvmsg (fd, &msg_recv, MSG_DONTWAIT | MSG_NOSIGNAL);
  615. if (res == -1 && errno == EINTR) {
  616. goto retry_recv;
  617. } else
  618. if (res == -1 && errno != EAGAIN) {
  619. goto error_disconnect;
  620. } else
  621. if (res == 0) {
  622. goto error_disconnect;
  623. return (-1);
  624. }
  625. /*
  626. * Authenticate if this connection has not been authenticated
  627. */
  628. if (conn_info->authenticated == 0) {
  629. cmsg = CMSG_FIRSTHDR (&msg_recv);
  630. cred = (struct ucred *)CMSG_DATA (cmsg);
  631. if (cred) {
  632. if (cred->uid == 0 || cred->gid == gid_valid) {
  633. setsockopt(fd, SOL_SOCKET, SO_PASSCRED, &on, sizeof (on));
  634. conn_info->authenticated = 1;
  635. }
  636. }
  637. if (conn_info->authenticated == 0) {
  638. log_printf (LOG_LEVEL_SECURITY, "Connection not authenticated because gid is %d, expecting %d\n", cred->gid, gid_valid);
  639. }
  640. }
  641. /*
  642. * Dispatch all messages received in recvmsg that can be dispatched
  643. * sizeof (struct req_header) needed at minimum to do any processing
  644. */
  645. conn_info->inb_inuse += res;
  646. conn_info->inb_start += res;
  647. while (conn_info->inb_inuse >= sizeof (struct req_header) && res != -1) {
  648. header = (struct req_header *)&conn_info->inb[conn_info->inb_start - conn_info->inb_inuse];
  649. if (header->size > conn_info->inb_inuse) {
  650. break;
  651. }
  652. service = conn_info->service;
  653. /*
  654. * If this service is in init phase, initialize service
  655. * else handle message using service handlers
  656. */
  657. if (service == SOCKET_SERVICE_INIT) {
  658. res = ais_init_handlers[header->id] (conn_info, header);
  659. // TODO error in init_two_fn needs to be handled
  660. } else {
  661. /*
  662. * Not an init service, but a standard service
  663. */
  664. if (header->id < 0 || header->id > ais_service_handlers[service]->lib_handlers_count) {
  665. log_printf (LOG_LEVEL_SECURITY, "Invalid header id is %d min 0 max %d\n",
  666. header->id, ais_service_handlers[service]->lib_handlers_count);
  667. res = -1;
  668. goto error_disconnect;
  669. }
  670. /*
  671. * If flow control is required of the library handle, determine that
  672. * openais is not in synchronization and that totempg has room available
  673. * to queue a message, otherwise tell the library we are busy and to
  674. * try again later
  675. */
  676. send_ok_joined_iovec.iov_base = header;
  677. send_ok_joined_iovec.iov_len = header->size;
  678. send_ok_joined = totempg_groups_send_ok_joined (openais_group_handle,
  679. &send_ok_joined_iovec, 1);
  680. send_ok =
  681. (ykd_primary() == 1) && (
  682. (ais_service_handlers[service]->lib_handlers[header->id].flow_control == OPENAIS_FLOW_CONTROL_NOT_REQUIRED) ||
  683. ((ais_service_handlers[service]->lib_handlers[header->id].flow_control == OPENAIS_FLOW_CONTROL_REQUIRED) &&
  684. (send_ok_joined) &&
  685. (sync_in_process() == 0)));
  686. if (send_ok) {
  687. // *prio = 0;
  688. ais_service_handlers[service]->lib_handlers[header->id].lib_handler_fn(conn_info, header);
  689. } else {
  690. // *prio = (*prio) + 1;
  691. /*
  692. * Overload, tell library to retry
  693. */
  694. res_overlay.header.size =
  695. ais_service_handlers[service]->lib_handlers[header->id].response_size;
  696. res_overlay.header.id =
  697. ais_service_handlers[service]->lib_handlers[header->id].response_id;
  698. res_overlay.header.error = SA_AIS_ERR_TRY_AGAIN;
  699. libais_send_response (conn_info, &res_overlay,
  700. res_overlay.header.size);
  701. }
  702. }
  703. conn_info->inb_inuse -= header->size;
  704. } /* while */
  705. if (conn_info->inb_inuse == 0) {
  706. conn_info->inb_start = 0;
  707. } else
  708. // BUG if (connections[fd].inb_start + connections[fd].inb_inuse >= SIZEINB) {
  709. if (conn_info->inb_start >= SIZEINB) {
  710. /*
  711. * If in buffer is full, move it back to start
  712. */
  713. memmove (conn_info->inb,
  714. &conn_info->inb[conn_info->inb_start - conn_info->inb_inuse],
  715. sizeof (char) * conn_info->inb_inuse);
  716. conn_info->inb_start = conn_info->inb_inuse;
  717. }
  718. return (0);
  719. error_disconnect:
  720. res = libais_disconnect (conn_info);
  721. return (res);
  722. }
  723. void sigintr_handler (int signum)
  724. {
  725. #ifdef DEBUG_MEMPOOL
  726. int stats_inuse[MEMPOOL_GROUP_SIZE];
  727. int stats_avail[MEMPOOL_GROUP_SIZE];
  728. int stats_memoryused[MEMPOOL_GROUP_SIZE];
  729. int i;
  730. mempool_getstats (stats_inuse, stats_avail, stats_memoryused);
  731. log_printf (LOG_LEVEL_DEBUG, "Memory pools:\n");
  732. for (i = 0; i < MEMPOOL_GROUP_SIZE; i++) {
  733. log_printf (LOG_LEVEL_DEBUG, "order %d size %d inuse %d avail %d memory used %d\n",
  734. i, 1<<i, stats_inuse[i], stats_avail[i], stats_memoryused[i]);
  735. }
  736. #endif
  737. totempg_finalize ();
  738. ais_done (AIS_DONE_EXIT);
  739. }
  740. static struct sched_param sched_param = {
  741. sched_priority: 99
  742. };
  743. static int pool_sizes[] = { 0, 0, 0, 0, 0, 4096, 0, 1, 0, /* 256 */
  744. 1024, 0, 1, 4096, 0, 0, 0, 0, /* 65536 */
  745. 1, 1, 1, 1, 1, 1, 1, 1, 1 };
  746. static void openais_sync_completed (void)
  747. {
  748. }
  749. static int openais_sync_callbacks_retrieve (int sync_id,
  750. struct sync_callbacks *callbacks)
  751. {
  752. if (ais_service_handlers[sync_id] == NULL) {
  753. memset (callbacks, 0, sizeof (struct sync_callbacks));
  754. return (-1);
  755. }
  756. callbacks->sync_init = ais_service_handlers[sync_id]->sync_init;
  757. callbacks->sync_process = ais_service_handlers[sync_id]->sync_process;
  758. callbacks->sync_activate = ais_service_handlers[sync_id]->sync_activate;
  759. callbacks->sync_abort = ais_service_handlers[sync_id]->sync_abort;
  760. return (0);
  761. }
  762. char delivery_data[MESSAGE_SIZE_MAX];
  763. static void deliver_fn (
  764. struct totem_ip_address *source_addr,
  765. struct iovec *iovec,
  766. int iov_len,
  767. int endian_conversion_required)
  768. {
  769. struct req_header *header;
  770. int pos = 0;
  771. int i;
  772. int service;
  773. int fn_id;
  774. /*
  775. * Build buffer without iovecs to make processing easier
  776. * This is only used for messages which are multicast with iovecs
  777. * and self-delivered. All other mechanisms avoid the copy.
  778. */
  779. if (iov_len > 1) {
  780. for (i = 0; i < iov_len; i++) {
  781. memcpy (&delivery_data[pos], iovec[i].iov_base, iovec[i].iov_len);
  782. pos += iovec[i].iov_len;
  783. assert (pos < MESSAGE_SIZE_MAX);
  784. }
  785. header = (struct req_header *)delivery_data;
  786. } else {
  787. header = (struct req_header *)iovec[0].iov_base;
  788. }
  789. if (endian_conversion_required) {
  790. header->id = swab32 (header->id);
  791. header->size = swab32 (header->size);
  792. }
  793. // assert(iovec->iov_len == header->size);
  794. /*
  795. * Call the proper executive handler
  796. */
  797. service = header->id >> 16;
  798. fn_id = header->id & 0xffff;
  799. if (endian_conversion_required) {
  800. ais_service_handlers[service]->exec_handlers[fn_id].exec_endian_convert_fn
  801. (header);
  802. }
  803. ais_service_handlers[service]->exec_handlers[fn_id].exec_handler_fn
  804. (header, source_addr);
  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 openais_service_handler *handler,
  951. struct openais_config *config)
  952. {
  953. int res = 0;
  954. assert (ais_service_handlers[handler->id] == NULL);
  955. log_printf (LOG_LEVEL_NOTICE, "Registering service handler '%s'\n", handler->name);
  956. ais_service_handlers[handler->id] = handler;
  957. if (ais_service_handlers[handler->id]->exec_init_fn) {
  958. res = ais_service_handlers[handler->id]->exec_init_fn (config);
  959. }
  960. return (res);
  961. }
  962. void default_services_register (struct openais_config *openais_config)
  963. {
  964. #ifdef BUILD_DYNAMIC
  965. int i;
  966. for (i = 0; i < 8; i++) {
  967. lcr_ifact_reference (
  968. &dynamic_services[i].handle,
  969. dynamic_services[i].name,
  970. dynamic_services[i].ver,
  971. (void **)&dynamic_services[i].iface_ver0,
  972. (void *)0);
  973. service_handler_register (
  974. dynamic_services[i].iface_ver0->openais_get_service_handler_ver0(),
  975. openais_config);
  976. }
  977. #else /* NOT BUILD_DYNAMIC */
  978. /*
  979. * link everything together - better for debugging - smaller memory footprint
  980. */
  981. service_handler_register (&evs_service_handler, openais_config);
  982. service_handler_register (&clm_service_handler, openais_config);
  983. service_handler_register (&amf_service_handler, openais_config);
  984. service_handler_register (&ckpt_service_handler, openais_config);
  985. service_handler_register (&evt_service_handler, openais_config);
  986. service_handler_register (&lck_service_handler, openais_config);
  987. service_handler_register (&msg_service_handler, openais_config);
  988. service_handler_register (&cfg_service_handler, openais_config);
  989. #endif /* BUILD_DYNAMIC */
  990. }
  991. int main (int argc, char **argv)
  992. {
  993. int libais_server_fd;
  994. int res;
  995. char *error_string;
  996. struct openais_config openais_config;
  997. memset(&this_non_loopback_ip, 0, sizeof(struct totem_ip_address));
  998. totemip_localhost(AF_INET, &this_non_loopback_ip);
  999. aisexec_uid_determine ();
  1000. aisexec_gid_determine ();
  1001. aisexec_poll_handle = poll_create ();
  1002. //TODO signal (SIGUSR2, sigusr2_handler);
  1003. /*
  1004. * if totempg_initialize doesn't have root priveleges, it cannot
  1005. * bind to a specific interface. This only matters if
  1006. * there is more then one interface in a system, so
  1007. * in this case, only a warning is printed
  1008. */
  1009. res = openais_main_config_read (&error_string, &openais_config, 1);
  1010. if (res == -1) {
  1011. log_printf (LOG_LEVEL_NOTICE, "AIS Executive Service: Copyright (C) 2002-2004 MontaVista Software, Inc and contributors.\n");
  1012. log_printf (LOG_LEVEL_ERROR, error_string);
  1013. ais_done (AIS_DONE_MAINCONFIGREAD);
  1014. }
  1015. res = openais_amf_config_read (&error_string);
  1016. if (res == -1) {
  1017. log_printf (LOG_LEVEL_ERROR, error_string);
  1018. ais_done (AIS_DONE_AMFCONFIGREAD);
  1019. }
  1020. res = totem_config_read (&openais_config.totem_config, &error_string, 1);
  1021. if (res == -1) {
  1022. log_printf (LOG_LEVEL_NOTICE, "AIS Executive Service: Copyright (C) 2002-2004 MontaVista Software, Inc and contributors.\n");
  1023. log_printf (LOG_LEVEL_ERROR, error_string);
  1024. ais_done (AIS_DONE_MAINCONFIGREAD);
  1025. }
  1026. res = totem_config_keyread ("/etc/ais/authkey", &openais_config.totem_config, &error_string);
  1027. if (res == -1) {
  1028. log_printf (LOG_LEVEL_ERROR, error_string);
  1029. ais_done (AIS_DONE_MAINCONFIGREAD);
  1030. }
  1031. res = totem_config_validate (&openais_config.totem_config, &error_string);
  1032. if (res == -1) {
  1033. log_printf (LOG_LEVEL_ERROR, error_string);
  1034. ais_done (AIS_DONE_MAINCONFIGREAD);
  1035. }
  1036. res = log_setup (&error_string, openais_config.logmode, openais_config.logfile);
  1037. if (res == -1) {
  1038. log_printf (LOG_LEVEL_ERROR, error_string);
  1039. ais_done (AIS_DONE_LOGSETUP);
  1040. }
  1041. log_printf (LOG_LEVEL_NOTICE, "AIS Executive Service: Copyright (C) 2002-2004 MontaVista Software, Inc. and contributors.\n");
  1042. /*
  1043. * Set round robin realtime scheduling with priority 99
  1044. * Lock all memory to avoid page faults which may interrupt
  1045. * application healthchecking
  1046. */
  1047. aisexec_setscheduler ();
  1048. aisexec_mlockall ();
  1049. openais_config.totem_config.totem_logging_configuration = totem_logging_configuration;
  1050. openais_config.totem_config.totem_logging_configuration.log_level_security = mklog (LOG_LEVEL_SECURITY, LOG_SERVICE_GMI);
  1051. openais_config.totem_config.totem_logging_configuration.log_level_error = mklog (LOG_LEVEL_ERROR, LOG_SERVICE_GMI);
  1052. openais_config.totem_config.totem_logging_configuration.log_level_warning = mklog (LOG_LEVEL_WARNING, LOG_SERVICE_GMI);
  1053. openais_config.totem_config.totem_logging_configuration.log_level_notice = mklog (LOG_LEVEL_NOTICE, LOG_SERVICE_GMI);
  1054. openais_config.totem_config.totem_logging_configuration.log_level_debug = mklog (LOG_LEVEL_DEBUG, LOG_SERVICE_GMI);
  1055. openais_config.totem_config.totem_logging_configuration.log_printf = internal_log_printf;
  1056. totempg_initialize (
  1057. aisexec_poll_handle,
  1058. &openais_config.totem_config);
  1059. totempg_groups_initialize (
  1060. &openais_group_handle,
  1061. deliver_fn,
  1062. confchg_fn);
  1063. totempg_groups_join (
  1064. openais_group_handle,
  1065. &openais_group,
  1066. 1);
  1067. this_ip = &openais_config.totem_config.interfaces[0].boundto;
  1068. default_services_register(&openais_config);
  1069. sync_register (openais_sync_callbacks_retrieve, openais_sync_completed);
  1070. /*
  1071. * Drop root privleges to user 'ais'
  1072. * TODO: Don't really need full root capabilities;
  1073. * needed capabilities are:
  1074. * CAP_NET_RAW (bindtodevice)
  1075. * CAP_SYS_NICE (setscheduler)
  1076. * CAP_IPC_LOCK (mlockall)
  1077. */
  1078. aisexec_priv_drop ();
  1079. aisexec_mempool_init ();
  1080. signal (SIGINT, sigintr_handler);
  1081. aisexec_libais_bind (&libais_server_fd);
  1082. aisexec_tty_detach ();
  1083. log_printf (LOG_LEVEL_NOTICE, "AIS Executive Service: started and ready to receive connections.\n");
  1084. /*
  1085. * Setup libais connection dispatch routine
  1086. */
  1087. poll_dispatch_add (aisexec_poll_handle, libais_server_fd,
  1088. POLLIN, 0, poll_handler_libais_accept, 0);
  1089. /*
  1090. * Join multicast group and setup delivery
  1091. * and configuration change functions
  1092. */
  1093. /*
  1094. * Start main processing loop
  1095. */
  1096. poll_run (aisexec_poll_handle);
  1097. return (0);
  1098. }