--- lbbs/src/init.c 2025/04/30 09:18:19 1.13 +++ lbbs/src/init.c 2025/06/01 03:07:42 1.21 @@ -1,21 +1,21 @@ /*************************************************************************** init.c - description ------------------- - begin : Mon Oct 18 2004 - copyright : (C) 2004 by Leaflet - email : leaflet@leafok.com + Copyright : (C) 2004-2025 by Leaflet + Email : leaflet@leafok.com ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * + * the Free Software Foundation; either version 3 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "init.h" +#include "database.h" #include "bbs.h" #include "common.h" #include "log.h" @@ -28,26 +28,39 @@ #include #include -void init_daemon(void) +int init_daemon(void) { int pid; - int i; - if (pid = fork()) - exit(0); - else if (pid < 0) - exit(1); + pid = fork(); + if (pid > 0) // Parent process + { + _exit(0); + } + else if (pid < 0) // error + { + _exit(pid); + } + + // Child process setsid(); - if (pid = fork()) - exit(0); - else if (pid < 0) - exit(1); + pid = fork(); + + if (pid > 0) // Parent process + { + _exit(0); + } + else if (pid < 0) // error + { + _exit(pid); + } - umask(0); + // Child process + umask(022); - return; + return 0; } int load_conf(const char *conf_file) @@ -90,11 +103,20 @@ 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) { fscanf(fin, "%d", &BBS_max_client); + if (BBS_max_client > MAX_CLIENTS_LIMIT) + { + log_error("Config BBS_max_client > limit (%d), reset it to limit\n", BBS_max_client); + BBS_max_client = MAX_CLIENTS_LIMIT; + } + } + if (strcmp(c_name, "bbs_max_client_per_ip") == 0) + { + fscanf(fin, "%d", &BBS_max_client_per_ip); } if (strcmp(c_name, "bbs_max_user") == 0) { @@ -104,7 +126,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) {