corosync-notifyd.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222
  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 <qb/qbdefs.h>
  53. #include <qb/qbloop.h>
  54. #include <corosync/corotypes.h>
  55. #include <corosync/cfg.h>
  56. #include <corosync/quorum.h>
  57. #include <corosync/cmap.h>
  58. /*
  59. * generic declarations
  60. */
  61. enum {
  62. CS_NTF_LOG,
  63. CS_NTF_STDOUT,
  64. CS_NTF_SNMP,
  65. CS_NTF_DBUS,
  66. CS_NTF_FG,
  67. CS_NTF_MAX,
  68. };
  69. static int conf[CS_NTF_MAX];
  70. static int32_t _cs_is_quorate = 0;
  71. typedef void (*node_membership_fn_t)(char *nodename, uint32_t nodeid, char *state, char* ip);
  72. typedef void (*node_quorum_fn_t)(char *nodename, uint32_t nodeid, const char *state);
  73. typedef void (*application_connection_fn_t)(char *nodename, uint32_t nodeid, char *app_name, const char *state);
  74. typedef void (*rrp_faulty_fn_t)(char *nodename, uint32_t nodeid, uint32_t iface_no, const char *state);
  75. struct notify_callbacks {
  76. node_membership_fn_t node_membership_fn;
  77. node_quorum_fn_t node_quorum_fn;
  78. application_connection_fn_t application_connection_fn;
  79. rrp_faulty_fn_t rrp_faulty_fn;
  80. };
  81. #define MAX_NOTIFIERS 5
  82. static int num_notifiers = 0;
  83. static struct notify_callbacks notifiers[MAX_NOTIFIERS];
  84. static uint32_t local_nodeid = 0;
  85. static char local_nodename[CS_MAX_NAME_LENGTH];
  86. static qb_loop_t *main_loop;
  87. static quorum_handle_t quorum_handle;
  88. static void _cs_node_membership_event(char *nodename, uint32_t nodeid, char *state, char* ip);
  89. static void _cs_node_quorum_event(const char *state);
  90. static void _cs_application_connection_event(char *app_name, const char *state);
  91. static void _cs_rrp_faulty_event(uint32_t iface_no, const char *state);
  92. #ifdef HAVE_DBUS
  93. #include <dbus/dbus.h>
  94. /*
  95. * dbus
  96. */
  97. #define DBUS_CS_NAME "org.corosync"
  98. #define DBUS_CS_IFACE "org.corosync"
  99. #define DBUS_CS_PATH "/org/corosync"
  100. static DBusConnection *db = NULL;
  101. static char _err[512];
  102. static int err_set = 0;
  103. static void _cs_dbus_init(void);
  104. #endif /* HAVE_DBUS */
  105. #ifdef ENABLE_SNMP
  106. #include <net-snmp/net-snmp-config.h>
  107. #include <net-snmp/snmpv3_api.h>
  108. #include <net-snmp/agent/agent_trap.h>
  109. #include <net-snmp/library/mib.h>
  110. #include <net-snmp/library/snmp_api.h>
  111. #include <net-snmp/library/snmp_client.h>
  112. #include <net-snmp/library/snmp_debug.h>
  113. enum snmp_node_status {
  114. SNMP_NODE_STATUS_UNKNOWN = 0,
  115. SNMP_NODE_STATUS_JOINED = 1,
  116. SNMP_NODE_STATUS_LEFT = 2
  117. };
  118. #define SNMP_OID_COROSYNC "1.3.6.1.4.1.35488"
  119. #define SNMP_OID_OBJECT_ROOT SNMP_OID_COROSYNC ".1"
  120. #define SNMP_OID_OBJECT_NODE_NAME SNMP_OID_OBJECT_ROOT ".1"
  121. #define SNMP_OID_OBJECT_NODE_ID SNMP_OID_OBJECT_ROOT ".2"
  122. #define SNMP_OID_OBJECT_NODE_STATUS SNMP_OID_OBJECT_ROOT ".3"
  123. #define SNMP_OID_OBJECT_NODE_ADDR SNMP_OID_OBJECT_ROOT ".4"
  124. #define SNMP_OID_OBJECT_RINGSEQ SNMP_OID_OBJECT_ROOT ".20"
  125. #define SNMP_OID_OBJECT_QUORUM SNMP_OID_OBJECT_ROOT ".21"
  126. #define SNMP_OID_OBJECT_APP_NAME SNMP_OID_OBJECT_ROOT ".40"
  127. #define SNMP_OID_OBJECT_APP_STATUS SNMP_OID_OBJECT_ROOT ".41"
  128. #define SNMP_OID_OBJECT_RRP_IFACE_NO SNMP_OID_OBJECT_ROOT ".60"
  129. #define SNMP_OID_OBJECT_RRP_STATUS SNMP_OID_OBJECT_ROOT ".61"
  130. #define SNMP_OID_TRAPS_ROOT SNMP_OID_COROSYNC ".0"
  131. #define SNMP_OID_TRAPS_NODE SNMP_OID_TRAPS_ROOT ".1"
  132. #define SNMP_OID_TRAPS_QUORUM SNMP_OID_TRAPS_ROOT ".2"
  133. #define SNMP_OID_TRAPS_APP SNMP_OID_TRAPS_ROOT ".3"
  134. #define SNMP_OID_TRAPS_RRP SNMP_OID_TRAPS_ROOT ".4"
  135. #define CS_TIMESTAMP_STR_LEN 20
  136. static const char *local_host = "localhost";
  137. #endif /* ENABLE_SNMP */
  138. static char snmp_manager_buf[CS_MAX_NAME_LENGTH];
  139. static char *snmp_manager = 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. session = snmp_add(session,
  584. #ifdef NETSNMPV54
  585. netsnmp_transport_open_client ("snmptrap", target),
  586. #else
  587. netsnmp_tdomain_transport (default_port, 0, "udp"),
  588. #endif
  589. NULL, NULL);
  590. if (session == NULL) {
  591. qb_log(LOG_ERR, 0, "Could not create snmp transport");
  592. }
  593. return (session);
  594. }
  595. static inline void add_field (
  596. netsnmp_pdu *trap_pdu,
  597. u_char asn_type,
  598. const char *prefix,
  599. void *value,
  600. size_t value_size)
  601. {
  602. oid _oid[MAX_OID_LEN];
  603. size_t _oid_len = MAX_OID_LEN;
  604. if (snmp_parse_oid(prefix, _oid, &_oid_len)) {
  605. snmp_pdu_add_variable (trap_pdu, _oid, _oid_len, asn_type, (u_char *) value, value_size);
  606. }
  607. }
  608. static void
  609. _cs_snmp_node_membership_event(char *nodename, uint32_t nodeid, char *state, char* ip)
  610. {
  611. int ret;
  612. char csysuptime[CS_TIMESTAMP_STR_LEN];
  613. static oid snmptrap_oid[] = { 1,3,6,1,6,3,1,1,4,1,0 };
  614. static oid sysuptime_oid[] = { 1,3,6,1,2,1,1,3,0 };
  615. time_t now = time (NULL);
  616. netsnmp_pdu *trap_pdu;
  617. netsnmp_session *session = snmp_init (snmp_manager);
  618. if (session == NULL) {
  619. qb_log(LOG_NOTICE, "Failed to init SNMP session.");
  620. return ;
  621. }
  622. trap_pdu = snmp_pdu_create (SNMP_MSG_TRAP2);
  623. if (!trap_pdu) {
  624. qb_log(LOG_NOTICE, "Failed to create SNMP notification.");
  625. return ;
  626. }
  627. /* send uptime */
  628. snprintf (csysuptime, CS_TIMESTAMP_STR_LEN, "%ld", now);
  629. snmp_add_var (trap_pdu, sysuptime_oid, sizeof (sysuptime_oid) / sizeof (oid), 't', csysuptime);
  630. snmp_add_var (trap_pdu, snmptrap_oid, sizeof (snmptrap_oid) / sizeof (oid), 'o', SNMP_OID_TRAPS_NODE);
  631. /* Add extries to the trap */
  632. add_field (trap_pdu, ASN_OCTET_STR, SNMP_OID_OBJECT_NODE_NAME, (void*)nodename, strlen (nodename));
  633. add_field (trap_pdu, ASN_UNSIGNED, SNMP_OID_OBJECT_NODE_ID, (void*)&nodeid, sizeof (nodeid));
  634. add_field (trap_pdu, ASN_OCTET_STR, SNMP_OID_OBJECT_NODE_ADDR, (void*)ip, strlen (ip));
  635. add_field (trap_pdu, ASN_OCTET_STR, SNMP_OID_OBJECT_NODE_STATUS, (void*)state, strlen (state));
  636. /* Send and cleanup */
  637. ret = snmp_send (session, trap_pdu);
  638. if (ret == 0) {
  639. /* error */
  640. qb_log(LOG_ERR, "Could not send SNMP trap");
  641. snmp_free_pdu (trap_pdu);
  642. }
  643. }
  644. static void
  645. _cs_snmp_node_quorum_event(char *nodename, uint32_t nodeid,
  646. const char *state)
  647. {
  648. int ret;
  649. char csysuptime[20];
  650. static oid snmptrap_oid[] = { 1,3,6,1,6,3,1,1,4,1,0 };
  651. static oid sysuptime_oid[] = { 1,3,6,1,2,1,1,3,0 };
  652. time_t now = time (NULL);
  653. netsnmp_pdu *trap_pdu;
  654. netsnmp_session *session = snmp_init (snmp_manager);
  655. if (session == NULL) {
  656. qb_log(LOG_NOTICE, "Failed to init SNMP session.");
  657. return ;
  658. }
  659. trap_pdu = snmp_pdu_create (SNMP_MSG_TRAP2);
  660. if (!trap_pdu) {
  661. qb_log(LOG_NOTICE, "Failed to create SNMP notification.");
  662. return ;
  663. }
  664. /* send uptime */
  665. sprintf (csysuptime, "%ld", now);
  666. snmp_add_var (trap_pdu, sysuptime_oid, sizeof (sysuptime_oid) / sizeof (oid), 't', csysuptime);
  667. snmp_add_var (trap_pdu, snmptrap_oid, sizeof (snmptrap_oid) / sizeof (oid), 'o', SNMP_OID_TRAPS_QUORUM);
  668. /* Add extries to the trap */
  669. add_field (trap_pdu, ASN_OCTET_STR, SNMP_OID_OBJECT_NODE_NAME, (void*)nodename, strlen (nodename));
  670. add_field (trap_pdu, ASN_UNSIGNED, SNMP_OID_OBJECT_NODE_ID, (void*)&nodeid, sizeof (nodeid));
  671. add_field (trap_pdu, ASN_OCTET_STR, SNMP_OID_OBJECT_QUORUM, (void*)state, strlen (state));
  672. /* Send and cleanup */
  673. ret = snmp_send (session, trap_pdu);
  674. if (ret == 0) {
  675. /* error */
  676. qb_log(LOG_ERR, "Could not send SNMP trap");
  677. snmp_free_pdu (trap_pdu);
  678. }
  679. }
  680. static void
  681. _cs_snmp_rrp_faulty_event(char *nodename, uint32_t nodeid,
  682. uint32_t iface_no, const char *state)
  683. {
  684. int ret;
  685. char csysuptime[20];
  686. static oid snmptrap_oid[] = { 1,3,6,1,6,3,1,1,4,1,0 };
  687. static oid sysuptime_oid[] = { 1,3,6,1,2,1,1,3,0 };
  688. time_t now = time (NULL);
  689. netsnmp_pdu *trap_pdu;
  690. netsnmp_session *session = snmp_init (snmp_manager);
  691. if (session == NULL) {
  692. qb_log(LOG_NOTICE, "Failed to init SNMP session.");
  693. return ;
  694. }
  695. trap_pdu = snmp_pdu_create (SNMP_MSG_TRAP2);
  696. if (!trap_pdu) {
  697. qb_log(LOG_NOTICE, "Failed to create SNMP notification.");
  698. return ;
  699. }
  700. /* send uptime */
  701. sprintf (csysuptime, "%ld", now);
  702. snmp_add_var (trap_pdu, sysuptime_oid, sizeof (sysuptime_oid) / sizeof (oid), 't', csysuptime);
  703. snmp_add_var (trap_pdu, snmptrap_oid, sizeof (snmptrap_oid) / sizeof (oid), 'o', SNMP_OID_TRAPS_RRP);
  704. /* Add extries to the trap */
  705. add_field (trap_pdu, ASN_OCTET_STR, SNMP_OID_OBJECT_NODE_NAME, (void*)nodename, strlen (nodename));
  706. add_field (trap_pdu, ASN_UNSIGNED, SNMP_OID_OBJECT_NODE_ID, (void*)&nodeid, sizeof (nodeid));
  707. add_field (trap_pdu, ASN_INTEGER, SNMP_OID_OBJECT_RRP_IFACE_NO, (void*)&iface_no, sizeof (iface_no));
  708. add_field (trap_pdu, ASN_OCTET_STR, SNMP_OID_OBJECT_RRP_STATUS, (void*)state, strlen (state));
  709. /* Send and cleanup */
  710. ret = snmp_send (session, trap_pdu);
  711. if (ret == 0) {
  712. /* error */
  713. qb_log(LOG_ERR, "Could not send SNMP trap");
  714. snmp_free_pdu (trap_pdu);
  715. }
  716. }
  717. static void
  718. _cs_snmp_init(void)
  719. {
  720. if (snmp_manager == NULL) {
  721. snmp_manager = (char*)local_host;
  722. }
  723. notifiers[num_notifiers].node_membership_fn =
  724. _cs_snmp_node_membership_event;
  725. notifiers[num_notifiers].node_quorum_fn =
  726. _cs_snmp_node_quorum_event;
  727. notifiers[num_notifiers].application_connection_fn = NULL;
  728. notifiers[num_notifiers].rrp_faulty_fn =
  729. _cs_snmp_rrp_faulty_event;
  730. num_notifiers++;
  731. }
  732. #endif /* ENABLE_SNMP */
  733. static void
  734. _cs_syslog_node_membership_event(char *nodename, uint32_t nodeid, char *state, char* ip)
  735. {
  736. qb_log(LOG_NOTICE, "%s[%d] ip:%s %s", nodename, nodeid, ip, state);
  737. }
  738. static void
  739. _cs_syslog_node_quorum_event(char *nodename, uint32_t nodeid, const char *state)
  740. {
  741. if (strcmp(state, "quorate") == 0) {
  742. qb_log(LOG_NOTICE, "%s[%d] is now %s", nodename, nodeid, state);
  743. } else {
  744. qb_log(LOG_NOTICE, "%s[%d] has lost quorum", nodename, nodeid);
  745. }
  746. }
  747. static void
  748. _cs_syslog_application_connection_event(char *nodename, uint32_t nodeid, char* app_name, const char *state)
  749. {
  750. if (strcmp(state, "connected") == 0) {
  751. qb_log(LOG_NOTICE, "%s[%d] %s is now %s to corosync", nodename, nodeid, app_name, state);
  752. } else {
  753. qb_log(LOG_NOTICE, "%s[%d] %s is now %s from corosync", nodename, nodeid, app_name, state);
  754. }
  755. }
  756. static void
  757. _cs_syslog_rrp_faulty_event(char *nodename, uint32_t nodeid, uint32_t iface_no, const char *state)
  758. {
  759. qb_log(LOG_NOTICE, "%s[%d] interface %u is now %s", nodename, nodeid, iface_no, state);
  760. }
  761. static void
  762. _cs_node_membership_event(char *nodename, uint32_t nodeid, char *state, char* ip)
  763. {
  764. int i;
  765. for (i = 0; i < num_notifiers; i++) {
  766. if (notifiers[i].node_membership_fn) {
  767. notifiers[i].node_membership_fn(nodename, nodeid, state, ip);
  768. }
  769. }
  770. }
  771. static void
  772. _cs_local_node_info_get(char **nodename, uint32_t *nodeid)
  773. {
  774. cs_error_t rc;
  775. corosync_cfg_handle_t cfg_handle;
  776. if (local_nodeid == 0) {
  777. rc = corosync_cfg_initialize(&cfg_handle, NULL);
  778. if (rc != CS_OK) {
  779. syslog (LOG_ERR, "Failed to initialize the cfg API. Error %d\n", rc);
  780. exit (EXIT_FAILURE);
  781. }
  782. rc = corosync_cfg_local_get (cfg_handle, &local_nodeid);
  783. corosync_cfg_finalize(cfg_handle);
  784. if (rc != CS_OK) {
  785. local_nodeid = 0;
  786. strncpy(local_nodename, "localhost", sizeof (local_nodename));
  787. local_nodename[sizeof (local_nodename) - 1] = '\0';
  788. } else {
  789. gethostname(local_nodename, CS_MAX_NAME_LENGTH);
  790. }
  791. }
  792. *nodeid = local_nodeid;
  793. *nodename = local_nodename;
  794. }
  795. static void
  796. _cs_node_quorum_event(const char *state)
  797. {
  798. int i;
  799. char *nodename;
  800. uint32_t nodeid;
  801. _cs_local_node_info_get(&nodename, &nodeid);
  802. for (i = 0; i < num_notifiers; i++) {
  803. if (notifiers[i].node_quorum_fn) {
  804. notifiers[i].node_quorum_fn(nodename, nodeid, state);
  805. }
  806. }
  807. }
  808. static void
  809. _cs_application_connection_event(char *app_name, const char *state)
  810. {
  811. int i;
  812. char *nodename;
  813. uint32_t nodeid;
  814. _cs_local_node_info_get(&nodename, &nodeid);
  815. for (i = 0; i < num_notifiers; i++) {
  816. if (notifiers[i].application_connection_fn) {
  817. notifiers[i].application_connection_fn(nodename, nodeid, app_name, state);
  818. }
  819. }
  820. }
  821. static void
  822. _cs_rrp_faulty_event(uint32_t iface_no, const char *state)
  823. {
  824. int i;
  825. char *nodename;
  826. uint32_t nodeid;
  827. _cs_local_node_info_get(&nodename, &nodeid);
  828. for (i = 0; i < num_notifiers; i++) {
  829. if (notifiers[i].rrp_faulty_fn) {
  830. notifiers[i].rrp_faulty_fn(nodename, nodeid, iface_no, state);
  831. }
  832. }
  833. }
  834. static int32_t
  835. sig_exit_handler(int32_t num, void *data)
  836. {
  837. qb_loop_stop(main_loop);
  838. return 0;
  839. }
  840. static void
  841. _cs_cmap_init(void)
  842. {
  843. cs_error_t rc;
  844. int cmap_fd = 0;
  845. cmap_track_handle_t track_handle;
  846. rc = cmap_initialize (&cmap_handle);
  847. if (rc != CS_OK) {
  848. qb_log(LOG_ERR, "Failed to initialize the cmap API. Error %d", rc);
  849. exit (EXIT_FAILURE);
  850. }
  851. cmap_fd_get(cmap_handle, &cmap_fd);
  852. qb_loop_poll_add(main_loop, QB_LOOP_MED, cmap_fd, POLLIN|POLLNVAL, NULL,
  853. _cs_cmap_dispatch);
  854. rc = cmap_track_add(cmap_handle, "runtime.connections.",
  855. CMAP_TRACK_ADD | CMAP_TRACK_DELETE | CMAP_TRACK_PREFIX,
  856. _cs_cmap_connections_key_changed,
  857. NULL,
  858. &track_handle);
  859. if (rc != CS_OK) {
  860. qb_log(LOG_ERR,
  861. "Failed to track the connections key. Error %d", rc);
  862. exit (EXIT_FAILURE);
  863. }
  864. rc = cmap_track_add(cmap_handle, "runtime.totem.pg.mrp.srp.members.",
  865. CMAP_TRACK_ADD | CMAP_TRACK_MODIFY | CMAP_TRACK_PREFIX,
  866. _cs_cmap_members_key_changed,
  867. NULL,
  868. &track_handle);
  869. if (rc != CS_OK) {
  870. qb_log(LOG_ERR,
  871. "Failed to track the members key. Error %d", rc);
  872. exit (EXIT_FAILURE);
  873. }
  874. rc = cmap_track_add(cmap_handle, "runtime.totem.pg.mrp.rrp.",
  875. CMAP_TRACK_ADD | CMAP_TRACK_MODIFY | CMAP_TRACK_PREFIX,
  876. _cs_cmap_rrp_faulty_key_changed,
  877. NULL,
  878. &track_handle);
  879. if (rc != CS_OK) {
  880. qb_log(LOG_ERR,
  881. "Failed to track the rrp key. Error %d", rc);
  882. exit (EXIT_FAILURE);
  883. }
  884. }
  885. static void
  886. _cs_cmap_finalize(void)
  887. {
  888. cmap_finalize (cmap_handle);
  889. }
  890. static void
  891. _cs_check_config(void)
  892. {
  893. if (conf[CS_NTF_LOG] == QB_FALSE &&
  894. conf[CS_NTF_STDOUT] == QB_FALSE &&
  895. conf[CS_NTF_SNMP] == QB_FALSE &&
  896. conf[CS_NTF_DBUS] == QB_FALSE) {
  897. qb_log(LOG_ERR, "no event type enabled, see corosync-notifyd -h, exiting.");
  898. exit(EXIT_FAILURE);
  899. }
  900. #ifndef ENABLE_SNMP
  901. if (conf[CS_NTF_SNMP]) {
  902. qb_log(LOG_ERR, "Not compiled with SNMP support enabled, exiting.");
  903. exit(EXIT_FAILURE);
  904. }
  905. #endif
  906. #ifndef HAVE_DBUS
  907. if (conf[CS_NTF_DBUS]) {
  908. qb_log(LOG_ERR, "Not compiled with DBus support enabled, exiting.");
  909. exit(EXIT_FAILURE);
  910. }
  911. #endif
  912. if (conf[CS_NTF_STDOUT] && !conf[CS_NTF_FG]) {
  913. qb_log(LOG_ERR, "configured to print to stdout and run in the background, exiting");
  914. exit(EXIT_FAILURE);
  915. }
  916. if (conf[CS_NTF_SNMP] && conf[CS_NTF_DBUS]) {
  917. qb_log(LOG_ERR, "configured to send snmp traps and dbus signals - are you sure?.");
  918. }
  919. }
  920. static void
  921. _cs_usage(void)
  922. {
  923. fprintf(stderr, "usage:\n"\
  924. " -f : Start application in foreground.\n"\
  925. " -l : Log all events.\n"\
  926. " -o : Print events to stdout (turns on -l).\n"\
  927. " -s : Send SNMP traps on all events.\n"\
  928. " -m : Set the SNMP Manager IP address (defaults to localhost).\n"\
  929. " -d : Send DBUS signals on all events.\n"\
  930. " -h : Print this help.\n\n");
  931. }
  932. int
  933. main(int argc, char *argv[])
  934. {
  935. int ch;
  936. conf[CS_NTF_FG] = QB_FALSE;
  937. conf[CS_NTF_LOG] = QB_FALSE;
  938. conf[CS_NTF_STDOUT] = QB_FALSE;
  939. conf[CS_NTF_SNMP] = QB_FALSE;
  940. conf[CS_NTF_DBUS] = QB_FALSE;
  941. while ((ch = getopt (argc, argv, "floshdm:")) != EOF) {
  942. switch (ch) {
  943. case 'f':
  944. conf[CS_NTF_FG] = QB_TRUE;
  945. break;
  946. case 'l':
  947. conf[CS_NTF_LOG] = QB_TRUE;
  948. break;
  949. case 'm':
  950. conf[CS_NTF_SNMP] = QB_TRUE;
  951. strncpy(snmp_manager_buf, optarg, sizeof (snmp_manager_buf));
  952. snmp_manager_buf[sizeof (snmp_manager_buf) - 1] = '\0';
  953. snmp_manager = snmp_manager_buf;
  954. break;
  955. case 'o':
  956. conf[CS_NTF_LOG] = QB_TRUE;
  957. conf[CS_NTF_STDOUT] = QB_TRUE;
  958. break;
  959. case 's':
  960. conf[CS_NTF_SNMP] = QB_TRUE;
  961. break;
  962. case 'd':
  963. conf[CS_NTF_DBUS] = QB_TRUE;
  964. break;
  965. case 'h':
  966. default:
  967. _cs_usage();
  968. return EXIT_FAILURE;
  969. }
  970. }
  971. qb_log_init("notifyd", LOG_DAEMON, LOG_INFO);
  972. if (conf[CS_NTF_STDOUT]) {
  973. qb_log_filter_ctl(QB_LOG_STDERR, QB_LOG_FILTER_ADD,
  974. QB_LOG_FILTER_FILE, "*", LOG_DEBUG);
  975. qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, conf[CS_NTF_STDOUT]);
  976. }
  977. _cs_check_config();
  978. if (!conf[CS_NTF_FG]) {
  979. if (daemon(0, 0) < 0)
  980. {
  981. perror("daemon() failed");
  982. return EXIT_FAILURE;
  983. }
  984. }
  985. num_notifiers = 0;
  986. if (conf[CS_NTF_LOG]) {
  987. notifiers[num_notifiers].node_membership_fn =
  988. _cs_syslog_node_membership_event;
  989. notifiers[num_notifiers].node_quorum_fn =
  990. _cs_syslog_node_quorum_event;
  991. notifiers[num_notifiers].application_connection_fn =
  992. _cs_syslog_application_connection_event;
  993. notifiers[num_notifiers].rrp_faulty_fn =
  994. _cs_syslog_rrp_faulty_event;
  995. num_notifiers++;
  996. }
  997. main_loop = qb_loop_create();
  998. _cs_cmap_init();
  999. _cs_quorum_init();
  1000. #ifdef HAVE_DBUS
  1001. if (conf[CS_NTF_DBUS]) {
  1002. _cs_dbus_init();
  1003. }
  1004. #endif /* HAVE_DBUS */
  1005. #ifdef ENABLE_SNMP
  1006. if (conf[CS_NTF_SNMP]) {
  1007. _cs_snmp_init();
  1008. }
  1009. #endif /* ENABLE_SNMP */
  1010. qb_loop_signal_add(main_loop,
  1011. QB_LOOP_HIGH,
  1012. SIGINT,
  1013. NULL,
  1014. sig_exit_handler,
  1015. NULL);
  1016. qb_loop_signal_add(main_loop,
  1017. QB_LOOP_HIGH,
  1018. SIGQUIT,
  1019. NULL,
  1020. sig_exit_handler,
  1021. NULL);
  1022. qb_loop_signal_add(main_loop,
  1023. QB_LOOP_HIGH,
  1024. SIGTERM,
  1025. NULL,
  1026. sig_exit_handler,
  1027. NULL);
  1028. qb_loop_run(main_loop);
  1029. #ifdef HAVE_DBUS
  1030. if (conf[CS_NTF_DBUS]) {
  1031. _cs_dbus_release();
  1032. }
  1033. #endif /* HAVE_DBUS */
  1034. _cs_quorum_finalize();
  1035. _cs_cmap_finalize();
  1036. return 0;
  1037. }