diff options
author | Oleg Nesterov <oleg@redhat.com> | 2015-10-19 12:59:42 +0200 |
---|---|---|
committer | Will Deacon <will.deacon@arm.com> | 2015-10-27 17:03:18 +0000 |
commit | 26e94dc4257933b7c03b4da4a90c156e5a1d38fd (patch) | |
tree | 9d60d338be411a0ecdd00973cfcbf9ec83c5764e | |
parent | a44c32936dffd6d5b01abf2fbf8e9f1632f3273d (diff) | |
download | kvmtool-26e94dc4257933b7c03b4da4a90c156e5a1d38fd.tar.gz |
kvmtool/setup: Introduce extract_file() helper
Turn kvm_setup_guest_init(guestfs_name) into a more generic helper,
extract_file(guestfs_name, filename, data, size) and reimplement
kvm_setup_guest_init() as a trivial wrapper.
Acked-by: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
-rw-r--r-- | builtin-setup.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/builtin-setup.c b/builtin-setup.c index 40fef15d..bb7c71c5 100644 --- a/builtin-setup.c +++ b/builtin-setup.c @@ -122,30 +122,34 @@ static const char *guestfs_symlinks[] = { }; #ifdef CONFIG_GUEST_INIT -extern char _binary_guest_init_start; -extern char _binary_guest_init_size; - -int kvm_setup_guest_init(const char *guestfs_name) +static int extract_file(const char *guestfs_name, const char *filename, + const void *data, const void *_size) { char path[PATH_MAX]; - size_t size; int fd, ret; - char *data; - size = (size_t)&_binary_guest_init_size; - data = (char *)&_binary_guest_init_start; - snprintf(path, PATH_MAX, "%s%s/virt/init", kvm__get_dir(), guestfs_name); + snprintf(path, PATH_MAX, "%s%s/%s", kvm__get_dir(), + guestfs_name, filename); remove(path); fd = open(path, O_CREAT | O_WRONLY, 0755); if (fd < 0) die("Fail to setup %s", path); - ret = xwrite(fd, data, size); + ret = xwrite(fd, data, (size_t)_size); if (ret < 0) die("Fail to setup %s", path); close(fd); return 0; +} +extern char _binary_guest_init_start; +extern char _binary_guest_init_size; + +int kvm_setup_guest_init(const char *guestfs_name) +{ + return extract_file(guestfs_name, "virt/init", + &_binary_guest_init_start, + &_binary_guest_init_size); } #else int kvm_setup_guest_init(const char *guestfs_name) |