2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Jan Olszak <j.olszak@samsung.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License
22 * @author Jan Olszak (j.olszak@samsung.com)
23 * @brief Main file for the Vasum Daemon
28 #include "exception.hpp"
31 #include "logger/logger.hpp"
32 #include "logger/backend-stderr.hpp"
33 #include "logger/backend-journal.hpp"
34 #include "logger/backend-syslog.hpp"
35 #include "utils/typeinfo.hpp"
37 #include <boost/program_options.hpp>
40 using namespace logger;
41 using namespace vasum;
43 namespace po = boost::program_options;
48 const std::string PROGRAM_NAME_AND_VERSION =
49 "Vasum Zones Daemon " PROGRAM_VERSION;
54 int main(int argc, char* argv[])
57 po::options_description desc("Allowed options");
60 ("help,h", "print this help")
61 ("version,v", "show application version")
62 ("log-level,l", po::value<std::string>()->default_value("DEBUG"), "set log level")
66 po::basic_parsed_options< char > parsed =
67 po::command_line_parser(argc, argv).options(desc).allow_unregistered().run();
69 std::vector<std::string> unrecognized_options =
70 po::collect_unrecognized(parsed.options, po::include_positional);
72 if (!unrecognized_options.empty()) {
73 std::cerr << "Unrecognized options: ";
75 for (auto& uo : unrecognized_options) {
76 std::cerr << ' ' << uo;
79 std::cerr << std::endl << std::endl;
80 std::cerr << desc << std::endl;
85 po::store(parsed, vm);
88 if (vm.count("help")) {
89 std::cout << desc << std::endl;
91 } else if (vm.count("version")) {
92 std::cout << PROGRAM_NAME_AND_VERSION << std::endl;
96 Logger::setLogLevel(vm["log-level"].as<std::string>());
98 Logger::setLogBackend(new StderrBackend());
100 Logger::setLogBackend(new SystemdJournalBackend());
102 Logger::setLogBackend(new SyslogBackend());
105 } catch (std::exception& e) {
106 std::cerr << e.what() << std::endl;
111 zone_daemon::Runner daemon;
114 } catch (std::exception& e) {
115 LOGE("Unexpected: " << utils::getTypeName(e) << ": " << e.what());