Created
March 17, 2012 02:12
-
-
Save hiboma/2054384 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mkmf' | |
# http://www.ruby-lang.org/ja/old-man/html/mkmf.html | |
# http://brandish.xrea.jp/BlackCity/labo/labo_ruby_ext_2.html | |
# http://d.hatena.ne.jp/yarb/20090724/p1 | |
dir_config('lxc') | |
if have_header('lxc/namespace.h') and have_library('lxc') and have_func("lxc_attach") | |
$libs = append_library($libs, "lxc") | |
create_makefile("lxc") | |
else | |
raise "lxc_attach is not defined" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ruby.h" | |
#include "lxc/namespace.h" | |
static VALUE lxc_lxc_attach(VALUE, VALUE); | |
void | |
Init_lxc(void){ | |
VALUE lxc; | |
lxc = rb_define_class("Lxc", rb_cObject); | |
rb_define_method(lxc, "attach", lxc_lxc_attach, 1); | |
} | |
static VALUE | |
lxc_lxc_attach(VALUE self, VALUE name) { | |
char *lxc_name = StringValuePtr(name); | |
pid_t pid; | |
int ret; | |
pid = get_init_pid(lxc_name); | |
if(pid == -1) { | |
rb_raise(rb_eRuntimeError, "container '%s' is not running", lxc_name); | |
} | |
ret = lxc_attach(pid); | |
if(ret == -1) { | |
rb_raise(rb_eRuntimeError, "failed to lxc_attach (pid %d)", pid); | |
} | |
return self; | |
} |
Author
hiboma
commented
Mar 17, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment