corosync-notifyd.c 29 KB

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