1 /*
2  * Copyright (C) 2019 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 <common/libs/device_config/device_config.h>
18 #include <gflags/gflags.h>
19 #include <android-base/logging.h>
20 
21 #include "common/libs/fs/shared_fd.h"
22 #include "common/libs/utils/tee_logging.h"
23 #include "host/libs/config/logging.h"
24 
25 DEFINE_int32(
26     server_fd, -1,
27     "File descriptor to an already created vsock server. Must be specified.");
28 
main(int argc,char ** argv)29 int main(int argc, char** argv) {
30   cuttlefish::DefaultSubprocessLogging(argv);
31   google::ParseCommandLineFlags(&argc, &argv, true);
32 
33   auto device_config = cuttlefish::DeviceConfig::Get();
34 
35   CHECK(device_config) << "Could not open device config";
36 
37   cuttlefish::SharedFD server_fd = cuttlefish::SharedFD::Dup(FLAGS_server_fd);
38 
39   CHECK(server_fd->IsOpen()) << "Inheriting logcat server: "
40                              << server_fd->StrError();
41 
42   // Server loop
43   while (true) {
44     auto conn = cuttlefish::SharedFD::Accept(*server_fd);
45     LOG(DEBUG) << "Connection received on configuration server";
46 
47     bool succeeded = device_config->SendRawData(conn);
48     if (succeeded) {
49       LOG(DEBUG) << "Successfully sent device configuration";
50     } else {
51       LOG(ERROR) << "Failed to send the device configuration: "
52                  << conn->StrError();
53     }
54   }
55 }
56