--- lbbs/src/init.c 2025/04/28 03:30:59 1.11 +++ lbbs/src/init.c 2025/05/05 14:27:57 1.17 @@ -15,9 +15,14 @@ * * ***************************************************************************/ +#include "init.h" +#include "database.h" #include "bbs.h" #include "common.h" +#include "log.h" #include "io.h" +#include +#include #include #include #include @@ -27,21 +32,34 @@ void init_daemon(void) { int pid; - int i; - if (pid = fork()) + pid = fork(); + + if (pid > 0) // Parent process + { exit(0); - else if (pid < 0) + } + else if (pid < 0) // Error + { exit(1); + } + // Child process setsid(); - if (pid = fork()) + pid = fork(); + + if (pid > 0) // Parent process + { exit(0); - else if (pid < 0) + } + else if (pid < 0) // Error + { exit(1); + } - umask(0); + // Child process + umask(022); return; } @@ -86,7 +104,7 @@ int load_conf(const char *conf_file) } if (strcmp(c_name, "bbs_port") == 0) { - fscanf(fin, "%ud", &BBS_port); + fscanf(fin, "%hu", &BBS_port); } if (strcmp(c_name, "bbs_max_client") == 0) { @@ -100,7 +118,7 @@ int load_conf(const char *conf_file) { int y = 0, m = 0, d = 0; fscanf(fin, "%d-%d-%d", &y, &m, &d); - sprintf(BBS_start_dt, "%4d年%2d月%2d日", y, m, d); + snprintf(BBS_start_dt, sizeof(BBS_start_dt), "%4d年%2d月%2d日", y, m, d); } if (strcmp(c_name, "db_host") == 0) { @@ -118,6 +136,10 @@ int load_conf(const char *conf_file) { fscanf(fin, "%s", DB_database); } + if (strcmp(c_name, "db_timezone") == 0) + { + fscanf(fin, "%s", DB_timezone); + } } fclose(fin);