summaryrefslogtreecommitdiff
path: root/src/dumm/ext/dumm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dumm/ext/dumm.c')
-rw-r--r--src/dumm/ext/dumm.c93
1 files changed, 47 insertions, 46 deletions
diff --git a/src/dumm/ext/dumm.c b/src/dumm/ext/dumm.c
index f7caf252d..230e8ae68 100644
--- a/src/dumm/ext/dumm.c
+++ b/src/dumm/ext/dumm.c
@@ -29,6 +29,7 @@
#undef PACKAGE_VERSION
#undef PACKAGE_STRING
#undef PACKAGE_BUGREPORT
+#undef PACKAGE_URL
#include <ruby.h>
static dumm_t *dumm;
@@ -45,7 +46,7 @@ static VALUE rbc_template;
static pid_t invoke(void *null, guest_t *guest, char *args[], int argc)
{
pid_t pid;
-
+
pid = fork();
switch (pid)
{
@@ -71,7 +72,7 @@ static void sigchld_handler(int signal, siginfo_t *info, void* ptr)
{
enumerator_t *enumerator;
guest_t *guest;
-
+
enumerator = dumm->create_guest_enumerator(dumm);
while (enumerator->enumerate(enumerator, &guest))
{
@@ -91,7 +92,7 @@ static VALUE guest_find(VALUE class, VALUE key)
{
enumerator_t *enumerator;
guest_t *guest, *found = NULL;
-
+
if (TYPE(key) == T_SYMBOL)
{
key = rb_convert_type(key, T_STRING, "String", "to_s");
@@ -128,7 +129,7 @@ static VALUE guest_each(int argc, VALUE *argv, VALUE class)
linked_list_t *list;
enumerator_t *enumerator;
guest_t *guest;
-
+
if (!rb_block_given_p())
{
rb_raise(rb_eArgError, "must be called with a block");
@@ -152,7 +153,7 @@ static VALUE guest_new(VALUE class, VALUE name, VALUE kernel,
VALUE master, VALUE args)
{
guest_t *guest;
-
+
guest = dumm->create_guest(dumm, StringValuePtr(name), StringValuePtr(kernel),
StringValuePtr(master), StringValuePtr(args));
if (!guest)
@@ -165,7 +166,7 @@ static VALUE guest_new(VALUE class, VALUE name, VALUE kernel,
static VALUE guest_to_s(VALUE self)
{
guest_t *guest;
-
+
Data_Get_Struct(self, guest_t, guest);
return rb_str_new2(guest->get_name(guest));
}
@@ -173,9 +174,9 @@ static VALUE guest_to_s(VALUE self)
static VALUE guest_start(VALUE self)
{
guest_t *guest;
-
+
Data_Get_Struct(self, guest_t, guest);
-
+
if (!guest->start(guest, invoke, NULL, NULL))
{
rb_raise(rb_eRuntimeError, "starting guest failed");
@@ -186,7 +187,7 @@ static VALUE guest_start(VALUE self)
static VALUE guest_stop(VALUE self)
{
guest_t *guest;
-
+
Data_Get_Struct(self, guest_t, guest);
guest->stop(guest, NULL);
return self;
@@ -195,7 +196,7 @@ static VALUE guest_stop(VALUE self)
static VALUE guest_running(VALUE self)
{
guest_t *guest;
-
+
Data_Get_Struct(self, guest_t, guest);
return guest->get_pid(guest) ? Qtrue : Qfalse;
}
@@ -210,7 +211,7 @@ static VALUE guest_exec(VALUE self, VALUE cmd)
guest_t *guest;
bool block;
int ret;
-
+
block = rb_block_given_p();
Data_Get_Struct(self, guest_t, guest);
if ((ret = guest->exec_str(guest, block ? (void*)exec_cb : NULL, TRUE, NULL,
@@ -226,7 +227,7 @@ static VALUE guest_mconsole(VALUE self, VALUE cmd)
guest_t *guest;
bool block;
int ret;
-
+
block = rb_block_given_p();
Data_Get_Struct(self, guest_t, guest);
if ((ret = guest->exec_str(guest, block ? (void*)exec_cb : NULL, TRUE, NULL,
@@ -241,7 +242,7 @@ static VALUE guest_add_iface(VALUE self, VALUE name)
{
guest_t *guest;
iface_t *iface;
-
+
Data_Get_Struct(self, guest_t, guest);
iface = guest->create_iface(guest, StringValuePtr(name));
if (!iface)
@@ -256,7 +257,7 @@ static VALUE guest_find_iface(VALUE self, VALUE key)
enumerator_t *enumerator;
iface_t *iface, *found = NULL;
guest_t *guest;
-
+
if (TYPE(key) == T_SYMBOL)
{
key = rb_convert_type(key, T_STRING, "String", "to_s");
@@ -295,7 +296,7 @@ static VALUE guest_each_iface(int argc, VALUE *argv, VALUE self)
linked_list_t *list;
guest_t *guest;
iface_t *iface;
-
+
if (!rb_block_given_p())
{
rb_raise(rb_eArgError, "must be called with a block");
@@ -319,7 +320,7 @@ static VALUE guest_each_iface(int argc, VALUE *argv, VALUE self)
static VALUE guest_delete(VALUE self)
{
guest_t *guest;
-
+
Data_Get_Struct(self, guest_t, guest);
if (guest->get_pid(guest))
{
@@ -334,13 +335,13 @@ static void guest_init()
rbc_guest = rb_define_class_under(rbm_dumm , "Guest", rb_cObject);
rb_include_module(rb_class_of(rbc_guest), rb_mEnumerable);
rb_include_module(rbc_guest, rb_mEnumerable);
-
+
rb_define_singleton_method(rbc_guest, "[]", guest_get, 1);
rb_define_singleton_method(rbc_guest, "each", guest_each, -1);
rb_define_singleton_method(rbc_guest, "new", guest_new, 4);
rb_define_singleton_method(rbc_guest, "include?", guest_find, 1);
rb_define_singleton_method(rbc_guest, "guest?", guest_find, 1);
-
+
rb_define_method(rbc_guest, "to_s", guest_to_s, 0);
rb_define_method(rbc_guest, "start", guest_start, 0);
rb_define_method(rbc_guest, "stop", guest_stop, 0);
@@ -362,7 +363,7 @@ static VALUE bridge_find(VALUE class, VALUE key)
{
enumerator_t *enumerator;
bridge_t *bridge, *found = NULL;
-
+
if (TYPE(key) == T_SYMBOL)
{
key = rb_convert_type(key, T_STRING, "String", "to_s");
@@ -399,7 +400,7 @@ static VALUE bridge_each(int argc, VALUE *argv, VALUE class)
enumerator_t *enumerator;
linked_list_t *list;
bridge_t *bridge;
-
+
if (!rb_block_given_p())
{
rb_raise(rb_eArgError, "must be called with a block");
@@ -423,7 +424,7 @@ static VALUE bridge_new(VALUE class, VALUE name)
{
bridge_t *bridge;
-
+
bridge = dumm->create_bridge(dumm, StringValuePtr(name));
if (!bridge)
{
@@ -435,7 +436,7 @@ static VALUE bridge_new(VALUE class, VALUE name)
static VALUE bridge_to_s(VALUE self)
{
bridge_t *bridge;
-
+
Data_Get_Struct(self, bridge_t, bridge);
return rb_str_new2(bridge->get_name(bridge));
}
@@ -446,7 +447,7 @@ static VALUE bridge_each_iface(int argc, VALUE *argv, VALUE self)
linked_list_t *list;
bridge_t *bridge;
iface_t *iface;
-
+
if (!rb_block_given_p())
{
rb_raise(rb_eArgError, "must be called with a block");
@@ -470,7 +471,7 @@ static VALUE bridge_each_iface(int argc, VALUE *argv, VALUE self)
static VALUE bridge_delete(VALUE self)
{
bridge_t *bridge;
-
+
Data_Get_Struct(self, bridge_t, bridge);
dumm->delete_bridge(dumm, bridge);
return Qnil;
@@ -481,13 +482,13 @@ static void bridge_init()
rbc_bridge = rb_define_class_under(rbm_dumm , "Bridge", rb_cObject);
rb_include_module(rb_class_of(rbc_bridge), rb_mEnumerable);
rb_include_module(rbc_bridge, rb_mEnumerable);
-
+
rb_define_singleton_method(rbc_bridge, "[]", bridge_get, 1);
rb_define_singleton_method(rbc_bridge, "each", bridge_each, -1);
rb_define_singleton_method(rbc_bridge, "new", bridge_new, 1);
rb_define_singleton_method(rbc_bridge, "include?", bridge_find, 1);
rb_define_singleton_method(rbc_bridge, "bridge?", bridge_find, 1);
-
+
rb_define_method(rbc_bridge, "to_s", bridge_to_s, 0);
rb_define_method(rbc_bridge, "each", bridge_each_iface, -1);
rb_define_method(rbc_bridge, "delete", bridge_delete, 0);
@@ -499,7 +500,7 @@ static void bridge_init()
static VALUE iface_to_s(VALUE self)
{
iface_t *iface;
-
+
Data_Get_Struct(self, iface_t, iface);
return rb_str_new2(iface->get_hostif(iface));
}
@@ -508,7 +509,7 @@ static VALUE iface_connect(VALUE self, VALUE vbridge)
{
iface_t *iface;
bridge_t *bridge;
-
+
Data_Get_Struct(self, iface_t, iface);
Data_Get_Struct(vbridge, bridge_t, bridge);
if (!bridge->connect_iface(bridge, iface))
@@ -522,7 +523,7 @@ static VALUE iface_disconnect(VALUE self)
{
iface_t *iface;
bridge_t *bridge;
-
+
Data_Get_Struct(self, iface_t, iface);
bridge = iface->get_bridge(iface);
if (!bridge || !bridge->disconnect_iface(bridge, iface))
@@ -536,7 +537,7 @@ static VALUE iface_add_addr(VALUE self, VALUE name)
{
iface_t *iface;
host_t *addr;
-
+
addr = host_create_from_string(StringValuePtr(name), 0);
if (!addr)
{
@@ -563,7 +564,7 @@ static VALUE iface_each_addr(int argc, VALUE *argv, VALUE self)
iface_t *iface;
host_t *addr;
char buf[64];
-
+
if (!rb_block_given_p())
{
rb_raise(rb_eArgError, "must be called with a block");
@@ -589,7 +590,7 @@ static VALUE iface_del_addr(VALUE self, VALUE vaddr)
{
iface_t *iface;
host_t *addr;
-
+
addr = host_create_from_string(StringValuePtr(vaddr), 0);
if (!addr)
{
@@ -613,7 +614,7 @@ static VALUE iface_delete(VALUE self)
{
guest_t *guest;
iface_t *iface;
-
+
Data_Get_Struct(self, iface_t, iface);
guest = iface->get_guest(iface);
guest->destroy_iface(guest, iface);
@@ -624,7 +625,7 @@ static void iface_init()
{
rbc_iface = rb_define_class_under(rbm_dumm , "Iface", rb_cObject);
rb_include_module(rbc_iface, rb_mEnumerable);
-
+
rb_define_method(rbc_iface, "to_s", iface_to_s, 0);
rb_define_method(rbc_iface, "connect", iface_connect, 1);
rb_define_method(rbc_iface, "disconnect", iface_disconnect, 0);
@@ -656,7 +657,7 @@ static VALUE template_each(int argc, VALUE *argv, VALUE class)
{
enumerator_t *enumerator;
char *template;
-
+
if (!rb_block_given_p())
{
rb_raise(rb_eArgError, "must be called with a block");
@@ -673,7 +674,7 @@ static VALUE template_each(int argc, VALUE *argv, VALUE class)
static void template_init()
{
rbc_template = rb_define_class_under(rbm_dumm , "Template", rb_cObject);
-
+
rb_define_singleton_method(rbc_template, "load", template_load, 1);
rb_define_singleton_method(rbc_template, "unload", template_unload, 0);
rb_define_singleton_method(rbc_template, "each", template_each, -1);
@@ -685,14 +686,14 @@ static void template_init()
void Final_dumm()
{
struct sigaction action;
-
+
dumm->destroy(dumm);
-
+
sigemptyset(&action.sa_mask);
action.sa_handler = SIG_DFL;
action.sa_flags = 0;
sigaction(SIGCHLD, &action, NULL);
-
+
library_deinit();
}
@@ -702,25 +703,25 @@ void Final_dumm()
void Init_dumm()
{
struct sigaction action;
-
+
/* there are too many to report, rubyruby... */
setenv("LEAK_DETECTIVE_DISABLE", "1", 1);
-
+
library_init(NULL);
-
+
dumm = dumm_create(NULL);
-
+
rbm_dumm = rb_define_module("Dumm");
-
+
guest_init();
bridge_init();
iface_init();
template_init();
-
+
sigemptyset(&action.sa_mask);
action.sa_sigaction = sigchld_handler;
action.sa_flags = SA_SIGINFO;
sigaction(SIGCHLD, &action, NULL);
-
+
rb_set_end_proc(Final_dumm, 0);
}