[Openais] Make it possible to adjust the log priority and tags at runtime.
Steven Dake
sdake at redhat.com
Thu Oct 23 03:30:57 PDT 2008
Patch looks good except for one compatibility issue.
syslog_level is changed to priority (which seems reasonable). Wouldn't
it be possible to make the syslog_level still have the same effect as
priority in the config file? I would prefer this.
Please wait to rebase until I have the logsysv2 patch committed. Commit
will happen this week. After it is committed repost patch with above
change and we should be good to go.
Regards
-steve
On Thu, 2008-10-23 at 21:54 +1300, Angus & Anna Salkeld wrote:
> This patch allows you to use confdb to set the following objects at runtime:
> logging {
> subsys {
> priority: debug
> tags: trace1|trace5
> }
> }
>
> Note:
> -this needs to be on top of syslogv2
> -the change from syslog_level (not actually used) to priority.
>
> Regards
> Angus
>
> conf/corosync.conf | 3 +-
> exec/logsys.c | 36 +++++++++++
> exec/mainconfig.c | 119 ++++++++++++++++++++++---------------
> include/corosync/engine/logsys.h | 3 +
> lib/Makefile | 2 +
> man/corosync.conf.5 | 16 ++----
> services/confdb.c | 8 +-
> tools/Makefile | 7 +-
> tools/corosync-objctl.c | 2 +-
> 9 files changed, 127 insertions(+), 69 deletions(-)
>
> diff --git a/conf/corosync.conf b/conf/corosync.conf
> index 0e2bdf4..3b5fc79 100644
> --- a/conf/corosync.conf
> +++ b/conf/corosync.conf
> @@ -17,11 +17,10 @@ logging {
> to_file: yes
> to_syslog: yes
> logfile: /tmp/corosync.log
> - debug: off
> timestamp: on
> logger {
> ident: AMF
> - debug: off
> + priority: info
> tags: enter|leave|trace1|trace2|trace3|trace4|trace6
> }
> }
> diff --git a/exec/logsys.c b/exec/logsys.c
> index 7f4c499..15f11f2 100644
> --- a/exec/logsys.c
> +++ b/exec/logsys.c
> @@ -246,6 +246,42 @@ static inline int strcpy_cutoff (char *dest, char
> *src, int cutoff)
> return (cutoff);
> }
>
> +unsigned int logsys_trace_mask_get (const char *config)
> +{
> + char trace_buf[256];
> + char * token;
> + unsigned int tags = 0;
> +
> + strncpy (trace_buf, config, 256);
> + token = strtok (trace_buf, "|");
> +
> + while (token != NULL) {
> + if (strcmp (token, "enter") == 0) {
> + tags |= LOGSYS_TAG_ENTER;
> + } else if (strcmp (token, "leave") == 0) {
> + tags |= LOGSYS_TAG_LEAVE;
> + } else if (strcmp (token, "trace1") == 0) {
> + tags |= LOGSYS_TAG_TRACE1;
> + } else if (strcmp (token, "trace2") == 0) {
> + tags |= LOGSYS_TAG_TRACE2;
> + } else if (strcmp (token, "trace3") == 0) {
> + tags |= LOGSYS_TAG_TRACE3;
> + } else if (strcmp (token, "trace4") == 0) {
> + tags |= LOGSYS_TAG_TRACE4;
> + } else if (strcmp (token, "trace5") == 0) {
> + tags |= LOGSYS_TAG_TRACE5;
> + } else if (strcmp (token, "trace6") == 0) {
> + tags |= LOGSYS_TAG_TRACE6;
> + } else if (strcmp (token, "trace7") == 0) {
> + tags |= LOGSYS_TAG_TRACE7;
> + } else if (strcmp (token, "trace8") == 0) {
> + tags |= LOGSYS_TAG_TRACE8;
> + }
> +
> + token = strtok(NULL, "|");
> + }
> + return tags;
> +}
> /*
> * %s SUBSYSTEM
> * %n FUNCTION NAME
> diff --git a/exec/mainconfig.c b/exec/mainconfig.c
> index 35c384a..9a4bb5c 100644
> --- a/exec/mainconfig.c
> +++ b/exec/mainconfig.c
> @@ -98,6 +98,63 @@ static struct logsys_config_struct {
> unsigned int tags;
> } logsys_logger;
>
> +
> +void logcfg_object_key_changed (
> + object_change_type_t change_type,
> + unsigned int parent_object_handle,
> + unsigned int object_handle,
> + void *object_name_pt, int object_name_len,
> + void *key_name_pt, int key_len,
> + void *key_value_pt, int key_value_len,
> + void *priv_data_pt)
> +{
> + char *value;
> + int subsys_id;
> + unsigned int tags;
> + unsigned int priority;
> + struct objdb_iface_ver0 *objdb = priv_data_pt;
> +
> + if (strncmp (object_name_pt, "logger_subsys", 13) == 0) {
> +
> + /* get the subsys field, if we can't then it's a new field
> + * so wait until it's created.
> + */
> + if (!objdb_get_string (objdb, object_handle, "subsys", &value)) {
> + subsys_id = logsys_config_subsys_get (value, &tags, &priority);
> + if (subsys_id == -1) {
> + /* log this incorrect config */
> + return;
> + }
> + } else {
> + /* not created yet. */
> + return;
> + }
> +
> + if (strncmp (key_name_pt, "priority", 8) == 0) {
> + if (change_type == OBJECT_KEY_DELETED) {
> + /* restore some sensible default */
> + priority = LOG_LEVEL_NOTICE;
> + } else {
> + priority = logsys_priority_id_get (key_value_pt);
> + if (priority == -1) {
> + return;
> + }
> + }
> + logsys_config_subsys_set (value, tags, priority);
> +
> + } else if (strncmp (key_name_pt, "tags", 4) == 0) {
> + if (change_type == OBJECT_KEY_DELETED) {
> + /* restore some sensible default */
> + tags = 0;
> + } else {
> + tags = logsys_trace_mask_get (key_value_pt);
> + }
> + logsys_config_subsys_set (value, tags, priority);
> + }
> + }
> +}
> +
> +
> int corosync_main_config_read (
> struct objdb_iface_ver0 *objdb,
> char **error_string,
> @@ -109,7 +166,7 @@ int corosync_main_config_read (
> char *error_reason = error_string_response;
> unsigned int object_find_handle;
> unsigned int object_find_logsys_handle;
> - int global_debug = 0;
> + int priority;
>
>
> memset (main_config, 0, sizeof (struct main_config));
> @@ -120,6 +177,12 @@ int corosync_main_config_read (
> strlen ("logging"),
> &object_find_handle);
>
> +
> + objdb->object_track_start (object_find_handle,
> + OBJECT_TRACK_DEPTH_RECURSIVE,
> + logcfg_object_key_changed,
> + NULL, NULL, NULL, objdb);
> +
> main_config->logmode = LOG_MODE_THREADED | LOG_MODE_FORK;
> if (objdb->object_find_next (
> object_find_handle,
> @@ -150,16 +213,6 @@ int corosync_main_config_read (
> }
> }
>
> - if (!objdb_get_string (objdb,object_service_handle, "debug", &value)) {
> - if (strcmp (value, "on") == 0) {
> - global_debug = 1;
> - } else
> - if (strcmp (value, "off") == 0) {
> - global_debug = 0;
> - } else {
> - goto parse_error;
> - }
> - }
> if (!objdb_get_string (objdb,object_service_handle, "timestamp", &value)) {
> /* todo change format string
> if (strcmp (value, "on") == 0) {
> @@ -241,47 +294,17 @@ int corosync_main_config_read (
> error_reason = "subsys required for logger directive";
> goto parse_error;
> }
> - if (!objdb_get_string (objdb, object_logger_subsys_handle,
> "debug", &value)) {
> - if (strcmp (value, "on") == 0) {
> - logsys_logger.priority = LOG_LEVEL_DEBUG;
> - } else
> - if (strcmp (value, "off") == 0) {
> - logsys_logger.priority &= ~LOG_LEVEL_DEBUG;
> - } else {
> +
> + if (!objdb_get_string (objdb, object_logger_subsys_handle,
> "priority", &value)) {
> + priority = logsys_priority_id_get (value);
> + if (priority == -1) {
> + error_reason = "invalid priority";
> goto parse_error;
> }
> + logsys_logger.priority = priority;
> }
> if (!objdb_get_string (objdb, object_logger_subsys_handle, "tags",
> &value)) {
> - char *token = strtok (value, "|");
> -
> - while (token != NULL) {
> - if (strcmp (token, "enter") == 0) {
> - logsys_logger.tags |= LOGSYS_TAG_ENTER;
> - } else if (strcmp (token, "leave") == 0) {
> - logsys_logger.tags |= LOGSYS_TAG_LEAVE;
> - } else if (strcmp (token, "trace1") == 0) {
> - logsys_logger.tags |= LOGSYS_TAG_TRACE1;
> - } else if (strcmp (token, "trace2") == 0) {
> - logsys_logger.tags |= LOGSYS_TAG_TRACE2;
> - } else if (strcmp (token, "trace3") == 0) {
> - logsys_logger.tags |= LOGSYS_TAG_TRACE3;
> - } else if (strcmp (token, "trace4") == 0) {
> - logsys_logger.tags |= LOGSYS_TAG_TRACE4;
> - } else if (strcmp (token, "trace5") == 0) {
> - logsys_logger.tags |= LOGSYS_TAG_TRACE5;
> - } else if (strcmp (token, "trace6") == 0) {
> - logsys_logger.tags |= LOGSYS_TAG_TRACE6;
> - } else if (strcmp (token, "trace7") == 0) {
> - logsys_logger.tags |= LOGSYS_TAG_TRACE7;
> - } else if (strcmp (token, "trace8") == 0) {
> - logsys_logger.tags |= LOGSYS_TAG_TRACE8;
> - } else {
> - error_reason = "bad tags value";
> - goto parse_error;
> - }
> -
> - token = strtok(NULL, "|");
> - }
> + logsys_logger.tags = logsys_trace_mask_get (value);
> }
> /*
> * set individual logger configurations
> diff --git a/include/corosync/engine/logsys.h b/include/corosync/engine/logsys.h
> index 4361f1d..b1ee436 100644
> --- a/include/corosync/engine/logsys.h
> +++ b/include/corosync/engine/logsys.h
> @@ -136,6 +136,9 @@ extern const char *logsys_priority_name_get (
>
> extern void logsys_fork_completed (void);
>
> +extern unsigned int logsys_trace_mask_get (
> + const char *config);
> +
> extern void logsys_flush (void);
>
> extern void logsys_atsegv (void);
> diff --git a/lib/Makefile b/lib/Makefile
> index 7f623dc..7971848 100644
> --- a/lib/Makefile
> +++ b/lib/Makefile
> @@ -44,6 +44,8 @@ all: libcpg.a libcpg.so.2.0.0 \
> libquorum.a libquorum.so.2.0.0 \
> libcoroutil.a libcoroutil.so.2.0.0
>
> +LIBAIS_SRC=cfg.c confdb.c cpg.c evs.c sa-confdb.c util.c
> +
> libcoroutil.a: util.o
> $(AR) -rc libcoroutil.a util.o
>
> diff --git a/man/corosync.conf.5 b/man/corosync.conf.5
> index c915b09..2912dd0 100644
> --- a/man/corosync.conf.5
> +++ b/man/corosync.conf.5
> @@ -472,23 +472,17 @@ name used by a service in the log_init () call.
> E.g. 'CKPT'. This directive is
> required.
>
> .TP
> -debug
> -This specifies whether debug output is logged for this particular logger.
> -
> -The default is off.
> -
> -.TP
> -syslog_level
> -This specifies the syslog level for this particular subsystem.
> Ignored if debug is on.
> -Possible values are: alert, crit, debug (same as debug = on), emerg,
> err, info, notice, warning.
> +priority
> +This specifies the syslog priority for this particular subsystem.
> +Possible values are: alert, crit, debug, emerg, err, info, notice, warning.
>
> The default is: info.
>
> .TP
> tags
> This specifies which tags should be traced for this particular logger.
> -Set debug directive to
> -.B on
> +Set priority directive to
> +.B debug
> in order to enable tracing using tags.
> Values are specified using a vertical bar as a logical OR separator:
>
> diff --git a/services/confdb.c b/services/confdb.c
> index d59c184..053ec56 100644
> --- a/services/confdb.c
> +++ b/services/confdb.c
> @@ -49,7 +49,7 @@
> #include <corosync/engine/logsys.h>
> #include <corosync/engine/coroapi.h>
>
> -LOGSYS_DECLARE_SUBSYS ("CONFDB", LOG_DEBUG);
> +LOGSYS_DECLARE_SUBSYS ("CONFDB", LOG_INFO);
>
> static struct corosync_api_v1 *api;
>
> @@ -268,13 +268,13 @@ static int confdb_exec_init_fn (
>
> static int confdb_lib_init_fn (void *conn)
> {
> - log_printf(LOG_LEVEL_DEBUG, "lib_init_fn: conn=%p\n", conn);
> + ENTER();
> return (0);
> }
>
> static int confdb_lib_exit_fn (void *conn)
> {
> - log_printf(LOG_LEVEL_DEBUG, "exit_fn for conn=%p\n", conn);
> + ENTER();
> /* cleanup the object trackers for this client. */
> api->object_track_stop(confdb_notify_lib_of_key_change,
> confdb_notify_lib_of_new_object,
> @@ -325,7 +325,7 @@ static void
> message_handler_req_lib_confdb_object_find_destroy (void *conn, void
> mar_res_header_t res;
> int ret = SA_AIS_OK;
>
> - log_printf(LOG_LEVEL_DEBUG, "object_find_destroy for conn=%p, %d\n",
> conn, req_lib_confdb_object_find_destroy->find_handle);
> + ENTER();
>
> if (api->object_find_destroy(req_lib_confdb_object_find_destroy->find_handle))
> ret = SA_AIS_ERR_ACCESS;
> diff --git a/tools/Makefile b/tools/Makefile
> index 30ed173..4242adb 100644
> --- a/tools/Makefile
> +++ b/tools/Makefile
> @@ -33,7 +33,8 @@
> # Include configuration
> #
> srcdir ?= $(CURDIR)/../
> -subdir ?= apps/
> +subdir ?= tools/
> +
>
> include $(srcdir)Makefile.inc
>
> @@ -43,7 +44,7 @@ endif
>
> LIBS = ../lib/libconfdb.a ../lib/libcfg.a
> BINARIES=corosync-objctl corosync-cfgtool corosync-keygen corosync-fplay
> -APPS_SRC=$(addsuffix .c,$(BINARIES))
> +TOOLS_SRC=$(addsuffix .c,$(BINARIES))
> EXTRA_CFLAGS = -I$(srcdir)include
>
> all: $(BINARIES)
> @@ -67,4 +68,4 @@ clean:
> $(CC) $(CFLAGS) $(CPPFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
>
> depend:
> - makedepend -Y -- $(CFLAGS) $(CPPFLAGS) $(APPS_SRC) > /dev/null 2>&1
> + makedepend -Y -- $(CFLAGS) $(CPPFLAGS) $(TOOLS_SRC) > /dev/null 2>&1
> diff --git a/tools/corosync-objctl.c b/tools/corosync-objctl.c
> index e6106ad..332ffa3 100644
> --- a/tools/corosync-objctl.c
> +++ b/tools/corosync-objctl.c
> @@ -261,7 +261,7 @@ static confdb_error_t find_object (confdb_handle_t handle,
> uint32_t obj_handle;
> confdb_handle_t parent_object_handle = OBJECT_PARENT_HANDLE;
> char tmp_name[OBJ_NAME_SIZE];
> - confdb_error_t res;
> + confdb_error_t res = CONFDB_OK;
>
> strncpy (tmp_name, name_pt, OBJ_NAME_SIZE);
> obj_name_pt = strtok_r(tmp_name, SEPERATOR_STR, &save_pt);
> _______________________________________________
> Openais mailing list
> Openais at lists.linux-foundation.org
> https://lists.linux-foundation.org/mailman/listinfo/openais
More information about the Openais
mailing list