All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jérémie Galarneau" <jeremie.galarneau@efficios.com>
To: lttng-dev@lists.lttng.org
Subject: [PATCH lttng-tools 1/2] Override the session.xsd path with an environment variable
Date: Mon, 14 Apr 2014 12:10:44 -0400	[thread overview]
Message-ID: <1397491844-32336-1-git-send-email-jeremie.galarneau__15902.0205996514$1397491944$gmane$org@efficios.com> (raw)
In-Reply-To: <20140414143458.GC9369@thessa>

The LTTNG_SESSION_CONFIG_XSD_PATH environment variable can be used
to specify a path which contains the session configuration schema.
This will allow save-load tests to be ran without installing
the XSD on the system.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
---
 src/common/config/config.c | 40 +++++++++++++++++++++++++++++++++++++++-
 src/common/defaults.h      |  6 +++---
 2 files changed, 42 insertions(+), 4 deletions(-)

diff --git a/src/common/config/config.c b/src/common/config/config.c
index e61791b..8b34d02 100644
--- a/src/common/config/config.c
+++ b/src/common/config/config.c
@@ -569,12 +569,49 @@ void fini_session_config_validation_ctx(
 }
 
 static
+char *get_session_config_xsd_path()
+{
+	char *xsd_path;
+	const char *base_path = getenv(DEFAULT_SESSION_CONFIG_XSD_PATH_ENV);
+	size_t base_path_len;
+	size_t max_path_len;
+
+	if (!base_path) {
+		base_path = DEFAULT_SESSION_CONFIG_XSD_PATH;
+	}
+
+	base_path_len = strlen(base_path);
+	max_path_len = base_path_len +
+		sizeof(DEFAULT_SESSION_CONFIG_XSD_FILENAME) + 1;
+	xsd_path = zmalloc(max_path_len);
+	if (!xsd_path) {
+		goto end;
+	}
+
+	strncpy(xsd_path, base_path, max_path_len);
+	if (xsd_path[base_path_len - 1] != '/') {
+		xsd_path[base_path_len++] = '/';
+	}
+
+	strncpy(xsd_path + base_path_len, DEFAULT_SESSION_CONFIG_XSD_FILENAME,
+		max_path_len - base_path_len);
+end:
+	return xsd_path;
+}
+
+static
 int init_session_config_validation_ctx(
 	struct session_config_validation_ctx *ctx)
 {
 	int ret;
+	char *xsd_path = get_session_config_xsd_path();
+
+	if (!xsd_path) {
+		ret = -LTTNG_ERR_NOMEM;
+		goto end;
+	}
 
-	ctx->parser_ctx = xmlSchemaNewParserCtxt(DEFAULT_SESSION_CONFIG_XSD_PATH);
+	ctx->parser_ctx = xmlSchemaNewParserCtxt(xsd_path);
 	if (!ctx->parser_ctx) {
 		ERR("XSD parser context creation failed");
 		ret = -LTTNG_ERR_LOAD_INVALID_CONFIG;
@@ -606,6 +643,7 @@ end:
 		fini_session_config_validation_ctx(ctx);
 	}
 
+	free(xsd_path);
 	return ret;
 }
 
diff --git a/src/common/defaults.h b/src/common/defaults.h
index 7acabf1..de61064 100644
--- a/src/common/defaults.h
+++ b/src/common/defaults.h
@@ -125,9 +125,9 @@
 #define DEFAULT_SESSION_SYSTEM_CONFIGPATH       DEFAULT_SYSTEM_CONFIGPATH "/" \
 	DEFAULT_SESSION_PATH
 #define DEFAULT_SESSION_CONFIG_FILE_EXTENSION   ".lttng"
-#define DEFAULT_SESSION_CONFIG_XSD_PATH         CONFIG_LTTNG_SYSTEM_DATADIR \
-	"/xml/lttng/session.xsd"
-
+#define DEFAULT_SESSION_CONFIG_XSD_FILENAME     "session.xsd"
+#define DEFAULT_SESSION_CONFIG_XSD_PATH         CONFIG_LTTNG_SYSTEM_DATADIR "/xml/lttng/"
+#define DEFAULT_SESSION_CONFIG_XSD_PATH_ENV     "LTTNG_SESSION_CONFIG_XSD_PATH"
 
 #define DEFAULT_GLOBAL_APPS_UNIX_SOCK \
 	DEFAULT_LTTNG_RUNDIR "/" LTTNG_UST_SOCK_FILENAME
-- 
1.9.2


_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

  parent reply	other threads:[~2014-04-14 16:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1397188683-25626-1-git-send-email-jeremie.galarneau@efficios.com>
2014-04-11  3:58 ` [PATCH lttng-tools 2/2] Use the in-tree session.xsd in test_load Jérémie Galarneau
2014-04-14 14:34 ` [PATCH lttng-tools 1/2] Override the session.xsd path with an environment variable David Goulet
     [not found] ` <20140414143458.GC9369@thessa>
2014-04-14 16:10   ` Jérémie Galarneau [this message]
2014-04-14 16:11   ` Jérémie Galarneau
     [not found]   ` <1397491844-32336-1-git-send-email-jeremie.galarneau@efficios.com>
2014-04-14 19:24     ` David Goulet
2014-04-11  3:58 Jérémie Galarneau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='1397491844-32336-1-git-send-email-jeremie.galarneau__15902.0205996514$1397491944$gmane$org@efficios.com' \
    --to=jeremie.galarneau@efficios.com \
    --cc=lttng-dev@lists.lttng.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.