41 #ifdef LOGCONFIG_USE_ICMAP
43 #define MAP_KEYNAME_MAXLEN ICMAP_KEYNAME_MAXLEN
44 #define map_get_string(key_name, value) icmap_get_string(key_name, value)
48 static const char *main_logfile;
49 #define MAP_KEYNAME_MAXLEN CMAP_KEYNAME_MAXLEN
50 #define map_get_string(key_name, value) cmap_get_string(cmap_handle, key_name, value)
56 static char error_string_response[512];
79 static int insert_into_buffer(
85 const char *current_format = NULL;
90 if (strstr(current_format, entry) != NULL) {
97 if (snprintf(target_buffer, bufferlen - 1,
"%s%s",
99 current_format) >= bufferlen - 1) {
103 const char *afterpos;
109 afterpos = strstr(current_format, after);
110 afterlen = strlen(after);
111 if ((!afterpos) || (!afterlen)) {
115 templen = afterpos - current_format + afterlen;
116 if (snprintf(target_buffer, templen + 1,
"%s", current_format)
120 if (snprintf(target_buffer + templen, bufferlen - ( templen + 1 ),
121 "%s%s", entry, current_format + templen)
122 >= bufferlen - ( templen + 1 )) {
133 static int corosync_main_config_format_set (
134 const char **error_string)
136 const char *error_reason;
137 char new_format_buffer[PATH_MAX];
142 if (strcmp (value,
"on") == 0) {
143 if (!insert_into_buffer(new_format_buffer,
144 sizeof(new_format_buffer),
148 if (!insert_into_buffer(new_format_buffer,
149 sizeof(new_format_buffer),
154 if (strcmp (value,
"off") == 0) {
157 error_reason =
"unknown value for fileline";
166 error_reason =
"not enough memory to set logging format buffer";
171 if (strcmp (value,
"on") == 0) {
172 if (!insert_into_buffer(new_format_buffer,
173 sizeof(new_format_buffer),
177 if (!insert_into_buffer(new_format_buffer,
178 sizeof(new_format_buffer),
183 if (strcmp (value,
"off") == 0) {
186 error_reason =
"unknown value for function_name";
195 error_reason =
"not enough memory to set logging format buffer";
200 if (strcmp (value,
"on") == 0) {
201 if(!insert_into_buffer(new_format_buffer,
202 sizeof(new_format_buffer),
207 if (strcmp (value,
"off") == 0) {
210 error_reason =
"unknown value for timestamp";
219 error_reason =
"not enough memory to set logging format buffer";
226 *error_string = error_reason;
235 static int corosync_main_config_blackbox_set (
236 const char **error_string)
238 const char *error_reason;
242 if (strcmp (value,
"on") == 0) {
244 }
else if (strcmp (value,
"off") == 0) {
247 error_reason =
"unknown value for blackbox";
260 *error_string = error_reason;
265 static int corosync_main_config_log_destination_set (
269 const char **error_string,
270 unsigned int mode_mask,
273 const char *replacement)
275 static char formatted_error_reason[128];
284 "Warning: the %s config parameter has been obsoleted."
285 " See corosync.conf man page %s directive.",
291 if (strcmp (value,
"yes") == 0 || strcmp (value,
"on") == 0) {
294 sprintf (formatted_error_reason,
"unable to set mode %s", key);
298 if (strcmp (value,
"no") == 0 || strcmp (value,
"off") == 0) {
301 sprintf (formatted_error_reason,
"unable to unset mode %s", key);
305 sprintf (formatted_error_reason,
"unknown value for %s", key);
310 else if (!subsys && !deprecated) {
320 sprintf (formatted_error_reason,
"unable to change mode %s", key);
329 *error_string = formatted_error_reason;
334 static int corosync_main_config_set (
337 const char **error_string)
339 const char *error_reason = error_string_response;
353 if (subsys != NULL) {
355 error_reason =
"unable to create new logging subsystem";
362 error_reason =
"unable to get mode";
366 if (corosync_main_config_log_destination_set (path,
"to_stderr", subsys, &error_reason,
370 if (corosync_main_config_log_destination_set (path,
"to_syslog", subsys, &error_reason,
378 syslog_facility = qb_log_facility2int(value);
379 if (syslog_facility < 0) {
380 error_reason =
"unknown syslog facility specified";
384 syslog_facility) < 0) {
385 error_reason =
"unable to set syslog facility";
394 qb_log_facility2int(
"daemon")) < 0) {
395 error_reason =
"unable to set syslog facility";
405 "Warning: the syslog_level config parameter has been obsoleted."
406 " See corosync.conf man page syslog_priority directive.");
411 if (syslog_priority < 0) {
412 error_reason =
"unknown syslog level specified";
416 syslog_priority) < 0) {
417 error_reason =
"unable to set syslog level";
428 if (syslog_priority < 0) {
429 error_reason =
"unknown syslog priority specified";
433 syslog_priority) < 0) {
434 error_reason =
"unable to set syslog priority";
438 else if(strcmp(key_name,
"logging.syslog_priority") == 0){
441 error_reason =
"unable to set syslog level";
446 #ifdef LOGCONFIG_USE_ICMAP
462 if (corosync_main_config_log_destination_set (path,
"to_file", subsys, &error_reason,
466 if (corosync_main_config_log_destination_set (path,
"to_logfile", subsys, &error_reason,
472 int logfile_priority;
476 if (logfile_priority < 0) {
477 error_reason =
"unknown logfile priority specified";
481 logfile_priority) < 0) {
482 error_reason =
"unable to set logfile priority";
486 else if(strcmp(key_name,
"logging.logfile_priority") == 0){
489 error_reason =
"unable to set syslog level";
496 if (strcmp (value,
"trace") == 0) {
498 error_reason =
"unable to set debug trace";
503 if (strcmp (value,
"on") == 0) {
505 error_reason =
"unable to set debug on";
510 if (strcmp (value,
"off") == 0) {
512 error_reason =
"unable to set debug off";
517 error_reason =
"unknown value for debug";
525 error_reason =
"unable to set debug off";
534 *error_string = error_reason;
539 static int corosync_main_config_read_logging (
540 const char **error_string)
542 const char *error_reason;
543 #ifdef LOGCONFIG_USE_ICMAP
545 const char *key_name;
555 if (corosync_main_config_format_set(&error_reason) < 0) {
559 if (corosync_main_config_blackbox_set(&error_reason) < 0) {
563 if (corosync_main_config_set (
"logging", NULL, &error_reason) < 0) {
571 #ifdef LOGCONFIG_USE_ICMAP
578 res = sscanf(key_name,
"logging.logger_subsys.%[^.].%s", key_subsys, key_item);
584 if (strcmp(key_item,
"subsys") != 0) {
590 if (corosync_main_config_set(key_item, key_subsys, &error_reason) < 0) {
594 #ifdef LOGCONFIG_USE_ICMAP
604 *error_string = error_reason;
609 #ifdef LOGCONFIG_USE_ICMAP
610 static void main_logging_notify(
612 const char *key_name,
617 static void main_logging_notify(
621 const char *key_name,
627 const char *error_string;
628 static int reload_in_progress = 0;
633 if (strcmp(key_name,
"config.reload_in_progress") == 0) {
634 if (*(uint8_t *)new_val.
data == 1) {
635 reload_in_progress = 1;
637 reload_in_progress = 0;
640 if (reload_in_progress) {
649 fprintf (stderr,
"Unable to setup logging format.\n");
651 corosync_main_config_read_logging(&error_string);
654 #ifdef LOGCONFIG_USE_ICMAP
655 static void add_logsys_config_notification(
void)
672 static void add_logsys_config_notification(
void)
691 #ifndef LOGCONFIG_USE_ICMAP
693 const char *default_logfile,
695 const char **error_string)
697 const char *error_reason = error_string_response;
699 #ifndef LOGCONFIG_USE_ICMAP
701 error_reason =
"No cmap handle";
704 if (!default_logfile) {
705 error_reason =
"No default logfile";
709 main_logfile = default_logfile;
712 if (corosync_main_config_read_logging(error_string) < 0) {
713 error_reason = *error_string;
717 add_logsys_config_notification();
722 snprintf (error_string_response,
sizeof(error_string_response),
723 "parse error in config: %s.\n",
726 *error_string = error_string_response;