removed trailing spaces ([[:space:]]+$)
This commit is contained in:
+3
-3
@@ -36,7 +36,7 @@ struct private_bridge_t {
|
||||
* defined in iface.c
|
||||
*/
|
||||
bool iface_control(char *name, bool up);
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of bridge_t.get_name.
|
||||
*/
|
||||
@@ -149,7 +149,7 @@ static void destroy(private_bridge_t *this)
|
||||
bridge_t *bridge_create(char *name)
|
||||
{
|
||||
private_bridge_t *this;
|
||||
|
||||
|
||||
if (instances == 0)
|
||||
{
|
||||
if (br_init() != 0)
|
||||
@@ -158,7 +158,7 @@ bridge_t *bridge_create(char *name)
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this = malloc_thing(private_bridge_t);
|
||||
this->public.get_name = (char*(*)(bridge_t*))get_name;
|
||||
this->public.create_iface_enumerator = (enumerator_t*(*)(bridge_t*))create_iface_enumerator;
|
||||
|
||||
+6
-6
@@ -27,14 +27,14 @@ typedef struct bridge_t bridge_t;
|
||||
* Interface in a guest, connected to a tap device on the host.
|
||||
*/
|
||||
struct bridge_t {
|
||||
|
||||
|
||||
/**
|
||||
* Get the name of the bridge.
|
||||
*
|
||||
* @return name of the bridge
|
||||
*/
|
||||
char* (*get_name)(bridge_t *this);
|
||||
|
||||
|
||||
/**
|
||||
* Add an interface to a bridge.
|
||||
*
|
||||
@@ -42,7 +42,7 @@ struct bridge_t {
|
||||
* @return TRUE if interface added
|
||||
*/
|
||||
bool (*connect_iface)(bridge_t *this, iface_t *iface);
|
||||
|
||||
|
||||
/**
|
||||
* Remove an interface from a bridge.
|
||||
*
|
||||
@@ -50,14 +50,14 @@ struct bridge_t {
|
||||
* @return TRUE if interface removed
|
||||
*/
|
||||
bool (*disconnect_iface)(bridge_t *this, iface_t *iface);
|
||||
|
||||
|
||||
/**
|
||||
* Create an enumerator over all interfaces.
|
||||
*
|
||||
* @return enumerator over iface_t's
|
||||
*/
|
||||
enumerator_t* (*create_iface_enumerator)(bridge_t *this);
|
||||
|
||||
enumerator_t* (*create_iface_enumerator)(bridge_t *this);
|
||||
|
||||
/**
|
||||
* Destroy a bridge
|
||||
*/
|
||||
|
||||
+53
-53
@@ -96,7 +96,7 @@ static void rel(const char **path)
|
||||
static int get_rd(const char *path)
|
||||
{
|
||||
private_cowfs_t *this = get_this();
|
||||
|
||||
|
||||
if (this->over_fd > 0 && faccessat(this->over_fd, path, F_OK, 0) == 0)
|
||||
{
|
||||
return this->over_fd;
|
||||
@@ -130,7 +130,7 @@ static bool clone_path(int rd, int wr, const char *path)
|
||||
struct stat st;
|
||||
full = strdupa(path);
|
||||
pos = full;
|
||||
|
||||
|
||||
while ((pos = strchr(pos, '/')))
|
||||
{
|
||||
*pos = '\0';
|
||||
@@ -162,10 +162,10 @@ static int copy(const char *path)
|
||||
int rd, wr;
|
||||
int from, to;
|
||||
struct stat st;
|
||||
|
||||
|
||||
rd = get_rd(path);
|
||||
wr = get_wr(path);
|
||||
|
||||
|
||||
if (rd == wr)
|
||||
{
|
||||
/* already writeable */
|
||||
@@ -223,7 +223,7 @@ static int copy(const char *path)
|
||||
static int cowfs_getattr(const char *path, struct stat *stbuf)
|
||||
{
|
||||
rel(&path);
|
||||
|
||||
|
||||
if (fstatat(get_rd(path), path, stbuf, AT_SYMLINK_NOFOLLOW) < 0)
|
||||
{
|
||||
return -errno;
|
||||
@@ -237,7 +237,7 @@ static int cowfs_getattr(const char *path, struct stat *stbuf)
|
||||
static int cowfs_access(const char *path, int mask)
|
||||
{
|
||||
rel(&path);
|
||||
|
||||
|
||||
if (faccessat(get_rd(path), path, mask, 0) < 0)
|
||||
{
|
||||
return -errno;
|
||||
@@ -251,9 +251,9 @@ static int cowfs_access(const char *path, int mask)
|
||||
static int cowfs_readlink(const char *path, char *buf, size_t size)
|
||||
{
|
||||
int res;
|
||||
|
||||
|
||||
rel(&path);
|
||||
|
||||
|
||||
res = readlinkat(get_rd(path), path, buf, size - 1);
|
||||
if (res < 0)
|
||||
{
|
||||
@@ -269,16 +269,16 @@ static int cowfs_readlink(const char *path, char *buf, size_t size)
|
||||
static DIR* get_dir(char *dir, const char *subdir)
|
||||
{
|
||||
char *full;
|
||||
|
||||
|
||||
if (dir == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
full = alloca(strlen(dir) + strlen(subdir) + 1);
|
||||
strcpy(full, dir);
|
||||
strcat(full, subdir);
|
||||
|
||||
|
||||
return opendir(full);
|
||||
}
|
||||
|
||||
@@ -290,7 +290,7 @@ static bool contains_dir(DIR *d, char *dirname)
|
||||
if (d)
|
||||
{
|
||||
struct dirent *ent;
|
||||
|
||||
|
||||
rewinddir(d);
|
||||
while ((ent = readdir(d)))
|
||||
{
|
||||
@@ -313,13 +313,13 @@ static int cowfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
|
||||
DIR *d1, *d2, *d3;
|
||||
struct stat st;
|
||||
struct dirent *ent;
|
||||
|
||||
|
||||
memset(&st, 0, sizeof(st));
|
||||
|
||||
|
||||
d1 = get_dir(this->master, path);
|
||||
d2 = get_dir(this->host, path);
|
||||
d3 = get_dir(this->over, path);
|
||||
|
||||
|
||||
if (d1)
|
||||
{
|
||||
while ((ent = readdir(d1)))
|
||||
@@ -369,13 +369,13 @@ static int cowfs_mknod(const char *path, mode_t mode, dev_t rdev)
|
||||
{
|
||||
int fd;
|
||||
rel(&path);
|
||||
|
||||
|
||||
fd = get_wr(path);
|
||||
if (!clone_path(get_rd(path), fd, path))
|
||||
{
|
||||
return -errno;
|
||||
}
|
||||
|
||||
|
||||
if (mknodat(fd, path, mode, rdev) < 0)
|
||||
{
|
||||
return -errno;
|
||||
@@ -390,7 +390,7 @@ static int cowfs_mkdir(const char *path, mode_t mode)
|
||||
{
|
||||
int fd;
|
||||
rel(&path);
|
||||
|
||||
|
||||
fd = get_wr(path);
|
||||
if (!clone_path(get_rd(path), fd, path))
|
||||
{
|
||||
@@ -409,7 +409,7 @@ static int cowfs_mkdir(const char *path, mode_t mode)
|
||||
static int cowfs_unlink(const char *path)
|
||||
{
|
||||
rel(&path);
|
||||
|
||||
|
||||
/* TODO: whiteout master */
|
||||
if (unlinkat(get_wr(path), path, 0) < 0)
|
||||
{
|
||||
@@ -424,7 +424,7 @@ static int cowfs_unlink(const char *path)
|
||||
static int cowfs_rmdir(const char *path)
|
||||
{
|
||||
rel(&path);
|
||||
|
||||
|
||||
/* TODO: whiteout master */
|
||||
if (unlinkat(get_wr(path), path, AT_REMOVEDIR) < 0)
|
||||
{
|
||||
@@ -440,10 +440,10 @@ static int cowfs_symlink(const char *from, const char *to)
|
||||
{
|
||||
int fd;
|
||||
const char *fromrel = from;
|
||||
|
||||
|
||||
rel(&to);
|
||||
rel(&fromrel);
|
||||
|
||||
|
||||
fd = get_wr(to);
|
||||
if (!clone_path(get_rd(fromrel), fd, fromrel))
|
||||
{
|
||||
@@ -462,10 +462,10 @@ static int cowfs_symlink(const char *from, const char *to)
|
||||
static int cowfs_rename(const char *from, const char *to)
|
||||
{
|
||||
int fd;
|
||||
|
||||
|
||||
rel(&from);
|
||||
rel(&to);
|
||||
|
||||
|
||||
fd = copy(from);
|
||||
if (fd < 0)
|
||||
{
|
||||
@@ -484,13 +484,13 @@ static int cowfs_rename(const char *from, const char *to)
|
||||
static int cowfs_link(const char *from, const char *to)
|
||||
{
|
||||
int rd, wr;
|
||||
|
||||
|
||||
rel(&from);
|
||||
rel(&to);
|
||||
|
||||
|
||||
rd = get_rd(from);
|
||||
wr = get_wr(to);
|
||||
|
||||
|
||||
if (!clone_path(rd, wr, to))
|
||||
{
|
||||
DBG1("cloning path '%s' failed", to);
|
||||
@@ -511,7 +511,7 @@ static int cowfs_chmod(const char *path, mode_t mode)
|
||||
{
|
||||
int fd;
|
||||
struct stat st;
|
||||
|
||||
|
||||
rel(&path);
|
||||
fd = get_rd(path);
|
||||
if (fstatat(fd, path, &st, 0) < 0)
|
||||
@@ -541,7 +541,7 @@ static int cowfs_chown(const char *path, uid_t uid, gid_t gid)
|
||||
{
|
||||
int fd;
|
||||
struct stat st;
|
||||
|
||||
|
||||
rel(&path);
|
||||
fd = get_rd(path);
|
||||
if (fstatat(fd, path, &st, 0) < 0)
|
||||
@@ -571,7 +571,7 @@ static int cowfs_truncate(const char *path, off_t size)
|
||||
{
|
||||
int fd;
|
||||
struct stat st;
|
||||
|
||||
|
||||
rel(&path);
|
||||
fd = get_rd(path);
|
||||
if (fstatat(fd, path, &st, 0) < 0)
|
||||
@@ -608,19 +608,19 @@ static int cowfs_utimens(const char *path, const struct timespec ts[2])
|
||||
{
|
||||
struct timeval tv[2];
|
||||
int fd;
|
||||
|
||||
|
||||
rel(&path);
|
||||
fd = copy(path);
|
||||
if (fd < 0)
|
||||
{
|
||||
return -errno;
|
||||
}
|
||||
|
||||
|
||||
tv[0].tv_sec = ts[0].tv_sec;
|
||||
tv[0].tv_usec = ts[0].tv_nsec / 1000;
|
||||
tv[1].tv_sec = ts[1].tv_sec;
|
||||
tv[1].tv_usec = ts[1].tv_nsec / 1000;
|
||||
|
||||
|
||||
if (futimesat(fd, path, tv) < 0)
|
||||
{
|
||||
return -errno;
|
||||
@@ -634,10 +634,10 @@ static int cowfs_utimens(const char *path, const struct timespec ts[2])
|
||||
static int cowfs_open(const char *path, struct fuse_file_info *fi)
|
||||
{
|
||||
int fd;
|
||||
|
||||
|
||||
rel(&path);
|
||||
fd = get_rd(path);
|
||||
|
||||
|
||||
fd = openat(fd, path, fi->flags);
|
||||
if (fd < 0)
|
||||
{
|
||||
@@ -654,17 +654,17 @@ static int cowfs_read(const char *path, char *buf, size_t size, off_t offset,
|
||||
struct fuse_file_info *fi)
|
||||
{
|
||||
int file, fd, res;
|
||||
|
||||
|
||||
rel(&path);
|
||||
|
||||
|
||||
fd = get_rd(path);
|
||||
|
||||
|
||||
file = openat(fd, path, O_RDONLY);
|
||||
if (file < 0)
|
||||
{
|
||||
return -errno;
|
||||
}
|
||||
|
||||
|
||||
res = pread(file, buf, size, offset);
|
||||
if (res < 0)
|
||||
{
|
||||
@@ -681,9 +681,9 @@ static int cowfs_write(const char *path, const char *buf, size_t size,
|
||||
off_t offset, struct fuse_file_info *fi)
|
||||
{
|
||||
int file, fd, res;
|
||||
|
||||
|
||||
rel(&path);
|
||||
|
||||
|
||||
fd = copy(path);
|
||||
if (fd < 0)
|
||||
{
|
||||
@@ -709,25 +709,25 @@ static int cowfs_write(const char *path, const char *buf, size_t size,
|
||||
static int cowfs_statfs(const char *path, struct statvfs *stbuf)
|
||||
{
|
||||
int fd;
|
||||
|
||||
|
||||
fd = get_rd(path);
|
||||
if (fstatvfs(fd, stbuf) < 0)
|
||||
{
|
||||
return -errno;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* FUSE init method
|
||||
*/
|
||||
static void *cowfs_init(struct fuse_conn_info *conn)
|
||||
{
|
||||
struct fuse_context *ctx;
|
||||
|
||||
|
||||
ctx = fuse_get_context();
|
||||
|
||||
|
||||
return ctx->private_data;
|
||||
}
|
||||
|
||||
@@ -814,10 +814,10 @@ cowfs_t *cowfs_create(char *master, char *host, char *mount)
|
||||
{
|
||||
struct fuse_args args = {0, NULL, 0};
|
||||
private_cowfs_t *this = malloc_thing(private_cowfs_t);
|
||||
|
||||
|
||||
this->public.set_overlay = (bool(*)(cowfs_t*, char *path))set_overlay;
|
||||
this->public.destroy = (void(*)(cowfs_t*))destroy;
|
||||
|
||||
|
||||
this->master_fd = open(master, O_RDONLY | O_DIRECTORY);
|
||||
if (this->master_fd < 0)
|
||||
{
|
||||
@@ -834,7 +834,7 @@ cowfs_t *cowfs_create(char *master, char *host, char *mount)
|
||||
return NULL;
|
||||
}
|
||||
this->over_fd = -1;
|
||||
|
||||
|
||||
this->chan = fuse_mount(mount, &args);
|
||||
if (this->chan == NULL)
|
||||
{
|
||||
@@ -844,7 +844,7 @@ cowfs_t *cowfs_create(char *master, char *host, char *mount)
|
||||
free(this);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
this->fuse = fuse_new(this->chan, &args, &cowfs_operations,
|
||||
sizeof(cowfs_operations), this);
|
||||
if (this->fuse == NULL)
|
||||
@@ -856,12 +856,12 @@ cowfs_t *cowfs_create(char *master, char *host, char *mount)
|
||||
free(this);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
this->mount = strdup(mount);
|
||||
this->master = strdup(master);
|
||||
this->host = strdup(host);
|
||||
this->over = NULL;
|
||||
|
||||
|
||||
if (pthread_create(&this->thread, NULL, (void*)fuse_loop, this->fuse) != 0)
|
||||
{
|
||||
DBG1("creating thread to handle FUSE failed");
|
||||
@@ -874,7 +874,7 @@ cowfs_t *cowfs_create(char *master, char *host, char *mount)
|
||||
free(this);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -25,7 +25,7 @@ typedef struct cowfs_t cowfs_t;
|
||||
*
|
||||
*/
|
||||
struct cowfs_t {
|
||||
|
||||
|
||||
/**
|
||||
* Set an additional copy on write overlay.
|
||||
*
|
||||
@@ -33,7 +33,7 @@ struct cowfs_t {
|
||||
* @return FALSE if failed
|
||||
*/
|
||||
bool (*set_overlay)(cowfs_t *this, char *path);
|
||||
|
||||
|
||||
/**
|
||||
* Stop, umount and destroy a cowfs FUSE filesystem.
|
||||
*/
|
||||
|
||||
+22
-22
@@ -52,11 +52,11 @@ struct private_dumm_t {
|
||||
/**
|
||||
* Implementation of dumm_t.create_guest.
|
||||
*/
|
||||
static guest_t* create_guest(private_dumm_t *this, char *name, char *kernel,
|
||||
static guest_t* create_guest(private_dumm_t *this, char *name, char *kernel,
|
||||
char *master, char *args)
|
||||
{
|
||||
guest_t *guest;
|
||||
|
||||
|
||||
guest = guest_create(this->guest_dir, name, kernel, master, args);
|
||||
if (guest)
|
||||
{
|
||||
@@ -82,7 +82,7 @@ static void delete_guest(private_dumm_t *this, guest_t *guest)
|
||||
{
|
||||
char buf[512];
|
||||
int len;
|
||||
|
||||
|
||||
len = snprintf(buf, sizeof(buf), "rm -Rf %s/%s",
|
||||
this->guest_dir, guest->get_name(guest));
|
||||
guest->destroy(guest);
|
||||
@@ -99,7 +99,7 @@ static void delete_guest(private_dumm_t *this, guest_t *guest)
|
||||
static bridge_t* create_bridge(private_dumm_t *this, char *name)
|
||||
{
|
||||
bridge_t *bridge;
|
||||
|
||||
|
||||
bridge = bridge_create(name);
|
||||
if (bridge)
|
||||
{
|
||||
@@ -128,16 +128,16 @@ static void delete_bridge(private_dumm_t *this, bridge_t *bridge)
|
||||
}
|
||||
|
||||
/**
|
||||
* disable the currently enabled template
|
||||
* disable the currently enabled template
|
||||
*/
|
||||
static void clear_template(private_dumm_t *this)
|
||||
{
|
||||
enumerator_t *enumerator;
|
||||
guest_t *guest;
|
||||
|
||||
|
||||
free(this->template);
|
||||
this->template = NULL;
|
||||
|
||||
|
||||
enumerator = this->guests->create_enumerator(this->guests);
|
||||
while (enumerator->enumerate(enumerator, (void**)&guest))
|
||||
{
|
||||
@@ -153,9 +153,9 @@ static bool load_template(private_dumm_t *this, char *dir)
|
||||
{
|
||||
enumerator_t *enumerator;
|
||||
guest_t *guest;
|
||||
|
||||
|
||||
clear_template(this);
|
||||
|
||||
|
||||
if (dir == NULL)
|
||||
{
|
||||
return TRUE;
|
||||
@@ -165,7 +165,7 @@ static bool load_template(private_dumm_t *this, char *dir)
|
||||
DBG1("template directory string '%s' is too long", dir);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
if (asprintf(&this->template, "%s/%s", TEMPLATE_DIR, dir) < 0)
|
||||
{
|
||||
this->template = NULL;
|
||||
@@ -210,7 +210,7 @@ static bool template_enumerate(template_enumerator_t *this, char **template)
|
||||
{
|
||||
struct stat st;
|
||||
char *rel;
|
||||
|
||||
|
||||
while (this->inner->enumerate(this->inner, &rel, NULL, &st))
|
||||
{
|
||||
if (S_ISDIR(st.st_mode) && *rel != '.')
|
||||
@@ -237,12 +237,12 @@ static void template_enumerator_destroy(template_enumerator_t *this)
|
||||
static enumerator_t* create_template_enumerator(private_dumm_t *this)
|
||||
{
|
||||
template_enumerator_t *enumerator;
|
||||
|
||||
|
||||
enumerator = malloc_thing(template_enumerator_t);
|
||||
enumerator->public.enumerate = (void*)template_enumerate;
|
||||
enumerator->public.destroy = (void*)template_enumerator_destroy;
|
||||
enumerator->inner = enumerator_create_directory(TEMPLATE_DIR);
|
||||
|
||||
|
||||
return &enumerator->public;
|
||||
}
|
||||
|
||||
@@ -253,16 +253,16 @@ static void destroy(private_dumm_t *this)
|
||||
{
|
||||
enumerator_t *enumerator;
|
||||
guest_t *guest;
|
||||
|
||||
|
||||
this->bridges->destroy_offset(this->bridges, offsetof(bridge_t, destroy));
|
||||
|
||||
|
||||
enumerator = this->guests->create_enumerator(this->guests);
|
||||
while (enumerator->enumerate(enumerator, (void**)&guest))
|
||||
{
|
||||
guest->stop(guest, NULL);
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
|
||||
|
||||
while (this->guests->remove_last(this->guests, (void**)&guest) == SUCCESS)
|
||||
{
|
||||
guest->destroy(guest);
|
||||
@@ -282,13 +282,13 @@ static void load_guests(private_dumm_t *this)
|
||||
DIR *dir;
|
||||
struct dirent *ent;
|
||||
guest_t *guest;
|
||||
|
||||
|
||||
dir = opendir(this->guest_dir);
|
||||
if (dir == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
while ((ent = readdir(dir)))
|
||||
{
|
||||
if (*ent->d_name == '.')
|
||||
@@ -315,7 +315,7 @@ dumm_t *dumm_create(char *dir)
|
||||
{
|
||||
char cwd[PATH_MAX];
|
||||
private_dumm_t *this = malloc_thing(private_dumm_t);
|
||||
|
||||
|
||||
this->public.create_guest = (guest_t*(*)(dumm_t*,char*,char*,char*,char*))create_guest;
|
||||
this->public.create_guest_enumerator = (enumerator_t*(*)(dumm_t*))create_guest_enumerator;
|
||||
this->public.delete_guest = (void(*)(dumm_t*,guest_t*))delete_guest;
|
||||
@@ -325,7 +325,7 @@ dumm_t *dumm_create(char *dir)
|
||||
this->public.load_template = (bool(*)(dumm_t*, char *name))load_template;
|
||||
this->public.create_template_enumerator = (enumerator_t*(*)(dumm_t*))create_template_enumerator;
|
||||
this->public.destroy = (void(*)(dumm_t*))destroy;
|
||||
|
||||
|
||||
if (dir && *dir == '/')
|
||||
{
|
||||
this->dir = strdup(dir);
|
||||
@@ -356,7 +356,7 @@ dumm_t *dumm_create(char *dir)
|
||||
}
|
||||
this->guests = linked_list_create();
|
||||
this->bridges = linked_list_create();
|
||||
|
||||
|
||||
if (this->dir == NULL || this->guest_dir == NULL ||
|
||||
(mkdir(this->guest_dir, PERME) < 0 && errno != EEXIST))
|
||||
{
|
||||
@@ -364,7 +364,7 @@ dumm_t *dumm_create(char *dir)
|
||||
destroy(this);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
load_guests(this);
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
+9
-9
@@ -43,23 +43,23 @@ struct dumm_t {
|
||||
* @param args additional args to pass to kernel
|
||||
* @return guest if started, NULL if failed
|
||||
*/
|
||||
guest_t* (*create_guest) (dumm_t *this, char *name, char *kernel,
|
||||
guest_t* (*create_guest) (dumm_t *this, char *name, char *kernel,
|
||||
char *master, char *args);
|
||||
|
||||
|
||||
/**
|
||||
* Create an enumerator over all guests.
|
||||
*
|
||||
* @return enumerator over guest_t's
|
||||
*/
|
||||
enumerator_t* (*create_guest_enumerator) (dumm_t *this);
|
||||
|
||||
|
||||
/**
|
||||
* Delete a guest from disk.
|
||||
*
|
||||
* @param guest guest to destroy
|
||||
*/
|
||||
void (*delete_guest) (dumm_t *this, guest_t *guest);
|
||||
|
||||
|
||||
/**
|
||||
* Create a new bridge.
|
||||
*
|
||||
@@ -67,21 +67,21 @@ struct dumm_t {
|
||||
* @return created bridge
|
||||
*/
|
||||
bridge_t* (*create_bridge)(dumm_t *this, char *name);
|
||||
|
||||
|
||||
/**
|
||||
* Create an enumerator over all bridges.
|
||||
*
|
||||
* @return enumerator over bridge_t's
|
||||
*/
|
||||
enumerator_t* (*create_bridge_enumerator)(dumm_t *this);
|
||||
|
||||
|
||||
/**
|
||||
* Delete a bridge.
|
||||
*
|
||||
* @param bridge bridge to destroy
|
||||
*/
|
||||
void (*delete_bridge) (dumm_t *this, bridge_t *bridge);
|
||||
|
||||
|
||||
/**
|
||||
* Loads a template, create a new one if it does not exist.
|
||||
*
|
||||
@@ -89,14 +89,14 @@ struct dumm_t {
|
||||
* @return FALSE if load/create failed
|
||||
*/
|
||||
bool (*load_template)(dumm_t *this, char *dir);
|
||||
|
||||
|
||||
/**
|
||||
* Create an enumerator over all available templates.
|
||||
*
|
||||
* @return enumerator over char*
|
||||
*/
|
||||
enumerator_t* (*create_template_enumerator)(dumm_t *this);
|
||||
|
||||
|
||||
/**
|
||||
* stop all guests and destroy the modeler
|
||||
*/
|
||||
|
||||
+46
-46
@@ -45,7 +45,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 +71,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 +91,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 +128,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 +152,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 +165,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 +173,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 +186,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 +195,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 +210,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 +226,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 +241,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 +256,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 +295,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 +319,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 +334,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 +362,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 +399,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 +423,7 @@ static VALUE bridge_new(VALUE class, VALUE name)
|
||||
|
||||
{
|
||||
bridge_t *bridge;
|
||||
|
||||
|
||||
bridge = dumm->create_bridge(dumm, StringValuePtr(name));
|
||||
if (!bridge)
|
||||
{
|
||||
@@ -435,7 +435,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 +446,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 +470,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 +481,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 +499,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 +508,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 +522,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 +536,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 +563,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 +589,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 +613,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 +624,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 +656,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 +673,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 +685,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 +702,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);
|
||||
}
|
||||
|
||||
+38
-38
@@ -97,13 +97,13 @@ static iface_t* create_iface(private_guest_t *this, char *name)
|
||||
{
|
||||
enumerator_t *enumerator;
|
||||
iface_t *iface;
|
||||
|
||||
|
||||
if (this->state != GUEST_RUNNING)
|
||||
{
|
||||
DBG1("guest '%s' not running, unable to add interface", this->name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
enumerator = this->ifaces->create_enumerator(this->ifaces);
|
||||
while (enumerator->enumerate(enumerator, (void**)&iface))
|
||||
{
|
||||
@@ -131,7 +131,7 @@ static void destroy_iface(private_guest_t *this, iface_t *iface)
|
||||
{
|
||||
enumerator_t *enumerator;
|
||||
iface_t *current;
|
||||
|
||||
|
||||
enumerator = this->ifaces->create_enumerator(this->ifaces);
|
||||
while (enumerator->enumerate(enumerator, (void**)¤t))
|
||||
{
|
||||
@@ -152,7 +152,7 @@ static enumerator_t* create_iface_enumerator(private_guest_t *this)
|
||||
{
|
||||
return this->ifaces->create_enumerator(this->ifaces);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of guest_t.get_state.
|
||||
*/
|
||||
@@ -224,7 +224,7 @@ static void stop(private_guest_t *this, idle_function_t idle)
|
||||
void savepid(private_guest_t *this)
|
||||
{
|
||||
FILE *file;
|
||||
|
||||
|
||||
file = fdopen(openat(this->dir, PID_FILE, O_RDWR | O_CREAT | O_TRUNC,
|
||||
PERM), "w");
|
||||
if (file)
|
||||
@@ -246,18 +246,18 @@ static bool start(private_guest_t *this, invoke_function_t invoke, void* data,
|
||||
char *args[32];
|
||||
int i = 0;
|
||||
size_t left = sizeof(buf);
|
||||
|
||||
|
||||
memset(args, 0, sizeof(args));
|
||||
|
||||
|
||||
if (this->state != GUEST_STOPPED)
|
||||
{
|
||||
DBG1("unable to start guest in state %N", guest_state_names, this->state);
|
||||
return FALSE;
|
||||
}
|
||||
this->state = GUEST_STARTING;
|
||||
|
||||
|
||||
notify = write_arg(&pos, &left, "%s/%s", this->dirname, NOTIFY_FILE);
|
||||
|
||||
|
||||
args[i++] = write_arg(&pos, &left, "nice");
|
||||
args[i++] = write_arg(&pos, &left, "%s/%s", this->dirname, KERNEL_FILE);
|
||||
args[i++] = write_arg(&pos, &left, "root=/dev/root");
|
||||
@@ -271,7 +271,7 @@ static bool start(private_guest_t *this, invoke_function_t invoke, void* data,
|
||||
{
|
||||
args[i++] = this->args;
|
||||
}
|
||||
|
||||
|
||||
this->pid = invoke(data, &this->public, args, i);
|
||||
if (!this->pid)
|
||||
{
|
||||
@@ -279,7 +279,7 @@ static bool start(private_guest_t *this, invoke_function_t invoke, void* data,
|
||||
return FALSE;
|
||||
}
|
||||
savepid(this);
|
||||
|
||||
|
||||
/* open mconsole */
|
||||
this->mconsole = mconsole_create(notify, idle);
|
||||
if (this->mconsole == NULL)
|
||||
@@ -288,11 +288,11 @@ static bool start(private_guest_t *this, invoke_function_t invoke, void* data,
|
||||
stop(this, NULL);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
this->state = GUEST_RUNNING;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of guest_t.load_template.
|
||||
*/
|
||||
@@ -300,12 +300,12 @@ static bool load_template(private_guest_t *this, char *path)
|
||||
{
|
||||
char dir[PATH_MAX];
|
||||
size_t len;
|
||||
|
||||
|
||||
if (path == NULL)
|
||||
{
|
||||
return this->cowfs->set_overlay(this->cowfs, NULL);
|
||||
return this->cowfs->set_overlay(this->cowfs, NULL);
|
||||
}
|
||||
|
||||
|
||||
len = snprintf(dir, sizeof(dir), "%s/%s", path, this->name);
|
||||
if (len < 0 || len >= sizeof(dir))
|
||||
{
|
||||
@@ -334,11 +334,11 @@ static int vexec(private_guest_t *this, void(*cb)(void*,char*,size_t), void *dat
|
||||
{
|
||||
char buf[1024];
|
||||
size_t len;
|
||||
|
||||
|
||||
if (this->mconsole)
|
||||
{
|
||||
len = vsnprintf(buf, sizeof(buf), cmd, args);
|
||||
|
||||
|
||||
if (len > 0 && len < sizeof(buf))
|
||||
{
|
||||
return this->mconsole->exec(this->mconsole, cb, data, buf);
|
||||
@@ -389,7 +389,7 @@ static void exec_str_cb(exec_str_t *data, char *buf, size_t len)
|
||||
}
|
||||
strncat(data->buf.ptr, buf, len);
|
||||
}
|
||||
|
||||
|
||||
if (data->cb)
|
||||
{
|
||||
char *nl;
|
||||
@@ -477,7 +477,7 @@ static bool mount_unionfs(private_guest_t *this)
|
||||
snprintf(master, sizeof(master), "%s/%s", this->dirname, MASTER_DIR);
|
||||
snprintf(diff, sizeof(diff), "%s/%s", this->dirname, DIFF_DIR);
|
||||
snprintf(mount, sizeof(mount), "%s/%s", this->dirname, UNION_DIR);
|
||||
|
||||
|
||||
this->cowfs = cowfs_create(master, diff, mount);
|
||||
if (this->cowfs)
|
||||
{
|
||||
@@ -494,7 +494,7 @@ char *loadargs(private_guest_t *this)
|
||||
{
|
||||
FILE *file;
|
||||
char buf[512], *args = NULL;
|
||||
|
||||
|
||||
file = fdopen(openat(this->dir, ARGS_FILE, O_RDONLY, PERM), "r");
|
||||
if (file)
|
||||
{
|
||||
@@ -514,7 +514,7 @@ bool saveargs(private_guest_t *this, char *args)
|
||||
{
|
||||
FILE *file;
|
||||
bool retval = FALSE;
|
||||
|
||||
|
||||
file = fdopen(openat(this->dir, ARGS_FILE, O_RDWR | O_CREAT | O_TRUNC,
|
||||
PERM), "w");
|
||||
if (file)
|
||||
@@ -554,7 +554,7 @@ static private_guest_t *guest_create_generic(char *parent, char *name,
|
||||
{
|
||||
char cwd[PATH_MAX];
|
||||
private_guest_t *this = malloc_thing(private_guest_t);
|
||||
|
||||
|
||||
this->public.get_name = (void*)get_name;
|
||||
this->public.get_pid = (pid_t(*)(guest_t*))get_pid;
|
||||
this->public.get_state = (guest_state_t(*)(guest_t*))get_state;
|
||||
@@ -568,7 +568,7 @@ static private_guest_t *guest_create_generic(char *parent, char *name,
|
||||
this->public.exec_str = (int(*)(guest_t*, void(*cb)(void*,char*),bool,void*,char*,...))exec_str;
|
||||
this->public.sigchild = (void(*)(guest_t*))sigchild;
|
||||
this->public.destroy = (void*)destroy;
|
||||
|
||||
|
||||
if (*parent == '/' || getcwd(cwd, sizeof(cwd)) == NULL)
|
||||
{
|
||||
if (asprintf(&this->dirname, "%s/%s", parent, name) < 0)
|
||||
@@ -607,7 +607,7 @@ static private_guest_t *guest_create_generic(char *parent, char *name,
|
||||
this->args = NULL;
|
||||
this->name = strdup(name);
|
||||
this->cowfs = NULL;
|
||||
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -618,7 +618,7 @@ static bool make_symlink(private_guest_t *this, char *old, char *new)
|
||||
{
|
||||
char cwd[PATH_MAX];
|
||||
char buf[PATH_MAX];
|
||||
|
||||
|
||||
if (*old == '/' || getcwd(cwd, sizeof(cwd)) == NULL)
|
||||
{
|
||||
snprintf(buf, sizeof(buf), "%s", old);
|
||||
@@ -632,18 +632,18 @@ static bool make_symlink(private_guest_t *this, char *old, char *new)
|
||||
|
||||
|
||||
/**
|
||||
* create the guest instance, including required dirs and mounts
|
||||
* create the guest instance, including required dirs and mounts
|
||||
*/
|
||||
guest_t *guest_create(char *parent, char *name, char *kernel,
|
||||
char *master, char *args)
|
||||
{
|
||||
private_guest_t *this = guest_create_generic(parent, name, TRUE);
|
||||
|
||||
|
||||
if (this == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
if (!make_symlink(this, master, MASTER_DIR) ||
|
||||
!make_symlink(this, kernel, KERNEL_FILE))
|
||||
{
|
||||
@@ -651,22 +651,22 @@ guest_t *guest_create(char *parent, char *name, char *kernel,
|
||||
destroy(this);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (mkdirat(this->dir, UNION_DIR, PERME) != 0 ||
|
||||
|
||||
if (mkdirat(this->dir, UNION_DIR, PERME) != 0 ||
|
||||
mkdirat(this->dir, DIFF_DIR, PERME) != 0)
|
||||
{
|
||||
DBG1("unable to create directories for '%s': %m", name);
|
||||
destroy(this);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
this->args = args;
|
||||
if (args && !saveargs(this, args))
|
||||
{
|
||||
destroy(this);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
if (!mount_unionfs(this))
|
||||
{
|
||||
destroy(this);
|
||||
@@ -682,20 +682,20 @@ guest_t *guest_create(char *parent, char *name, char *kernel,
|
||||
guest_t *guest_load(char *parent, char *name)
|
||||
{
|
||||
private_guest_t *this = guest_create_generic(parent, name, FALSE);
|
||||
|
||||
|
||||
if (this == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
this->args = loadargs(this);
|
||||
|
||||
|
||||
if (!mount_unionfs(this))
|
||||
{
|
||||
destroy(this);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
|
||||
+20
-20
@@ -56,10 +56,10 @@ extern enum_name_t *guest_state_names;
|
||||
* @param guest guest to start
|
||||
* @param args args to use for guest invocation, args[0] is kernel
|
||||
* @param argc number of elements in args
|
||||
* @param idle
|
||||
* @param idle
|
||||
* @return PID of child, 0 if failed
|
||||
*/
|
||||
typedef pid_t (*invoke_function_t)(void *data, guest_t *guest,
|
||||
typedef pid_t (*invoke_function_t)(void *data, guest_t *guest,
|
||||
char *args[], int argc);
|
||||
|
||||
/**
|
||||
@@ -71,28 +71,28 @@ typedef void (*idle_function_t)(void);
|
||||
* A guest is a UML instance running on the host.
|
||||
**/
|
||||
struct guest_t {
|
||||
|
||||
|
||||
/**
|
||||
* Get the name of this guest.
|
||||
*
|
||||
* @return name of the guest
|
||||
*/
|
||||
char* (*get_name) (guest_t *this);
|
||||
|
||||
|
||||
/**
|
||||
* Get the process ID of the guest child process.
|
||||
*
|
||||
* @return name of the guest
|
||||
*/
|
||||
pid_t (*get_pid) (guest_t *this);
|
||||
|
||||
|
||||
/**
|
||||
* Get the state of the guest (stopped, started, etc.).
|
||||
*
|
||||
* @return guests state
|
||||
*/
|
||||
guest_state_t (*get_state)(guest_t *this);
|
||||
|
||||
guest_state_t (*get_state)(guest_t *this);
|
||||
|
||||
/**
|
||||
* Start the guest.
|
||||
*
|
||||
@@ -103,14 +103,14 @@ struct guest_t {
|
||||
*/
|
||||
bool (*start) (guest_t *this, invoke_function_t invoke, void *data,
|
||||
idle_function_t idle);
|
||||
|
||||
|
||||
/**
|
||||
* Kill the guest.
|
||||
*
|
||||
* @param idle idle function to call while waiting to termination
|
||||
*/
|
||||
void (*stop) (guest_t *this, idle_function_t idle);
|
||||
|
||||
|
||||
/**
|
||||
* Create a new interface in the current scenario.
|
||||
*
|
||||
@@ -118,21 +118,21 @@ struct guest_t {
|
||||
* @return created interface, or NULL if failed
|
||||
*/
|
||||
iface_t* (*create_iface)(guest_t *this, char *name);
|
||||
|
||||
|
||||
/**
|
||||
* Destroy an interface on guest.
|
||||
*
|
||||
* @param iface interface to destroy
|
||||
*/
|
||||
void (*destroy_iface)(guest_t *this, iface_t *iface);
|
||||
|
||||
|
||||
/**
|
||||
* Create an enumerator over all guest interfaces.
|
||||
*
|
||||
* @return enumerator over iface_t's
|
||||
*/
|
||||
enumerator_t* (*create_iface_enumerator)(guest_t *this);
|
||||
|
||||
|
||||
/**
|
||||
* Set the template COWFS overlay to use.
|
||||
*
|
||||
@@ -140,7 +140,7 @@ struct guest_t {
|
||||
* @return FALSE if failed
|
||||
*/
|
||||
bool (*load_template)(guest_t *this, char *parent);
|
||||
|
||||
|
||||
/**
|
||||
* Execute a command on the guests mconsole.
|
||||
*
|
||||
@@ -152,15 +152,15 @@ struct guest_t {
|
||||
*/
|
||||
int (*exec)(guest_t *this, void(*cb)(void*,char*,size_t), void *data,
|
||||
char *cmd, ...);
|
||||
|
||||
|
||||
/**
|
||||
* Execute a command on the guests mconsole, with output formatter.
|
||||
*
|
||||
*
|
||||
* 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
|
||||
* @param data data to pass to callback
|
||||
@@ -170,15 +170,15 @@ struct guest_t {
|
||||
*/
|
||||
int (*exec_str)(guest_t *this, void(*cb)(void*,char*), bool lines,
|
||||
void *data, char *cmd, ...);
|
||||
|
||||
|
||||
/**
|
||||
* Called whenever a SIGCHILD for the guests PID is received.
|
||||
*/
|
||||
void (*sigchild)(guest_t *this);
|
||||
|
||||
|
||||
/**
|
||||
* Close and destroy a guest with all interfaces
|
||||
*/
|
||||
*/
|
||||
void (*destroy) (guest_t *this);
|
||||
};
|
||||
|
||||
|
||||
+8
-8
@@ -55,10 +55,10 @@ bool iface_control(char *name, bool up)
|
||||
int s;
|
||||
bool good = FALSE;
|
||||
struct ifreq ifr;
|
||||
|
||||
|
||||
memset(&ifr, 0, sizeof(struct ifreq));
|
||||
strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
||||
|
||||
|
||||
s = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (!s)
|
||||
{
|
||||
@@ -104,7 +104,7 @@ 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,
|
||||
return (this->guest->exec(this->guest, NULL, NULL,
|
||||
"exec ip addr add %H dev %s", addr, this->guestif) == 0);
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ static guest_t* get_guest(private_iface_t *this)
|
||||
{
|
||||
return this->guest;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* destroy the tap device
|
||||
*/
|
||||
@@ -193,7 +193,7 @@ static bool destroy_tap(private_iface_t *this)
|
||||
{
|
||||
struct ifreq ifr;
|
||||
int tap;
|
||||
|
||||
|
||||
if (!iface_control(this->hostif, FALSE))
|
||||
{
|
||||
DBG1("bringing iface down failed: %m");
|
||||
@@ -201,7 +201,7 @@ static bool destroy_tap(private_iface_t *this)
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
|
||||
strncpy(ifr.ifr_name, this->hostif, sizeof(ifr.ifr_name) - 1);
|
||||
|
||||
|
||||
tap = open(TAP_DEVICE, O_RDWR);
|
||||
if (tap < 0)
|
||||
{
|
||||
@@ -245,7 +245,7 @@ static char* create_tap(private_iface_t *this)
|
||||
DBG1("creating new tap device failed: %m");
|
||||
close(tap);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
close(tap);
|
||||
return strdup(ifr.ifr_name);
|
||||
}
|
||||
@@ -274,7 +274,7 @@ static void destroy(private_iface_t *this)
|
||||
iface_t *iface_create(char *name, guest_t *guest, mconsole_t *mconsole)
|
||||
{
|
||||
private_iface_t *this = malloc_thing(private_iface_t);
|
||||
|
||||
|
||||
this->public.get_hostif = (char*(*)(iface_t*))get_hostif;
|
||||
this->public.get_guestif = (char*(*)(iface_t*))get_guestif;
|
||||
this->public.add_address = (bool(*)(iface_t*, host_t *addr))add_address;
|
||||
|
||||
+10
-10
@@ -32,21 +32,21 @@ typedef struct iface_t iface_t;
|
||||
* Interface in a guest, connected to a tap device on the host.
|
||||
*/
|
||||
struct iface_t {
|
||||
|
||||
|
||||
/**
|
||||
* Get the interface name in the guest (e.g. eth0).
|
||||
*
|
||||
* @return guest interface name
|
||||
*/
|
||||
char* (*get_guestif)(iface_t *this);
|
||||
|
||||
|
||||
/**
|
||||
* Get the interface name at the host (e.g. tap0).
|
||||
*
|
||||
* @return host interface (tap device) name
|
||||
*/
|
||||
char* (*get_hostif)(iface_t *this);
|
||||
|
||||
|
||||
/**
|
||||
* Add an address to the interface.
|
||||
*
|
||||
@@ -54,43 +54,43 @@ struct iface_t {
|
||||
* @return TRUE if address added
|
||||
*/
|
||||
bool (*add_address)(iface_t *this, host_t *addr);
|
||||
|
||||
|
||||
/**
|
||||
* Create an enumerator over all installed addresses.
|
||||
*
|
||||
* @return enumerator over host_t*
|
||||
*/
|
||||
enumerator_t* (*create_address_enumerator)(iface_t *this);
|
||||
|
||||
|
||||
/**
|
||||
* Remove an address from an interface.
|
||||
*
|
||||
* @param addr address to remove
|
||||
* @return TRUE if address removed
|
||||
*/
|
||||
bool (*delete_address)(iface_t *this, host_t *addr);
|
||||
|
||||
bool (*delete_address)(iface_t *this, host_t *addr);
|
||||
|
||||
/**
|
||||
* Set the bridge this interface is attached to.
|
||||
*
|
||||
* @param bridge assigned bridge, or NULL for none
|
||||
*/
|
||||
void (*set_bridge)(iface_t *this, bridge_t *bridge);
|
||||
|
||||
|
||||
/**
|
||||
* Get the bridge this iface is connected, or NULL.
|
||||
*
|
||||
* @return connected bridge, or NULL
|
||||
*/
|
||||
bridge_t* (*get_bridge)(iface_t *this);
|
||||
|
||||
|
||||
/**
|
||||
* Get the guest this iface belongs to.
|
||||
*
|
||||
* @return guest of this iface
|
||||
*/
|
||||
guest_t* (*get_guest)(iface_t *this);
|
||||
|
||||
|
||||
/**
|
||||
* Destroy an interface
|
||||
*/
|
||||
|
||||
+3
-3
@@ -26,10 +26,10 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
int state, i;
|
||||
char buf[512];
|
||||
|
||||
|
||||
ruby_init();
|
||||
ruby_init_loadpath();
|
||||
|
||||
|
||||
rb_eval_string_protect("require 'dumm' and include Dumm", &state);
|
||||
if (state)
|
||||
{
|
||||
@@ -53,7 +53,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
rb_p(ruby_errinfo);
|
||||
}
|
||||
|
||||
|
||||
ruby_finalize();
|
||||
return 0;
|
||||
}
|
||||
|
||||
+61
-61
@@ -62,7 +62,7 @@ static void child_exited(VteReaper *vtereaper, gint pid, gint status)
|
||||
{
|
||||
enumerator_t *enumerator;
|
||||
page_t *page;
|
||||
|
||||
|
||||
enumerator = pages->create_enumerator(pages);
|
||||
while (enumerator->enumerate(enumerator, (void**)&page))
|
||||
{
|
||||
@@ -81,7 +81,7 @@ static page_t* get_page(int num)
|
||||
{
|
||||
enumerator_t *enumerator;
|
||||
page_t *page, *found = NULL;
|
||||
|
||||
|
||||
enumerator = pages->create_enumerator(pages);
|
||||
while (enumerator->enumerate(enumerator, (void**)&page))
|
||||
{
|
||||
@@ -114,7 +114,7 @@ void idle(void)
|
||||
static void start_guest()
|
||||
{
|
||||
page_t *page;
|
||||
|
||||
|
||||
page = get_page(gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)));
|
||||
if (page && page->guest->get_state(page->guest) == GUEST_STOPPED)
|
||||
{
|
||||
@@ -128,7 +128,7 @@ static void start_all_guests()
|
||||
{
|
||||
enumerator_t *enumerator;
|
||||
page_t *page;
|
||||
|
||||
|
||||
enumerator = pages->create_enumerator(pages);
|
||||
while (enumerator->enumerate(enumerator, (void**)&page))
|
||||
{
|
||||
@@ -146,7 +146,7 @@ static void start_all_guests()
|
||||
static void stop_guest()
|
||||
{
|
||||
page_t *page;
|
||||
|
||||
|
||||
page = get_page(gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)));
|
||||
if (page && page->guest->get_state(page->guest) == GUEST_RUNNING)
|
||||
{
|
||||
@@ -163,12 +163,12 @@ static void quit()
|
||||
page_t *page;
|
||||
|
||||
dumm->load_template(dumm, NULL);
|
||||
|
||||
|
||||
enumerator = pages->create_enumerator(pages);
|
||||
while (enumerator->enumerate(enumerator, &page))
|
||||
{
|
||||
if (page->guest->get_state(page->guest) != GUEST_STOPPED)
|
||||
{
|
||||
{
|
||||
page->guest->stop(page->guest, idle);
|
||||
}
|
||||
}
|
||||
@@ -191,32 +191,32 @@ static void create_switch()
|
||||
{
|
||||
GtkWidget *dialog, *table, *label, *name;
|
||||
bridge_t *bridge;
|
||||
|
||||
|
||||
dialog = gtk_dialog_new_with_buttons("Create new switch", GTK_WINDOW(window),
|
||||
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
|
||||
GTK_STOCK_NEW, GTK_RESPONSE_ACCEPT, NULL);
|
||||
|
||||
|
||||
table = gtk_table_new(1, 2, TRUE);
|
||||
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), table);
|
||||
|
||||
|
||||
label = gtk_label_new("Switch name");
|
||||
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, 0, 0, 0, 0);
|
||||
gtk_widget_show(label);
|
||||
|
||||
|
||||
name = gtk_entry_new();
|
||||
gtk_table_attach(GTK_TABLE(table), name, 1, 2, 0, 1,
|
||||
GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0, 0);
|
||||
gtk_widget_show(name);
|
||||
|
||||
|
||||
gtk_widget_show(table);
|
||||
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
switch (gtk_dialog_run(GTK_DIALOG(dialog)))
|
||||
{
|
||||
case GTK_RESPONSE_ACCEPT:
|
||||
{
|
||||
{
|
||||
if (streq(gtk_entry_get_text(GTK_ENTRY(name)), ""))
|
||||
{
|
||||
continue;
|
||||
@@ -250,34 +250,34 @@ static void connect_guest()
|
||||
bridge_t *bridge;
|
||||
iface_t *iface;
|
||||
enumerator_t *enumerator;
|
||||
|
||||
|
||||
page = get_page(gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)));
|
||||
if (!page || page->guest->get_state(page->guest) != GUEST_RUNNING)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
dialog = gtk_dialog_new_with_buttons("Connect guest", GTK_WINDOW(window),
|
||||
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
|
||||
GTK_STOCK_NEW, GTK_RESPONSE_ACCEPT, NULL);
|
||||
|
||||
|
||||
table = gtk_table_new(2, 2, TRUE);
|
||||
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), table);
|
||||
|
||||
|
||||
label = gtk_label_new("Interface name");
|
||||
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, 0, 0, 0, 0);
|
||||
gtk_widget_show(label);
|
||||
|
||||
|
||||
name = gtk_entry_new();
|
||||
gtk_table_attach(GTK_TABLE(table), name, 1, 2, 0, 1,
|
||||
GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0, 0);
|
||||
gtk_widget_show(name);
|
||||
|
||||
|
||||
label = gtk_label_new("Connected switch");
|
||||
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, 0, 0, 0, 0);
|
||||
gtk_widget_show(label);
|
||||
|
||||
|
||||
box = gtk_combo_box_new_text();
|
||||
gtk_table_attach(GTK_TABLE(table), box, 1, 2, 1, 2,
|
||||
GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0, 0);
|
||||
@@ -288,20 +288,20 @@ static void connect_guest()
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
gtk_widget_show(box);
|
||||
|
||||
|
||||
gtk_widget_show(table);
|
||||
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
switch (gtk_dialog_run(GTK_DIALOG(dialog)))
|
||||
{
|
||||
case GTK_RESPONSE_ACCEPT:
|
||||
{
|
||||
{
|
||||
if (streq(gtk_entry_get_text(GTK_ENTRY(name)), ""))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
iface = page->guest->create_iface(page->guest,
|
||||
(char*)gtk_entry_get_text(GTK_ENTRY(name)));
|
||||
if (!iface)
|
||||
@@ -337,7 +337,7 @@ static void disconnect_guest()
|
||||
static void delete_guest()
|
||||
{
|
||||
page_t *page;
|
||||
|
||||
|
||||
page = get_page(gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)));
|
||||
if (page)
|
||||
{
|
||||
@@ -356,7 +356,7 @@ static page_t* create_page(guest_t *guest)
|
||||
{
|
||||
GtkWidget *label;
|
||||
page_t *page;
|
||||
|
||||
|
||||
page = g_new(page_t, 1);
|
||||
page->guest = guest;
|
||||
page->vte = vte_terminal_new();
|
||||
@@ -375,55 +375,55 @@ static void create_guest()
|
||||
{
|
||||
guest_t *guest;
|
||||
GtkWidget *dialog, *table, *label, *name, *kernel, *master, *args;
|
||||
|
||||
|
||||
dialog = gtk_dialog_new_with_buttons("Create new guest", GTK_WINDOW(window),
|
||||
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
|
||||
GTK_STOCK_NEW, GTK_RESPONSE_ACCEPT, NULL);
|
||||
|
||||
|
||||
table = gtk_table_new(4, 2, TRUE);
|
||||
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), table);
|
||||
|
||||
|
||||
label = gtk_label_new("Guest name");
|
||||
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, 0, 0, 0, 0);
|
||||
gtk_widget_show(label);
|
||||
|
||||
|
||||
label = gtk_label_new("UML kernel");
|
||||
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, 0, 0, 0, 0);
|
||||
gtk_widget_show(label);
|
||||
|
||||
|
||||
label = gtk_label_new("Master filesystem");
|
||||
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3, 0, 0, 0, 0);
|
||||
gtk_widget_show(label);
|
||||
|
||||
|
||||
label = gtk_label_new("Kernel arguments");
|
||||
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 3, 4, 0, 0, 0, 0);
|
||||
gtk_widget_show(label);
|
||||
|
||||
|
||||
name = gtk_entry_new();
|
||||
gtk_table_attach(GTK_TABLE(table), name, 1, 2, 0, 1,
|
||||
GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0, 0);
|
||||
gtk_widget_show(name);
|
||||
|
||||
|
||||
kernel = gtk_file_chooser_button_new("Select UML kernel image",
|
||||
GTK_FILE_CHOOSER_ACTION_OPEN);
|
||||
gtk_table_attach(GTK_TABLE(table), kernel, 1, 2, 1, 2,
|
||||
GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0, 0);
|
||||
gtk_widget_show(kernel);
|
||||
|
||||
|
||||
master = gtk_file_chooser_button_new("Select master filesystem",
|
||||
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
|
||||
gtk_table_attach(GTK_TABLE(table), master, 1, 2, 2, 3,
|
||||
GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0, 0);
|
||||
gtk_widget_show(master);
|
||||
|
||||
|
||||
args = gtk_entry_new();
|
||||
gtk_table_attach(GTK_TABLE(table), args, 1, 2, 3, 4,
|
||||
GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0, 0);
|
||||
gtk_widget_show(args);
|
||||
|
||||
|
||||
gtk_widget_show(table);
|
||||
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
switch (gtk_dialog_run(GTK_DIALOG(dialog)))
|
||||
@@ -432,12 +432,12 @@ static void create_guest()
|
||||
{
|
||||
char *sname, *skernel, *smaster, *sargs;
|
||||
page_t *page;
|
||||
|
||||
|
||||
sname = (char*)gtk_entry_get_text(GTK_ENTRY(name));
|
||||
skernel = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(kernel));
|
||||
smaster = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(master));
|
||||
sargs = (char*)gtk_entry_get_text(GTK_ENTRY(args));
|
||||
|
||||
|
||||
if (!sname[0] || !skernel || !smaster)
|
||||
{
|
||||
continue;
|
||||
@@ -469,10 +469,10 @@ int main(int argc, char *argv[])
|
||||
GtkWidget *dummMenu, *guestMenu, *switchMenu;
|
||||
enumerator_t *enumerator;
|
||||
guest_t *guest;
|
||||
|
||||
|
||||
library_init(NULL);
|
||||
gtk_init(&argc, &argv);
|
||||
|
||||
|
||||
pages = linked_list_create();
|
||||
dumm = dumm_create(NULL);
|
||||
|
||||
@@ -483,7 +483,7 @@ int main(int argc, char *argv[])
|
||||
gtk_window_set_default_size(GTK_WINDOW (window), 1000, 500);
|
||||
g_signal_connect(G_OBJECT(vte_reaper_get()), "child-exited",
|
||||
G_CALLBACK(child_exited), NULL);
|
||||
|
||||
|
||||
/* add vbox with menubar, notebook */
|
||||
vbox = gtk_vbox_new(FALSE, 0);
|
||||
gtk_container_add(GTK_CONTAINER(window), vbox);
|
||||
@@ -500,7 +500,7 @@ int main(int argc, char *argv[])
|
||||
gtk_menu_bar_append(GTK_MENU_BAR(menubar), dummMenu);
|
||||
gtk_widget_show(dummMenu);
|
||||
gtk_menu_item_set_submenu(GTK_MENU_ITEM(dummMenu), menu);
|
||||
|
||||
|
||||
/* Dumm -> exit */
|
||||
menuitem = gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT, NULL);
|
||||
g_signal_connect(G_OBJECT(menuitem), "activate",
|
||||
@@ -514,57 +514,57 @@ int main(int argc, char *argv[])
|
||||
gtk_menu_bar_append(GTK_MENU_BAR(menubar), guestMenu);
|
||||
gtk_widget_show(guestMenu);
|
||||
gtk_menu_item_set_submenu(GTK_MENU_ITEM(guestMenu), menu);
|
||||
|
||||
|
||||
/* Guest -> new */
|
||||
menuitem = gtk_image_menu_item_new_from_stock(GTK_STOCK_NEW, NULL);
|
||||
g_signal_connect(G_OBJECT(menuitem), "activate",
|
||||
G_CALLBACK(create_guest), NULL);
|
||||
gtk_menu_append(GTK_MENU(menu), menuitem);
|
||||
gtk_widget_show(menuitem);
|
||||
|
||||
|
||||
/* Guest -> delete */
|
||||
menuitem = gtk_image_menu_item_new_from_stock(GTK_STOCK_DELETE, NULL);
|
||||
g_signal_connect(G_OBJECT(menuitem), "activate",
|
||||
G_CALLBACK(delete_guest), NULL);
|
||||
gtk_menu_append(GTK_MENU(menu), menuitem);
|
||||
gtk_widget_show(menuitem);
|
||||
|
||||
|
||||
menuitem = gtk_separator_menu_item_new();
|
||||
gtk_menu_append(GTK_MENU(menu), menuitem);
|
||||
gtk_widget_show(menuitem);
|
||||
|
||||
|
||||
/* Guest -> start */
|
||||
menuitem = gtk_menu_item_new_with_mnemonic("_Start");
|
||||
g_signal_connect(G_OBJECT(menuitem), "activate",
|
||||
G_CALLBACK(start_guest), NULL);
|
||||
gtk_menu_append(GTK_MENU(menu), menuitem);
|
||||
gtk_widget_show(menuitem);
|
||||
|
||||
|
||||
/* Guest -> startall */
|
||||
menuitem = gtk_menu_item_new_with_mnemonic("Start _all");
|
||||
g_signal_connect(G_OBJECT(menuitem), "activate",
|
||||
G_CALLBACK(start_all_guests), NULL);
|
||||
gtk_menu_append(GTK_MENU(menu), menuitem);
|
||||
gtk_widget_show(menuitem);
|
||||
|
||||
|
||||
/* Guest -> stop */
|
||||
menuitem = gtk_image_menu_item_new_from_stock(GTK_STOCK_STOP, NULL);
|
||||
g_signal_connect(G_OBJECT(menuitem), "activate",
|
||||
G_CALLBACK(stop_guest), NULL);
|
||||
gtk_menu_append(GTK_MENU(menu), menuitem);
|
||||
gtk_widget_show(menuitem);
|
||||
|
||||
|
||||
menuitem = gtk_separator_menu_item_new();
|
||||
gtk_menu_append(GTK_MENU(menu), menuitem);
|
||||
gtk_widget_show(menuitem);
|
||||
|
||||
|
||||
/* Guest -> connect */
|
||||
menuitem = gtk_image_menu_item_new_from_stock(GTK_STOCK_CONNECT, NULL);
|
||||
g_signal_connect(G_OBJECT(menuitem), "activate",
|
||||
G_CALLBACK(connect_guest), NULL);
|
||||
gtk_menu_append(GTK_MENU(menu), menuitem);
|
||||
gtk_widget_show(menuitem);
|
||||
|
||||
|
||||
/* Guest -> disconnect */
|
||||
menuitem = gtk_image_menu_item_new_from_stock(GTK_STOCK_DISCONNECT, NULL);
|
||||
g_signal_connect(G_OBJECT(menuitem), "activate",
|
||||
@@ -579,14 +579,14 @@ int main(int argc, char *argv[])
|
||||
gtk_menu_bar_append(GTK_MENU_BAR(menubar), switchMenu);
|
||||
gtk_widget_show(switchMenu);
|
||||
gtk_menu_item_set_submenu(GTK_MENU_ITEM(switchMenu), menu);
|
||||
|
||||
|
||||
/* Switch -> new */
|
||||
menuitem = gtk_image_menu_item_new_from_stock(GTK_STOCK_NEW, NULL);
|
||||
g_signal_connect(G_OBJECT(menuitem), "activate",
|
||||
G_CALLBACK(create_switch), NULL);
|
||||
gtk_menu_append(GTK_MENU(menu), menuitem);
|
||||
gtk_widget_show(menuitem);
|
||||
|
||||
|
||||
/* Switch -> delete */
|
||||
menuitem = gtk_image_menu_item_new_from_stock(GTK_STOCK_DELETE, NULL);
|
||||
g_signal_connect(G_OBJECT(menuitem), "activate",
|
||||
@@ -594,13 +594,13 @@ int main(int argc, char *argv[])
|
||||
gtk_menu_append(GTK_MENU(menu), menuitem);
|
||||
gtk_widget_set_sensitive(menuitem, FALSE);
|
||||
gtk_widget_show(menuitem);
|
||||
|
||||
|
||||
/* show widgets */
|
||||
gtk_widget_show(menubar);
|
||||
gtk_widget_show(notebook);
|
||||
gtk_widget_show(vbox);
|
||||
gtk_widget_show(window);
|
||||
|
||||
|
||||
/* fill notebook with guests */
|
||||
enumerator = dumm->create_guest_enumerator(dumm);
|
||||
while (enumerator->enumerate(enumerator, (void**)&guest))
|
||||
@@ -608,12 +608,12 @@ int main(int argc, char *argv[])
|
||||
create_page(guest);
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
|
||||
|
||||
gtk_main();
|
||||
|
||||
|
||||
dumm->destroy(dumm);
|
||||
pages->destroy_function(pages, g_free);
|
||||
|
||||
|
||||
library_deinit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
+15
-15
@@ -95,14 +95,14 @@ static int request(private_mconsole_t *this, void(*cb)(void*,char*,size_t),
|
||||
mconsole_reply reply;
|
||||
int len, flags = 0;
|
||||
va_list args;
|
||||
|
||||
|
||||
memset(&request, 0, sizeof(request));
|
||||
request.magic = MCONSOLE_MAGIC;
|
||||
request.version = MCONSOLE_VERSION;
|
||||
va_start(args, command);
|
||||
request.len = vsnprintf(request.data, sizeof(request.data), command, args);
|
||||
va_end(args);
|
||||
|
||||
|
||||
if (this->idle)
|
||||
{
|
||||
flags = MSG_DONTWAIT;
|
||||
@@ -117,13 +117,13 @@ static int request(private_mconsole_t *this, void(*cb)(void*,char*,size_t),
|
||||
(struct sockaddr*)&this->uml, sizeof(this->uml));
|
||||
}
|
||||
while (len < 0 && (errno == EINTR || errno == EAGAIN));
|
||||
|
||||
|
||||
if (len < 0)
|
||||
{
|
||||
DBG1("sending mconsole command to UML failed: %m");
|
||||
return -1;
|
||||
}
|
||||
do
|
||||
do
|
||||
{
|
||||
len = recv(this->console, &reply, sizeof(reply), flags);
|
||||
if (len < 0 && (errno == EINTR || errno == EAGAIN))
|
||||
@@ -157,7 +157,7 @@ static int request(private_mconsole_t *this, void(*cb)(void*,char*,size_t),
|
||||
}
|
||||
}
|
||||
while (reply.more);
|
||||
|
||||
|
||||
return reply.err;
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ static void ignore(void *data, char *buf, size_t len)
|
||||
static bool add_iface(private_mconsole_t *this, char *guest, char *host)
|
||||
{
|
||||
int tries = 0;
|
||||
|
||||
|
||||
while (tries++ < 5)
|
||||
{
|
||||
if (request(this, ignore, NULL, "config %s=tuntap,%s", guest, host) == 0)
|
||||
@@ -190,7 +190,7 @@ static bool add_iface(private_mconsole_t *this, char *guest, char *host)
|
||||
* Implementation of mconsole_t.del_iface.
|
||||
*/
|
||||
static bool del_iface(private_mconsole_t *this, char *guest)
|
||||
{
|
||||
{
|
||||
if (request(this, NULL, NULL, "remove %s", guest) != 0)
|
||||
{
|
||||
return FALSE;
|
||||
@@ -270,7 +270,7 @@ static bool wait_for_notify(private_mconsole_t *this, char *nsock)
|
||||
len = recvfrom(this->notify, ¬ify, sizeof(notify), flags, NULL, 0);
|
||||
}
|
||||
while (len < 0 && (errno == EINTR || errno == EAGAIN));
|
||||
|
||||
|
||||
if (len < 0 || len >= sizeof(notify))
|
||||
{
|
||||
DBG1("reading from mconsole notify socket failed: %m");
|
||||
@@ -300,7 +300,7 @@ static bool wait_for_notify(private_mconsole_t *this, char *nsock)
|
||||
static bool setup_console(private_mconsole_t *this)
|
||||
{
|
||||
struct sockaddr_un addr;
|
||||
|
||||
|
||||
this->console = socket(AF_UNIX, SOCK_DGRAM, 0);
|
||||
if (this->console < 0)
|
||||
{
|
||||
@@ -326,20 +326,20 @@ static bool setup_console(private_mconsole_t *this)
|
||||
mconsole_t *mconsole_create(char *notify, void(*idle)(void))
|
||||
{
|
||||
private_mconsole_t *this = malloc_thing(private_mconsole_t);
|
||||
|
||||
|
||||
this->public.add_iface = (bool(*)(mconsole_t*, char *guest, char *host))add_iface;
|
||||
this->public.del_iface = (bool(*)(mconsole_t*, char *guest))del_iface;
|
||||
this->public.exec = (int(*)(mconsole_t*, void(*cb)(void*,char*,size_t), void *data, char *cmd))exec;
|
||||
this->public.destroy = (void*)destroy;
|
||||
|
||||
|
||||
this->idle = idle;
|
||||
|
||||
|
||||
if (!wait_for_notify(this, notify))
|
||||
{
|
||||
free(this);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
if (!setup_console(this))
|
||||
{
|
||||
close(this->notify);
|
||||
@@ -348,9 +348,9 @@ mconsole_t *mconsole_create(char *notify, void(*idle)(void))
|
||||
return NULL;
|
||||
}
|
||||
unlink(notify);
|
||||
|
||||
|
||||
wait_bootup(this);
|
||||
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -24,7 +24,7 @@ typedef struct mconsole_t mconsole_t;
|
||||
* UML mconsole, change running UML configuration using mconsole.
|
||||
*/
|
||||
struct mconsole_t {
|
||||
|
||||
|
||||
/**
|
||||
* Create a guest interface and connect it to tap host interface.
|
||||
*
|
||||
@@ -33,7 +33,7 @@ struct mconsole_t {
|
||||
* @return TRUE if interface created
|
||||
*/
|
||||
bool (*add_iface)(mconsole_t *this, char *guest, char *host);
|
||||
|
||||
|
||||
/**
|
||||
* Delete a guest interface.
|
||||
*
|
||||
@@ -41,7 +41,7 @@ struct mconsole_t {
|
||||
* @return TRUE if interface deleted
|
||||
*/
|
||||
bool (*del_iface)(mconsole_t *this, char *guest);
|
||||
|
||||
|
||||
/**
|
||||
* Execute a command on the mconsole.
|
||||
*
|
||||
@@ -52,7 +52,7 @@ struct mconsole_t {
|
||||
*/
|
||||
int (*exec)(mconsole_t *this, void(*cb)(void*,char*,size_t), void *data,
|
||||
char *cmd);
|
||||
|
||||
|
||||
/**
|
||||
* Destroy the mconsole instance
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user