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 <app_mgmt_port_consts.h>
18 #include <app_mgmt_test.h>
19 #include <stddef.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <trusty_ipc.h>
24 #include <uapi/err.h>
25 
26 #define TLOG_TAG "never-start-srv"
27 
main(void)28 int main(void) {
29     int rc;
30     handle_t phandle;
31     handle_t chandle;
32     uevent_t uevt;
33 
34     TLOGE("ERROR: Starting server that should never start\n");
35 
36     rc = port_create(NEVER_START_PORT, 1, 1, IPC_PORT_ALLOW_TA_CONNECT);
37     if (rc < 0) {
38         TLOGI("failed (%d) to create ctrl port\n", rc);
39         return rc;
40     }
41     phandle = (handle_t)rc;
42 
43     rc = wait(phandle, &uevt, -1);
44     if (rc != NO_ERROR || !(uevt.event & IPC_HANDLE_POLL_READY)) {
45         TLOGI("Port wait failed(%d) event:%d handle:%d\n", rc, uevt.event,
46               phandle);
47         return rc;
48     }
49 
50     chandle = (handle_t)rc;
51 
52     rc = close(chandle);
53     if (rc < 0) {
54         TLOGI("Close failed(%d) handle:%d\n", rc, chandle);
55         return rc;
56     }
57 
58     return 0;
59 }
60