1 /*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <unistd.h>
18
19 #include <thread>
20
21 #include <gflags/gflags.h>
22 #include <glog/logging.h>
23
24 #include "host/libs/config/cuttlefish_config.h"
25 #include "host/commands/ivserver/ivserver.h"
26 #include "host/commands/ivserver/options.h"
27
28 DEFINE_int32(
29 qemu_socket_fd, -1,
30 "A file descriptor to use as the server Qemu connects to. If not specified "
31 "a unix socket will be created in the default location.");
32 DEFINE_int32(
33 client_socket_fd, -1,
34 "A file descriptor to use as the server clients connects to. If not "
35 "specified a unix socket will be created in the default location.");
36
main(int argc,char * argv[])37 int main(int argc, char* argv[]) {
38 ::android::base::InitLogging(argv, android::base::StderrLogger);
39 google::ParseCommandLineFlags(&argc, &argv, true);
40
41 auto config = vsoc::CuttlefishConfig::Get();
42 if (!config) {
43 LOG(ERROR) << "Unable to get cuttlefish config";
44 return 1;
45 }
46
47 ivserver::IVServer server(
48 ivserver::IVServerOptions(config->mempath(),
49 config->ivshmem_qemu_socket_path(),
50 vsoc::GetDomain()),
51 FLAGS_qemu_socket_fd, FLAGS_client_socket_fd);
52
53 // Close the file descriptors as they have been dupped by now.
54 if (FLAGS_qemu_socket_fd > 0) {
55 close(FLAGS_qemu_socket_fd);
56 }
57 if (FLAGS_client_socket_fd > 0) {
58 close(FLAGS_client_socket_fd);
59 }
60
61 server.Serve();
62
63 return 0;
64 }
65