--- lbbs/src/init.c 2025/04/30 09:18:19 1.13 +++ lbbs/src/init.c 2025/05/05 14:27:57 1.17 @@ -16,6 +16,7 @@ ***************************************************************************/ #include "init.h" +#include "database.h" #include "bbs.h" #include "common.h" #include "log.h" @@ -31,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; } @@ -90,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) { @@ -104,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) {