From 9d78dac57ecba0893b5fa95c320f5437c3dad3e8 Mon Sep 17 00:00:00 2001 From: Andre Nathan Date: Thu, 5 Dec 2013 16:40:12 -0200 Subject: [PATCH] Implement LXC::run_command --- ext/lxc.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/ext/lxc.c b/ext/lxc.c index b9b3d68..6d3d170 100644 --- a/ext/lxc.c +++ b/ext/lxc.c @@ -1136,6 +1136,24 @@ container_wait(int argc, VALUE *argv, VALUE self) return self; } +static VALUE +lxc_run_command(VALUE self, VALUE rb_command) +{ + int ret; + lxc_attach_command_t cmd; + VALUE rb_program; + + rb_program = rb_ary_shift(rb_command); + cmd.program = StringValuePtr(rb_program); + cmd.argv = ruby_to_c_string_array(rb_command); + + ret = lxc_attach_run_command(&cmd); + if (ret == -1) + rb_raise(Error, "unable to run command"); + /* NOTREACHED */ + return Qnil; +} + static VALUE lxc_default_config_path(VALUE self) { @@ -1200,8 +1218,7 @@ Init_lxc(void) //rb_define_singleton_method(LXC, "arch_to_personality", // lxc_arch_to_personality, 1); - //rb_define_singleton_method(LXC, "attach_run_command", - // lxc_attach_run_command, 0); + rb_define_singleton_method(LXC, "run_command", lxc_run_command, 0); //rb_define_singleton_method(LXC, "attach_run_shell", // lxc_attach_run_shell, 0); rb_define_singleton_method(LXC, "default_config_path",