• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef CONTROL_FD_
17 #define CONTROL_FD_
18 
19 #include <stdint.h>
20 #include <fcntl.h>
21 #include <limits.h>
22 
23 #include "list.h"
24 #include "loop_event.h"
25 
26 #ifdef __cplusplus
27 #if __cplusplus
28 extern "C" {
29 #endif
30 #endif
31 
32 #define INIT_CONTROL_FD_SOCKET_PATH "/dev/unix/socket/init_control_fd"
33 
34 #define CONTROL_FD_FIFO_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
35 #define PTY_BUF_SIZE 4096
36 #define PTY_PATH_SIZE 128
37 
38 #ifdef STARTUP_INIT_TEST
39 #define CONTROL_FD_STATIC
40 #else
41 #define CONTROL_FD_STATIC static
42 #endif
43 
44 typedef struct CmdService_ {
45     TaskHandle serverTask;
46     struct ListNode head;
47 } CmdService;
48 
49 typedef struct CmdAgent_ {
50     TaskHandle task;
51     WatcherHandle input; // watch stdin
52     WatcherHandle reader; // watch read pty
53     int ptyFd;
54 } CmdAgent;
55 
56 typedef struct CmdTask_ {
57     TaskHandle task;
58     struct ListNode item;
59     int ptyFd;
60     pid_t pid;
61 } CmdTask;
62 
63 typedef void (* CallbackControlFdProcess)(uint16_t type, const char *serviceCmd, const void *context);
64 
65 typedef enum {
66     ACTION_SANDBOX = 0,
67     ACTION_DUMP,
68     ACTION_MODULEMGR,
69     ACTION_MAX
70 } ActionType;
71 
72 typedef struct {
73     uint16_t msgSize;
74     uint16_t type;
75     char ptyName[PTY_PATH_SIZE];
76     char cmd[0];
77 } CmdMessage;
78 
79 void CmdServiceInit(const char *socketPath, CallbackControlFdProcess func, LoopHandle loop);
80 void CmdClientInit(const char *socketPath, uint16_t type, const char *cmd);
81 void CmdServiceProcessDelClient(pid_t pid);
82 void CmdServiceProcessDestroyClient(void);
83 
84 #ifdef __cplusplus
85 #if __cplusplus
86 }
87 #endif
88 #endif
89 
90 #endif
91