Skip to content

Commit 1842a70

Browse files
committed
完善可执行文件的命名问题
1 parent ad8c1ba commit 1842a70

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/core_start.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ enum {
1313

1414
#define MAX_FILENAME_LEN (1 << 10)
1515

16+
#define exe_filename cfadmin_get_exefile()
17+
1618
static char script_entry[MAX_FILENAME_LEN] = "script/main.lua";
1719

1820
static char pid_filename[MAX_FILENAME_LEN] = "cfadmin.pid";
1921

20-
static char exe_filename[MAX_FILENAME_LEN];
21-
2222
static int nprocess = 1;
2323

2424
static int daemoned = 0;
@@ -30,6 +30,17 @@ static int nostd = 1;
3030
#define MasterPrefix ("cfadmin - Manager Process :")
3131
#define WorkerPrefix ("cfadmin - Worker Process")
3232

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+
3344
/* 打印使用指南 */
3445
static inline void cfadmin_usage_print() {
3546
printf("cfadmin System : %s(%s)\n", __OS__, __VERSION__ );
@@ -106,9 +117,7 @@ static inline void cfadmin_specify_process_daemon() {
106117
}
107118

108119
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+
112121
int opt = -1;
113122
// int opterr = 0;
114123
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) {
187196
#endif
188197
}
189198

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-
198199
/* 多进程 - 运行工作进程 */
199200
static inline int cfadmin_worker_run(const char* entry) {
200201
return core_worker_run(entry);
@@ -317,6 +318,8 @@ int main(int argc, char const *argv[]) {
317318
多进程模型目前仅在Linux下可以利用到多核`Accept`, 其他环境仅用多进程来做为`Worker`使用.
318319
*/
319320

321+
cfadmin_set_exefile(argv[0]);
322+
320323
/* 是否需要后台运行 */
321324
pid_t p = daemoned ? cfadmin_daemon(nostd) : getpid() ;
322325

0 commit comments

Comments
 (0)