Store the exit code of executed commands in Dumm::Guest.execstatus.

Also, no exception is risen for failed exec calls, anymore.
This commit is contained in:
Tobias Brunner
2010-10-12 15:41:17 +02:00
parent d679266fe1
commit d4b8f98c1a
2 changed files with 13 additions and 17 deletions
+6 -6
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2008-2009 Tobias Brunner * Copyright (C) 2008-2010 Tobias Brunner
* Copyright (C) 2008 Martin Willi * Copyright (C) 2008 Martin Willi
* Hochschule fuer Technik Rapperswil * Hochschule fuer Technik Rapperswil
* *
@@ -240,11 +240,9 @@ static VALUE guest_exec(VALUE self, VALUE cmd)
block = rb_block_given_p(); block = rb_block_given_p();
Data_Get_Struct(self, guest_t, guest); Data_Get_Struct(self, guest_t, guest);
if ((ret = guest->exec_str(guest, block ? (void*)exec_cb : NULL, TRUE, NULL, ret = guest->exec_str(guest, block ? (void*)exec_cb : NULL, TRUE, NULL,
"exec %s", StringValuePtr(cmd))) != 0) "exec %s", StringValuePtr(cmd));
{ rb_iv_set(self, "@execstatus", INT2NUM(ret));
rb_raise(rb_eRuntimeError, "executing command failed (%d)", ret);
}
return self; return self;
} }
@@ -411,6 +409,8 @@ static void guest_init()
rb_define_method(rbc_guest, "add_overlay", guest_add_overlay, 1); rb_define_method(rbc_guest, "add_overlay", guest_add_overlay, 1);
rb_define_method(rbc_guest, "del_overlay", guest_del_overlay, 1); rb_define_method(rbc_guest, "del_overlay", guest_del_overlay, 1);
rb_define_method(rbc_guest, "pop_overlay", guest_pop_overlay, 0); rb_define_method(rbc_guest, "pop_overlay", guest_pop_overlay, 0);
rb_define_attr(rbc_guest, "execstatus", 1, 0);
} }
/** /**
+7 -11
View File
@@ -1,5 +1,5 @@
=begin =begin
Copyright (C) 2008-2009 Tobias Brunner Copyright (C) 2008-2010 Tobias Brunner
Hochschule fuer Technik Rapperswil Hochschule fuer Technik Rapperswil
This program is free software; you can redistribute it and/or modify it This program is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@ module Dumm
end end
Guest[id] Guest[id]
end end
# accessor for interfaces # accessor for interfaces
# e.g. guest.eth0 instead of guest["eth0"] # e.g. guest.eth0 instead of guest["eth0"]
def method_missing(id, *args) def method_missing(id, *args)
@@ -32,7 +32,7 @@ module Dumm
end end
self[id] self[id]
end end
# remove all overlays, delete all interfaces # remove all overlays, delete all interfaces
def reset def reset
while pop_overlay; end while pop_overlay; end
@@ -40,17 +40,13 @@ module Dumm
i.delete i.delete
} }
end end
# has the guest booted up? # has the guest booted up?
def booted? def booted?
begin exec("pgrep getty")
exec("pgrep getty") execstatus == 0
rescue
return false
end
return true
end end
# wait until the guest has booted # wait until the guest has booted
def boot def boot
while not booted? while not booted?