69feb2496f7531fd5806f82bca33556726bc6982
[iec.git] / src / type3_AndroidCloud / anbox-master / src / anbox / daemon.cpp
1 /*
2  * Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
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 <signal.h>
19 #include <sys/prctl.h>
20
21 #include "anbox/system_configuration.h"
22 #include "anbox/daemon.h"
23 #include "anbox/logger.h"
24
25 #include "anbox/cmds/container_manager.h"
26 #include "anbox/cmds/session_manager.h"
27 #include "anbox/cmds/system_info.h"
28 #include "anbox/cmds/launch.h"
29 #include "anbox/cmds/version.h"
30 #include "anbox/cmds/wait_ready.h"
31 #include "anbox/cmds/check_features.h"
32
33 #include <boost/filesystem.hpp>
34
35 namespace fs = boost::filesystem;
36
37 namespace anbox {
38 Daemon::Daemon()
39     : cmd{cli::Name{"anbox"}, cli::Usage{"anbox"},
40           cli::Description{"The Android in a Box runtime"}} {
41   cmd.command(std::make_shared<cmds::Version>())
42      .command(std::make_shared<cmds::SessionManager>())
43      .command(std::make_shared<cmds::Launch>())
44      .command(std::make_shared<cmds::ContainerManager>())
45      .command(std::make_shared<cmds::SystemInfo>())
46      .command(std::make_shared<cmds::WaitReady>())
47      .command(std::make_shared<cmds::CheckFeatures>());
48
49   Log().Init(anbox::Logger::Severity::kWarning);
50
51   const auto log_level = utils::get_env_value("ANBOX_LOG_LEVEL", "");
52   if (!log_level.empty() && !Log().SetSeverityFromString(log_level))
53     WARNING("Failed to set logging severity to '%s'", log_level);
54 }
55
56 int Daemon::Run(const std::vector<std::string> &arguments) try {
57   auto argv = arguments;
58   if (arguments.size() == 0) argv = {"help"};
59   return cmd.run({std::cin, std::cout, argv});
60 } catch (std::exception &err) {
61   ERROR("%s", err.what());
62
63   return EXIT_FAILURE;
64 }
65 }  // namespace anbox