Merge branch 'master' of https://github.com/anbox/anbox into adjust-find-gtest-and-gmock
This commit is contained in:
commit
df852f5c5b
4 changed files with 21 additions and 11 deletions
|
|
@ -22,7 +22,7 @@ parts:
|
|||
install: |
|
||||
# FIXME: downloading with a source: field doesn't work as snapcraft
|
||||
# expects the downloaded file to be an archive it can extract.
|
||||
wget https://s3.eu-central-1.amazonaws.com/anbox/images/anbox-android-1.img
|
||||
wget http://build.anbox.io/android-images/2017/04/12/android_1_amd64.img
|
||||
mv anbox-android-1.img $SNAPCRAFT_PART_INSTALL/android.img
|
||||
anbox-common:
|
||||
plugin: dump
|
||||
|
|
|
|||
|
|
@ -100,9 +100,17 @@ bool anbox::cmds::ContainerManager::setup_mounts() {
|
|||
if (!fs::exists(android_rootfs_dir))
|
||||
fs::create_directory(android_rootfs_dir);
|
||||
|
||||
auto loop_device = common::LoopDeviceAllocator::new_device();
|
||||
if (!loop_device)
|
||||
std::shared_ptr<common::LoopDevice> loop_device;
|
||||
|
||||
try {
|
||||
loop_device = common::LoopDeviceAllocator::new_device();
|
||||
} catch (const std::exception& e) {
|
||||
ERROR("Could not create loopback device: %s", e.what());
|
||||
return false;
|
||||
} catch (...) {
|
||||
ERROR("Could not create loopback device");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!loop_device->attach_file(android_img_path)) {
|
||||
ERROR("Failed to attach Android rootfs image to loopback device");
|
||||
|
|
|
|||
|
|
@ -18,7 +18,10 @@
|
|||
#include "anbox/common/loop_device.h"
|
||||
#include "anbox/defer_action.h"
|
||||
|
||||
#include <system_error>
|
||||
|
||||
#include <linux/loop.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
|
|
@ -27,7 +30,7 @@ namespace common {
|
|||
std::shared_ptr<LoopDevice> LoopDevice::create(const boost::filesystem::path &path) {
|
||||
const auto fd = ::open(path.c_str(), O_RDWR);
|
||||
if (fd < 0)
|
||||
return nullptr;
|
||||
throw std::system_error{errno, std::system_category()};
|
||||
|
||||
return std::shared_ptr<LoopDevice>(new LoopDevice(Fd{fd}, path));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,9 +23,12 @@
|
|||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <linux/loop.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <system_error>
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
namespace {
|
||||
|
|
@ -38,19 +41,15 @@ namespace common {
|
|||
std::shared_ptr<LoopDevice> LoopDeviceAllocator::new_device() {
|
||||
const auto ctl_fd = ::open(loop_control_path, O_RDWR);
|
||||
if (ctl_fd < 0)
|
||||
return nullptr;
|
||||
throw std::system_error{errno, std::system_category()};
|
||||
|
||||
DeferAction close_ctl_fd{[&]() { ::close(ctl_fd); }};
|
||||
|
||||
const auto device_nr = ::ioctl(ctl_fd, LOOP_CTL_GET_FREE);
|
||||
if (device_nr < 0)
|
||||
return nullptr;
|
||||
throw std::system_error{errno, std::system_category()};
|
||||
|
||||
const auto path = utils::string_format("%s%d", base_loop_path, device_nr);
|
||||
if (!fs::exists(path))
|
||||
return nullptr;
|
||||
|
||||
return LoopDevice::create(path);
|
||||
return LoopDevice::create(utils::string_format("%s%d", base_loop_path, device_nr));
|
||||
}
|
||||
} // namespace common
|
||||
} // namespace anbox
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue