2 * Copyright (C) 2018 Canonical Ltd.
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "anbox/common/binder_device.h"
19 #include "anbox/common/binderfs.h"
20 #include "anbox/defer_action.h"
21 #include "anbox/logger.h"
22 #include "anbox/utils.h"
24 #include <system_error>
28 #include <linux/loop.h>
29 #include <sys/ioctl.h>
34 std::unique_ptr<BinderDevice> BinderDevice::create(const std::string& path) {
35 return std::unique_ptr<BinderDevice>(new BinderDevice(path));
38 BinderDevice::BinderDevice(const std::string& path) :
40 if (::chmod(path.c_str(), 0666) < 0)
41 ERROR("Failed to change permissions of binder node %s: %s", path, std::strerror(errno));
44 BinderDevice::~BinderDevice() {
45 if (::unlink(path_.c_str()) < 0)
46 ERROR("Failed to remove binder node %s: %s", path_, std::strerror(errno));