corosync-notifyd.c 30 KB

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