corosync-notifyd.c 30 KB

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