95
static struct logsys_config_struct {
97
unsigned int priority;
101
int corosync_main_config_read (
102
struct objdb_iface_ver0 *objdb,
104
struct main_config *main_config)
106
unsigned int object_service_handle;
107
unsigned int object_logger_subsys_handle;
109
char *error_reason = error_string_response;
110
unsigned int object_find_handle;
111
unsigned int object_find_logsys_handle;
112
int global_debug = 0;
115
memset (main_config, 0, sizeof (struct main_config));
107
* @target_buffer: a buffer where to write results
108
* @bufferlen: tell us the size of the buffer to avoid overflows
109
* @entry: entry that needs to be added to the buffer
110
* @after: can either be NULL or set to a string.
111
* if NULL, @entry is prependend to logsys_format_get buffer.
112
* if set, @entry is added immediately after @after.
114
* Since the function is specific to logsys_format_get handling, it is implicit
115
* that source is logsys_format_get();
117
* In case of failure, target_buffer could be left dirty. So don't trust
118
* any data leftover in it.
120
* Searching for "after" assumes that there is only entry of "after"
121
* in the source. Afterall we control the string here and for logging format
122
* it makes little to no sense to have duplicate format entries.
124
* Returns: 0 on success, -1 on failure
126
static int insert_into_buffer(
132
const char *current_format = NULL;
134
current_format = logsys_format_get();
136
/* if the entry is already in the format we don't add it again */
137
if (strstr(current_format, entry) != NULL) {
141
/* if there is no "after", simply prepend the requested entry
142
* otherwise go for beautiful string manipulation.... </sarcasm> */
144
if (snprintf(target_buffer, bufferlen - 1, "%s%s",
146
current_format) >= bufferlen - 1) {
150
const char *afterpos;
154
/* check if after is contained in the format
155
* and afterlen has a meaning or return an error */
156
afterpos = strstr(current_format, after);
157
afterlen = strlen(after);
158
if ((!afterpos) || (!afterlen)) {
162
templen = afterpos - current_format + afterlen;
163
if (snprintf(target_buffer, templen + 1, "%s", current_format)
167
if (snprintf(target_buffer + templen, bufferlen - ( templen + 1 ),
168
"%s%s", entry, current_format + templen)
169
>= bufferlen - ( templen + 1 )) {
177
* format set is the only global specific option that
178
* doesn't apply at system/subsystem level.
180
static int corosync_main_config_format_set (
181
struct objdb_iface_ver0 *objdb,
182
hdb_handle_t object_handle,
183
const char **error_string)
185
const char *error_reason;
186
char new_format_buffer[PATH_MAX];
190
if (!objdb_get_string (objdb,object_handle, "fileline", &value)) {
191
if (strcmp (value, "on") == 0) {
192
if (!insert_into_buffer(new_format_buffer,
193
sizeof(new_format_buffer),
195
err = logsys_format_set(new_format_buffer);
197
if (!insert_into_buffer(new_format_buffer,
198
sizeof(new_format_buffer),
200
err = logsys_format_set(new_format_buffer);
203
if (strcmp (value, "off") == 0) {
204
/* nothing to do here */
206
error_reason = "unknown value for fileline";
210
if (!objdb_get_string (objdb,object_handle, "function_name", &value)) {
211
if (strcmp (value, "on") == 0) {
212
if (!insert_into_buffer(new_format_buffer,
213
sizeof(new_format_buffer),
215
err = logsys_format_set(new_format_buffer);
217
if (!insert_into_buffer(new_format_buffer,
218
sizeof(new_format_buffer),
220
err = logsys_format_set(new_format_buffer);
223
if (strcmp (value, "off") == 0) {
224
/* nothing to do here */
226
error_reason = "unknown value for function_name";
230
if (!objdb_get_string (objdb,object_handle, "timestamp", &value)) {
231
if (strcmp (value, "on") == 0) {
232
if(!insert_into_buffer(new_format_buffer,
233
sizeof(new_format_buffer),
235
err = logsys_format_set(new_format_buffer);
238
if (strcmp (value, "off") == 0) {
239
/* nothing to do here */
241
error_reason = "unknown value for timestamp";
246
error_reason = "exhausted virtual memory";
253
*error_string = error_reason;
258
static int corosync_main_config_set (
259
struct objdb_iface_ver0 *objdb,
260
hdb_handle_t object_handle,
262
const char **error_string)
264
const char *error_reason = error_string_response;
269
* this bit abuses the internal logsys exported API
270
* to guarantee that all configured subsystems are
273
* using this approach avoids some headaches caused
274
* by IPC and TOTEM that have a special logging
275
* handling requirements
277
if (subsys != NULL) {
278
if (_logsys_subsys_create(subsys) < 0) {
279
error_reason = "unable to create new logging subsystem";
284
mode = logsys_config_mode_get(subsys);
286
error_reason = "unable to get mode";
290
if (!objdb_get_string (objdb,object_handle, "to_file", &value)) {
292
log_printf(LOGSYS_LEVEL_WARNING,
293
"Warning: the to_file config paramater has been obsoleted."
294
" See corosync.conf man page to_logfile directive.");
296
if (strcmp (value, "yes") == 0) {
297
mode |= LOGSYS_MODE_OUTPUT_FILE;
298
if (logsys_config_mode_set(subsys, mode) < 0) {
299
error_reason = "unable to set mode to_file";
303
if (strcmp (value, "no") == 0) {
304
mode &= ~LOGSYS_MODE_OUTPUT_FILE;
305
if (logsys_config_mode_set(subsys, mode) < 0) {
306
error_reason = "unable to unset mode to_file";
310
error_reason = "unknown value for to_file";
315
if (!objdb_get_string (objdb,object_handle, "to_logfile", &value)) {
316
if (strcmp (value, "yes") == 0) {
317
mode |= LOGSYS_MODE_OUTPUT_FILE;
318
if (logsys_config_mode_set(subsys, mode) < 0) {
319
error_reason = "unable to set mode to_logfile";
323
if (strcmp (value, "no") == 0) {
324
mode &= ~LOGSYS_MODE_OUTPUT_FILE;
325
if (logsys_config_mode_set(subsys, mode) < 0) {
326
error_reason = "unable to unset mode to_logfile";
330
error_reason = "unknown value for to_logfile";
335
if (!objdb_get_string (objdb,object_handle, "to_syslog", &value)) {
336
if (strcmp (value, "yes") == 0) {
337
mode |= LOGSYS_MODE_OUTPUT_SYSLOG;
338
if (logsys_config_mode_set(subsys, mode) < 0) {
339
error_reason = "unable to set mode to_syslog";
343
if (strcmp (value, "no") == 0) {
344
mode &= ~LOGSYS_MODE_OUTPUT_SYSLOG;
345
if (logsys_config_mode_set(subsys, mode) < 0) {
346
error_reason = "unable to unset mode to_syslog";
350
error_reason = "unknown value for to_syslog";
355
if (!objdb_get_string (objdb,object_handle, "to_stderr", &value)) {
356
if (strcmp (value, "yes") == 0) {
357
mode |= LOGSYS_MODE_OUTPUT_STDERR;
358
if (logsys_config_mode_set(subsys, mode) < 0) {
359
error_reason = "unable to set mode to_stderr";
363
if (strcmp (value, "no") == 0) {
364
mode &= ~LOGSYS_MODE_OUTPUT_STDERR;
365
if (logsys_config_mode_set(subsys, mode) < 0) {
366
error_reason = "unable to unset mode to_stderr";
370
error_reason = "unknown value for to_syslog";
375
if (!objdb_get_string (objdb,object_handle, "syslog_facility", &value)) {
378
syslog_facility = logsys_facility_id_get(value);
379
if (syslog_facility < 0) {
380
error_reason = "unknown syslog facility specified";
383
if (logsys_config_syslog_facility_set(subsys,
384
syslog_facility) < 0) {
385
error_reason = "unable to set syslog facility";
390
if (!objdb_get_string (objdb,object_handle, "syslog_level", &value)) {
393
log_printf(LOGSYS_LEVEL_WARNING,
394
"Warning: the syslog_level config paramater has been obsoleted."
395
" See corosync.conf man page syslog_priority directive.");
397
syslog_priority = logsys_priority_id_get(value);
398
if (syslog_priority < 0) {
399
error_reason = "unknown syslog level specified";
402
if (logsys_config_syslog_priority_set(subsys,
403
syslog_priority) < 0) {
404
error_reason = "unable to set syslog level";
409
if (!objdb_get_string (objdb,object_handle, "syslog_priority", &value)) {
412
syslog_priority = logsys_priority_id_get(value);
413
if (syslog_priority < 0) {
414
error_reason = "unknown syslog priority specified";
417
if (logsys_config_syslog_priority_set(subsys,
418
syslog_priority) < 0) {
419
error_reason = "unable to set syslog priority";
424
if (!objdb_get_string (objdb,object_handle, "logfile", &value)) {
425
if (logsys_config_file_set (subsys, error_string, value) < 0) {
430
if (!objdb_get_string (objdb,object_handle, "logfile_priority", &value)) {
431
int logfile_priority;
433
logfile_priority = logsys_priority_id_get(value);
434
if (logfile_priority < 0) {
435
error_reason = "unknown logfile priority specified";
438
if (logsys_config_logfile_priority_set(subsys,
439
logfile_priority) < 0) {
440
error_reason = "unable to set logfile priority";
445
if (!objdb_get_string (objdb, object_handle, "debug", &value)) {
446
if (strcmp (value, "on") == 0) {
447
if (logsys_config_debug_set (subsys, 1) < 0) {
448
error_reason = "unable to set debug on";
452
if (strcmp (value, "off") == 0) {
453
if (logsys_config_debug_set (subsys, 0) < 0) {
454
error_reason = "unable to set debug off";
458
error_reason = "unknown value for debug";
466
*error_string = error_reason;
471
static int corosync_main_config_read_logging (
472
struct objdb_iface_ver0 *objdb,
473
const char **error_string)
475
hdb_handle_t object_service_handle;
476
hdb_handle_t object_logger_subsys_handle;
477
hdb_handle_t object_find_handle;
478
hdb_handle_t object_find_logsys_handle;
479
const char *error_reason;
117
482
objdb->object_find_create (
118
483
OBJECT_PARENT_HANDLE,
120
485
strlen ("logging"),
121
486
&object_find_handle);
123
main_config->logmode = LOG_MODE_FLUSH_AFTER_CONFIG;
124
488
if (objdb->object_find_next (
125
489
object_find_handle,
126
490
&object_service_handle) == 0) {
128
if (!objdb_get_string (objdb,object_service_handle, "to_file", &value)) {
129
if (strcmp (value, "yes") == 0) {
130
main_config->logmode |= LOG_MODE_OUTPUT_FILE;
132
if (strcmp (value, "no") == 0) {
133
main_config->logmode &= ~LOG_MODE_OUTPUT_FILE;
136
if (!objdb_get_string (objdb,object_service_handle, "to_syslog", &value)) {
137
if (strcmp (value, "yes") == 0) {
138
main_config->logmode |= LOG_MODE_OUTPUT_SYSLOG_THREADED;
140
if (strcmp (value, "no") == 0) {
141
main_config->logmode &= ~LOG_MODE_OUTPUT_SYSLOG_THREADED;
144
if (!objdb_get_string (objdb,object_service_handle, "to_stderr", &value)) {
145
if (strcmp (value, "yes") == 0) {
146
main_config->logmode |= LOG_MODE_OUTPUT_STDERR;
148
if (strcmp (value, "no") == 0) {
149
main_config->logmode &= ~LOG_MODE_OUTPUT_STDERR;
153
if (!objdb_get_string (objdb,object_service_handle, "debug", &value)) {
154
if (strcmp (value, "on") == 0) {
157
if (strcmp (value, "off") == 0) {
163
if (!objdb_get_string (objdb,object_service_handle, "timestamp", &value)) {
164
if (strcmp (value, "on") == 0) {
165
main_config->logmode |= LOG_MODE_DISPLAY_TIMESTAMP;
167
if (strcmp (value, "off") == 0) {
168
main_config->logmode &= ~LOG_MODE_DISPLAY_TIMESTAMP;
173
if (!objdb_get_string (objdb,object_service_handle, "logfile", &value)) {
174
main_config->logfile = strdup (value);
177
if (!objdb_get_string (objdb,object_service_handle, "fileline", &value)) {
178
if (strcmp (value, "on") == 0) {
179
main_config->logmode |= LOG_MODE_DISPLAY_FILELINE;
181
if (strcmp (value, "off") == 0) {
182
main_config->logmode &= ~LOG_MODE_DISPLAY_FILELINE;
188
if (!objdb_get_string (objdb,object_service_handle, "syslog_facility", &value)) {
189
if (strcmp (value, "daemon") == 0) {
190
main_config->syslog_facility = LOG_DAEMON;
192
if (strcmp (value, "local0") == 0) {
193
main_config->syslog_facility = LOG_LOCAL0;
195
if (strcmp (value, "local1") == 0) {
196
main_config->syslog_facility = LOG_LOCAL1;
198
if (strcmp (value, "local2") == 0) {
199
main_config->syslog_facility = LOG_LOCAL2;
201
if (strcmp (value, "local3") == 0) {
202
main_config->syslog_facility = LOG_LOCAL3;
204
if (strcmp (value, "local4") == 0) {
205
main_config->syslog_facility = LOG_LOCAL4;
207
if (strcmp (value, "local5") == 0) {
208
main_config->syslog_facility = LOG_LOCAL5;
210
if (strcmp (value, "local6") == 0) {
211
main_config->syslog_facility = LOG_LOCAL6;
213
if (strcmp (value, "local7") == 0) {
214
main_config->syslog_facility = LOG_LOCAL7;
216
error_reason = "unknown syslog facility specified";
492
/* format set is supported only for toplevel */
493
if (corosync_main_config_format_set (objdb,
494
object_service_handle,
495
&error_reason) < 0) {
499
if (corosync_main_config_set (objdb,
500
object_service_handle,
502
&error_reason) < 0) {
506
/* we will need 2 of these to compensate for new logging
221
509
objdb->object_find_create (
222
510
object_service_handle,
232
520
object_logger_subsys_handle,
233
521
"subsys", &value)) {
235
strncpy (logsys_logger.subsys, value,
236
sizeof (logsys_logger.subsys));
523
if (corosync_main_config_set (objdb,
524
object_logger_subsys_handle,
526
&error_reason) < 0) {
239
531
error_reason = "subsys required for logger directive";
240
532
goto parse_error;
242
if (!objdb_get_string (objdb, object_logger_subsys_handle, "debug", &value)) {
243
if (strcmp (value, "on") == 0) {
244
logsys_logger.priority = LOG_LEVEL_DEBUG;
246
if (strcmp (value, "off") == 0) {
247
logsys_logger.priority &= ~LOG_LEVEL_DEBUG;
252
if (!objdb_get_string (objdb, object_logger_subsys_handle, "tags", &value)) {
253
char *token = strtok (value, "|");
255
while (token != NULL) {
256
if (strcmp (token, "enter") == 0) {
257
logsys_logger.tags |= LOGSYS_TAG_ENTER;
258
} else if (strcmp (token, "leave") == 0) {
259
logsys_logger.tags |= LOGSYS_TAG_LEAVE;
260
} else if (strcmp (token, "trace1") == 0) {
261
logsys_logger.tags |= LOGSYS_TAG_TRACE1;
262
} else if (strcmp (token, "trace2") == 0) {
263
logsys_logger.tags |= LOGSYS_TAG_TRACE2;
264
} else if (strcmp (token, "trace3") == 0) {
265
logsys_logger.tags |= LOGSYS_TAG_TRACE3;
266
} else if (strcmp (token, "trace4") == 0) {
267
logsys_logger.tags |= LOGSYS_TAG_TRACE4;
268
} else if (strcmp (token, "trace5") == 0) {
269
logsys_logger.tags |= LOGSYS_TAG_TRACE5;
270
} else if (strcmp (token, "trace6") == 0) {
271
logsys_logger.tags |= LOGSYS_TAG_TRACE6;
272
} else if (strcmp (token, "trace7") == 0) {
273
logsys_logger.tags |= LOGSYS_TAG_TRACE7;
274
} else if (strcmp (token, "trace8") == 0) {
275
logsys_logger.tags |= LOGSYS_TAG_TRACE8;
277
error_reason = "bad tags value";
535
objdb->object_find_destroy (object_find_logsys_handle);
537
objdb->object_find_create (
538
object_service_handle,
540
strlen ("logging_daemon"),
541
&object_find_logsys_handle);
543
while (objdb->object_find_next (
544
object_find_logsys_handle,
545
&object_logger_subsys_handle) == 0) {
547
if (!objdb_get_string (objdb,
548
object_logger_subsys_handle,
551
if ((strcmp(value, "corosync") == 0) &&
552
(!objdb_get_string (objdb,
553
object_logger_subsys_handle,
554
"subsys", &value))) {
556
if (corosync_main_config_set (objdb,
557
object_logger_subsys_handle,
559
&error_reason) < 0) {
278
560
goto parse_error;
281
token = strtok(NULL, "|");
285
* set individual logger configurations
287
logsys_config_subsys_set (
288
logsys_logger.subsys,
290
logsys_logger.priority);
564
error_reason = "subsys required for logging_daemon directive";
569
error_reason = "name required for logging_daemon directive";
293
573
objdb->object_find_destroy (object_find_logsys_handle);
296
575
objdb->object_find_destroy (object_find_handle);
580
*error_string = error_reason;
585
static int uid_determine (const char *req_user)
587
struct passwd *passwd;
590
passwd = getpwnam(req_user);
592
log_printf (LOGSYS_LEVEL_ERROR, "ERROR: The '%s' user is not found in /etc/passwd, please read the documentation.\n", req_user);
593
corosync_exit_error (AIS_DONE_UID_DETERMINE);
595
ais_uid = passwd->pw_uid;
600
static int gid_determine (const char *req_group)
605
group = getgrnam (req_group);
607
log_printf (LOGSYS_LEVEL_ERROR, "ERROR: The '%s' group is not found in /etc/group, please read the documentation.\n", req_group);
608
corosync_exit_error (AIS_DONE_GID_DETERMINE);
610
ais_gid = group->gr_gid;
615
static void main_objdb_reload_notify(objdb_reload_notify_type_t type, int flush,
618
const char *error_string;
620
if (type == OBJDB_RELOAD_NOTIFY_END) {
623
* Reload the logsys configuration
625
logsys_format_set(NULL);
626
corosync_main_config_read_logging(global_objdb,
631
static void add_logsys_config_notification(
632
struct objdb_iface_ver0 *objdb)
635
global_objdb = objdb;
637
objdb->object_track_start(OBJECT_PARENT_HANDLE,
642
main_objdb_reload_notify,
647
static int corosync_main_config_read_uidgid (
648
struct objdb_iface_ver0 *objdb,
649
const char **error_string)
651
hdb_handle_t object_find_handle;
652
hdb_handle_t object_service_handle;
655
struct uidgid_item *ugi;
298
657
objdb->object_find_create (
299
658
OBJECT_PARENT_HANDLE,
302
661
&object_find_handle);
304
if (objdb->object_find_next (
663
while (objdb->object_find_next (
305
664
object_find_handle,
306
665
&object_service_handle) == 0) {
308
if (!objdb_get_string (objdb,object_service_handle, "user", &value)) {
309
main_config->user = strdup(value);
311
if (!objdb_get_string (objdb,object_service_handle, "group", &value)) {
312
main_config->group = strdup(value);
669
if (!objdb_get_string (objdb,object_service_handle, "uid", &value)) {
670
uid = uid_determine(value);
673
if (!objdb_get_string (objdb,object_service_handle, "gid", &value)) {
674
gid = gid_determine(value);
677
if (uid > -1 || gid > -1) {
678
ugi = malloc (sizeof (*ugi));
680
_corosync_out_of_memory_error();
684
list_init (&ugi->list);
685
list_add (&ugi->list, &uidgid_list_head);
316
688
objdb->object_find_destroy (object_find_handle);
318
/* Default user/group */
319
if (!main_config->user)
320
main_config->user = "ais";
322
if (!main_config->group)
323
main_config->group = "ais";
325
if ((main_config->logmode & LOG_MODE_OUTPUT_FILE) &&
326
(main_config->logfile == NULL)) {
327
error_reason = "logmode set to 'file' but no logfile specified";
693
int corosync_main_config_read (
694
struct objdb_iface_ver0 *objdb,
695
const char **error_string)
697
const char *error_reason = error_string_response;
699
if (corosync_main_config_read_logging(objdb, error_string) < 0) {
700
error_reason = *error_string;
328
701
goto parse_error;
331
if (main_config->syslog_facility == 0)
332
main_config->syslog_facility = LOG_DAEMON;
704
corosync_main_config_read_uidgid (objdb, error_string);
706
add_logsys_config_notification(objdb);
337
sprintf (error_string_response,
711
snprintf (error_string_response, sizeof(error_string_response),
338
712
"parse error in config: %s.\n",
341
715
*error_string = error_string_response;
719
int corosync_main_config_compatibility_read (
720
struct objdb_iface_ver0 *objdb,
721
enum cs_sync_mode *minimum_sync_mode,
722
const char **error_string)
724
const char *error_reason = error_string_response;
727
*minimum_sync_mode = CS_SYNC_V1;
728
if (!objdb_get_string (objdb, OBJECT_PARENT_HANDLE, "compatibility", &value)) {
730
if (strcmp (value, "whitetank") == 0) {
731
*minimum_sync_mode = CS_SYNC_V1;
733
if (strcmp (value, "none") == 0) {
734
*minimum_sync_mode = CS_SYNC_V2;
737
snprintf (error_string_response, sizeof (error_string_response),
738
"Invalid compatibility option '%s' specified, must be none or whitetank.\n", value);
746
*error_string = error_reason;