Tomasz Wiszkowski | e99c411 | 2017-07-05 10:17:43 -0700 | [diff] [blame] | 1 | #include <limits.h> |
Romit Dasgupta | 61b572a | 2017-06-23 17:48:22 -0700 | [diff] [blame] | 2 | #include <stdlib.h> |
| 3 | #include <unistd.h> |
Tomasz Wiszkowski | e99c411 | 2017-07-05 10:17:43 -0700 | [diff] [blame] | 4 | |
| 5 | #include <fstream> |
Romit Dasgupta | 61b572a | 2017-06-23 17:48:22 -0700 | [diff] [blame] | 6 | #include <memory> |
| 7 | |
Tomasz Wiszkowski | e99c411 | 2017-07-05 10:17:43 -0700 | [diff] [blame] | 8 | #include <gflags/gflags.h> |
Romit Dasgupta | 61b572a | 2017-06-23 17:48:22 -0700 | [diff] [blame] | 9 | #include <glog/logging.h> |
| 10 | |
Tomasz Wiszkowski | e99c411 | 2017-07-05 10:17:43 -0700 | [diff] [blame] | 11 | #include "host/ivserver/ivserver.h" |
| 12 | #include "host/ivserver/options.h" |
Romit Dasgupta | 61b572a | 2017-06-23 17:48:22 -0700 | [diff] [blame] | 13 | |
Tomasz Wiszkowski | e99c411 | 2017-07-05 10:17:43 -0700 | [diff] [blame] | 14 | DEFINE_string(layout, "", "Location of the vsoc_mem.json file."); |
| 15 | DEFINE_string(mempath, "/dev/shm/ivshmem", |
| 16 | "Target location for the shmem file."); |
| 17 | DEFINE_int32(shmsize, 4, "Size of the shared memory region in megabytes."); |
| 18 | DEFINE_string(qemusocket, "/tmp/ivshmem_socket_qemu", "QEmu socket path"); |
| 19 | DEFINE_string(clientsocket, "/tmp/ivshmem_socket_client", "Client socket path"); |
Romit Dasgupta | 61b572a | 2017-06-23 17:48:22 -0700 | [diff] [blame] | 20 | |
Tomasz Wiszkowski | e99c411 | 2017-07-05 10:17:43 -0700 | [diff] [blame] | 21 | namespace { |
| 22 | Json::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 Dasgupta | 61b572a | 2017-06-23 17:48:22 -0700 | [diff] [blame] | 27 | } |
| 28 | |
Tomasz Wiszkowski | e99c411 | 2017-07-05 10:17:43 -0700 | [diff] [blame] | 29 | 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 Dasgupta | 61b572a | 2017-06-23 17:48:22 -0700 | [diff] [blame] | 37 | } |
Tomasz Wiszkowski | e99c411 | 2017-07-05 10:17:43 -0700 | [diff] [blame] | 38 | } // anonymous namespace |
Romit Dasgupta | 61b572a | 2017-06-23 17:48:22 -0700 | [diff] [blame] | 39 | |
| 40 | int main(int argc, char **argv) { |
Tomasz Wiszkowski | a29455e | 2017-07-07 14:23:16 -0700 | [diff] [blame^] | 41 | google::InstallFailureSignalHandler(); |
Tomasz Wiszkowski | e99c411 | 2017-07-05 10:17:43 -0700 | [diff] [blame] | 42 | google::ParseCommandLineFlags(&argc, &argv, true); |
Romit Dasgupta | 61b572a | 2017-06-23 17:48:22 -0700 | [diff] [blame] | 43 | |
Tomasz Wiszkowski | e99c411 | 2017-07-05 10:17:43 -0700 | [diff] [blame] | 44 | std::unique_ptr<ivserver::IVServerOptions> ivserver_options( |
| 45 | new ivserver::IVServerOptions(FLAGS_layout, FLAGS_mempath, |
| 46 | FLAGS_qemusocket, FLAGS_clientsocket, |
| 47 | FLAGS_shmsize)); |
Romit Dasgupta | 61b572a | 2017-06-23 17:48:22 -0700 | [diff] [blame] | 48 | |
Tomasz Wiszkowski | e99c411 | 2017-07-05 10:17:43 -0700 | [diff] [blame] | 49 | Json::Value json_root = LoadLayoutFile(FLAGS_layout); |
Romit Dasgupta | 61b572a | 2017-06-23 17:48:22 -0700 | [diff] [blame] | 50 | ivserver::IVServer ivserver(*ivserver_options, json_root); |
Romit Dasgupta | 61b572a | 2017-06-23 17:48:22 -0700 | [diff] [blame] | 51 | ivserver.Serve(); |
Romit Dasgupta | 61b572a | 2017-06-23 17:48:22 -0700 | [diff] [blame] | 52 | LOG(FATAL) << "ivserver failed in Serve()."; |
Romit Dasgupta | 61b572a | 2017-06-23 17:48:22 -0700 | [diff] [blame] | 53 | } |