corosync-notifyd.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256
  1. /*
  2. * Copyright (c) 2011-2012 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Angus Salkeld <asalkeld@redhat.com>
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <config.h>
  35. #include <sys/select.h>
  36. #include <sys/socket.h>
  37. #include <sys/un.h>
  38. #include <sys/types.h>
  39. #include <netdb.h>
  40. #include <arpa/inet.h>
  41. #include <stdio.h>
  42. #include <stdlib.h>
  43. #include <errno.h>
  44. #include <unistd.h>
  45. #include <string.h>
  46. #include <ctype.h>
  47. #include <poll.h>
  48. #include <signal.h>
  49. #include <qb/qbdefs.h>
  50. #include <qb/qbloop.h>
  51. #include <qb/qblog.h>
  52. #include <corosync/corotypes.h>
  53. #include <corosync/cfg.h>
  54. #include <corosync/quorum.h>
  55. #include <corosync/cmap.h>
  56. /*
  57. * generic declarations
  58. */
  59. enum {
  60. CS_NTF_LOG,
  61. CS_NTF_STDOUT,
  62. CS_NTF_SNMP,
  63. CS_NTF_DBUS,
  64. CS_NTF_FG,
  65. CS_NTF_MAX,
  66. };
  67. static int conf[CS_NTF_MAX];
  68. static int32_t _cs_is_quorate = 0;
  69. typedef void (*node_membership_fn_t)(char *nodename, uint32_t nodeid, char *state, char* ip);
  70. typedef void (*node_quorum_fn_t)(char *nodename, uint32_t nodeid, const char *state);
  71. typedef void (*application_connection_fn_t)(char *nodename, uint32_t nodeid, char *app_name, const char *state);
  72. typedef void (*rrp_faulty_fn_t)(char *nodename, uint32_t nodeid, uint32_t iface_no, const char *state);
  73. struct notify_callbacks {
  74. node_membership_fn_t node_membership_fn;
  75. node_quorum_fn_t node_quorum_fn;
  76. application_connection_fn_t application_connection_fn;
  77. rrp_faulty_fn_t rrp_faulty_fn;
  78. };
  79. #define MAX_NOTIFIERS 5
  80. static int num_notifiers = 0;
  81. static struct notify_callbacks notifiers[MAX_NOTIFIERS];
  82. /*
  83. * Global variable with local nodeid
  84. */
  85. static uint32_t g_local_nodeid = 0;
  86. static char local_nodename[CS_MAX_NAME_LENGTH];
  87. static qb_loop_t *main_loop;
  88. static quorum_handle_t quorum_handle;
  89. static void _cs_node_membership_event(char *nodename, uint32_t nodeid, char *state, char* ip);
  90. static void _cs_node_quorum_event(const char *state);
  91. static void _cs_application_connection_event(char *app_name, const char *state);
  92. static void _cs_rrp_faulty_event(uint32_t iface_no, const char *state);
  93. #ifdef HAVE_DBUS
  94. #include <dbus/dbus.h>
  95. /*
  96. * dbus
  97. */
  98. #define DBUS_CS_NAME "org.corosync"
  99. #define DBUS_CS_IFACE "org.corosync"
  100. #define DBUS_CS_PATH "/org/corosync"
  101. static DBusConnection *db = NULL;
  102. static char _err[512];
  103. static int err_set = 0;
  104. static void _cs_dbus_init(void);
  105. #endif /* HAVE_DBUS */
  106. #ifdef ENABLE_SNMP
  107. #include <net-snmp/net-snmp-config.h>
  108. #include <net-snmp/snmpv3_api.h>
  109. #include <net-snmp/agent/agent_trap.h>
  110. #include <net-snmp/library/mib.h>
  111. #include <net-snmp/library/snmp_api.h>
  112. #include <net-snmp/library/snmp_client.h>
  113. #include <net-snmp/library/snmp_debug.h>
  114. enum snmp_node_status {
  115. SNMP_NODE_STATUS_UNKNOWN = 0,
  116. SNMP_NODE_STATUS_JOINED = 1,
  117. SNMP_NODE_STATUS_LEFT = 2
  118. };
  119. #define SNMP_OID_COROSYNC "1.3.6.1.4.1.35488"
  120. #define SNMP_OID_OBJECT_ROOT SNMP_OID_COROSYNC ".1"
  121. #define SNMP_OID_OBJECT_NODE_NAME SNMP_OID_OBJECT_ROOT ".1"
  122. #define SNMP_OID_OBJECT_NODE_ID SNMP_OID_OBJECT_ROOT ".2"
  123. #define SNMP_OID_OBJECT_NODE_STATUS SNMP_OID_OBJECT_ROOT ".3"
  124. #define SNMP_OID_OBJECT_NODE_ADDR SNMP_OID_OBJECT_ROOT ".4"
  125. #define SNMP_OID_OBJECT_RINGSEQ SNMP_OID_OBJECT_ROOT ".20"
  126. #define SNMP_OID_OBJECT_QUORUM SNMP_OID_OBJECT_ROOT ".21"
  127. #define SNMP_OID_OBJECT_APP_NAME SNMP_OID_OBJECT_ROOT ".40"
  128. #define SNMP_OID_OBJECT_APP_STATUS SNMP_OID_OBJECT_ROOT ".41"
  129. #define SNMP_OID_OBJECT_RRP_IFACE_NO SNMP_OID_OBJECT_ROOT ".60"
  130. #define SNMP_OID_OBJECT_RRP_STATUS SNMP_OID_OBJECT_ROOT ".61"
  131. #define SNMP_OID_TRAPS_ROOT SNMP_OID_COROSYNC ".0"
  132. #define SNMP_OID_TRAPS_NODE SNMP_OID_TRAPS_ROOT ".1"
  133. #define SNMP_OID_TRAPS_QUORUM SNMP_OID_TRAPS_ROOT ".2"
  134. #define SNMP_OID_TRAPS_APP SNMP_OID_TRAPS_ROOT ".3"
  135. #define SNMP_OID_TRAPS_RRP SNMP_OID_TRAPS_ROOT ".4"
  136. #define CS_TIMESTAMP_STR_LEN 20
  137. static const char *local_host = "localhost";
  138. #endif /* ENABLE_SNMP */
  139. static char snmp_manager_buf[CS_MAX_NAME_LENGTH];
  140. static char *snmp_manager = NULL;
  141. static char snmp_community_buf[CS_MAX_NAME_LENGTH];
  142. static char *snmp_community = NULL;
  143. #define CMAP_MAX_RETRIES 10
  144. /*
  145. * cmap
  146. */
  147. static cmap_handle_t cmap_handle;
  148. static int32_t _cs_ip_to_hostname(char* ip, char* name_out)
  149. {
  150. struct sockaddr_in sa;
  151. int rc;
  152. if (strchr(ip, ':') == NULL) {
  153. sa.sin_family = AF_INET;
  154. } else {
  155. sa.sin_family = AF_INET6;
  156. }
  157. rc = inet_pton(sa.sin_family, ip, &sa.sin_addr);
  158. if (rc == 0) {
  159. return -EINVAL;
  160. }
  161. rc = getnameinfo((struct sockaddr*)&sa, sizeof(sa),
  162. name_out, CS_MAX_NAME_LENGTH, NULL, 0, 0);
  163. if (rc != 0) {
  164. qb_log(LOG_ERR, "error looking up %s : %s", ip, gai_strerror(rc));
  165. return -EINVAL;
  166. }
  167. return 0;
  168. }
  169. static void _cs_cmap_members_key_changed (
  170. cmap_handle_t cmap_handle_c,
  171. cmap_track_handle_t cmap_track_handle,
  172. int32_t event,
  173. const char *key_name,
  174. struct cmap_notify_value new_value,
  175. struct cmap_notify_value old_value,
  176. void *user_data)
  177. {
  178. char nodename[CS_MAX_NAME_LENGTH];
  179. char* open_bracket = NULL;
  180. char* close_bracket = NULL;
  181. int res;
  182. uint32_t nodeid;
  183. char *ip_str;
  184. char tmp_key[CMAP_KEYNAME_MAXLEN];
  185. cs_error_t err;
  186. int no_retries;
  187. if (event != CMAP_TRACK_ADD && event != CMAP_TRACK_MODIFY) {
  188. return ;
  189. }
  190. if (NULL == key_name) {
  191. qb_log(LOG_ERR, "key_name: nil");
  192. }
  193. res = sscanf(key_name, "runtime.totem.pg.mrp.srp.members.%u.%s", &nodeid, tmp_key);
  194. if (res != 2)
  195. return ;
  196. if (strcmp(tmp_key, "status") != 0) {
  197. return ;
  198. }
  199. res = snprintf(tmp_key, CMAP_KEYNAME_MAXLEN, "runtime.totem.pg.mrp.srp.members.%u.ip", nodeid);
  200. if (res <= 0 || res >= CMAP_KEYNAME_MAXLEN) {
  201. qb_log(LOG_ERR, "temp_key: failed, res: %d, nodeid: %u", res, nodeid);
  202. return ;
  203. }
  204. no_retries = 0;
  205. while ((err = cmap_get_string(cmap_handle, tmp_key, &ip_str)) == CS_ERR_TRY_AGAIN &&
  206. no_retries++ < CMAP_MAX_RETRIES) {
  207. sleep(1);
  208. }
  209. if (err != CS_OK) {
  210. return ;
  211. }
  212. /*
  213. * We want the ip out of: "r(0) ip(192.168.100.92)"
  214. */
  215. open_bracket = strrchr(ip_str, '(');
  216. if (NULL == open_bracket) {
  217. qb_log(LOG_ERR, "ip_str: %s", ip_str);
  218. free(ip_str);
  219. return ;
  220. }
  221. open_bracket++;
  222. close_bracket = strchr(open_bracket, ')');
  223. if (NULL == close_bracket) {
  224. qb_log(LOG_ERR, "open_bracket: %s", open_bracket);
  225. free(ip_str);
  226. return ;
  227. }
  228. *close_bracket = '\0';
  229. res = _cs_ip_to_hostname(open_bracket, nodename);
  230. if (res) {
  231. strncpy(nodename, open_bracket, CS_MAX_NAME_LENGTH-1);
  232. }
  233. _cs_node_membership_event(nodename, nodeid, (char *)new_value.data, open_bracket);
  234. free(ip_str);
  235. }
  236. static void _cs_cmap_connections_key_changed (
  237. cmap_handle_t cmap_handle_c,
  238. cmap_track_handle_t cmap_track_handle,
  239. int32_t event,
  240. const char *key_name,
  241. struct cmap_notify_value new_value,
  242. struct cmap_notify_value old_value,
  243. void *user_data)
  244. {
  245. char obj_name[CS_MAX_NAME_LENGTH];
  246. char conn_str[CMAP_KEYNAME_MAXLEN];
  247. char tmp_key[CMAP_KEYNAME_MAXLEN];
  248. int res;
  249. res = sscanf(key_name, "runtime.connections.%[^.].%s", conn_str, tmp_key);
  250. if (res != 2) {
  251. return ;
  252. }
  253. if (strcmp(tmp_key, "service_id") != 0) {
  254. return ;
  255. }
  256. snprintf(obj_name, CS_MAX_NAME_LENGTH, "%s", conn_str);
  257. if (event == CMAP_TRACK_ADD) {
  258. _cs_application_connection_event(obj_name, "connected");
  259. }
  260. if (event == CMAP_TRACK_DELETE) {
  261. _cs_application_connection_event(obj_name, "disconnected");
  262. }
  263. }
  264. static void _cs_cmap_rrp_faulty_key_changed (
  265. cmap_handle_t cmap_handle_c,
  266. cmap_track_handle_t cmap_track_handle,
  267. int32_t event,
  268. const char *key_name,
  269. struct cmap_notify_value new_value,
  270. struct cmap_notify_value old_value,
  271. void *user_data)
  272. {
  273. uint32_t iface_no;
  274. char tmp_key[CMAP_KEYNAME_MAXLEN];
  275. int res;
  276. int no_retries;
  277. uint8_t faulty;
  278. cs_error_t err;
  279. res = sscanf(key_name, "runtime.totem.pg.mrp.rrp.%u.%s", &iface_no, tmp_key);
  280. if (res != 2) {
  281. return ;
  282. }
  283. if (strcmp(tmp_key, "faulty") != 0) {
  284. return ;
  285. }
  286. no_retries = 0;
  287. while ((err = cmap_get_uint8(cmap_handle, key_name, &faulty)) == CS_ERR_TRY_AGAIN &&
  288. no_retries++ < CMAP_MAX_RETRIES) {
  289. sleep(1);
  290. }
  291. if (err != CS_OK) {
  292. return ;
  293. }
  294. if (faulty) {
  295. _cs_rrp_faulty_event(iface_no, "faulty");
  296. } else {
  297. _cs_rrp_faulty_event(iface_no, "operational");
  298. }
  299. }
  300. static int
  301. _cs_cmap_dispatch(int fd, int revents, void *data)
  302. {
  303. cs_error_t err;
  304. err = cmap_dispatch(cmap_handle, CS_DISPATCH_ONE);
  305. if (err != CS_OK && err != CS_ERR_TRY_AGAIN && err != CS_ERR_TIMEOUT &&
  306. err != CS_ERR_QUEUE_FULL) {
  307. qb_log(LOG_ERR, "Could not dispatch cmap events. Error %u", err);
  308. qb_loop_stop(main_loop);
  309. return -1;
  310. }
  311. return 0;
  312. }
  313. static void _cs_quorum_notification(quorum_handle_t handle,
  314. uint32_t quorate, uint64_t ring_seq,
  315. uint32_t view_list_entries, uint32_t *view_list)
  316. {
  317. if (_cs_is_quorate == quorate) {
  318. return;
  319. }
  320. _cs_is_quorate = quorate;
  321. if (quorate) {
  322. _cs_node_quorum_event("quorate");
  323. } else {
  324. _cs_node_quorum_event("not quorate");
  325. }
  326. }
  327. static int
  328. _cs_quorum_dispatch(int fd, int revents, void *data)
  329. {
  330. cs_error_t err;
  331. err = quorum_dispatch(quorum_handle, CS_DISPATCH_ONE);
  332. if (err != CS_OK && err != CS_ERR_TRY_AGAIN && err != CS_ERR_TIMEOUT &&
  333. err != CS_ERR_QUEUE_FULL) {
  334. qb_log(LOG_ERR, "Could not dispatch quorum events. Error %u", err);
  335. qb_loop_stop(main_loop);
  336. return -1;
  337. }
  338. return 0;
  339. }
  340. static void
  341. _cs_quorum_init(void)
  342. {
  343. cs_error_t rc;
  344. uint32_t quorum_type;
  345. int fd;
  346. quorum_callbacks_t quorum_callbacks = {
  347. .quorum_notify_fn = _cs_quorum_notification,
  348. };
  349. rc = quorum_initialize (&quorum_handle, &quorum_callbacks,
  350. &quorum_type);
  351. if (rc != CS_OK) {
  352. qb_log(LOG_ERR, "Could not connect to corosync(quorum)");
  353. return;
  354. }
  355. quorum_fd_get(quorum_handle, &fd);
  356. qb_loop_poll_add(main_loop, QB_LOOP_MED, fd, POLLIN|POLLNVAL, NULL,
  357. _cs_quorum_dispatch);
  358. rc = quorum_trackstart(quorum_handle, CS_TRACK_CHANGES);
  359. if (rc != CS_OK) {
  360. qb_log(LOG_ERR, "Could not start tracking");
  361. return;
  362. }
  363. }
  364. static void
  365. _cs_quorum_finalize(void)
  366. {
  367. quorum_finalize (quorum_handle);
  368. }
  369. #ifdef HAVE_DBUS
  370. /*
  371. * dbus notifications
  372. */
  373. static void
  374. _cs_dbus_auto_flush(void)
  375. {
  376. dbus_connection_ref(db);
  377. while (dbus_connection_get_dispatch_status(db) == DBUS_DISPATCH_DATA_REMAINS) {
  378. dbus_connection_dispatch(db);
  379. }
  380. while (dbus_connection_has_messages_to_send(db)) {
  381. dbus_connection_flush(db);
  382. }
  383. dbus_connection_unref(db);
  384. }
  385. static void
  386. _cs_dbus_release(void)
  387. {
  388. DBusError err;
  389. if (!db)
  390. return;
  391. dbus_error_init(&err);
  392. dbus_bus_release_name(db, DBUS_CS_NAME, &err);
  393. dbus_error_free(&err);
  394. dbus_connection_unref(db);
  395. db = NULL;
  396. }
  397. static void
  398. _cs_dbus_node_quorum_event(char *nodename, uint32_t nodeid, const char *state)
  399. {
  400. DBusMessage *msg = NULL;
  401. if (err_set) {
  402. qb_log(LOG_ERR, "%s", _err);
  403. err_set = 0;
  404. }
  405. if (!db) {
  406. goto out_free;
  407. }
  408. if (dbus_connection_get_is_connected(db) != TRUE) {
  409. err_set = 1;
  410. snprintf(_err, sizeof(_err), "DBus connection lost");
  411. _cs_dbus_release();
  412. goto out_unlock;
  413. }
  414. _cs_dbus_auto_flush();
  415. if (!(msg = dbus_message_new_signal(DBUS_CS_PATH,
  416. DBUS_CS_IFACE,
  417. "QuorumStateChange"))) {
  418. qb_log(LOG_ERR, "error creating dbus signal");
  419. goto out_unlock;
  420. }
  421. if (!dbus_message_append_args(msg,
  422. DBUS_TYPE_STRING, &nodename,
  423. DBUS_TYPE_UINT32, &nodeid,
  424. DBUS_TYPE_STRING, &state,
  425. DBUS_TYPE_INVALID)) {
  426. qb_log(LOG_ERR, "error adding args to quorum signal");
  427. goto out_unlock;
  428. }
  429. dbus_connection_send(db, msg, NULL);
  430. out_unlock:
  431. if (msg) {
  432. dbus_message_unref(msg);
  433. }
  434. out_free:
  435. return;
  436. }
  437. static void
  438. _cs_dbus_node_membership_event(char *nodename, uint32_t nodeid, char *state, char* ip)
  439. {
  440. DBusMessage *msg = NULL;
  441. if (err_set) {
  442. qb_log(LOG_ERR, "%s", _err);
  443. err_set = 0;
  444. }
  445. if (!db) {
  446. goto out_free;
  447. }
  448. if (dbus_connection_get_is_connected(db) != TRUE) {
  449. err_set = 1;
  450. snprintf(_err, sizeof(_err), "DBus connection lost");
  451. _cs_dbus_release();
  452. goto out_unlock;
  453. }
  454. _cs_dbus_auto_flush();
  455. if (!(msg = dbus_message_new_signal(DBUS_CS_PATH,
  456. DBUS_CS_IFACE,
  457. "NodeStateChange"))) {
  458. qb_log(LOG_ERR, "error creating NodeStateChange signal");
  459. goto out_unlock;
  460. }
  461. if (!dbus_message_append_args(msg,
  462. DBUS_TYPE_STRING, &nodename,
  463. DBUS_TYPE_UINT32, &nodeid,
  464. DBUS_TYPE_STRING, &ip,
  465. DBUS_TYPE_STRING, &state,
  466. DBUS_TYPE_INVALID)) {
  467. qb_log(LOG_ERR, "error adding args to NodeStateChange signal");
  468. goto out_unlock;
  469. }
  470. dbus_connection_send(db, msg, NULL);
  471. out_unlock:
  472. if (msg) {
  473. dbus_message_unref(msg);
  474. }
  475. out_free:
  476. return;
  477. }
  478. static void
  479. _cs_dbus_application_connection_event(char *nodename, uint32_t nodeid, char *app_name, const char *state)
  480. {
  481. DBusMessage *msg = NULL;
  482. if (err_set) {
  483. qb_log(LOG_ERR, "%s", _err);
  484. err_set = 0;
  485. }
  486. if (!db) {
  487. goto out_free;
  488. }
  489. if (dbus_connection_get_is_connected(db) != TRUE) {
  490. err_set = 1;
  491. snprintf(_err, sizeof(_err), "DBus connection lost");
  492. _cs_dbus_release();
  493. goto out_unlock;
  494. }
  495. _cs_dbus_auto_flush();
  496. if (!(msg = dbus_message_new_signal(DBUS_CS_PATH,
  497. DBUS_CS_IFACE,
  498. "ConnectionStateChange"))) {
  499. qb_log(LOG_ERR, "error creating ConnectionStateChange signal");
  500. goto out_unlock;
  501. }
  502. if (!dbus_message_append_args(msg,
  503. DBUS_TYPE_STRING, &nodename,
  504. DBUS_TYPE_UINT32, &nodeid,
  505. DBUS_TYPE_STRING, &app_name,
  506. DBUS_TYPE_STRING, &state,
  507. DBUS_TYPE_INVALID)) {
  508. qb_log(LOG_ERR, "error adding args to ConnectionStateChange signal");
  509. goto out_unlock;
  510. }
  511. dbus_connection_send(db, msg, NULL);
  512. out_unlock:
  513. if (msg) {
  514. dbus_message_unref(msg);
  515. }
  516. out_free:
  517. return;
  518. }
  519. static void
  520. _cs_dbus_rrp_faulty_event(char *nodename, uint32_t nodeid, uint32_t iface_no, const char *state)
  521. {
  522. DBusMessage *msg = NULL;
  523. if (err_set) {
  524. qb_log(LOG_ERR, "%s", _err);
  525. err_set = 0;
  526. }
  527. if (!db) {
  528. goto out_free;
  529. }
  530. if (dbus_connection_get_is_connected(db) != TRUE) {
  531. err_set = 1;
  532. snprintf(_err, sizeof(_err), "DBus connection lost");
  533. _cs_dbus_release();
  534. goto out_unlock;
  535. }
  536. _cs_dbus_auto_flush();
  537. if (!(msg = dbus_message_new_signal(DBUS_CS_PATH,
  538. DBUS_CS_IFACE,
  539. "QuorumStateChange"))) {
  540. qb_log(LOG_ERR, "error creating dbus signal");
  541. goto out_unlock;
  542. }
  543. if (!dbus_message_append_args(msg,
  544. DBUS_TYPE_STRING, &nodename,
  545. DBUS_TYPE_UINT32, &nodeid,
  546. DBUS_TYPE_UINT32, &iface_no,
  547. DBUS_TYPE_STRING, &state,
  548. DBUS_TYPE_INVALID)) {
  549. qb_log(LOG_ERR, "error adding args to rrp signal");
  550. goto out_unlock;
  551. }
  552. dbus_connection_send(db, msg, NULL);
  553. out_unlock:
  554. if (msg) {
  555. dbus_message_unref(msg);
  556. }
  557. out_free:
  558. return;
  559. }
  560. static void
  561. _cs_dbus_init(void)
  562. {
  563. DBusConnection *dbc = NULL;
  564. DBusError err;
  565. dbus_error_init(&err);
  566. dbc = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
  567. if (!dbc) {
  568. snprintf(_err, sizeof(_err),
  569. "dbus_bus_get: %s", err.message);
  570. err_set = 1;
  571. dbus_error_free(&err);
  572. return;
  573. }
  574. dbus_connection_set_exit_on_disconnect(dbc, FALSE);
  575. db = dbc;
  576. notifiers[num_notifiers].node_membership_fn =
  577. _cs_dbus_node_membership_event;
  578. notifiers[num_notifiers].node_quorum_fn =
  579. _cs_dbus_node_quorum_event;
  580. notifiers[num_notifiers].application_connection_fn =
  581. _cs_dbus_application_connection_event;
  582. notifiers[num_notifiers].rrp_faulty_fn =
  583. _cs_dbus_rrp_faulty_event;
  584. num_notifiers++;
  585. }
  586. #endif /* HAVE_DBUS */
  587. #ifdef ENABLE_SNMP
  588. static netsnmp_session *snmp_init (const char *target)
  589. {
  590. static netsnmp_session *session = NULL;
  591. #ifndef NETSNMPV54
  592. char default_port[128];
  593. snprintf (default_port, sizeof (default_port), "%s:162", target);
  594. #endif
  595. if (session) {
  596. return (session);
  597. }
  598. if (target == NULL) {
  599. return NULL;
  600. }
  601. session = malloc (sizeof (netsnmp_session));
  602. snmp_sess_init (session);
  603. session->version = SNMP_VERSION_2c;
  604. session->callback = NULL;
  605. session->callback_magic = NULL;
  606. if (snmp_community) {
  607. session->community = (u_char *)snmp_community;
  608. session->community_len = strlen(snmp_community_buf);
  609. }
  610. session = snmp_add(session,
  611. #ifdef NETSNMPV54
  612. netsnmp_transport_open_client ("snmptrap", target),
  613. #else
  614. netsnmp_tdomain_transport (default_port, 0, "udp"),
  615. #endif
  616. NULL, NULL);
  617. if (session == NULL) {
  618. qb_log(LOG_ERR, 0, "Could not create snmp transport");
  619. }
  620. return (session);
  621. }
  622. static inline void add_field (
  623. netsnmp_pdu *trap_pdu,
  624. u_char asn_type,
  625. const char *prefix,
  626. void *value,
  627. size_t value_size)
  628. {
  629. oid _oid[MAX_OID_LEN];
  630. size_t _oid_len = MAX_OID_LEN;
  631. if (snmp_parse_oid(prefix, _oid, &_oid_len)) {
  632. snmp_pdu_add_variable (trap_pdu, _oid, _oid_len, asn_type, (u_char *) value, value_size);
  633. }
  634. }
  635. static void
  636. _cs_snmp_node_membership_event(char *nodename, uint32_t nodeid, char *state, char* ip)
  637. {
  638. int ret;
  639. char csysuptime[CS_TIMESTAMP_STR_LEN];
  640. static oid snmptrap_oid[] = { 1,3,6,1,6,3,1,1,4,1,0 };
  641. static oid sysuptime_oid[] = { 1,3,6,1,2,1,1,3,0 };
  642. time_t now = time (NULL);
  643. netsnmp_pdu *trap_pdu;
  644. netsnmp_session *session = snmp_init (snmp_manager);
  645. if (session == NULL) {
  646. qb_log(LOG_NOTICE, "Failed to init SNMP session.");
  647. return ;
  648. }
  649. trap_pdu = snmp_pdu_create (SNMP_MSG_TRAP2);
  650. if (!trap_pdu) {
  651. qb_log(LOG_NOTICE, "Failed to create SNMP notification.");
  652. return ;
  653. }
  654. /* send uptime */
  655. snprintf (csysuptime, CS_TIMESTAMP_STR_LEN, "%ld", now);
  656. snmp_add_var (trap_pdu, sysuptime_oid, sizeof (sysuptime_oid) / sizeof (oid), 't', csysuptime);
  657. snmp_add_var (trap_pdu, snmptrap_oid, sizeof (snmptrap_oid) / sizeof (oid), 'o', SNMP_OID_TRAPS_NODE);
  658. /* Add extries to the trap */
  659. add_field (trap_pdu, ASN_OCTET_STR, SNMP_OID_OBJECT_NODE_NAME, (void*)nodename, strlen (nodename));
  660. add_field (trap_pdu, ASN_INTEGER, SNMP_OID_OBJECT_NODE_ID, (void*)&nodeid, sizeof (nodeid));
  661. add_field (trap_pdu, ASN_OCTET_STR, SNMP_OID_OBJECT_NODE_ADDR, (void*)ip, strlen (ip));
  662. add_field (trap_pdu, ASN_OCTET_STR, SNMP_OID_OBJECT_NODE_STATUS, (void*)state, strlen (state));
  663. /* Send and cleanup */
  664. ret = snmp_send (session, trap_pdu);
  665. if (ret == 0) {
  666. /* error */
  667. qb_log(LOG_ERR, "Could not send SNMP trap");
  668. snmp_free_pdu (trap_pdu);
  669. }
  670. }
  671. static void
  672. _cs_snmp_node_quorum_event(char *nodename, uint32_t nodeid,
  673. const char *state)
  674. {
  675. int ret;
  676. char csysuptime[20];
  677. static oid snmptrap_oid[] = { 1,3,6,1,6,3,1,1,4,1,0 };
  678. static oid sysuptime_oid[] = { 1,3,6,1,2,1,1,3,0 };
  679. time_t now = time (NULL);
  680. netsnmp_pdu *trap_pdu;
  681. netsnmp_session *session = snmp_init (snmp_manager);
  682. if (session == NULL) {
  683. qb_log(LOG_NOTICE, "Failed to init SNMP session.");
  684. return ;
  685. }
  686. trap_pdu = snmp_pdu_create (SNMP_MSG_TRAP2);
  687. if (!trap_pdu) {
  688. qb_log(LOG_NOTICE, "Failed to create SNMP notification.");
  689. return ;
  690. }
  691. /* send uptime */
  692. sprintf (csysuptime, "%ld", now);
  693. snmp_add_var (trap_pdu, sysuptime_oid, sizeof (sysuptime_oid) / sizeof (oid), 't', csysuptime);
  694. snmp_add_var (trap_pdu, snmptrap_oid, sizeof (snmptrap_oid) / sizeof (oid), 'o', SNMP_OID_TRAPS_QUORUM);
  695. /* Add extries to the trap */
  696. add_field (trap_pdu, ASN_OCTET_STR, SNMP_OID_OBJECT_NODE_NAME, (void*)nodename, strlen (nodename));
  697. add_field (trap_pdu, ASN_INTEGER, SNMP_OID_OBJECT_NODE_ID, (void*)&nodeid, sizeof (nodeid));
  698. add_field (trap_pdu, ASN_OCTET_STR, SNMP_OID_OBJECT_QUORUM, (void*)state, strlen (state));
  699. /* Send and cleanup */
  700. ret = snmp_send (session, trap_pdu);
  701. if (ret == 0) {
  702. /* error */
  703. qb_log(LOG_ERR, "Could not send SNMP trap");
  704. snmp_free_pdu (trap_pdu);
  705. }
  706. }
  707. static void
  708. _cs_snmp_rrp_faulty_event(char *nodename, uint32_t nodeid,
  709. uint32_t iface_no, const char *state)
  710. {
  711. int ret;
  712. char csysuptime[20];
  713. static oid snmptrap_oid[] = { 1,3,6,1,6,3,1,1,4,1,0 };
  714. static oid sysuptime_oid[] = { 1,3,6,1,2,1,1,3,0 };
  715. time_t now = time (NULL);
  716. netsnmp_pdu *trap_pdu;
  717. netsnmp_session *session = snmp_init (snmp_manager);
  718. if (session == NULL) {
  719. qb_log(LOG_NOTICE, "Failed to init SNMP session.");
  720. return ;
  721. }
  722. trap_pdu = snmp_pdu_create (SNMP_MSG_TRAP2);
  723. if (!trap_pdu) {
  724. qb_log(LOG_NOTICE, "Failed to create SNMP notification.");
  725. return ;
  726. }
  727. /* send uptime */
  728. sprintf (csysuptime, "%ld", now);
  729. snmp_add_var (trap_pdu, sysuptime_oid, sizeof (sysuptime_oid) / sizeof (oid), 't', csysuptime);
  730. snmp_add_var (trap_pdu, snmptrap_oid, sizeof (snmptrap_oid) / sizeof (oid), 'o', SNMP_OID_TRAPS_RRP);
  731. /* Add extries to the trap */
  732. add_field (trap_pdu, ASN_OCTET_STR, SNMP_OID_OBJECT_NODE_NAME, (void*)nodename, strlen (nodename));
  733. add_field (trap_pdu, ASN_INTEGER, SNMP_OID_OBJECT_NODE_ID, (void*)&nodeid, sizeof (nodeid));
  734. add_field (trap_pdu, ASN_INTEGER, SNMP_OID_OBJECT_RRP_IFACE_NO, (void*)&iface_no, sizeof (iface_no));
  735. add_field (trap_pdu, ASN_OCTET_STR, SNMP_OID_OBJECT_RRP_STATUS, (void*)state, strlen (state));
  736. /* Send and cleanup */
  737. ret = snmp_send (session, trap_pdu);
  738. if (ret == 0) {
  739. /* error */
  740. qb_log(LOG_ERR, "Could not send SNMP trap");
  741. snmp_free_pdu (trap_pdu);
  742. }
  743. }
  744. static void
  745. _cs_snmp_init(void)
  746. {
  747. if (snmp_manager == NULL) {
  748. snmp_manager = (char*)local_host;
  749. }
  750. notifiers[num_notifiers].node_membership_fn =
  751. _cs_snmp_node_membership_event;
  752. notifiers[num_notifiers].node_quorum_fn =
  753. _cs_snmp_node_quorum_event;
  754. notifiers[num_notifiers].application_connection_fn = NULL;
  755. notifiers[num_notifiers].rrp_faulty_fn =
  756. _cs_snmp_rrp_faulty_event;
  757. num_notifiers++;
  758. }
  759. #endif /* ENABLE_SNMP */
  760. static void
  761. _cs_syslog_node_membership_event(char *nodename, uint32_t nodeid, char *state, char* ip)
  762. {
  763. qb_log(LOG_NOTICE, "%s[%d] ip:%s %s", nodename, nodeid, ip, state);
  764. }
  765. static void
  766. _cs_syslog_node_quorum_event(char *nodename, uint32_t nodeid, const char *state)
  767. {
  768. if (strcmp(state, "quorate") == 0) {
  769. qb_log(LOG_NOTICE, "%s[%d] is now %s", nodename, nodeid, state);
  770. } else {
  771. qb_log(LOG_NOTICE, "%s[%d] has lost quorum", nodename, nodeid);
  772. }
  773. }
  774. static void
  775. _cs_syslog_application_connection_event(char *nodename, uint32_t nodeid, char* app_name, const char *state)
  776. {
  777. if (strcmp(state, "connected") == 0) {
  778. qb_log(LOG_NOTICE, "%s[%d] %s is now %s to corosync", nodename, nodeid, app_name, state);
  779. } else {
  780. qb_log(LOG_NOTICE, "%s[%d] %s is now %s from corosync", nodename, nodeid, app_name, state);
  781. }
  782. }
  783. static void
  784. _cs_syslog_rrp_faulty_event(char *nodename, uint32_t nodeid, uint32_t iface_no, const char *state)
  785. {
  786. qb_log(LOG_NOTICE, "%s[%d] interface %u is now %s", nodename, nodeid, iface_no, state);
  787. }
  788. static void
  789. _cs_node_membership_event(char *nodename, uint32_t nodeid, char *state, char* ip)
  790. {
  791. int i;
  792. for (i = 0; i < num_notifiers; i++) {
  793. if (notifiers[i].node_membership_fn) {
  794. notifiers[i].node_membership_fn(nodename, nodeid, state, ip);
  795. }
  796. }
  797. }
  798. static void
  799. _cs_local_node_info_get(char **nodename, uint32_t *nodeid)
  800. {
  801. cs_error_t rc;
  802. corosync_cfg_handle_t cfg_handle;
  803. if (g_local_nodeid == 0) {
  804. rc = corosync_cfg_initialize(&cfg_handle, NULL);
  805. if (rc != CS_OK) {
  806. syslog (LOG_ERR, "Failed to initialize the cfg API. Error %d\n", rc);
  807. exit (EXIT_FAILURE);
  808. }
  809. rc = corosync_cfg_local_get (cfg_handle, &g_local_nodeid);
  810. corosync_cfg_finalize(cfg_handle);
  811. if (rc != CS_OK) {
  812. g_local_nodeid = 0;
  813. strncpy(local_nodename, "localhost", sizeof (local_nodename));
  814. local_nodename[sizeof (local_nodename) - 1] = '\0';
  815. } else {
  816. gethostname(local_nodename, CS_MAX_NAME_LENGTH);
  817. }
  818. }
  819. *nodeid = g_local_nodeid;
  820. *nodename = local_nodename;
  821. }
  822. static void
  823. _cs_node_quorum_event(const char *state)
  824. {
  825. int i;
  826. char *nodename;
  827. uint32_t nodeid;
  828. _cs_local_node_info_get(&nodename, &nodeid);
  829. for (i = 0; i < num_notifiers; i++) {
  830. if (notifiers[i].node_quorum_fn) {
  831. notifiers[i].node_quorum_fn(nodename, nodeid, state);
  832. }
  833. }
  834. }
  835. static void
  836. _cs_application_connection_event(char *app_name, const char *state)
  837. {
  838. int i;
  839. char *nodename;
  840. uint32_t nodeid;
  841. _cs_local_node_info_get(&nodename, &nodeid);
  842. for (i = 0; i < num_notifiers; i++) {
  843. if (notifiers[i].application_connection_fn) {
  844. notifiers[i].application_connection_fn(nodename, nodeid, app_name, state);
  845. }
  846. }
  847. }
  848. static void
  849. _cs_rrp_faulty_event(uint32_t iface_no, const char *state)
  850. {
  851. int i;
  852. char *nodename;
  853. uint32_t nodeid;
  854. _cs_local_node_info_get(&nodename, &nodeid);
  855. for (i = 0; i < num_notifiers; i++) {
  856. if (notifiers[i].rrp_faulty_fn) {
  857. notifiers[i].rrp_faulty_fn(nodename, nodeid, iface_no, state);
  858. }
  859. }
  860. }
  861. static int32_t
  862. sig_exit_handler(int32_t num, void *data)
  863. {
  864. qb_loop_stop(main_loop);
  865. return 0;
  866. }
  867. static void
  868. _cs_cmap_init(void)
  869. {
  870. cs_error_t rc;
  871. int cmap_fd = 0;
  872. cmap_track_handle_t track_handle;
  873. rc = cmap_initialize (&cmap_handle);
  874. if (rc != CS_OK) {
  875. qb_log(LOG_ERR, "Failed to initialize the cmap API. Error %d", rc);
  876. exit (EXIT_FAILURE);
  877. }
  878. cmap_fd_get(cmap_handle, &cmap_fd);
  879. qb_loop_poll_add(main_loop, QB_LOOP_MED, cmap_fd, POLLIN|POLLNVAL, NULL,
  880. _cs_cmap_dispatch);
  881. rc = cmap_track_add(cmap_handle, "runtime.connections.",
  882. CMAP_TRACK_ADD | CMAP_TRACK_DELETE | CMAP_TRACK_PREFIX,
  883. _cs_cmap_connections_key_changed,
  884. NULL,
  885. &track_handle);
  886. if (rc != CS_OK) {
  887. qb_log(LOG_ERR,
  888. "Failed to track the connections key. Error %d", rc);
  889. exit (EXIT_FAILURE);
  890. }
  891. rc = cmap_track_add(cmap_handle, "runtime.totem.pg.mrp.srp.members.",
  892. CMAP_TRACK_ADD | CMAP_TRACK_MODIFY | CMAP_TRACK_PREFIX,
  893. _cs_cmap_members_key_changed,
  894. NULL,
  895. &track_handle);
  896. if (rc != CS_OK) {
  897. qb_log(LOG_ERR,
  898. "Failed to track the members key. Error %d", rc);
  899. exit (EXIT_FAILURE);
  900. }
  901. rc = cmap_track_add(cmap_handle, "runtime.totem.pg.mrp.rrp.",
  902. CMAP_TRACK_ADD | CMAP_TRACK_MODIFY | CMAP_TRACK_PREFIX,
  903. _cs_cmap_rrp_faulty_key_changed,
  904. NULL,
  905. &track_handle);
  906. if (rc != CS_OK) {
  907. qb_log(LOG_ERR,
  908. "Failed to track the rrp key. Error %d", rc);
  909. exit (EXIT_FAILURE);
  910. }
  911. }
  912. static void
  913. _cs_cmap_finalize(void)
  914. {
  915. cmap_finalize (cmap_handle);
  916. }
  917. static void
  918. _cs_check_config(void)
  919. {
  920. if (conf[CS_NTF_LOG] == QB_FALSE &&
  921. conf[CS_NTF_STDOUT] == QB_FALSE &&
  922. conf[CS_NTF_SNMP] == QB_FALSE &&
  923. conf[CS_NTF_DBUS] == QB_FALSE) {
  924. qb_log(LOG_ERR, "no event type enabled, see corosync-notifyd -h, exiting.");
  925. exit(EXIT_FAILURE);
  926. }
  927. #ifndef ENABLE_SNMP
  928. if (conf[CS_NTF_SNMP]) {
  929. qb_log(LOG_ERR, "Not compiled with SNMP support enabled, exiting.");
  930. exit(EXIT_FAILURE);
  931. }
  932. #endif
  933. #ifndef HAVE_DBUS
  934. if (conf[CS_NTF_DBUS]) {
  935. qb_log(LOG_ERR, "Not compiled with DBus support enabled, exiting.");
  936. exit(EXIT_FAILURE);
  937. }
  938. #endif
  939. if (conf[CS_NTF_STDOUT] && !conf[CS_NTF_FG]) {
  940. qb_log(LOG_ERR, "configured to print to stdout and run in the background, exiting");
  941. exit(EXIT_FAILURE);
  942. }
  943. if (conf[CS_NTF_SNMP] && conf[CS_NTF_DBUS]) {
  944. qb_log(LOG_ERR, "configured to send snmp traps and dbus signals - are you sure?.");
  945. }
  946. }
  947. static void
  948. _cs_usage(void)
  949. {
  950. fprintf(stderr, "usage:\n"\
  951. " -c : SNMP Community name.\n"\
  952. " -f : Start application in foreground.\n"\
  953. " -l : Log all events.\n"\
  954. " -o : Print events to stdout (turns on -l).\n"\
  955. " -s : Send SNMP traps on all events.\n"\
  956. " -m : Set the SNMP Manager IP address (defaults to localhost).\n"\
  957. " -d : Send DBUS signals on all events.\n"\
  958. " -h : Print this help.\n\n");
  959. }
  960. int
  961. main(int argc, char *argv[])
  962. {
  963. int ch;
  964. conf[CS_NTF_FG] = QB_FALSE;
  965. conf[CS_NTF_LOG] = QB_FALSE;
  966. conf[CS_NTF_STDOUT] = QB_FALSE;
  967. conf[CS_NTF_SNMP] = QB_FALSE;
  968. conf[CS_NTF_DBUS] = QB_FALSE;
  969. while ((ch = getopt (argc, argv, "c:floshdm:")) != EOF) {
  970. switch (ch) {
  971. case 'c':
  972. strncpy(snmp_community_buf, optarg, sizeof (snmp_community_buf));
  973. snmp_community_buf[sizeof (snmp_community_buf) - 1] = '\0';
  974. snmp_community = snmp_community_buf;
  975. break;
  976. case 'f':
  977. conf[CS_NTF_FG] = QB_TRUE;
  978. break;
  979. case 'l':
  980. conf[CS_NTF_LOG] = QB_TRUE;
  981. break;
  982. case 'm':
  983. conf[CS_NTF_SNMP] = QB_TRUE;
  984. strncpy(snmp_manager_buf, optarg, sizeof (snmp_manager_buf));
  985. snmp_manager_buf[sizeof (snmp_manager_buf) - 1] = '\0';
  986. snmp_manager = snmp_manager_buf;
  987. break;
  988. case 'o':
  989. conf[CS_NTF_LOG] = QB_TRUE;
  990. conf[CS_NTF_STDOUT] = QB_TRUE;
  991. break;
  992. case 's':
  993. conf[CS_NTF_SNMP] = QB_TRUE;
  994. break;
  995. case 'd':
  996. conf[CS_NTF_DBUS] = QB_TRUE;
  997. break;
  998. case 'h':
  999. default:
  1000. _cs_usage();
  1001. return EXIT_FAILURE;
  1002. }
  1003. }
  1004. qb_log_init("notifyd", LOG_DAEMON, LOG_INFO);
  1005. if (conf[CS_NTF_STDOUT]) {
  1006. qb_log_filter_ctl(QB_LOG_STDERR, QB_LOG_FILTER_ADD,
  1007. QB_LOG_FILTER_FILE, "*", LOG_DEBUG);
  1008. qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, conf[CS_NTF_STDOUT]);
  1009. }
  1010. _cs_check_config();
  1011. if (!conf[CS_NTF_FG]) {
  1012. if (daemon(0, 0) < 0)
  1013. {
  1014. perror("daemon() failed");
  1015. return EXIT_FAILURE;
  1016. }
  1017. }
  1018. num_notifiers = 0;
  1019. if (conf[CS_NTF_LOG]) {
  1020. notifiers[num_notifiers].node_membership_fn =
  1021. _cs_syslog_node_membership_event;
  1022. notifiers[num_notifiers].node_quorum_fn =
  1023. _cs_syslog_node_quorum_event;
  1024. notifiers[num_notifiers].application_connection_fn =
  1025. _cs_syslog_application_connection_event;
  1026. notifiers[num_notifiers].rrp_faulty_fn =
  1027. _cs_syslog_rrp_faulty_event;
  1028. num_notifiers++;
  1029. }
  1030. main_loop = qb_loop_create();
  1031. _cs_cmap_init();
  1032. _cs_quorum_init();
  1033. #ifdef HAVE_DBUS
  1034. if (conf[CS_NTF_DBUS]) {
  1035. _cs_dbus_init();
  1036. }
  1037. #endif /* HAVE_DBUS */
  1038. #ifdef ENABLE_SNMP
  1039. if (conf[CS_NTF_SNMP]) {
  1040. _cs_snmp_init();
  1041. }
  1042. #endif /* ENABLE_SNMP */
  1043. qb_loop_signal_add(main_loop,
  1044. QB_LOOP_HIGH,
  1045. SIGINT,
  1046. NULL,
  1047. sig_exit_handler,
  1048. NULL);
  1049. qb_loop_signal_add(main_loop,
  1050. QB_LOOP_HIGH,
  1051. SIGQUIT,
  1052. NULL,
  1053. sig_exit_handler,
  1054. NULL);
  1055. qb_loop_signal_add(main_loop,
  1056. QB_LOOP_HIGH,
  1057. SIGTERM,
  1058. NULL,
  1059. sig_exit_handler,
  1060. NULL);
  1061. qb_loop_run(main_loop);
  1062. #ifdef HAVE_DBUS
  1063. if (conf[CS_NTF_DBUS]) {
  1064. _cs_dbus_release();
  1065. }
  1066. #endif /* HAVE_DBUS */
  1067. _cs_quorum_finalize();
  1068. _cs_cmap_finalize();
  1069. return 0;
  1070. }