Adding early nil return in config_item (when value is empty).

This commit is contained in:
NiR- 2014-06-06 10:31:39 +02:00
parent 755609c059
commit 2b9f45f8a5
2 changed files with 23 additions and 0 deletions

View file

@ -1238,6 +1238,9 @@ container_config_item(VALUE self, VALUE rb_key)
if (len1 < 0)
rb_raise(Error, "invalid configuration key: %s", key);
if (len1 == 0)
return Qnil;
value = malloc(sizeof(char) * len1 + 1);
if (value == NULL)
rb_raise(rb_eNoMemError, "unable to allocate configuration value");

View file

@ -41,6 +41,26 @@ class TestLXCCreated < Test::Unit::TestCase
assert_match(/^00:16:3e:/, @container.config_item('lxc.network.0.hwaddr'))
end
def test_container_fstab
config_path = @container.config_path + '/' + @name + '/config'
fstab_path = @container.config_path + '/' + @name + '/fstab'
@container.set_config_item('lxc.mount', fstab_path)
@container.save_config(config_path)
assert_instance_of(String, @container.config_item('lxc.mount'))
assert_not_nil(@container.config_item('lxc.mount'))
f = File.readlines(config_path)
f.reject! { |l| /^lxc\.mount = (.*)$/ =~ l }
File.write(config_path, f.join)
@container.clear_config
@container.load_config(config_path)
assert(@container.config_item('lxc.mount').nil?)
end
def test_clear_config
assert_not_nil(@container.config_item('lxc.utsname'))
assert(@container.clear_config)