blob: 1833ba8d5caf94ecabdf7de652520e9a2135449e [file] [log] [blame]
Tomasz Wiszkowskie99c4112017-07-05 10:17:43 -07001#include <limits.h>
Romit Dasgupta61b572a2017-06-23 17:48:22 -07002#include <stdlib.h>
3#include <unistd.h>
Tomasz Wiszkowskie99c4112017-07-05 10:17:43 -07004
5#include <fstream>
Romit Dasgupta61b572a2017-06-23 17:48:22 -07006#include <memory>
7
Tomasz Wiszkowskie99c4112017-07-05 10:17:43 -07008#include <gflags/gflags.h>
Romit Dasgupta61b572a2017-06-23 17:48:22 -07009#include <glog/logging.h>
10
Tomasz Wiszkowskie99c4112017-07-05 10:17:43 -070011#include "host/ivserver/ivserver.h"
12#include "host/ivserver/options.h"
Romit Dasgupta61b572a2017-06-23 17:48:22 -070013
Tomasz Wiszkowskie99c4112017-07-05 10:17:43 -070014DEFINE_string(layout, "", "Location of the vsoc_mem.json file.");
15DEFINE_string(mempath, "/dev/shm/ivshmem",
16 "Target location for the shmem file.");
17DEFINE_int32(shmsize, 4, "Size of the shared memory region in megabytes.");
18DEFINE_string(qemusocket, "/tmp/ivshmem_socket_qemu", "QEmu socket path");
19DEFINE_string(clientsocket, "/tmp/ivshmem_socket_client", "Client socket path");
Romit Dasgupta61b572a2017-06-23 17:48:22 -070020
Tomasz Wiszkowskie99c4112017-07-05 10:17:43 -070021namespace {
22Json::Value LoadLayoutFile(const std::string &file) {
23 char real_file_path[PATH_MAX];
24 if (realpath(file.c_str(), real_file_path) == nullptr) {
25 LOG(FATAL) << "Could not get real path for file " << file << ": "
26 << strerror(errno);
Romit Dasgupta61b572a2017-06-23 17:48:22 -070027 }
28
Tomasz Wiszkowskie99c4112017-07-05 10:17:43 -070029 Json::Value result;
30 Json::Reader reader;
31 std::ifstream ifs(real_file_path);
32 if (!reader.parse(ifs, result)) {
33 LOG(FATAL) << "Could not read layout file " << file << ": "
34 << reader.getFormattedErrorMessages();
35 }
36 return result;
Romit Dasgupta61b572a2017-06-23 17:48:22 -070037}
Tomasz Wiszkowskie99c4112017-07-05 10:17:43 -070038} // anonymous namespace
Romit Dasgupta61b572a2017-06-23 17:48:22 -070039
40int main(int argc, char **argv) {
Tomasz Wiszkowskia29455e2017-07-07 14:23:16 -070041 google::InstallFailureSignalHandler();
Tomasz Wiszkowskie99c4112017-07-05 10:17:43 -070042 google::ParseCommandLineFlags(&argc, &argv, true);
Romit Dasgupta61b572a2017-06-23 17:48:22 -070043
Tomasz Wiszkowskie99c4112017-07-05 10:17:43 -070044 std::unique_ptr<ivserver::IVServerOptions> ivserver_options(
45 new ivserver::IVServerOptions(FLAGS_layout, FLAGS_mempath,
46 FLAGS_qemusocket, FLAGS_clientsocket,
47 FLAGS_shmsize));
Romit Dasgupta61b572a2017-06-23 17:48:22 -070048
Tomasz Wiszkowskie99c4112017-07-05 10:17:43 -070049 Json::Value json_root = LoadLayoutFile(FLAGS_layout);
Romit Dasgupta61b572a2017-06-23 17:48:22 -070050 ivserver::IVServer ivserver(*ivserver_options, json_root);
Romit Dasgupta61b572a2017-06-23 17:48:22 -070051 ivserver.Serve();
Romit Dasgupta61b572a2017-06-23 17:48:22 -070052 LOG(FATAL) << "ivserver failed in Serve().";
Romit Dasgupta61b572a2017-06-23 17:48:22 -070053}