|
25 | 25 | #include <linux/uio.h>
|
26 | 26 | #include <log/log_read.h>
|
27 | 27 | #include <time.h>
|
| 28 | +#include <trusty/tipc.h> |
28 | 29 | #include <iostream>
|
29 | 30 |
|
30 | 31 | using android::base::ErrnoError;
|
31 | 32 | using android::base::Error;
|
32 | 33 | using android::base::Result;
|
33 | 34 | using android::base::unique_fd;
|
34 | 35 |
|
35 |
| -#define TIPC_IOC_MAGIC 'r' |
36 |
| -#define TIPC_IOC_CONNECT _IOW(TIPC_IOC_MAGIC, 0x80, char*) |
37 |
| - |
38 | 36 | namespace {
|
39 | 37 |
|
40 | 38 | const size_t kTimeoutSeconds = 5;
|
@@ -80,27 +78,14 @@ TrustyApp::TrustyApp(std::string tipc_dev, std::string ta_port)
|
80 | 78 | : tipc_dev_(tipc_dev), ta_port_(ta_port), ta_fd_(-1) {}
|
81 | 79 |
|
82 | 80 | Result<void> TrustyApp::Connect() {
|
83 |
| - /* |
84 |
| - * TODO: We can't use libtrusty because (yet) |
85 |
| - * (1) cc_fuzz can't deal with vendor components (b/170753563) |
86 |
| - * (2) We need non-blocking behavior to detect Trusty going down. |
87 |
| - * (we could implement the timeout in the fuzzing code though, as |
88 |
| - * it needs to be around the call to read()) |
89 |
| - */ |
90 | 81 | alarm(kTimeoutSeconds);
|
91 |
| - int fd = open(tipc_dev_.c_str(), O_RDWR); |
| 82 | + int fd = tipc_connect(tipc_dev_.c_str(), ta_port_.c_str()); |
92 | 83 | alarm(0);
|
93 | 84 | if (fd < 0) {
|
94 | 85 | return ErrnoError() << "failed to open TIPC device: ";
|
95 | 86 | }
|
96 | 87 | ta_fd_.reset(fd);
|
97 | 88 |
|
98 |
| - // This ioctl will time out in the kernel if it can't connect. |
99 |
| - int rc = TEMP_FAILURE_RETRY(ioctl(ta_fd_, TIPC_IOC_CONNECT, ta_port_.c_str())); |
100 |
| - if (rc < 0) { |
101 |
| - return ErrnoError() << "failed to connect to TIPC service: "; |
102 |
| - } |
103 |
| - |
104 | 89 | return {};
|
105 | 90 | }
|
106 | 91 |
|
|
0 commit comments