892222b7d5a80d4900ec1e53c9b4a7e50a1173b1
[iec.git] / src / type3_AndroidCloud / anbox-master / src / anbox / common / binder_device.cpp
1 /*
2  * Copyright (C) 2018 Canonical Ltd.
3  *
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.
7  *
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.
12  *
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/>.
15  *
16  */
17
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"
23
24 #include <system_error>
25
26 #include <cerrno>
27 #include <fcntl.h>
28 #include <linux/loop.h>
29 #include <sys/ioctl.h>
30 #include <sys/stat.h>
31
32 namespace anbox {
33 namespace common {
34 std::unique_ptr<BinderDevice> BinderDevice::create(const std::string& path) {
35   return std::unique_ptr<BinderDevice>(new BinderDevice(path));
36 }
37
38 BinderDevice::BinderDevice(const std::string& path) :
39     path_{path} {
40   if (::chmod(path.c_str(), 0666) < 0)
41     ERROR("Failed to change permissions of binder node %s: %s", path, std::strerror(errno));
42 }
43
44 BinderDevice::~BinderDevice() {
45   if (::unlink(path_.c_str()) < 0)
46     ERROR("Failed to remove binder node %s: %s", path_, std::strerror(errno));
47 }
48 } // namespace common
49 } // namespace anbox