/[LeafOK_CVS]/lbbs/src/net_server.c
ViewVC logotype

Diff of /lbbs/src/net_server.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.89 by sysadm, Mon Nov 17 09:33:58 2025 UTC Revision 1.96 by sysadm, Fri Nov 21 10:34:10 2025 UTC
# Line 446  static int fork_server(void) Line 446  static int fork_server(void)
446    
447          SYS_child_process_count = 0;          SYS_child_process_count = 0;
448    
449            // BWF compile
450            if (bwf_compile() < 0)
451            {
452                    log_error("bwf_compile() error\n");
453                    goto cleanup;
454            }
455    
456          bbs_main();          bbs_main();
457    
458  cleanup:  cleanup:
# Line 482  cleanup: Line 489  cleanup:
489          ssh_free(SSH_session);          ssh_free(SSH_session);
490          ssh_finalize();          ssh_finalize();
491    
492            // BWF cleanup
493            bwf_cleanup();
494    
495          // Close Input and Output for client          // Close Input and Output for client
496          io_cleanup();          io_cleanup();
497          close(STDIN_FILENO);          close(STDIN_FILENO);
# Line 511  int net_server(const char *hostaddr, in_ Line 521  int net_server(const char *hostaddr, in_
521          int nfds;          int nfds;
522          int notify_child_exit = 0;          int notify_child_exit = 0;
523          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;  
524          int i, j;          int i, j;
525          pid_t pid;          pid_t pid;
526          int ssh_log_level = SSH_LOG_NOLOG;          int ssh_log_level = SSH_LOG_NOLOG;
# Line 566  int net_server(const char *hostaddr, in_ Line 574  int net_server(const char *hostaddr, in_
574                  {                  {
575                          log_error("setsockopt SO_REUSEADDR error (%d)\n", errno);                          log_error("setsockopt SO_REUSEADDR error (%d)\n", errno);
576                  }                  }
577    #if defined(SO_REUSEPORT)
578                  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)
579                  {                  {
580                          log_error("setsockopt SO_REUSEPORT error (%d)\n", errno);                          log_error("setsockopt SO_REUSEPORT error (%d)\n", errno);
581                  }                  }
582    #endif
583    
584                  if (bind(socket_server[i], (struct sockaddr *)&sin, sizeof(sin)) < 0)                  if (bind(socket_server[i], (struct sockaddr *)&sin, sizeof(sin)) < 0)
585                  {                  {
# Line 639  int net_server(const char *hostaddr, in_ Line 649  int net_server(const char *hostaddr, in_
649                  {                  {
650                          SYS_child_exit = 0;                          SYS_child_exit = 0;
651    
652                          pid = waitpid(-1, NULL, WNOHANG);                          pid = waitpid(-1, &ret, WNOHANG);
653                          if (pid > 0)                          if (pid > 0)
654                          {                          {
655                                  SYS_child_exit = 1; // Retry waitid                                  SYS_child_exit = 1; // Retry waitid
   
656                                  SYS_child_process_count--;                                  SYS_child_process_count--;
657                                  log_common("Child process (%d) exited\n", pid);  
658                                    if (WIFEXITED(ret))
659                                    {
660                                            log_common("Child process (%d) exited, status=%d\n", pid, WEXITSTATUS(ret));
661                                    }
662                                    else if (WIFSIGNALED(ret))
663                                    {
664                                            log_common("Child process (%d) is killed, status=%d\n", pid, WTERMSIG(ret));
665                                    }
666                                    else
667                                    {
668                                            log_common("Child process (%d) exited abnormally, status=%d\n", pid, ret);
669                                    }
670    
671                                  if (pid != section_list_loader_pid)                                  if (pid != section_list_loader_pid)
672                                  {                                  {
# Line 691  int net_server(const char *hostaddr, in_ Line 712  int net_server(const char *hostaddr, in_
712                                  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);
713  #endif  #endif
714    
715                                  if (kill(-getpid(), SIGTERM) < 0)                                  if (kill(0, SIGTERM) < 0)
716                                  {                                  {
717                                          log_error("Send SIGTERM signal failed (%d)\n", errno);                                          log_error("Send SIGTERM signal failed (%d)\n", errno);
718                                  }                                  }
# Line 705  int net_server(const char *hostaddr, in_ Line 726  int net_server(const char *hostaddr, in_
726                                  sd_notifyf(0, "STATUS=Kill %d child process", SYS_child_process_count);                                  sd_notifyf(0, "STATUS=Kill %d child process", SYS_child_process_count);
727  #endif  #endif
728    
729                                  if (kill(-getpid(), SIGKILL) < 0)                                  if (kill(0, SIGKILL) < 0)
730                                  {                                  {
731                                          log_error("Send SIGKILL signal failed (%d)\n", errno);                                          log_error("Send SIGKILL signal failed (%d)\n", errno);
732                                  }                                  }
# Line 746  int net_server(const char *hostaddr, in_ Line 767  int net_server(const char *hostaddr, in_
767                                  log_error("Reload BWF conf failed\n");                                  log_error("Reload BWF conf failed\n");
768                          }                          }
769    
770                          if (load_menu(&bbs_menu_new, CONF_MENU) < 0)                          if (detach_menu_shm(&bbs_menu) < 0)
771                          {                          {
772                                  unload_menu(&bbs_menu_new);                                  log_error("detach_menu_shm(bbs_menu) error\n");
                                 log_error("Reload bbs menu failed\n");  
773                          }                          }
774                          else                          if (load_menu(&bbs_menu, CONF_MENU) < 0)
775                          {                          {
776                                    log_error("load_menu(bbs_menu) error\n");
777                                  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");  
778                          }                          }
779    
780                          if (load_menu(&top10_menu_new, CONF_TOP10_MENU) < 0)                          if (detach_menu_shm(&top10_menu) < 0)
781                          {                          {
782                                  unload_menu(&top10_menu_new);                                  log_error("detach_menu_shm(top10_menu) error\n");
                                 log_error("Reload top10 menu failed\n");  
783                          }                          }
784                          else                          if (load_menu(&top10_menu, CONF_TOP10_MENU) < 0)
785                          {                          {
786                                    log_error("load_menu(top10_menu) error\n");
787                                  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");  
788                          }                          }
789    
790                          for (int i = 0; i < data_files_load_startup_count; i++)                          for (int i = 0; i < data_files_load_startup_count; i++)
# Line 778  int net_server(const char *hostaddr, in_ Line 794  int net_server(const char *hostaddr, in_
794                                          log_error("load_file(%s) error\n", data_files_load_startup[i]);                                          log_error("load_file(%s) error\n", data_files_load_startup[i]);
795                                  }                                  }
796                          }                          }
                         log_common("Reload data files successfully\n");  
797    
798                          // Load section config and gen_ex                          // Load section config and gen_ex
799                          if (load_section_config_from_db(1) < 0)                          if (load_section_config_from_db(1) < 0)
800                          {                          {
801                                  log_error("load_section_config_from_db(1) error\n");                                  log_error("load_section_config_from_db(1) error\n");
802                          }                          }
                         else  
                         {  
                                 log_common("Reload section config and gen_ex successfully\n");  
                         }  
803    
804                          // Notify child processes to reload configuration                          // Notify child processes to reload configuration
805                          if (kill(-getpid(), SIGUSR1) < 0)                          if (kill(0, SIGUSR1) < 0)
806                          {                          {
807                                  log_error("Send SIGUSR1 signal failed (%d)\n", errno);                                  log_error("Send SIGUSR1 signal failed (%d)\n", errno);
808                          }                          }
# Line 849  int net_server(const char *hostaddr, in_ Line 860  int net_server(const char *hostaddr, in_
860                                  while (!SYS_server_exit) // Accept all incoming connections until error                                  while (!SYS_server_exit) // Accept all incoming connections until error
861                                  {                                  {
862                                          addrlen = sizeof(sin);                                          addrlen = sizeof(sin);
863                                          socket_client = accept(socket_server[SSH_v2], (struct sockaddr *)&sin, &addrlen);                                          socket_client = accept(socket_server[SSH_v2], (struct sockaddr *)&sin, (socklen_t *)&addrlen);
864                                          if (socket_client < 0)                                          if (socket_client < 0)
865                                          {                                          {
866                                                  if (errno == EAGAIN || errno == EWOULDBLOCK)                                                  if (errno == EAGAIN || errno == EWOULDBLOCK)


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1