4
0

logconfig.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. /*
  2. * Copyright (c) 2002-2005 MontaVista Software, Inc.
  3. * Copyright (c) 2006-2011 Red Hat, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Author: Steven Dake (sdake@redhat.com)
  8. * Jan Friesse (jfriesse@redhat.com)
  9. *
  10. * This software licensed under BSD license, the text of which follows:
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * - Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  21. * contributors may be used to endorse or promote products derived from this
  22. * software without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  28. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  30. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  31. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  32. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  33. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  34. * THE POSSIBILITY OF SUCH DAMAGE.
  35. */
  36. #include "config.h"
  37. #include <corosync/totem/totem.h>
  38. #include <corosync/logsys.h>
  39. #ifdef LOGCONFIG_USE_ICMAP
  40. #include <corosync/icmap.h>
  41. #define MAP_KEYNAME_MAXLEN ICMAP_KEYNAME_MAXLEN
  42. #define map_get_string(key_name, value) icmap_get_string(key_name, value)
  43. #else
  44. #include <corosync/cmap.h>
  45. static cmap_handle_t cmap_handle;
  46. static const char *main_logfile;
  47. #define MAP_KEYNAME_MAXLEN CMAP_KEYNAME_MAXLEN
  48. #define map_get_string(key_name, value) cmap_get_string(cmap_handle, key_name, value)
  49. #endif
  50. #include "util.h"
  51. #include "logconfig.h"
  52. static char error_string_response[512];
  53. /**
  54. * insert_into_buffer
  55. * @target_buffer: a buffer where to write results
  56. * @bufferlen: tell us the size of the buffer to avoid overflows
  57. * @entry: entry that needs to be added to the buffer
  58. * @after: can either be NULL or set to a string.
  59. * if NULL, @entry is prependend to logsys_format_get buffer.
  60. * if set, @entry is added immediately after @after.
  61. *
  62. * Since the function is specific to logsys_format_get handling, it is implicit
  63. * that source is logsys_format_get();
  64. *
  65. * In case of failure, target_buffer could be left dirty. So don't trust
  66. * any data leftover in it.
  67. *
  68. * Searching for "after" assumes that there is only entry of "after"
  69. * in the source. Afterall we control the string here and for logging format
  70. * it makes little to no sense to have duplicate format entries.
  71. *
  72. * Returns: 0 on success, -1 on failure
  73. **/
  74. static int insert_into_buffer(
  75. char *target_buffer,
  76. size_t bufferlen,
  77. const char *entry,
  78. const char *after)
  79. {
  80. const char *current_format = NULL;
  81. current_format = logsys_format_get();
  82. /* if the entry is already in the format we don't add it again */
  83. if (strstr(current_format, entry) != NULL) {
  84. return -1;
  85. }
  86. /* if there is no "after", simply prepend the requested entry
  87. * otherwise go for beautiful string manipulation.... </sarcasm> */
  88. if (!after) {
  89. if (snprintf(target_buffer, bufferlen - 1, "%s%s",
  90. entry,
  91. current_format) >= bufferlen - 1) {
  92. return -1;
  93. }
  94. } else {
  95. const char *afterpos;
  96. size_t afterlen;
  97. size_t templen;
  98. /* check if after is contained in the format
  99. * and afterlen has a meaning or return an error */
  100. afterpos = strstr(current_format, after);
  101. afterlen = strlen(after);
  102. if ((!afterpos) || (!afterlen)) {
  103. return -1;
  104. }
  105. templen = afterpos - current_format + afterlen;
  106. if (snprintf(target_buffer, templen + 1, "%s", current_format)
  107. >= bufferlen - 1) {
  108. return -1;
  109. }
  110. if (snprintf(target_buffer + templen, bufferlen - ( templen + 1 ),
  111. "%s%s", entry, current_format + templen)
  112. >= bufferlen - ( templen + 1 )) {
  113. return -1;
  114. }
  115. }
  116. return 0;
  117. }
  118. /*
  119. * format set is global specific option that
  120. * doesn't apply at system/subsystem level.
  121. */
  122. static int corosync_main_config_format_set (
  123. const char **error_string)
  124. {
  125. const char *error_reason;
  126. char new_format_buffer[PATH_MAX];
  127. char *value = NULL;
  128. int err = 0;
  129. if (map_get_string("logging.fileline", &value) == CS_OK) {
  130. if (strcmp (value, "on") == 0) {
  131. if (!insert_into_buffer(new_format_buffer,
  132. sizeof(new_format_buffer),
  133. " %f:%l", "g]")) {
  134. err = logsys_format_set(new_format_buffer);
  135. } else
  136. if (!insert_into_buffer(new_format_buffer,
  137. sizeof(new_format_buffer),
  138. "%f:%l", NULL)) {
  139. err = logsys_format_set(new_format_buffer);
  140. }
  141. } else
  142. if (strcmp (value, "off") == 0) {
  143. /* nothing to do here */
  144. } else {
  145. error_reason = "unknown value for fileline";
  146. free(value);
  147. goto parse_error;
  148. }
  149. free(value);
  150. }
  151. if (err) {
  152. error_reason = "not enough memory to set logging format buffer";
  153. goto parse_error;
  154. }
  155. if (map_get_string("logging.function_name", &value) == CS_OK) {
  156. if (strcmp (value, "on") == 0) {
  157. if (!insert_into_buffer(new_format_buffer,
  158. sizeof(new_format_buffer),
  159. "%n:", "f:")) {
  160. err = logsys_format_set(new_format_buffer);
  161. } else
  162. if (!insert_into_buffer(new_format_buffer,
  163. sizeof(new_format_buffer),
  164. " %n", "g]")) {
  165. err = logsys_format_set(new_format_buffer);
  166. }
  167. } else
  168. if (strcmp (value, "off") == 0) {
  169. /* nothing to do here */
  170. } else {
  171. error_reason = "unknown value for function_name";
  172. free(value);
  173. goto parse_error;
  174. }
  175. free(value);
  176. }
  177. if (err) {
  178. error_reason = "not enough memory to set logging format buffer";
  179. goto parse_error;
  180. }
  181. if (map_get_string("logging.timestamp", &value) == CS_OK) {
  182. if (strcmp (value, "on") == 0) {
  183. if(!insert_into_buffer(new_format_buffer,
  184. sizeof(new_format_buffer),
  185. "%t ", NULL)) {
  186. err = logsys_format_set(new_format_buffer);
  187. }
  188. } else
  189. if (strcmp (value, "off") == 0) {
  190. /* nothing to do here */
  191. } else {
  192. error_reason = "unknown value for timestamp";
  193. free(value);
  194. goto parse_error;
  195. }
  196. free(value);
  197. }
  198. if (err) {
  199. error_reason = "not enough memory to set logging format buffer";
  200. goto parse_error;
  201. }
  202. return (0);
  203. parse_error:
  204. *error_string = error_reason;
  205. return (-1);
  206. }
  207. /*
  208. * blackbox is another global specific option that
  209. * doesn't apply at system/subsystem level.
  210. */
  211. static int corosync_main_config_blackbox_set (
  212. const char **error_string)
  213. {
  214. const char *error_reason;
  215. char *value = NULL;
  216. if (map_get_string("logging.blackbox", &value) == CS_OK) {
  217. if (strcmp (value, "on") == 0) {
  218. (void)logsys_blackbox_set(QB_TRUE);
  219. } else if (strcmp (value, "off") == 0) {
  220. (void)logsys_blackbox_set(QB_FALSE);
  221. } else {
  222. error_reason = "unknown value for blackbox";
  223. free(value);
  224. goto parse_error;
  225. }
  226. free(value);
  227. } else {
  228. (void)logsys_blackbox_set(QB_TRUE);
  229. }
  230. return (0);
  231. parse_error:
  232. *error_string = error_reason;
  233. return (-1);
  234. }
  235. static int corosync_main_config_log_destination_set (
  236. const char *path,
  237. const char *key,
  238. const char *subsys,
  239. const char **error_string,
  240. unsigned int mode_mask,
  241. char deprecated,
  242. char default_value,
  243. const char *replacement)
  244. {
  245. static char formatted_error_reason[128];
  246. char *value = NULL;
  247. unsigned int mode;
  248. char key_name[MAP_KEYNAME_MAXLEN];
  249. snprintf(key_name, MAP_KEYNAME_MAXLEN, "%s.%s", path, key);
  250. if (map_get_string(key_name, &value) == CS_OK) {
  251. if (deprecated) {
  252. log_printf(LOGSYS_LEVEL_WARNING,
  253. "Warning: the %s config parameter has been obsoleted."
  254. " See corosync.conf man page %s directive.",
  255. key, replacement);
  256. }
  257. mode = logsys_config_mode_get (subsys);
  258. if (strcmp (value, "yes") == 0 || strcmp (value, "on") == 0) {
  259. mode |= mode_mask;
  260. if (logsys_config_mode_set(subsys, mode) < 0) {
  261. sprintf (formatted_error_reason, "unable to set mode %s", key);
  262. goto parse_error;
  263. }
  264. } else
  265. if (strcmp (value, "no") == 0 || strcmp (value, "off") == 0) {
  266. mode &= ~mode_mask;
  267. if (logsys_config_mode_set(subsys, mode) < 0) {
  268. sprintf (formatted_error_reason, "unable to unset mode %s", key);
  269. goto parse_error;
  270. }
  271. } else {
  272. sprintf (formatted_error_reason, "unknown value for %s", key);
  273. goto parse_error;
  274. }
  275. }
  276. /* Set to default if we are the top-level logger */
  277. else if (!subsys && !deprecated) {
  278. mode = logsys_config_mode_get (subsys);
  279. if (default_value) {
  280. mode |= mode_mask;
  281. }
  282. else {
  283. mode &= ~mode_mask;
  284. }
  285. if (logsys_config_mode_set(subsys, mode) < 0) {
  286. sprintf (formatted_error_reason, "unable to change mode %s", key);
  287. goto parse_error;
  288. }
  289. }
  290. free(value);
  291. return (0);
  292. parse_error:
  293. *error_string = formatted_error_reason;
  294. free(value);
  295. return (-1);
  296. }
  297. static int corosync_main_config_set (
  298. const char *path,
  299. const char *subsys,
  300. const char **error_string)
  301. {
  302. const char *error_reason = error_string_response;
  303. char *value = NULL;
  304. int mode;
  305. char key_name[MAP_KEYNAME_MAXLEN];
  306. /*
  307. * this bit abuses the internal logsys exported API
  308. * to guarantee that all configured subsystems are
  309. * initialized too.
  310. *
  311. * using this approach avoids some headaches caused
  312. * by IPC and TOTEM that have a special logging
  313. * handling requirements
  314. */
  315. if (subsys != NULL) {
  316. if (_logsys_subsys_create(subsys, NULL) < 0) {
  317. error_reason = "unable to create new logging subsystem";
  318. goto parse_error;
  319. }
  320. }
  321. mode = logsys_config_mode_get(subsys);
  322. if (mode < 0) {
  323. error_reason = "unable to get mode";
  324. goto parse_error;
  325. }
  326. if (corosync_main_config_log_destination_set (path, "to_stderr", subsys, &error_reason,
  327. LOGSYS_MODE_OUTPUT_STDERR, 0, 1, NULL) != 0)
  328. goto parse_error;
  329. if (corosync_main_config_log_destination_set (path, "to_syslog", subsys, &error_reason,
  330. LOGSYS_MODE_OUTPUT_SYSLOG, 0, 1, NULL) != 0)
  331. goto parse_error;
  332. snprintf(key_name, MAP_KEYNAME_MAXLEN, "%s.%s", path, "syslog_facility");
  333. if (map_get_string(key_name, &value) == CS_OK) {
  334. int syslog_facility;
  335. syslog_facility = qb_log_facility2int(value);
  336. if (syslog_facility < 0) {
  337. error_reason = "unknown syslog facility specified";
  338. goto parse_error;
  339. }
  340. if (logsys_config_syslog_facility_set(subsys,
  341. syslog_facility) < 0) {
  342. error_reason = "unable to set syslog facility";
  343. goto parse_error;
  344. }
  345. free(value);
  346. }
  347. else {
  348. /* Set default here in case of a reload */
  349. if (logsys_config_syslog_facility_set(subsys,
  350. qb_log_facility2int("daemon")) < 0) {
  351. error_reason = "unable to set syslog facility";
  352. goto parse_error;
  353. }
  354. }
  355. snprintf(key_name, MAP_KEYNAME_MAXLEN, "%s.%s", path, "syslog_level");
  356. if (map_get_string(key_name, &value) == CS_OK) {
  357. int syslog_priority;
  358. log_printf(LOGSYS_LEVEL_WARNING,
  359. "Warning: the syslog_level config parameter has been obsoleted."
  360. " See corosync.conf man page syslog_priority directive.");
  361. syslog_priority = logsys_priority_id_get(value);
  362. free(value);
  363. if (syslog_priority < 0) {
  364. error_reason = "unknown syslog level specified";
  365. goto parse_error;
  366. }
  367. if (logsys_config_syslog_priority_set(subsys,
  368. syslog_priority) < 0) {
  369. error_reason = "unable to set syslog level";
  370. goto parse_error;
  371. }
  372. }
  373. snprintf(key_name, MAP_KEYNAME_MAXLEN, "%s.%s", path, "syslog_priority");
  374. if (map_get_string(key_name, &value) == CS_OK) {
  375. int syslog_priority;
  376. syslog_priority = logsys_priority_id_get(value);
  377. free(value);
  378. if (syslog_priority < 0) {
  379. error_reason = "unknown syslog priority specified";
  380. goto parse_error;
  381. }
  382. if (logsys_config_syslog_priority_set(subsys,
  383. syslog_priority) < 0) {
  384. error_reason = "unable to set syslog priority";
  385. goto parse_error;
  386. }
  387. }
  388. else if(strcmp(key_name, "logging.syslog_priority") == 0){
  389. if (logsys_config_syslog_priority_set(subsys,
  390. logsys_priority_id_get("info")) < 0) {
  391. error_reason = "unable to set syslog level";
  392. goto parse_error;
  393. }
  394. }
  395. #ifdef LOGCONFIG_USE_ICMAP
  396. snprintf(key_name, MAP_KEYNAME_MAXLEN, "%s.%s", path, "logfile");
  397. if (map_get_string(key_name, &value) == CS_OK) {
  398. if (logsys_config_file_set (subsys, &error_reason, value) < 0) {
  399. goto parse_error;
  400. }
  401. free(value);
  402. }
  403. #else
  404. if (!subsys) {
  405. if (logsys_config_file_set (subsys, &error_reason, main_logfile) < 0) {
  406. goto parse_error;
  407. }
  408. }
  409. #endif
  410. if (corosync_main_config_log_destination_set (path, "to_file", subsys, &error_reason,
  411. LOGSYS_MODE_OUTPUT_FILE, 1, 0, "to_logfile") != 0)
  412. goto parse_error;
  413. if (corosync_main_config_log_destination_set (path, "to_logfile", subsys, &error_reason,
  414. LOGSYS_MODE_OUTPUT_FILE, 0, 0, NULL) != 0)
  415. goto parse_error;
  416. snprintf(key_name, MAP_KEYNAME_MAXLEN, "%s.%s", path, "logfile_priority");
  417. if (map_get_string(key_name, &value) == CS_OK) {
  418. int logfile_priority;
  419. logfile_priority = logsys_priority_id_get(value);
  420. free(value);
  421. if (logfile_priority < 0) {
  422. error_reason = "unknown logfile priority specified";
  423. goto parse_error;
  424. }
  425. if (logsys_config_logfile_priority_set(subsys,
  426. logfile_priority) < 0) {
  427. error_reason = "unable to set logfile priority";
  428. goto parse_error;
  429. }
  430. }
  431. else if(strcmp(key_name,"logging.logfile_priority") == 0){
  432. if (logsys_config_logfile_priority_set(subsys,
  433. logsys_priority_id_get("info")) < 0) {
  434. error_reason = "unable to set syslog level";
  435. goto parse_error;
  436. }
  437. }
  438. snprintf(key_name, MAP_KEYNAME_MAXLEN, "%s.%s", path, "debug");
  439. if (map_get_string(key_name, &value) == CS_OK) {
  440. if (strcmp (value, "trace") == 0) {
  441. if (logsys_config_debug_set (subsys, LOGSYS_DEBUG_TRACE) < 0) {
  442. error_reason = "unable to set debug trace";
  443. free(value);
  444. goto parse_error;
  445. }
  446. } else
  447. if (strcmp (value, "on") == 0) {
  448. if (logsys_config_debug_set (subsys, LOGSYS_DEBUG_ON) < 0) {
  449. error_reason = "unable to set debug on";
  450. free(value);
  451. goto parse_error;
  452. }
  453. } else
  454. if (strcmp (value, "off") == 0) {
  455. if (logsys_config_debug_set (subsys, LOGSYS_DEBUG_OFF) < 0) {
  456. error_reason = "unable to set debug off";
  457. free(value);
  458. goto parse_error;
  459. }
  460. } else {
  461. error_reason = "unknown value for debug";
  462. free(value);
  463. goto parse_error;
  464. }
  465. free(value);
  466. }
  467. else {
  468. if (logsys_config_debug_set (subsys, LOGSYS_DEBUG_OFF) < 0) {
  469. error_reason = "unable to set debug off";
  470. goto parse_error;
  471. }
  472. }
  473. return (0);
  474. parse_error:
  475. *error_string = error_reason;
  476. return (-1);
  477. }
  478. static int corosync_main_config_read_logging (
  479. const char **error_string)
  480. {
  481. const char *error_reason;
  482. #ifdef LOGCONFIG_USE_ICMAP
  483. icmap_iter_t iter;
  484. const char *key_name;
  485. #else
  486. cmap_iter_handle_t iter;
  487. char key_name[CMAP_KEYNAME_MAXLEN];
  488. #endif
  489. char key_subsys[MAP_KEYNAME_MAXLEN];
  490. char key_item[MAP_KEYNAME_MAXLEN];
  491. int res;
  492. /* format set is supported only for toplevel */
  493. if (corosync_main_config_format_set(&error_reason) < 0) {
  494. goto parse_error;
  495. }
  496. if (corosync_main_config_blackbox_set(&error_reason) < 0) {
  497. goto parse_error;
  498. }
  499. if (corosync_main_config_set ("logging", NULL, &error_reason) < 0) {
  500. goto parse_error;
  501. }
  502. /*
  503. * we will need 2 of these to compensate for new logging
  504. * config format
  505. */
  506. #ifdef LOGCONFIG_USE_ICMAP
  507. iter = icmap_iter_init("logging.logger_subsys.");
  508. while ((key_name = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  509. #else
  510. cmap_iter_init(cmap_handle, "logging.logger_subsys.", &iter);
  511. while ((cmap_iter_next(cmap_handle, iter, key_name, NULL, NULL)) == CS_OK) {
  512. #endif
  513. res = sscanf(key_name, "logging.logger_subsys.%[^.].%s", key_subsys, key_item);
  514. if (res != 2) {
  515. continue ;
  516. }
  517. if (strcmp(key_item, "subsys") != 0) {
  518. continue ;
  519. }
  520. snprintf(key_item, MAP_KEYNAME_MAXLEN, "logging.logger_subsys.%s", key_subsys);
  521. if (corosync_main_config_set(key_item, key_subsys, &error_reason) < 0) {
  522. goto parse_error;
  523. }
  524. }
  525. #ifdef LOGCONFIG_USE_ICMAP
  526. icmap_iter_finalize(iter);
  527. #else
  528. cmap_iter_finalize(cmap_handle, iter);
  529. #endif
  530. logsys_config_apply();
  531. return 0;
  532. parse_error:
  533. *error_string = error_reason;
  534. return (-1);
  535. }
  536. #ifdef LOGCONFIG_USE_ICMAP
  537. static void main_logging_notify(
  538. int32_t event,
  539. const char *key_name,
  540. struct icmap_notify_value new_val,
  541. struct icmap_notify_value old_val,
  542. void *user_data)
  543. #else
  544. static void main_logging_notify(
  545. cmap_handle_t cmap_handle_unused,
  546. cmap_handle_t cmap_track_handle_unused,
  547. int32_t event,
  548. const char *key_name,
  549. struct cmap_notify_value new_val,
  550. struct cmap_notify_value old_val,
  551. void *user_data)
  552. #endif
  553. {
  554. const char *error_string;
  555. static int reload_in_progress = 0;
  556. /* If a full reload happens then suspend updates for individual keys until
  557. * it's all completed
  558. */
  559. if (strcmp(key_name, "config.reload_in_progress") == 0) {
  560. if (*(uint8_t *)new_val.data == 1) {
  561. reload_in_progress = 1;
  562. } else {
  563. reload_in_progress = 0;
  564. }
  565. }
  566. if (reload_in_progress) {
  567. log_printf(LOGSYS_LEVEL_DEBUG, "Ignoring key change, reload in progress. %s\n", key_name);
  568. return;
  569. }
  570. /*
  571. * Reload the logsys configuration
  572. */
  573. if (logsys_format_set(NULL) == -1) {
  574. fprintf (stderr, "Unable to setup logging format.\n");
  575. }
  576. corosync_main_config_read_logging(&error_string);
  577. }
  578. #ifdef LOGCONFIG_USE_ICMAP
  579. static void add_logsys_config_notification(void)
  580. {
  581. icmap_track_t icmap_track = NULL;
  582. icmap_track_add("logging.",
  583. ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX,
  584. main_logging_notify,
  585. NULL,
  586. &icmap_track);
  587. icmap_track_add("config.reload_in_progress",
  588. ICMAP_TRACK_ADD | ICMAP_TRACK_MODIFY,
  589. main_logging_notify,
  590. NULL,
  591. &icmap_track);
  592. }
  593. #else
  594. static void add_logsys_config_notification(void)
  595. {
  596. cmap_track_handle_t cmap_track;
  597. cmap_track_add(cmap_handle, "logging.",
  598. CMAP_TRACK_ADD | CMAP_TRACK_DELETE | CMAP_TRACK_MODIFY | CMAP_TRACK_PREFIX,
  599. main_logging_notify,
  600. NULL,
  601. &cmap_track);
  602. cmap_track_add(cmap_handle, "config.reload_in_progress",
  603. CMAP_TRACK_ADD | CMAP_TRACK_MODIFY,
  604. main_logging_notify,
  605. NULL,
  606. &cmap_track);
  607. }
  608. #endif
  609. int corosync_log_config_read (
  610. #ifndef LOGCONFIG_USE_ICMAP
  611. cmap_handle_t cmap_h,
  612. const char *default_logfile,
  613. #endif
  614. const char **error_string)
  615. {
  616. const char *error_reason = error_string_response;
  617. #ifndef LOGCONFIG_USE_ICMAP
  618. if (!cmap_h) {
  619. error_reason = "No cmap handle";
  620. return (-1);
  621. }
  622. if (!default_logfile) {
  623. error_reason = "No default logfile";
  624. return (-1);
  625. }
  626. cmap_handle = cmap_h;
  627. main_logfile = default_logfile;
  628. #endif
  629. if (corosync_main_config_read_logging(error_string) < 0) {
  630. error_reason = *error_string;
  631. goto parse_error;
  632. }
  633. add_logsys_config_notification();
  634. return 0;
  635. parse_error:
  636. snprintf (error_string_response, sizeof(error_string_response),
  637. "parse error in config: %s.\n",
  638. error_reason);
  639. *error_string = error_string_response;
  640. return (-1);
  641. }