diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/dumm/ext/dumm.c | 17 | ||||
-rw-r--r-- | src/dumm/guest.h | 14 | ||||
-rw-r--r-- | src/dumm/iface.c | 12 | ||||
-rw-r--r-- | src/dumm/mconsole.c | 2 | ||||
-rw-r--r-- | src/dumm/mconsole.h | 2 |
5 files changed, 33 insertions, 14 deletions
diff --git a/src/dumm/ext/dumm.c b/src/dumm/ext/dumm.c index 3cc256fda..adb89d632 100644 --- a/src/dumm/ext/dumm.c +++ b/src/dumm/ext/dumm.c @@ -207,6 +207,22 @@ static VALUE guest_exec(VALUE self, VALUE cmd) 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, + "exec %s", StringValuePtr(cmd))) != 0) + { + rb_raise(rb_eRuntimeError, "executing command failed (%d)", ret); + } + return self; +} + +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, "%s", StringValuePtr(cmd))) != 0) { rb_raise(rb_eRuntimeError, "executing command failed (%d)", ret); @@ -310,6 +326,7 @@ static void guest_init() rb_define_method(rbc_guest, "stop", guest_stop, 0); rb_define_method(rbc_guest, "running?", guest_running, 0); rb_define_method(rbc_guest, "exec", guest_exec, 1); + rb_define_method(rbc_guest, "mconsole", guest_mconsole, 1); rb_define_method(rbc_guest, "add", guest_add_iface, 1); rb_define_method(rbc_guest, "[]", guest_get_iface, 1); rb_define_method(rbc_guest, "each", guest_each_iface, -1); diff --git a/src/dumm/guest.h b/src/dumm/guest.h index 0e48b1d06..19dc8a8bf 100644 --- a/src/dumm/guest.h +++ b/src/dumm/guest.h @@ -142,7 +142,7 @@ struct guest_t { bool (*load_template)(guest_t *this, char *parent); /** - * Execute a command in the guest. + * Execute a command on the guests mconsole. * * @param cb callback to call for each read block * @param data data to pass to callback @@ -154,20 +154,22 @@ struct guest_t { char *cmd, ...); /** - * Execute a command in the guest and return the output by lines or as combined - * string. + * Execute a command on the guests mconsole, with output formatter. * - * @note This function does not work with binary output (i.e. containing 0 bytes). + * If lines is TRUE, callback is invoked for each output line. Otherwise + * the full result is returned in one callback invocation. + * + * @note This function does not work with binary output. * * @param cb callback to call for each line or for the complete output - * @param lines TRUE if the callback should be called for each line (instead of for the combined output) + * @param lines TRUE if the callback should be called for each line * @param data data to pass to callback * @param cmd command to execute * @param ... printf style argument list for cmd * @return return value */ int (*exec_str)(guest_t *this, void(*cb)(void*,char*), bool lines, - void *data, char *cmd, ...); + void *data, char *cmd, ...); /** * @brief Called whenever a SIGCHILD for the guests PID is received. diff --git a/src/dumm/iface.c b/src/dumm/iface.c index 78c6c7c92..bf73c82a5 100644 --- a/src/dumm/iface.c +++ b/src/dumm/iface.c @@ -104,8 +104,8 @@ static char* get_hostif(private_iface_t *this) */ static bool add_address(private_iface_t *this, host_t *addr) { - return (this->guest->exec(this->guest, NULL, NULL, "ip addr add %H dev %s", - addr, this->guestif) == 0); + return (this->guest->exec(this->guest, NULL, NULL, + "exec ip addr add %H dev %s", addr, this->guestif) == 0); } /** @@ -136,7 +136,7 @@ static enumerator_t* create_address_enumerator(private_iface_t *this) linked_list_t *addresses = linked_list_create(); this->guest->exec_str(this->guest, (void(*)(void*,char*))compile_address_list, TRUE, addresses, - "ip addr list dev %s scope global | " + "exec ip addr list dev %s scope global | " "grep '^ \\+\\(inet6\\? \\)' | " "awk -F '( +|/)' '{ print $3 }'", this->guestif); return enumerator_create_cleaner(addresses->create_enumerator(addresses), @@ -149,7 +149,7 @@ static enumerator_t* create_address_enumerator(private_iface_t *this) static bool delete_address(private_iface_t *this, host_t *addr) { return (this->guest->exec(this->guest, NULL, NULL, - "ip addr del %H dev %s", addr, this->guestif) == 0); + "exec ip addr del %H dev %s", addr, this->guestif) == 0); } /** @@ -160,12 +160,12 @@ static void set_bridge(private_iface_t *this, bridge_t *bridge) if (this->bridge == NULL && bridge) { this->guest->exec(this->guest, NULL, NULL, - "ip link set %s up", this->guestif); + "exec ip link set %s up", this->guestif); } else if (this->bridge && bridge == NULL) { this->guest->exec(this->guest, NULL, NULL, - "ip link set %s down", this->guestif); + "exec ip link set %s down", this->guestif); } this->bridge = bridge; } diff --git a/src/dumm/mconsole.c b/src/dumm/mconsole.c index c6e0c2f08..85c090e27 100644 --- a/src/dumm/mconsole.c +++ b/src/dumm/mconsole.c @@ -201,7 +201,7 @@ static bool del_iface(private_mconsole_t *this, char *guest) static int exec(private_mconsole_t *this, void(*cb)(void*,char*,size_t), void *data, char *cmd) { - return request(this, cb, data, "exec %s", cmd); + return request(this, cb, data, "%s", cmd); } /** diff --git a/src/dumm/mconsole.h b/src/dumm/mconsole.h index 329c40c06..e8493b5bb 100644 --- a/src/dumm/mconsole.h +++ b/src/dumm/mconsole.h @@ -43,7 +43,7 @@ struct mconsole_t { bool (*del_iface)(mconsole_t *this, char *guest); /** - * Execute a command in the UML host. + * Execute a command on the mconsole. * * @param cb callback function to invoke for each line * @param data data to pass to callback |