summaryrefslogtreecommitdiff
path: root/src/dumm
diff options
context:
space:
mode:
authorRene Mayrhofer <rene@mayrhofer.eu.org>2008-12-05 16:44:41 +0000
committerRene Mayrhofer <rene@mayrhofer.eu.org>2008-12-05 16:44:41 +0000
commit2db1ef4ac8928944958712923b9c89c263a337d2 (patch)
tree700043d9d97b7e7ba344b448918728af0a8be8d1 /src/dumm
parent5dc75410286b0e3a16845b44dd696ba0f40df573 (diff)
downloadvyos-strongswan-2db1ef4ac8928944958712923b9c89c263a337d2.tar.gz
vyos-strongswan-2db1ef4ac8928944958712923b9c89c263a337d2.zip
- Updated to new upstream.
Diffstat (limited to 'src/dumm')
-rw-r--r--src/dumm/Makefile.am4
-rw-r--r--src/dumm/Makefile.in8
-rw-r--r--src/dumm/dumm.c17
-rw-r--r--src/dumm/ext/dumm.c19
-rw-r--r--src/dumm/guest.c15
-rw-r--r--src/dumm/guest.h14
-rw-r--r--src/dumm/iface.c12
-rw-r--r--src/dumm/main.c1
-rw-r--r--src/dumm/mconsole.c14
-rw-r--r--src/dumm/mconsole.h2
10 files changed, 70 insertions, 36 deletions
diff --git a/src/dumm/Makefile.am b/src/dumm/Makefile.am
index 11d65bba9..029290fb6 100644
--- a/src/dumm/Makefile.am
+++ b/src/dumm/Makefile.am
@@ -11,8 +11,8 @@ irdumm_SOURCES = irdumm.c
libdumm_la_LIBADD = $(top_builddir)/src/libstrongswan/libstrongswan.la \
-lbridge -lfuse -lutil
-dumm_LDADD = -ldumm ${gtk_LIBS}
-irdumm_LDADD = -ldumm -lruby1.8
+dumm_LDADD = libdumm.la ${gtk_LIBS}
+irdumm_LDADD = libdumm.la -lruby1.8
INCLUDES = -I$(top_srcdir)/src/libstrongswan ${gtk_CFLAGS} \
-I/usr/lib/ruby/1.8/i486-linux/
diff --git a/src/dumm/Makefile.in b/src/dumm/Makefile.in
index 333e616d3..7c3f28191 100644
--- a/src/dumm/Makefile.in
+++ b/src/dumm/Makefile.in
@@ -61,10 +61,10 @@ PROGRAMS = $(ipsec_PROGRAMS)
am_dumm_OBJECTS = main.$(OBJEXT)
dumm_OBJECTS = $(am_dumm_OBJECTS)
am__DEPENDENCIES_1 =
-dumm_DEPENDENCIES = $(am__DEPENDENCIES_1)
+dumm_DEPENDENCIES = libdumm.la $(am__DEPENDENCIES_1)
am_irdumm_OBJECTS = irdumm.$(OBJEXT)
irdumm_OBJECTS = $(am_irdumm_OBJECTS)
-irdumm_DEPENDENCIES =
+irdumm_DEPENDENCIES = libdumm.la
DEFAULT_INCLUDES = -I.@am__isrc@
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
@@ -230,8 +230,8 @@ irdumm_SOURCES = irdumm.c
libdumm_la_LIBADD = $(top_builddir)/src/libstrongswan/libstrongswan.la \
-lbridge -lfuse -lutil
-dumm_LDADD = -ldumm ${gtk_LIBS}
-irdumm_LDADD = -ldumm -lruby1.8
+dumm_LDADD = libdumm.la ${gtk_LIBS}
+irdumm_LDADD = libdumm.la -lruby1.8
INCLUDES = -I$(top_srcdir)/src/libstrongswan ${gtk_CFLAGS} \
-I/usr/lib/ruby/1.8/i486-linux/
diff --git a/src/dumm/dumm.c b/src/dumm/dumm.c
index eaefddb60..cf8d9719c 100644
--- a/src/dumm/dumm.c
+++ b/src/dumm/dumm.c
@@ -87,7 +87,7 @@ static void delete_guest(private_dumm_t *this, guest_t *guest)
guest->destroy(guest);
if (len > 8 && len < 512)
{
- system(buf);
+ ignore_result(system(buf));
}
}
}
@@ -280,7 +280,10 @@ dumm_t *dumm_create(char *dir)
}
if (dir)
{
- asprintf(&this->dir, "%s/%s", cwd, dir);
+ if (asprintf(&this->dir, "%s/%s", cwd, dir) < 0)
+ {
+ this->dir = NULL;
+ }
}
else
{
@@ -288,17 +291,21 @@ dumm_t *dumm_create(char *dir)
}
}
this->template = NULL;
- asprintf(&this->guest_dir, "%s/%s", this->dir, GUEST_DIR);
+ if (asprintf(&this->guest_dir, "%s/%s", this->dir, GUEST_DIR) < 0)
+ {
+ this->guest_dir = NULL;
+ }
this->guests = linked_list_create();
this->bridges = linked_list_create();
- if (mkdir(this->guest_dir, PERME) < 0 && errno != EEXIST)
+ if (this->dir == NULL || this->guest_dir == NULL ||
+ (mkdir(this->guest_dir, PERME) < 0 && errno != EEXIST))
{
DBG1("creating guest directory '%s' failed: %m", this->guest_dir);
destroy(this);
return NULL;
}
-
+
load_guests(this);
return &this->public;
}
diff --git a/src/dumm/ext/dumm.c b/src/dumm/ext/dumm.c
index 97f14ef85..2610affc3 100644
--- a/src/dumm/ext/dumm.c
+++ b/src/dumm/ext/dumm.c
@@ -13,7 +13,7 @@
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
- * $Id: dumm.c 4410 2008-10-10 11:20:04Z martin $
+ * $Id: dumm.c 4447 2008-10-15 14:47:52Z martin $
*/
#include <stdio.h>
@@ -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.c b/src/dumm/guest.c
index aed2a3e18..014a9113f 100644
--- a/src/dumm/guest.c
+++ b/src/dumm/guest.c
@@ -576,11 +576,22 @@ static private_guest_t *guest_create_generic(char *parent, char *name,
if (*parent == '/' || getcwd(cwd, sizeof(cwd)) == NULL)
{
- asprintf(&this->dirname, "%s/%s", parent, name);
+ if (asprintf(&this->dirname, "%s/%s", parent, name) < 0)
+ {
+ this->dirname = NULL;
+ }
}
else
{
- asprintf(&this->dirname, "%s/%s/%s", cwd, parent, name);
+ if (asprintf(&this->dirname, "%s/%s/%s", cwd, parent, name) < 0)
+ {
+ this->dirname = NULL;
+ }
+ }
+ if (this->dirname == NULL)
+ {
+ free(this);
+ return NULL;
}
if (create)
{
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/main.c b/src/dumm/main.c
index e2f2fc255..ba2801760 100644
--- a/src/dumm/main.c
+++ b/src/dumm/main.c
@@ -19,6 +19,7 @@
#include <sys/types.h>
#include <unistd.h>
+#include <sched.h>
#include <glib.h>
#include <gtk/gtk.h>
diff --git a/src/dumm/mconsole.c b/src/dumm/mconsole.c
index c6e0c2f08..02db5ab7e 100644
--- a/src/dumm/mconsole.c
+++ b/src/dumm/mconsole.c
@@ -201,13 +201,13 @@ 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);
}
/**
* Poll until guest is ready
*/
-static bool wait_bootup(private_mconsole_t *this)
+static void wait_bootup(private_mconsole_t *this)
{
/* wait for init process to appear */
while (request(this, ignore, NULL, "exec ps -p 1 > /dev/null"))
@@ -247,7 +247,7 @@ static bool wait_for_notify(private_mconsole_t *this, char *nsock)
}
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
- strncpy(addr.sun_path, nsock, sizeof(addr));
+ strncpy(addr.sun_path, nsock, sizeof(addr.sun_path));
if (bind(this->notify, (struct sockaddr*)&addr, sizeof(addr)) < 0)
{
DBG1("binding mconsole notify socket to '%s' failed: %m", nsock);
@@ -306,7 +306,7 @@ static bool setup_console(private_mconsole_t *this)
}
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
- snprintf(&addr.sun_path[1], sizeof(addr.sun_path), "%5d-%d",
+ snprintf(&addr.sun_path[1], sizeof(addr.sun_path)-1, "%5d-%d",
getpid(), this->console);
if (bind(this->console, (struct sockaddr*)&addr, sizeof(addr)) < 0)
{
@@ -346,11 +346,7 @@ mconsole_t *mconsole_create(char *notify, void(*idle)(void))
}
unlink(notify);
- if (!wait_bootup(this))
- {
- destroy(this);
- return NULL;
- }
+ wait_bootup(this);
return &this->public;
}
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