4
0

main.c 35 KB

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