This repository has been archived by the owner on Sep 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init_conf.h
128 lines (106 loc) · 3.27 KB
/
init_conf.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
typedef int offset;
/* A linked list of ptrnode-s */
struct ptrlist {
offset head;
offset last;
int count;
};
struct ptrnode {
offset next;
/* void payload[]; but alas we can't write this in C */
};
/* payload is actually either initrec (for scrath.inittab)
or an env string (scrach.env) */
struct scratch {
struct ptrlist inittab;
struct ptrlist env;
};
/* The three mmaped blocks. See init_conf_map.c.
These should have been anonymous structures, but they are declared
extern in several files. */
struct cblock {
void* addr;
int len;
}; /* cfgblock */
struct nblock {
void* addr;
int len;
int ptr;
}; /* newblock */
struct fblock {
char* buf;
int len;
const char* name;
int line;
char* ls;
char* le;
}; /* fileblock */
/* newblock layout looks like this:
struct config; <- NCF
struct scratch; <- SCR
ptrnode
initrec
ptrnode
initrec
ptrnode
envline
ptrnode
initrec
...
inittab[]
envp[]
Trailing arrays are only added in finishinittab */
#define newblockptr(offset, type) ((type)(newblock.addr + offset))
#define NCF newblockptr(0, struct config*)
#define SCR newblockptr(sizeof(struct config), struct scratch*)
#define FBN fileblock.name
#define FBL fileblock.line
/* Offsets of scratch.{inittab,env} within newblock, for linknode */
#define TABLIST (sizeof(struct config) + offsetof(struct scratch, inittab))
#define ENVLIST (sizeof(struct config) + offsetof(struct scratch, env))
/* For addptrsarray */
#define NULL_FRONT (1<<0)
#define NULL_BACK (1<<1)
#define NULL_BOTH (NULL_FRONT | NULL_BACK)
/* Some versions of musl (0.9.14 but not 0.9.10) #define NULL as 0L,
apparently to cater to C++ folk. Surprisingly, C standard allows this.
C compilers are less than happy with such a turn though, especially when
rebasing pointers: (ptr1 + (ptr2 - NULL)). This only matters for conf
code, the rest of init is ok with 0L. */
#ifdef NULL
#undef NULL
#endif
#define NULL ((void*)0)
extern struct nblock newblock;
extern struct fblock fileblock;
/* cfgblock is never used cross-file */
/* top-level functions handling configuration */
extern int readinittab(const char* file, int strict);
extern int readinitdir(const char* dir, int strict);
extern int addinitrec(const char* name, const char* rlvl, char* cmd, int exe);
extern int addrecargv(struct initrec* entry, char* cmd, int exe);
extern int setrunflags(struct initrec* entry, const char* type);
extern int addenviron(const char* def);
extern int addinitrec(const char* name, const char* flags, char* cmd, int exe);
extern int mmapblock(int size);
extern void munmapblock(void);
extern int mmapfile(const char* filename, int maxlen);
extern int munmapfile(void);
extern offset extendblock(int size);
extern void exchangeblocks(void);
extern char* nextline(void);
extern char* strssep(char** str);
#ifdef exportall
int finishinittab(void);
void rewirepointers();
void rewireptrsarray(void** a);
int parseinitline(char* line);
int addparsedargv(char* str);
int addstaticargv(const char** args, int n);
int addstring(const char* s);
int linknode(offset listptr, offset ptr);
int parsesrvfile(char* fullname, char* basename);
int readinitdir(const char* dir, int strict);
int shellneeded(const char* cmd);
void transferpids(void);
#endif