From 0c3abf0de24813ffa7d89ccdc0084f6f47dcf3fd Mon Sep 17 00:00:00 2001 From: Andre Nathan Date: Tue, 14 Jan 2014 08:51:22 -0200 Subject: [PATCH] Remove LXC.default_config_path, add LXC.global_config_item Follows lxc@593e84786e2b4709059989bee489deab5c923779 --- ext/lxc/lxc.c | 20 +++++++++++++------- test/test_lxc_undefined.rb | 3 ++- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/ext/lxc/lxc.c b/ext/lxc/lxc.c index 6c6cfc0..5a6441c 100644 --- a/ext/lxc/lxc.c +++ b/ext/lxc/lxc.c @@ -133,14 +133,20 @@ lxc_run_shell(VALUE self) /* * call-seq: - * LXC.default_config_path + * LXC.global_config_item(key) * - * Returns the +liblxc+ configuration path, usually +/var/lib/lxc+. + * Returns value for the given global config key. */ static VALUE -lxc_default_config_path(VALUE self) +lxc_global_config_item(VALUE self, VALUE rb_key) { - return rb_str_new2(lxc_get_default_config_path()); + char *key; + const char *value; + key = StringValuePtr(rb_key); + value = lxc_get_global_config_item(key); + if (value == NULL) + rb_raise(Error, "invalid configuration key %s", key); + return rb_str_new2(value); } /* @@ -241,7 +247,7 @@ container_alloc(VALUE klass) /* * call-seq: - * LXC::Container.new(name, config_path = LXC.default_config_path) + * LXC::Container.new(name, config_path = LXC.global_config_item('lxc.lxcpath')) * * Creates a new container instance with the given name, under the given * configuration path. @@ -1633,8 +1639,8 @@ Init_lxc(void) lxc_arch_to_personality, 1); rb_define_singleton_method(LXC, "run_command", lxc_run_command, 1); rb_define_singleton_method(LXC, "run_shell", lxc_run_shell, 0); - rb_define_singleton_method(LXC, "default_config_path", - lxc_default_config_path, 0); + rb_define_singleton_method(LXC, "global_config_item", + lxc_global_config_item, 1); rb_define_singleton_method(LXC, "version", lxc_version, 0); rb_define_singleton_method(LXC, "list_containers", lxc_list_containers, -1); diff --git a/test/test_lxc_undefined.rb b/test/test_lxc_undefined.rb index 2c49f19..9e22211 100644 --- a/test/test_lxc_undefined.rb +++ b/test/test_lxc_undefined.rb @@ -10,7 +10,8 @@ class TestLXCUndefined < Test::Unit::TestCase end def test_container_config_file_name - config_path = File.join(LXC.default_config_path, @name, 'config') + lxc_path = LXC.global_config_item('lxc.lxcpath') + config_path = File.join(lxc_path, @name, 'config') assert_equal(config_path, @container.config_file_name) end