@@ -13,12 +13,12 @@ enum {
13
13
14
14
#define MAX_FILENAME_LEN (1 << 10)
15
15
16
+ #define exe_filename cfadmin_get_exefile()
17
+
16
18
static char script_entry [MAX_FILENAME_LEN ] = "script/main.lua" ;
17
19
18
20
static char pid_filename [MAX_FILENAME_LEN ] = "cfadmin.pid" ;
19
21
20
- static char exe_filename [MAX_FILENAME_LEN ];
21
-
22
22
static int nprocess = 1 ;
23
23
24
24
static int daemoned = 0 ;
@@ -30,6 +30,17 @@ static int nostd = 1;
30
30
#define MasterPrefix ("cfadmin - Manager Process :")
31
31
#define WorkerPrefix ("cfadmin - Worker Process")
32
32
33
+ const char * cfadmin_get_exefile () {
34
+ const char * filename = getenv ("cfadmin_exefile" );
35
+ if (!filename )
36
+ filename = "./cfadmin" ;
37
+ return filename ;
38
+ }
39
+
40
+ void cfadmin_set_exefile (const char * filename ) {
41
+ setenv ("cfadmin_exefile" , filename , 1 );
42
+ }
43
+
33
44
/* 打印使用指南 */
34
45
static inline void cfadmin_usage_print () {
35
46
printf ("cfadmin System : %s(%s)\n" , __OS__ , __VERSION__ );
@@ -106,9 +117,7 @@ static inline void cfadmin_specify_process_daemon() {
106
117
}
107
118
108
119
static inline void cfadmin_init_args (int argc , char const * argv []) {
109
- // 可执行文件名
110
- memset (exe_filename , 0x0 , MAX_FILENAME_LEN );
111
- memcpy (exe_filename , argv [0 ], strlen (argv [0 ]));
120
+
112
121
int opt = -1 ;
113
122
// int opterr = 0;
114
123
while ((opt = getopt (argc , (char * const * )argv , "hde:p:k:w:" )) != -1 ) {
@@ -187,14 +196,6 @@ static inline void cfadmin_set_cpu_affinity(int num, pid_t pid) {
187
196
#endif
188
197
}
189
198
190
- // /* 初始化参数 */
191
- // static inline void cfadmin_unset_parameters() {
192
- // unsetenv("cfadmin_isMaster");
193
- // unsetenv("cfadmin_isWorker");
194
- // unsetenv("cfadmin_nprocess");
195
- // unsetenv("cfadmin_script");
196
- // }
197
-
198
199
/* 多进程 - 运行工作进程 */
199
200
static inline int cfadmin_worker_run (const char * entry ) {
200
201
return core_worker_run (entry );
@@ -317,6 +318,8 @@ int main(int argc, char const *argv[]) {
317
318
多进程模型目前仅在Linux下可以利用到多核`Accept`, 其他环境仅用多进程来做为`Worker`使用.
318
319
*/
319
320
321
+ cfadmin_set_exefile (argv [0 ]);
322
+
320
323
/* 是否需要后台运行 */
321
324
pid_t p = daemoned ? cfadmin_daemon (nostd ) : getpid () ;
322
325
0 commit comments