logconfig.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  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. #ifdef QB_FEATURE_LOG_HIRES_TIMESTAMPS
  189. } else if (strcmp (value, "hires") == 0) {
  190. if(!insert_into_buffer(new_format_buffer,
  191. sizeof(new_format_buffer),
  192. "%T ", NULL)) {
  193. err = logsys_format_set(new_format_buffer);
  194. }
  195. #endif
  196. } else if (strcmp (value, "off") == 0) {
  197. /* nothing to do here */
  198. } else {
  199. error_reason = "unknown value for timestamp";
  200. free(value);
  201. goto parse_error;
  202. }
  203. free(value);
  204. }
  205. if (err) {
  206. error_reason = "not enough memory to set logging format buffer";
  207. goto parse_error;
  208. }
  209. return (0);
  210. parse_error:
  211. *error_string = error_reason;
  212. return (-1);
  213. }
  214. /*
  215. * blackbox is another global specific option that
  216. * doesn't apply at system/subsystem level.
  217. */
  218. static int corosync_main_config_blackbox_set (
  219. const char **error_string)
  220. {
  221. const char *error_reason;
  222. char *value = NULL;
  223. if (map_get_string("logging.blackbox", &value) == CS_OK) {
  224. if (strcmp (value, "on") == 0) {
  225. (void)logsys_blackbox_set(QB_TRUE);
  226. } else if (strcmp (value, "off") == 0) {
  227. (void)logsys_blackbox_set(QB_FALSE);
  228. } else {
  229. error_reason = "unknown value for blackbox";
  230. free(value);
  231. goto parse_error;
  232. }
  233. free(value);
  234. } else {
  235. (void)logsys_blackbox_set(QB_TRUE);
  236. }
  237. return (0);
  238. parse_error:
  239. *error_string = error_reason;
  240. return (-1);
  241. }
  242. static int corosync_main_config_log_destination_set (
  243. const char *path,
  244. const char *key,
  245. const char *subsys,
  246. const char **error_string,
  247. unsigned int mode_mask,
  248. char deprecated,
  249. char default_value,
  250. const char *replacement)
  251. {
  252. static char formatted_error_reason[128];
  253. char *value = NULL;
  254. unsigned int mode;
  255. char key_name[MAP_KEYNAME_MAXLEN];
  256. snprintf(key_name, MAP_KEYNAME_MAXLEN, "%s.%s", path, key);
  257. if (map_get_string(key_name, &value) == CS_OK) {
  258. if (deprecated) {
  259. log_printf(LOGSYS_LEVEL_WARNING,
  260. "Warning: the %s config parameter has been obsoleted."
  261. " See corosync.conf man page %s directive.",
  262. key, replacement);
  263. }
  264. mode = logsys_config_mode_get (subsys);
  265. if (strcmp (value, "yes") == 0 || strcmp (value, "on") == 0) {
  266. mode |= mode_mask;
  267. if (logsys_config_mode_set(subsys, mode) < 0) {
  268. sprintf (formatted_error_reason, "unable to set mode %s", key);
  269. goto parse_error;
  270. }
  271. } else
  272. if (strcmp (value, "no") == 0 || strcmp (value, "off") == 0) {
  273. mode &= ~mode_mask;
  274. if (logsys_config_mode_set(subsys, mode) < 0) {
  275. sprintf (formatted_error_reason, "unable to unset mode %s", key);
  276. goto parse_error;
  277. }
  278. } else {
  279. sprintf (formatted_error_reason, "unknown value for %s", key);
  280. goto parse_error;
  281. }
  282. }
  283. /* Set to default if we are the top-level logger */
  284. else if (!subsys && !deprecated) {
  285. mode = logsys_config_mode_get (subsys);
  286. if (default_value) {
  287. mode |= mode_mask;
  288. }
  289. else {
  290. mode &= ~mode_mask;
  291. }
  292. if (logsys_config_mode_set(subsys, mode) < 0) {
  293. sprintf (formatted_error_reason, "unable to change mode %s", key);
  294. goto parse_error;
  295. }
  296. }
  297. free(value);
  298. return (0);
  299. parse_error:
  300. *error_string = formatted_error_reason;
  301. free(value);
  302. return (-1);
  303. }
  304. static int corosync_main_config_set (
  305. const char *path,
  306. const char *subsys,
  307. const char **error_string)
  308. {
  309. const char *error_reason = error_string_response;
  310. char *value = NULL;
  311. int mode;
  312. char key_name[MAP_KEYNAME_MAXLEN];
  313. /*
  314. * this bit abuses the internal logsys exported API
  315. * to guarantee that all configured subsystems are
  316. * initialized too.
  317. *
  318. * using this approach avoids some headaches caused
  319. * by IPC and TOTEM that have a special logging
  320. * handling requirements
  321. */
  322. if (subsys != NULL) {
  323. if (_logsys_subsys_create(subsys, NULL) < 0) {
  324. error_reason = "unable to create new logging subsystem";
  325. goto parse_error;
  326. }
  327. }
  328. mode = logsys_config_mode_get(subsys);
  329. if (mode < 0) {
  330. error_reason = "unable to get mode";
  331. goto parse_error;
  332. }
  333. if (corosync_main_config_log_destination_set (path, "to_stderr", subsys, &error_reason,
  334. LOGSYS_MODE_OUTPUT_STDERR, 0, 1, NULL) != 0)
  335. goto parse_error;
  336. if (corosync_main_config_log_destination_set (path, "to_syslog", subsys, &error_reason,
  337. LOGSYS_MODE_OUTPUT_SYSLOG, 0, 1, NULL) != 0)
  338. goto parse_error;
  339. snprintf(key_name, MAP_KEYNAME_MAXLEN, "%s.%s", path, "syslog_facility");
  340. if (map_get_string(key_name, &value) == CS_OK) {
  341. int syslog_facility;
  342. syslog_facility = qb_log_facility2int(value);
  343. if (syslog_facility < 0) {
  344. error_reason = "unknown syslog facility specified";
  345. goto parse_error;
  346. }
  347. if (logsys_config_syslog_facility_set(subsys,
  348. syslog_facility) < 0) {
  349. error_reason = "unable to set syslog facility";
  350. goto parse_error;
  351. }
  352. free(value);
  353. }
  354. else {
  355. /* Set default here in case of a reload */
  356. if (logsys_config_syslog_facility_set(subsys,
  357. qb_log_facility2int("daemon")) < 0) {
  358. error_reason = "unable to set syslog facility";
  359. goto parse_error;
  360. }
  361. }
  362. snprintf(key_name, MAP_KEYNAME_MAXLEN, "%s.%s", path, "syslog_level");
  363. if (map_get_string(key_name, &value) == CS_OK) {
  364. int syslog_priority;
  365. log_printf(LOGSYS_LEVEL_WARNING,
  366. "Warning: the syslog_level config parameter has been obsoleted."
  367. " See corosync.conf man page syslog_priority directive.");
  368. syslog_priority = logsys_priority_id_get(value);
  369. free(value);
  370. if (syslog_priority < 0) {
  371. error_reason = "unknown syslog level specified";
  372. goto parse_error;
  373. }
  374. if (logsys_config_syslog_priority_set(subsys,
  375. syslog_priority) < 0) {
  376. error_reason = "unable to set syslog level";
  377. goto parse_error;
  378. }
  379. }
  380. snprintf(key_name, MAP_KEYNAME_MAXLEN, "%s.%s", path, "syslog_priority");
  381. if (map_get_string(key_name, &value) == CS_OK) {
  382. int syslog_priority;
  383. syslog_priority = logsys_priority_id_get(value);
  384. free(value);
  385. if (syslog_priority < 0) {
  386. error_reason = "unknown syslog priority specified";
  387. goto parse_error;
  388. }
  389. if (logsys_config_syslog_priority_set(subsys,
  390. syslog_priority) < 0) {
  391. error_reason = "unable to set syslog priority";
  392. goto parse_error;
  393. }
  394. }
  395. else if(strcmp(key_name, "logging.syslog_priority") == 0){
  396. if (logsys_config_syslog_priority_set(subsys,
  397. logsys_priority_id_get("info")) < 0) {
  398. error_reason = "unable to set syslog level";
  399. goto parse_error;
  400. }
  401. }
  402. #ifdef LOGCONFIG_USE_ICMAP
  403. snprintf(key_name, MAP_KEYNAME_MAXLEN, "%s.%s", path, "logfile");
  404. if (map_get_string(key_name, &value) == CS_OK) {
  405. if (logsys_config_file_set (subsys, &error_reason, value) < 0) {
  406. goto parse_error;
  407. }
  408. free(value);
  409. }
  410. #else
  411. if (!subsys) {
  412. if (logsys_config_file_set (subsys, &error_reason, main_logfile) < 0) {
  413. goto parse_error;
  414. }
  415. }
  416. #endif
  417. if (corosync_main_config_log_destination_set (path, "to_file", subsys, &error_reason,
  418. LOGSYS_MODE_OUTPUT_FILE, 1, 0, "to_logfile") != 0)
  419. goto parse_error;
  420. if (corosync_main_config_log_destination_set (path, "to_logfile", subsys, &error_reason,
  421. LOGSYS_MODE_OUTPUT_FILE, 0, 0, NULL) != 0)
  422. goto parse_error;
  423. snprintf(key_name, MAP_KEYNAME_MAXLEN, "%s.%s", path, "logfile_priority");
  424. if (map_get_string(key_name, &value) == CS_OK) {
  425. int logfile_priority;
  426. logfile_priority = logsys_priority_id_get(value);
  427. free(value);
  428. if (logfile_priority < 0) {
  429. error_reason = "unknown logfile priority specified";
  430. goto parse_error;
  431. }
  432. if (logsys_config_logfile_priority_set(subsys,
  433. logfile_priority) < 0) {
  434. error_reason = "unable to set logfile priority";
  435. goto parse_error;
  436. }
  437. }
  438. else if(strcmp(key_name,"logging.logfile_priority") == 0){
  439. if (logsys_config_logfile_priority_set(subsys,
  440. logsys_priority_id_get("info")) < 0) {
  441. error_reason = "unable to set syslog level";
  442. goto parse_error;
  443. }
  444. }
  445. snprintf(key_name, MAP_KEYNAME_MAXLEN, "%s.%s", path, "debug");
  446. if (map_get_string(key_name, &value) == CS_OK) {
  447. if (strcmp (value, "trace") == 0) {
  448. if (logsys_config_debug_set (subsys, LOGSYS_DEBUG_TRACE) < 0) {
  449. error_reason = "unable to set debug trace";
  450. free(value);
  451. goto parse_error;
  452. }
  453. } else
  454. if (strcmp (value, "on") == 0) {
  455. if (logsys_config_debug_set (subsys, LOGSYS_DEBUG_ON) < 0) {
  456. error_reason = "unable to set debug on";
  457. free(value);
  458. goto parse_error;
  459. }
  460. } else
  461. if (strcmp (value, "off") == 0) {
  462. if (logsys_config_debug_set (subsys, LOGSYS_DEBUG_OFF) < 0) {
  463. error_reason = "unable to set debug off";
  464. free(value);
  465. goto parse_error;
  466. }
  467. } else {
  468. error_reason = "unknown value for debug";
  469. free(value);
  470. goto parse_error;
  471. }
  472. free(value);
  473. }
  474. else {
  475. if (logsys_config_debug_set (subsys, LOGSYS_DEBUG_OFF) < 0) {
  476. error_reason = "unable to set debug off";
  477. free(value);
  478. goto parse_error;
  479. }
  480. }
  481. return (0);
  482. parse_error:
  483. *error_string = error_reason;
  484. return (-1);
  485. }
  486. static int corosync_main_config_read_logging (
  487. const char **error_string)
  488. {
  489. const char *error_reason;
  490. #ifdef LOGCONFIG_USE_ICMAP
  491. icmap_iter_t iter;
  492. const char *key_name;
  493. #else
  494. cmap_iter_handle_t iter;
  495. char key_name[CMAP_KEYNAME_MAXLEN];
  496. #endif
  497. char key_subsys[MAP_KEYNAME_MAXLEN];
  498. char key_item[MAP_KEYNAME_MAXLEN];
  499. int res;
  500. /* format set is supported only for toplevel */
  501. if (corosync_main_config_format_set(&error_reason) < 0) {
  502. goto parse_error;
  503. }
  504. if (corosync_main_config_blackbox_set(&error_reason) < 0) {
  505. goto parse_error;
  506. }
  507. if (corosync_main_config_set ("logging", NULL, &error_reason) < 0) {
  508. goto parse_error;
  509. }
  510. /*
  511. * we will need 2 of these to compensate for new logging
  512. * config format
  513. */
  514. #ifdef LOGCONFIG_USE_ICMAP
  515. iter = icmap_iter_init("logging.logger_subsys.");
  516. while ((key_name = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  517. #else
  518. cmap_iter_init(cmap_handle, "logging.logger_subsys.", &iter);
  519. while ((cmap_iter_next(cmap_handle, iter, key_name, NULL, NULL)) == CS_OK) {
  520. #endif
  521. res = sscanf(key_name, "logging.logger_subsys.%[^.].%s", key_subsys, key_item);
  522. if (res != 2) {
  523. continue ;
  524. }
  525. if (strcmp(key_item, "subsys") != 0) {
  526. continue ;
  527. }
  528. if (snprintf(key_item, MAP_KEYNAME_MAXLEN, "logging.logger_subsys.%s",
  529. key_subsys) >= MAP_KEYNAME_MAXLEN) {
  530. /*
  531. * This should never happen
  532. */
  533. error_reason = "Can't snprintf logger_subsys key_item";
  534. goto parse_error;
  535. }
  536. if (corosync_main_config_set(key_item, key_subsys, &error_reason) < 0) {
  537. goto parse_error;
  538. }
  539. }
  540. #ifdef LOGCONFIG_USE_ICMAP
  541. icmap_iter_finalize(iter);
  542. #else
  543. cmap_iter_finalize(cmap_handle, iter);
  544. #endif
  545. logsys_config_apply();
  546. return 0;
  547. parse_error:
  548. *error_string = error_reason;
  549. return (-1);
  550. }
  551. #ifdef LOGCONFIG_USE_ICMAP
  552. static void main_logging_notify(
  553. int32_t event,
  554. const char *key_name,
  555. struct icmap_notify_value new_val,
  556. struct icmap_notify_value old_val,
  557. void *user_data)
  558. #else
  559. static void main_logging_notify(
  560. cmap_handle_t cmap_handle_unused,
  561. cmap_handle_t cmap_track_handle_unused,
  562. int32_t event,
  563. const char *key_name,
  564. struct cmap_notify_value new_val,
  565. struct cmap_notify_value old_val,
  566. void *user_data)
  567. #endif
  568. {
  569. const char *error_string;
  570. static int reload_in_progress = 0;
  571. /* If a full reload happens then suspend updates for individual keys until
  572. * it's all completed
  573. */
  574. if (strcmp(key_name, "config.reload_in_progress") == 0) {
  575. if (*(uint8_t *)new_val.data == 1) {
  576. reload_in_progress = 1;
  577. } else {
  578. reload_in_progress = 0;
  579. }
  580. }
  581. if (reload_in_progress) {
  582. log_printf(LOGSYS_LEVEL_DEBUG, "Ignoring key change, reload in progress. %s\n", key_name);
  583. return;
  584. }
  585. /*
  586. * Reload the logsys configuration
  587. */
  588. if (logsys_format_set(NULL) == -1) {
  589. fprintf (stderr, "Unable to setup logging format.\n");
  590. }
  591. corosync_main_config_read_logging(&error_string);
  592. }
  593. #ifdef LOGCONFIG_USE_ICMAP
  594. static void add_logsys_config_notification(void)
  595. {
  596. icmap_track_t icmap_track = NULL;
  597. icmap_track_add("logging.",
  598. ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX,
  599. main_logging_notify,
  600. NULL,
  601. &icmap_track);
  602. icmap_track_add("config.reload_in_progress",
  603. ICMAP_TRACK_ADD | ICMAP_TRACK_MODIFY,
  604. main_logging_notify,
  605. NULL,
  606. &icmap_track);
  607. }
  608. #else
  609. static void add_logsys_config_notification(void)
  610. {
  611. cmap_track_handle_t cmap_track;
  612. cmap_track_add(cmap_handle, "logging.",
  613. CMAP_TRACK_ADD | CMAP_TRACK_DELETE | CMAP_TRACK_MODIFY | CMAP_TRACK_PREFIX,
  614. main_logging_notify,
  615. NULL,
  616. &cmap_track);
  617. cmap_track_add(cmap_handle, "config.reload_in_progress",
  618. CMAP_TRACK_ADD | CMAP_TRACK_MODIFY,
  619. main_logging_notify,
  620. NULL,
  621. &cmap_track);
  622. }
  623. #endif
  624. int corosync_log_config_read (
  625. #ifndef LOGCONFIG_USE_ICMAP
  626. cmap_handle_t cmap_h,
  627. const char *default_logfile,
  628. #endif
  629. const char **error_string)
  630. {
  631. const char *error_reason = error_string_response;
  632. #ifndef LOGCONFIG_USE_ICMAP
  633. if (!cmap_h) {
  634. error_reason = "No cmap handle";
  635. return (-1);
  636. }
  637. if (!default_logfile) {
  638. error_reason = "No default logfile";
  639. return (-1);
  640. }
  641. cmap_handle = cmap_h;
  642. main_logfile = default_logfile;
  643. #endif
  644. if (corosync_main_config_read_logging(error_string) < 0) {
  645. error_reason = *error_string;
  646. goto parse_error;
  647. }
  648. add_logsys_config_notification();
  649. return 0;
  650. parse_error:
  651. snprintf (error_string_response, sizeof(error_string_response),
  652. "parse error in config: %s.\n",
  653. error_reason);
  654. *error_string = error_string_response;
  655. return (-1);
  656. }