/[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.90 by sysadm, Mon Nov 17 09:42:52 2025 UTC Revision 1.97 by sysadm, Fri Nov 28 03:23:58 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_key_valid = 0;
527          int ssh_log_level = SSH_LOG_NOLOG;          int ssh_log_level = SSH_LOG_NOLOG;
528    
529  #ifdef HAVE_SYSTEMD_SD_DAEMON_H  #ifdef HAVE_SYSTEMD_SD_DAEMON_H
# Line 525  int net_server(const char *hostaddr, in_ Line 534  int net_server(const char *hostaddr, in_
534    
535          sshbind = ssh_bind_new();          sshbind = ssh_bind_new();
536    
537            if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, SSH_HOST_RSA_KEY_FILE) < 0)
538            {
539                    log_error("Error setting SSH RSA key: %s\n", SSH_HOST_RSA_KEY_FILE);
540            }
541            else
542            {
543                    ssh_key_valid = 1;
544            }
545            if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, SSH_HOST_ED25519_KEY_FILE) < 0)
546            {
547                    log_error("Error setting SSH ED25519 key: %s\n", SSH_HOST_ED25519_KEY_FILE);
548            }
549            else
550            {
551                    ssh_key_valid = 1;
552            }
553    
554            if (!ssh_key_valid)
555            {
556                    log_error("Error: no valid SSH host key\n");
557                    ssh_bind_free(sshbind);
558                    return -1;
559            }
560    
561          if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDADDR, hostaddr) < 0 ||          if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDADDR, hostaddr) < 0 ||
562                  ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDPORT, &port) < 0 ||                  ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDPORT, &port) < 0 ||
563                  ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, SSH_HOST_KEYFILE) < 0 ||                  ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY_ALGORITHMS, "ssh-rsa,rsa-sha2-512,rsa-sha2-256,ssh-ed25519") < 0 ||
                 ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY_ALGORITHMS, "ssh-rsa,rsa-sha2-512,rsa-sha2-256") < 0 ||  
564                  ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_LOG_VERBOSITY, &ssh_log_level) < 0)                  ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_LOG_VERBOSITY, &ssh_log_level) < 0)
565          {          {
566                  log_error("Error setting SSH bind options: %s\n", ssh_get_error(sshbind));                  log_error("Error setting SSH bind options: %s\n", ssh_get_error(sshbind));
# Line 641  int net_server(const char *hostaddr, in_ Line 673  int net_server(const char *hostaddr, in_
673                  {                  {
674                          SYS_child_exit = 0;                          SYS_child_exit = 0;
675    
676                          pid = waitpid(-1, NULL, WNOHANG);                          pid = waitpid(-1, &ret, WNOHANG);
677                          if (pid > 0)                          if (pid > 0)
678                          {                          {
679                                  SYS_child_exit = 1; // Retry waitid                                  SYS_child_exit = 1; // Retry waitid
   
680                                  SYS_child_process_count--;                                  SYS_child_process_count--;
681                                  log_common("Child process (%d) exited\n", pid);  
682                                    if (WIFEXITED(ret))
683                                    {
684                                            log_common("Child process (%d) exited, status=%d\n", pid, WEXITSTATUS(ret));
685                                    }
686                                    else if (WIFSIGNALED(ret))
687                                    {
688                                            log_common("Child process (%d) is killed, status=%d\n", pid, WTERMSIG(ret));
689                                    }
690                                    else
691                                    {
692                                            log_common("Child process (%d) exited abnormally, status=%d\n", pid, ret);
693                                    }
694    
695                                  if (pid != section_list_loader_pid)                                  if (pid != section_list_loader_pid)
696                                  {                                  {
# Line 693  int net_server(const char *hostaddr, in_ Line 736  int net_server(const char *hostaddr, in_
736                                  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);
737  #endif  #endif
738    
739                                  if (kill(-getpid(), SIGTERM) < 0)                                  if (kill(0, SIGTERM) < 0)
740                                  {                                  {
741                                          log_error("Send SIGTERM signal failed (%d)\n", errno);                                          log_error("Send SIGTERM signal failed (%d)\n", errno);
742                                  }                                  }
# Line 707  int net_server(const char *hostaddr, in_ Line 750  int net_server(const char *hostaddr, in_
750                                  sd_notifyf(0, "STATUS=Kill %d child process", SYS_child_process_count);                                  sd_notifyf(0, "STATUS=Kill %d child process", SYS_child_process_count);
751  #endif  #endif
752    
753                                  if (kill(-getpid(), SIGKILL) < 0)                                  if (kill(0, SIGKILL) < 0)
754                                  {                                  {
755                                          log_error("Send SIGKILL signal failed (%d)\n", errno);                                          log_error("Send SIGKILL signal failed (%d)\n", errno);
756                                  }                                  }
# Line 748  int net_server(const char *hostaddr, in_ Line 791  int net_server(const char *hostaddr, in_
791                                  log_error("Reload BWF conf failed\n");                                  log_error("Reload BWF conf failed\n");
792                          }                          }
793    
794                          if (load_menu(&bbs_menu_new, CONF_MENU) < 0)                          if (detach_menu_shm(&bbs_menu) < 0)
795                          {                          {
796                                  unload_menu(&bbs_menu_new);                                  log_error("detach_menu_shm(bbs_menu) error\n");
                                 log_error("Reload bbs menu failed\n");  
797                          }                          }
798                          else                          if (load_menu(&bbs_menu, CONF_MENU) < 0)
799                          {                          {
800                                    log_error("load_menu(bbs_menu) error\n");
801                                  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");  
802                          }                          }
803    
804                          if (load_menu(&top10_menu_new, CONF_TOP10_MENU) < 0)                          if (detach_menu_shm(&top10_menu) < 0)
805                          {                          {
806                                  unload_menu(&top10_menu_new);                                  log_error("detach_menu_shm(top10_menu) error\n");
                                 log_error("Reload top10 menu failed\n");  
807                          }                          }
808                          else                          if (load_menu(&top10_menu, CONF_TOP10_MENU) < 0)
809                          {                          {
810                                    log_error("load_menu(top10_menu) error\n");
811                                  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");  
812                          }                          }
813    
814                          for (int i = 0; i < data_files_load_startup_count; i++)                          for (int i = 0; i < data_files_load_startup_count; i++)
# Line 780  int net_server(const char *hostaddr, in_ Line 818  int net_server(const char *hostaddr, in_
818                                          log_error("load_file(%s) error\n", data_files_load_startup[i]);                                          log_error("load_file(%s) error\n", data_files_load_startup[i]);
819                                  }                                  }
820                          }                          }
                         log_common("Reload data files successfully\n");  
821    
822                          // Load section config and gen_ex                          // Load section config and gen_ex
823                          if (load_section_config_from_db(1) < 0)                          if (load_section_config_from_db(1) < 0)
824                          {                          {
825                                  log_error("load_section_config_from_db(1) error\n");                                  log_error("load_section_config_from_db(1) error\n");
826                          }                          }
                         else  
                         {  
                                 log_common("Reload section config and gen_ex successfully\n");  
                         }  
827    
828                          // Notify child processes to reload configuration                          // Notify child processes to reload configuration
829                          if (kill(-getpid(), SIGUSR1) < 0)                          if (kill(0, SIGUSR1) < 0)
830                          {                          {
831                                  log_error("Send SIGUSR1 signal failed (%d)\n", errno);                                  log_error("Send SIGUSR1 signal failed (%d)\n", errno);
832                          }                          }
# Line 851  int net_server(const char *hostaddr, in_ Line 884  int net_server(const char *hostaddr, in_
884                                  while (!SYS_server_exit) // Accept all incoming connections until error                                  while (!SYS_server_exit) // Accept all incoming connections until error
885                                  {                                  {
886                                          addrlen = sizeof(sin);                                          addrlen = sizeof(sin);
887                                          socket_client = accept(socket_server[SSH_v2], (struct sockaddr *)&sin, &addrlen);                                          socket_client = accept(socket_server[SSH_v2], (struct sockaddr *)&sin, (socklen_t *)&addrlen);
888                                          if (socket_client < 0)                                          if (socket_client < 0)
889                                          {                                          {
890                                                  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