• 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 STARTUP_INIT_CONTEXT
17 #define STARTUP_INIT_CONTEXT
18 #include <stdio.h>
19 #include <stdint.h>
20 #include <sys/types.h>
21 
22 #include "init_cmds.h"
23 #ifdef __cplusplus
24 #if __cplusplus
25 extern "C" {
26 #endif
27 #endif
28 
29 #define MAX_CMD_LEN 512
30 typedef enum {
31     SUB_INIT_STATE_IDLE,
32     SUB_INIT_STATE_STARTING,
33     SUB_INIT_STATE_RUNNING
34 } SubInitState;
35 
36 typedef struct {
37     InitContextType type;
38     int sendFd;
39     int recvFd;
40     pid_t subPid;
41     SubInitState state;
42 } SubInitInfo;
43 
44 typedef struct {
45     InitContextType type;
46     int (*startSubInit)(InitContextType type);
47     void (*stopSubInit)(pid_t pid);
48     int (*executeCmdInSubInit)(InitContextType type, const char *, const char *);
49     int (*setSubInitContext)(InitContextType type);
50 } SubInitContext;
51 
52 int StartSubInit(InitContextType type);
53 int InitSubInitContext(InitContextType type, const SubInitContext *context);
54 #ifdef STARTUP_INIT_TEST
55 SubInitInfo *GetSubInitInfo(InitContextType type);
56 #endif
57 
58 typedef struct {
59     int socket[2];
60     InitContextType type;
61 } SubInitForkArg;
62 pid_t SubInitFork(int (*childFunc)(const SubInitForkArg *arg), const SubInitForkArg *args);
63 
64 #ifdef __cplusplus
65 #if __cplusplus
66 }
67 #endif
68 #endif
69 #endif