logconfig.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  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. #include "totemknet.h"
  53. static char error_string_response[512];
  54. /**
  55. * insert_into_buffer
  56. * @target_buffer: a buffer where to write results
  57. * @bufferlen: tell us the size of the buffer to avoid overflows
  58. * @entry: entry that needs to be added to the buffer
  59. * @after: can either be NULL or set to a string.
  60. * if NULL, @entry is prependend to logsys_format_get buffer.
  61. * if set, @entry is added immediately after @after.
  62. *
  63. * Since the function is specific to logsys_format_get handling, it is implicit
  64. * that source is logsys_format_get();
  65. *
  66. * In case of failure, target_buffer could be left dirty. So don't trust
  67. * any data leftover in it.
  68. *
  69. * Searching for "after" assumes that there is only entry of "after"
  70. * in the source. Afterall we control the string here and for logging format
  71. * it makes little to no sense to have duplicate format entries.
  72. *
  73. * Returns: 0 on success, -1 on failure
  74. **/
  75. static int insert_into_buffer(
  76. char *target_buffer,
  77. size_t bufferlen,
  78. const char *entry,
  79. const char *after)
  80. {
  81. const char *current_format = NULL;
  82. current_format = logsys_format_get();
  83. /* if the entry is already in the format we don't add it again */
  84. if (strstr(current_format, entry) != NULL) {
  85. return -1;
  86. }
  87. /* if there is no "after", simply prepend the requested entry
  88. * otherwise go for beautiful string manipulation.... </sarcasm> */
  89. if (!after) {
  90. if (snprintf(target_buffer, bufferlen - 1, "%s%s",
  91. entry,
  92. current_format) >= bufferlen - 1) {
  93. return -1;
  94. }
  95. } else {
  96. const char *afterpos;
  97. size_t afterlen;
  98. size_t templen;
  99. /* check if after is contained in the format
  100. * and afterlen has a meaning or return an error */
  101. afterpos = strstr(current_format, after);
  102. afterlen = strlen(after);
  103. if ((!afterpos) || (!afterlen)) {
  104. return -1;
  105. }
  106. templen = afterpos - current_format + afterlen;
  107. if (snprintf(target_buffer, templen + 1, "%s", current_format)
  108. >= bufferlen - 1) {
  109. return -1;
  110. }
  111. if (snprintf(target_buffer + templen, bufferlen - ( templen + 1 ),
  112. "%s%s", entry, current_format + templen)
  113. >= bufferlen - ( templen + 1 )) {
  114. return -1;
  115. }
  116. }
  117. return 0;
  118. }
  119. /*
  120. * format set is global specific option that
  121. * doesn't apply at system/subsystem level.
  122. */
  123. static int corosync_main_config_format_set (
  124. const char **error_string)
  125. {
  126. const char *error_reason;
  127. char new_format_buffer[PATH_MAX];
  128. char *value = NULL;
  129. int err = 0;
  130. char timestamp_str_to_add[8];
  131. if (map_get_string("logging.fileline", &value) == CS_OK) {
  132. if (strcmp (value, "on") == 0) {
  133. if (!insert_into_buffer(new_format_buffer,
  134. sizeof(new_format_buffer),
  135. " %f:%l", "g]")) {
  136. err = logsys_format_set(new_format_buffer);
  137. } else
  138. if (!insert_into_buffer(new_format_buffer,
  139. sizeof(new_format_buffer),
  140. "%f:%l", NULL)) {
  141. err = logsys_format_set(new_format_buffer);
  142. }
  143. } else
  144. if (strcmp (value, "off") == 0) {
  145. /* nothing to do here */
  146. } else {
  147. error_reason = "unknown value for fileline";
  148. free(value);
  149. goto parse_error;
  150. }
  151. free(value);
  152. }
  153. if (err) {
  154. error_reason = "not enough memory to set logging format buffer";
  155. goto parse_error;
  156. }
  157. if (map_get_string("logging.function_name", &value) == CS_OK) {
  158. if (strcmp (value, "on") == 0) {
  159. if (!insert_into_buffer(new_format_buffer,
  160. sizeof(new_format_buffer),
  161. "%n:", "f:")) {
  162. err = logsys_format_set(new_format_buffer);
  163. } else
  164. if (!insert_into_buffer(new_format_buffer,
  165. sizeof(new_format_buffer),
  166. " %n", "g]")) {
  167. err = logsys_format_set(new_format_buffer);
  168. }
  169. } else
  170. if (strcmp (value, "off") == 0) {
  171. /* nothing to do here */
  172. } else {
  173. error_reason = "unknown value for function_name";
  174. free(value);
  175. goto parse_error;
  176. }
  177. free(value);
  178. }
  179. if (err) {
  180. error_reason = "not enough memory to set logging format buffer";
  181. goto parse_error;
  182. }
  183. memset(timestamp_str_to_add, 0, sizeof(timestamp_str_to_add));
  184. if (map_get_string("logging.timestamp", &value) == CS_OK) {
  185. if (strcmp (value, "on") == 0) {
  186. strcpy(timestamp_str_to_add, "%t");
  187. #ifdef QB_FEATURE_LOG_HIRES_TIMESTAMPS
  188. } else if (strcmp (value, "hires") == 0) {
  189. strcpy(timestamp_str_to_add, "%T");
  190. #endif
  191. } else if (strcmp (value, "off") == 0) {
  192. /* nothing to do here */
  193. } else {
  194. error_reason = "unknown value for timestamp";
  195. free(value);
  196. goto parse_error;
  197. }
  198. free(value);
  199. } else {
  200. /*
  201. * Display hires timestamp by default, otherwise standard timestamp
  202. */
  203. #ifdef QB_FEATURE_LOG_HIRES_TIMESTAMPS
  204. strcpy(timestamp_str_to_add, "%T");
  205. #else
  206. strcpy(timestamp_str_to_add, "%t");
  207. #endif
  208. }
  209. if(strcmp(timestamp_str_to_add, "") != 0) {
  210. strcat(timestamp_str_to_add, " ");
  211. if (insert_into_buffer(new_format_buffer, sizeof(new_format_buffer),
  212. timestamp_str_to_add, NULL) == 0) {
  213. err = logsys_format_set(new_format_buffer);
  214. }
  215. }
  216. if (err) {
  217. error_reason = "not enough memory to set logging format buffer";
  218. goto parse_error;
  219. }
  220. return (0);
  221. parse_error:
  222. *error_string = error_reason;
  223. return (-1);
  224. }
  225. /*
  226. * blackbox is another global specific option that
  227. * doesn't apply at system/subsystem level.
  228. */
  229. static int corosync_main_config_blackbox_set (
  230. const char **error_string)
  231. {
  232. const char *error_reason;
  233. char *value = NULL;
  234. if (map_get_string("logging.blackbox", &value) == CS_OK) {
  235. if (strcmp (value, "on") == 0) {
  236. (void)logsys_blackbox_set(QB_TRUE);
  237. } else if (strcmp (value, "off") == 0) {
  238. (void)logsys_blackbox_set(QB_FALSE);
  239. } else {
  240. error_reason = "unknown value for blackbox";
  241. free(value);
  242. goto parse_error;
  243. }
  244. free(value);
  245. } else {
  246. (void)logsys_blackbox_set(QB_TRUE);
  247. }
  248. return (0);
  249. parse_error:
  250. *error_string = error_reason;
  251. return (-1);
  252. }
  253. static int corosync_main_config_log_destination_set (
  254. const char *path,
  255. const char *key,
  256. const char *subsys,
  257. const char **error_string,
  258. unsigned int mode_mask,
  259. char deprecated,
  260. char default_value,
  261. const char *replacement)
  262. {
  263. static char formatted_error_reason[128];
  264. char *value = NULL;
  265. unsigned int mode;
  266. char key_name[MAP_KEYNAME_MAXLEN];
  267. snprintf(key_name, MAP_KEYNAME_MAXLEN, "%s.%s", path, key);
  268. if (map_get_string(key_name, &value) == CS_OK) {
  269. if (deprecated) {
  270. log_printf(LOGSYS_LEVEL_WARNING,
  271. "Warning: the %s config parameter has been obsoleted."
  272. " See corosync.conf man page %s directive.",
  273. key, replacement);
  274. }
  275. mode = logsys_config_mode_get (subsys);
  276. if (strcmp (value, "yes") == 0 || strcmp (value, "on") == 0) {
  277. mode |= mode_mask;
  278. if (logsys_config_mode_set(subsys, mode) < 0) {
  279. sprintf (formatted_error_reason, "unable to set mode %s", key);
  280. goto parse_error;
  281. }
  282. } else
  283. if (strcmp (value, "no") == 0 || strcmp (value, "off") == 0) {
  284. mode &= ~mode_mask;
  285. if (logsys_config_mode_set(subsys, mode) < 0) {
  286. sprintf (formatted_error_reason, "unable to unset mode %s", key);
  287. goto parse_error;
  288. }
  289. } else {
  290. sprintf (formatted_error_reason, "unknown value for %s", key);
  291. goto parse_error;
  292. }
  293. }
  294. /* Set to default if we are the top-level logger */
  295. else if (!subsys && !deprecated) {
  296. mode = logsys_config_mode_get (subsys);
  297. if (default_value) {
  298. mode |= mode_mask;
  299. }
  300. else {
  301. mode &= ~mode_mask;
  302. }
  303. if (logsys_config_mode_set(subsys, mode) < 0) {
  304. sprintf (formatted_error_reason, "unable to change mode %s", key);
  305. goto parse_error;
  306. }
  307. }
  308. free(value);
  309. return (0);
  310. parse_error:
  311. *error_string = formatted_error_reason;
  312. free(value);
  313. return (-1);
  314. }
  315. static int corosync_main_config_set (
  316. const char *path,
  317. const char *subsys,
  318. const char **error_string)
  319. {
  320. const char *error_reason = error_string_response;
  321. char *value = NULL;
  322. int mode;
  323. char key_name[MAP_KEYNAME_MAXLEN];
  324. /*
  325. * this bit abuses the internal logsys exported API
  326. * to guarantee that all configured subsystems are
  327. * initialized too.
  328. *
  329. * using this approach avoids some headaches caused
  330. * by IPC and TOTEM that have a special logging
  331. * handling requirements
  332. */
  333. if (subsys != NULL) {
  334. if (_logsys_subsys_create(subsys, NULL) < 0) {
  335. error_reason = "unable to create new logging subsystem";
  336. goto parse_error;
  337. }
  338. }
  339. mode = logsys_config_mode_get(subsys);
  340. if (mode < 0) {
  341. error_reason = "unable to get mode";
  342. goto parse_error;
  343. }
  344. if (corosync_main_config_log_destination_set (path, "to_stderr", subsys, &error_reason,
  345. LOGSYS_MODE_OUTPUT_STDERR, 0, 1, NULL) != 0)
  346. goto parse_error;
  347. if (corosync_main_config_log_destination_set (path, "to_syslog", subsys, &error_reason,
  348. LOGSYS_MODE_OUTPUT_SYSLOG, 0, 1, NULL) != 0)
  349. goto parse_error;
  350. snprintf(key_name, MAP_KEYNAME_MAXLEN, "%s.%s", path, "syslog_facility");
  351. if (map_get_string(key_name, &value) == CS_OK) {
  352. int syslog_facility;
  353. syslog_facility = qb_log_facility2int(value);
  354. if (syslog_facility < 0) {
  355. error_reason = "unknown syslog facility specified";
  356. goto parse_error;
  357. }
  358. if (logsys_config_syslog_facility_set(subsys,
  359. syslog_facility) < 0) {
  360. error_reason = "unable to set syslog facility";
  361. goto parse_error;
  362. }
  363. free(value);
  364. }
  365. else {
  366. /* Set default here in case of a reload */
  367. if (logsys_config_syslog_facility_set(subsys,
  368. qb_log_facility2int("daemon")) < 0) {
  369. error_reason = "unable to set syslog facility";
  370. goto parse_error;
  371. }
  372. }
  373. snprintf(key_name, MAP_KEYNAME_MAXLEN, "%s.%s", path, "syslog_level");
  374. if (map_get_string(key_name, &value) == CS_OK) {
  375. int syslog_priority;
  376. log_printf(LOGSYS_LEVEL_WARNING,
  377. "Warning: the syslog_level config parameter has been obsoleted."
  378. " See corosync.conf man page syslog_priority directive.");
  379. syslog_priority = logsys_priority_id_get(value);
  380. free(value);
  381. if (syslog_priority < 0) {
  382. error_reason = "unknown syslog level specified";
  383. goto parse_error;
  384. }
  385. if (logsys_config_syslog_priority_set(subsys,
  386. syslog_priority) < 0) {
  387. error_reason = "unable to set syslog level";
  388. goto parse_error;
  389. }
  390. }
  391. snprintf(key_name, MAP_KEYNAME_MAXLEN, "%s.%s", path, "syslog_priority");
  392. if (map_get_string(key_name, &value) == CS_OK) {
  393. int syslog_priority;
  394. syslog_priority = logsys_priority_id_get(value);
  395. free(value);
  396. if (syslog_priority < 0) {
  397. error_reason = "unknown syslog priority specified";
  398. goto parse_error;
  399. }
  400. if (logsys_config_syslog_priority_set(subsys,
  401. syslog_priority) < 0) {
  402. error_reason = "unable to set syslog priority";
  403. goto parse_error;
  404. }
  405. }
  406. else if(strcmp(key_name, "logging.syslog_priority") == 0){
  407. if (logsys_config_syslog_priority_set(subsys,
  408. logsys_priority_id_get("info")) < 0) {
  409. error_reason = "unable to set syslog level";
  410. goto parse_error;
  411. }
  412. }
  413. #ifdef LOGCONFIG_USE_ICMAP
  414. snprintf(key_name, MAP_KEYNAME_MAXLEN, "%s.%s", path, "logfile");
  415. if (map_get_string(key_name, &value) == CS_OK) {
  416. if (logsys_config_file_set (subsys, &error_reason, value) < 0) {
  417. goto parse_error;
  418. }
  419. free(value);
  420. }
  421. #else
  422. if (!subsys) {
  423. if (logsys_config_file_set (subsys, &error_reason, main_logfile) < 0) {
  424. goto parse_error;
  425. }
  426. }
  427. #endif
  428. if (corosync_main_config_log_destination_set (path, "to_file", subsys, &error_reason,
  429. LOGSYS_MODE_OUTPUT_FILE, 1, 0, "to_logfile") != 0)
  430. goto parse_error;
  431. if (corosync_main_config_log_destination_set (path, "to_logfile", subsys, &error_reason,
  432. LOGSYS_MODE_OUTPUT_FILE, 0, 0, NULL) != 0)
  433. goto parse_error;
  434. snprintf(key_name, MAP_KEYNAME_MAXLEN, "%s.%s", path, "logfile_priority");
  435. if (map_get_string(key_name, &value) == CS_OK) {
  436. int logfile_priority;
  437. logfile_priority = logsys_priority_id_get(value);
  438. free(value);
  439. if (logfile_priority < 0) {
  440. error_reason = "unknown logfile priority specified";
  441. goto parse_error;
  442. }
  443. if (logsys_config_logfile_priority_set(subsys,
  444. logfile_priority) < 0) {
  445. error_reason = "unable to set logfile priority";
  446. goto parse_error;
  447. }
  448. }
  449. else if(strcmp(key_name,"logging.logfile_priority") == 0){
  450. if (logsys_config_logfile_priority_set(subsys,
  451. logsys_priority_id_get("info")) < 0) {
  452. error_reason = "unable to set syslog level";
  453. goto parse_error;
  454. }
  455. }
  456. snprintf(key_name, MAP_KEYNAME_MAXLEN, "%s.%s", path, "debug");
  457. if (map_get_string(key_name, &value) == CS_OK) {
  458. if (strcmp (value, "trace") == 0) {
  459. if (logsys_config_debug_set (subsys, LOGSYS_DEBUG_TRACE) < 0) {
  460. error_reason = "unable to set debug trace";
  461. free(value);
  462. goto parse_error;
  463. }
  464. } else
  465. if (strcmp (value, "on") == 0) {
  466. if (logsys_config_debug_set (subsys, LOGSYS_DEBUG_ON) < 0) {
  467. error_reason = "unable to set debug on";
  468. free(value);
  469. goto parse_error;
  470. }
  471. } else
  472. if (strcmp (value, "off") == 0) {
  473. if (logsys_config_debug_set (subsys, LOGSYS_DEBUG_OFF) < 0) {
  474. error_reason = "unable to set debug off";
  475. free(value);
  476. goto parse_error;
  477. }
  478. } else {
  479. error_reason = "unknown value for debug";
  480. free(value);
  481. goto parse_error;
  482. }
  483. free(value);
  484. }
  485. else {
  486. if (logsys_config_debug_set (subsys, LOGSYS_DEBUG_OFF) < 0) {
  487. error_reason = "unable to set debug off";
  488. goto parse_error;
  489. }
  490. }
  491. return (0);
  492. parse_error:
  493. *error_string = error_reason;
  494. return (-1);
  495. }
  496. static int corosync_main_config_read_logging (
  497. const char **error_string)
  498. {
  499. const char *error_reason;
  500. #ifdef LOGCONFIG_USE_ICMAP
  501. icmap_iter_t iter;
  502. const char *key_name;
  503. #else
  504. cmap_iter_handle_t iter;
  505. char key_name[CMAP_KEYNAME_MAXLEN];
  506. #endif
  507. char key_subsys[MAP_KEYNAME_MAXLEN];
  508. char key_item[MAP_KEYNAME_MAXLEN];
  509. int res;
  510. /* format set is supported only for toplevel */
  511. if (corosync_main_config_format_set(&error_reason) < 0) {
  512. goto parse_error;
  513. }
  514. if (corosync_main_config_blackbox_set(&error_reason) < 0) {
  515. goto parse_error;
  516. }
  517. if (corosync_main_config_set ("logging", NULL, &error_reason) < 0) {
  518. goto parse_error;
  519. }
  520. /*
  521. * we will need 2 of these to compensate for new logging
  522. * config format
  523. */
  524. #ifdef LOGCONFIG_USE_ICMAP
  525. iter = icmap_iter_init("logging.logger_subsys.");
  526. while ((key_name = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  527. #else
  528. cmap_iter_init(cmap_handle, "logging.logger_subsys.", &iter);
  529. while ((cmap_iter_next(cmap_handle, iter, key_name, NULL, NULL)) == CS_OK) {
  530. #endif
  531. res = sscanf(key_name, "logging.logger_subsys.%[^.].%s", key_subsys, key_item);
  532. if (res != 2) {
  533. continue ;
  534. }
  535. if (strcmp(key_item, "subsys") != 0) {
  536. continue ;
  537. }
  538. if (snprintf(key_item, MAP_KEYNAME_MAXLEN, "logging.logger_subsys.%s",
  539. key_subsys) >= MAP_KEYNAME_MAXLEN) {
  540. /*
  541. * This should never happen
  542. */
  543. error_reason = "Can't snprintf logger_subsys key_item";
  544. goto parse_error;
  545. }
  546. if (corosync_main_config_set(key_item, key_subsys, &error_reason) < 0) {
  547. goto parse_error;
  548. }
  549. }
  550. #ifdef LOGCONFIG_USE_ICMAP
  551. icmap_iter_finalize(iter);
  552. #else
  553. cmap_iter_finalize(cmap_handle, iter);
  554. #endif
  555. logsys_config_apply();
  556. /* Reconfigure knet logging */
  557. totemknet_configure_log_level();
  558. return 0;
  559. parse_error:
  560. *error_string = error_reason;
  561. return (-1);
  562. }
  563. #ifdef LOGCONFIG_USE_ICMAP
  564. static void main_logging_notify(
  565. int32_t event,
  566. const char *key_name,
  567. struct icmap_notify_value new_val,
  568. struct icmap_notify_value old_val,
  569. void *user_data)
  570. #else
  571. static void main_logging_notify(
  572. cmap_handle_t cmap_handle_unused,
  573. cmap_handle_t cmap_track_handle_unused,
  574. int32_t event,
  575. const char *key_name,
  576. struct cmap_notify_value new_val,
  577. struct cmap_notify_value old_val,
  578. void *user_data)
  579. #endif
  580. {
  581. const char *error_string;
  582. static int reload_in_progress = 0;
  583. /* If a full reload happens then suspend updates for individual keys until
  584. * it's all completed
  585. */
  586. if (strcmp(key_name, "config.reload_in_progress") == 0) {
  587. if (*(uint8_t *)new_val.data == 1) {
  588. reload_in_progress = 1;
  589. } else {
  590. reload_in_progress = 0;
  591. }
  592. }
  593. if (reload_in_progress) {
  594. log_printf(LOGSYS_LEVEL_DEBUG, "Ignoring key change, reload in progress. %s\n", key_name);
  595. return;
  596. }
  597. /*
  598. * Reload the logsys configuration
  599. */
  600. if (logsys_format_set(NULL) == -1) {
  601. fprintf (stderr, "Unable to setup logging format.\n");
  602. }
  603. corosync_main_config_read_logging(&error_string);
  604. }
  605. #ifdef LOGCONFIG_USE_ICMAP
  606. static void add_logsys_config_notification(void)
  607. {
  608. icmap_track_t icmap_track = NULL;
  609. icmap_track_add("logging.",
  610. ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX,
  611. main_logging_notify,
  612. NULL,
  613. &icmap_track);
  614. icmap_track_add("config.reload_in_progress",
  615. ICMAP_TRACK_ADD | ICMAP_TRACK_MODIFY,
  616. main_logging_notify,
  617. NULL,
  618. &icmap_track);
  619. }
  620. #else
  621. static void add_logsys_config_notification(void)
  622. {
  623. cmap_track_handle_t cmap_track;
  624. cmap_track_add(cmap_handle, "logging.",
  625. CMAP_TRACK_ADD | CMAP_TRACK_DELETE | CMAP_TRACK_MODIFY | CMAP_TRACK_PREFIX,
  626. main_logging_notify,
  627. NULL,
  628. &cmap_track);
  629. cmap_track_add(cmap_handle, "config.reload_in_progress",
  630. CMAP_TRACK_ADD | CMAP_TRACK_MODIFY,
  631. main_logging_notify,
  632. NULL,
  633. &cmap_track);
  634. }
  635. #endif
  636. int corosync_log_config_read (
  637. #ifndef LOGCONFIG_USE_ICMAP
  638. cmap_handle_t cmap_h,
  639. const char *default_logfile,
  640. #endif
  641. const char **error_string)
  642. {
  643. const char *error_reason = error_string_response;
  644. #ifndef LOGCONFIG_USE_ICMAP
  645. if (!cmap_h) {
  646. error_reason = "No cmap handle";
  647. return (-1);
  648. }
  649. if (!default_logfile) {
  650. error_reason = "No default logfile";
  651. return (-1);
  652. }
  653. cmap_handle = cmap_h;
  654. main_logfile = default_logfile;
  655. #endif
  656. if (corosync_main_config_read_logging(error_string) < 0) {
  657. error_reason = *error_string;
  658. goto parse_error;
  659. }
  660. add_logsys_config_notification();
  661. return 0;
  662. parse_error:
  663. snprintf (error_string_response, sizeof(error_string_response),
  664. "parse error in config: %s.\n",
  665. error_reason);
  666. *error_string = error_string_response;
  667. return (-1);
  668. }