diff --git a/packaging/snap/snapcraft.yaml b/packaging/snap/snapcraft.yaml index 364b265..7f8a445 100644 --- a/packaging/snap/snapcraft.yaml +++ b/packaging/snap/snapcraft.yaml @@ -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 diff --git a/src/anbox/cmds/container_manager.cpp b/src/anbox/cmds/container_manager.cpp index b4d7a19..1d3dcef 100644 --- a/src/anbox/cmds/container_manager.cpp +++ b/src/anbox/cmds/container_manager.cpp @@ -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 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"); diff --git a/src/anbox/common/loop_device.cpp b/src/anbox/common/loop_device.cpp index dc43450..f17222d 100644 --- a/src/anbox/common/loop_device.cpp +++ b/src/anbox/common/loop_device.cpp @@ -18,7 +18,10 @@ #include "anbox/common/loop_device.h" #include "anbox/defer_action.h" +#include + #include +#include #include #include @@ -27,7 +30,7 @@ namespace common { std::shared_ptr 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(new LoopDevice(Fd{fd}, path)); } diff --git a/src/anbox/common/loop_device_allocator.cpp b/src/anbox/common/loop_device_allocator.cpp index f7b7c7f..06fefc2 100644 --- a/src/anbox/common/loop_device_allocator.cpp +++ b/src/anbox/common/loop_device_allocator.cpp @@ -23,9 +23,12 @@ #include #include +#include #include #include +#include + namespace fs = boost::filesystem; namespace { @@ -38,19 +41,15 @@ namespace common { std::shared_ptr 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