| 511 |
int nfds; |
int nfds; |
| 512 |
int notify_child_exit = 0; |
int notify_child_exit = 0; |
| 513 |
time_t tm_notify_child_exit = time(NULL); |
time_t tm_notify_child_exit = time(NULL); |
|
MENU_SET bbs_menu_new; |
|
|
MENU_SET top10_menu_new; |
|
| 514 |
int i, j; |
int i, j; |
| 515 |
pid_t pid; |
pid_t pid; |
| 516 |
int ssh_log_level = SSH_LOG_NOLOG; |
int ssh_log_level = SSH_LOG_NOLOG; |
| 564 |
{ |
{ |
| 565 |
log_error("setsockopt SO_REUSEADDR error (%d)\n", errno); |
log_error("setsockopt SO_REUSEADDR error (%d)\n", errno); |
| 566 |
} |
} |
| 567 |
|
#if defined(SO_REUSEPORT) |
| 568 |
if (setsockopt(socket_server[i], SOL_SOCKET, SO_REUSEPORT, &flags_server[i], sizeof(flags_server[i])) < 0) |
if (setsockopt(socket_server[i], SOL_SOCKET, SO_REUSEPORT, &flags_server[i], sizeof(flags_server[i])) < 0) |
| 569 |
{ |
{ |
| 570 |
log_error("setsockopt SO_REUSEPORT error (%d)\n", errno); |
log_error("setsockopt SO_REUSEPORT error (%d)\n", errno); |
| 571 |
} |
} |
| 572 |
|
#endif |
| 573 |
|
|
| 574 |
if (bind(socket_server[i], (struct sockaddr *)&sin, sizeof(sin)) < 0) |
if (bind(socket_server[i], (struct sockaddr *)&sin, sizeof(sin)) < 0) |
| 575 |
{ |
{ |
| 639 |
{ |
{ |
| 640 |
SYS_child_exit = 0; |
SYS_child_exit = 0; |
| 641 |
|
|
| 642 |
pid = waitpid(-1, NULL, WNOHANG); |
pid = waitpid(-1, &ret, WNOHANG); |
| 643 |
if (pid > 0) |
if (pid > 0) |
| 644 |
{ |
{ |
| 645 |
SYS_child_exit = 1; // Retry waitid |
SYS_child_exit = 1; // Retry waitid |
|
|
|
| 646 |
SYS_child_process_count--; |
SYS_child_process_count--; |
| 647 |
log_common("Child process (%d) exited\n", pid); |
|
| 648 |
|
if (WIFEXITED(ret)) |
| 649 |
|
{ |
| 650 |
|
log_common("Child process (%d) exited, status=%d\n", pid, WEXITSTATUS(ret)); |
| 651 |
|
} |
| 652 |
|
else if (WIFSIGNALED(ret)) |
| 653 |
|
{ |
| 654 |
|
log_common("Child process (%d) is killed, status=%d\n", pid, WTERMSIG(ret)); |
| 655 |
|
} |
| 656 |
|
else |
| 657 |
|
{ |
| 658 |
|
log_common("Child process (%d) exited abnormally, status=%d\n", pid, ret); |
| 659 |
|
} |
| 660 |
|
|
| 661 |
if (pid != section_list_loader_pid) |
if (pid != section_list_loader_pid) |
| 662 |
{ |
{ |
| 702 |
log_common("Notify %d child process to exit\n", SYS_child_process_count); |
log_common("Notify %d child process to exit\n", SYS_child_process_count); |
| 703 |
#endif |
#endif |
| 704 |
|
|
| 705 |
if (kill(-getpid(), SIGTERM) < 0) |
if (kill(0, SIGTERM) < 0) |
| 706 |
{ |
{ |
| 707 |
log_error("Send SIGTERM signal failed (%d)\n", errno); |
log_error("Send SIGTERM signal failed (%d)\n", errno); |
| 708 |
} |
} |
| 716 |
sd_notifyf(0, "STATUS=Kill %d child process", SYS_child_process_count); |
sd_notifyf(0, "STATUS=Kill %d child process", SYS_child_process_count); |
| 717 |
#endif |
#endif |
| 718 |
|
|
| 719 |
if (kill(-getpid(), SIGKILL) < 0) |
if (kill(0, SIGKILL) < 0) |
| 720 |
{ |
{ |
| 721 |
log_error("Send SIGKILL signal failed (%d)\n", errno); |
log_error("Send SIGKILL signal failed (%d)\n", errno); |
| 722 |
} |
} |
| 757 |
log_error("Reload BWF conf failed\n"); |
log_error("Reload BWF conf failed\n"); |
| 758 |
} |
} |
| 759 |
|
|
| 760 |
if (load_menu(&bbs_menu_new, CONF_MENU) < 0) |
if (detach_menu_shm(&bbs_menu) < 0) |
| 761 |
{ |
{ |
| 762 |
unload_menu(&bbs_menu_new); |
log_error("detach_menu_shm(bbs_menu) error\n"); |
|
log_error("Reload bbs menu failed\n"); |
|
| 763 |
} |
} |
| 764 |
else |
if (load_menu(&bbs_menu, CONF_MENU) < 0) |
| 765 |
{ |
{ |
| 766 |
|
log_error("load_menu(bbs_menu) error\n"); |
| 767 |
unload_menu(&bbs_menu); |
unload_menu(&bbs_menu); |
|
memcpy(&bbs_menu, &bbs_menu_new, sizeof(bbs_menu_new)); |
|
|
log_common("Reload bbs menu successfully\n"); |
|
| 768 |
} |
} |
| 769 |
|
|
| 770 |
if (load_menu(&top10_menu_new, CONF_TOP10_MENU) < 0) |
if (detach_menu_shm(&top10_menu) < 0) |
| 771 |
{ |
{ |
| 772 |
unload_menu(&top10_menu_new); |
log_error("detach_menu_shm(top10_menu) error\n"); |
|
log_error("Reload top10 menu failed\n"); |
|
| 773 |
} |
} |
| 774 |
else |
if (load_menu(&top10_menu, CONF_TOP10_MENU) < 0) |
| 775 |
{ |
{ |
| 776 |
|
log_error("load_menu(top10_menu) error\n"); |
| 777 |
unload_menu(&top10_menu); |
unload_menu(&top10_menu); |
|
top10_menu_new.allow_exit = 1; |
|
|
memcpy(&top10_menu, &top10_menu_new, sizeof(top10_menu_new)); |
|
|
log_common("Reload top10 menu successfully\n"); |
|
| 778 |
} |
} |
| 779 |
|
|
| 780 |
for (int i = 0; i < data_files_load_startup_count; i++) |
for (int i = 0; i < data_files_load_startup_count; i++) |
| 784 |
log_error("load_file(%s) error\n", data_files_load_startup[i]); |
log_error("load_file(%s) error\n", data_files_load_startup[i]); |
| 785 |
} |
} |
| 786 |
} |
} |
|
log_common("Reload data files successfully\n"); |
|
| 787 |
|
|
| 788 |
// Load section config and gen_ex |
// Load section config and gen_ex |
| 789 |
if (load_section_config_from_db(1) < 0) |
if (load_section_config_from_db(1) < 0) |
| 790 |
{ |
{ |
| 791 |
log_error("load_section_config_from_db(1) error\n"); |
log_error("load_section_config_from_db(1) error\n"); |
| 792 |
} |
} |
|
else |
|
|
{ |
|
|
log_common("Reload section config and gen_ex successfully\n"); |
|
|
} |
|
| 793 |
|
|
| 794 |
// Notify child processes to reload configuration |
// Notify child processes to reload configuration |
| 795 |
if (kill(-getpid(), SIGUSR1) < 0) |
if (kill(0, SIGUSR1) < 0) |
| 796 |
{ |
{ |
| 797 |
log_error("Send SIGUSR1 signal failed (%d)\n", errno); |
log_error("Send SIGUSR1 signal failed (%d)\n", errno); |
| 798 |
} |
} |
| 850 |
while (!SYS_server_exit) // Accept all incoming connections until error |
while (!SYS_server_exit) // Accept all incoming connections until error |
| 851 |
{ |
{ |
| 852 |
addrlen = sizeof(sin); |
addrlen = sizeof(sin); |
| 853 |
socket_client = accept(socket_server[SSH_v2], (struct sockaddr *)&sin, &addrlen); |
socket_client = accept(socket_server[SSH_v2], (struct sockaddr *)&sin, (socklen_t *)&addrlen); |
| 854 |
if (socket_client < 0) |
if (socket_client < 0) |
| 855 |
{ |
{ |
| 856 |
if (errno == EAGAIN || errno == EWOULDBLOCK) |
if (errno == EAGAIN || errno == EWOULDBLOCK) |