/[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.67 by sysadm, Wed Jun 25 02:49:20 2025 UTC Revision 1.70 by sysadm, Sun Jun 29 03:32:39 2025 UTC
# Line 45  Line 45 
45  #include <sys/wait.h>  #include <sys/wait.h>
46  #include <systemd/sd-daemon.h>  #include <systemd/sd-daemon.h>
47    
48    #define WAIT_CHILD_PROCESS_EXIT_TIMEOUT 5 // second
49    #define WAIT_CHILD_PROCESS_KILL_TIMEOUT 1 // second
50    
51  struct process_sockaddr_t  struct process_sockaddr_t
52  {  {
53          pid_t pid;          pid_t pid;
# Line 258  int net_server(const char *hostaddr, in_ Line 261  int net_server(const char *hostaddr, in_
261          struct epoll_event ev, events[MAX_EVENTS];          struct epoll_event ev, events[MAX_EVENTS];
262          int nfds, epollfd;          int nfds, epollfd;
263          siginfo_t siginfo;          siginfo_t siginfo;
264            int notify_child_exit = 0;
265            time_t tm_notify_child_exit = time(NULL);
266          int sd_notify_stopping = 0;          int sd_notify_stopping = 0;
267          MENU_SET bbs_menu_new;          MENU_SET bbs_menu_new;
268          int i, j;          int i, j;
# Line 400  int net_server(const char *hostaddr, in_ Line 405  int net_server(const char *hostaddr, in_
405    
406                  if (SYS_server_exit && !SYS_child_exit && SYS_child_process_count > 0)                  if (SYS_server_exit && !SYS_child_exit && SYS_child_process_count > 0)
407                  {                  {
408                          log_common("Notify %d child process to exit\n", SYS_child_process_count);                          if (notify_child_exit == 0)
                         if (kill(0, SIGTERM) < 0)  
409                          {                          {
410                                  log_error("Send SIGTERM signal failed (%d)\n", errno);                                  sd_notifyf(0, "STATUS=Notify %d child process to exit", SYS_child_process_count);
411                                    log_common("Notify %d child process to exit\n", SYS_child_process_count);
412    
413                                    if (kill(0, SIGTERM) < 0)
414                                    {
415                                            log_error("Send SIGTERM signal failed (%d)\n", errno);
416                                    }
417    
418                                    notify_child_exit = 1;
419                                    tm_notify_child_exit = time(NULL);
420                          }                          }
421                            else if (notify_child_exit == 1 && time(NULL) - tm_notify_child_exit >= WAIT_CHILD_PROCESS_EXIT_TIMEOUT)
422                            {
423                                    sd_notifyf(0, "STATUS=Kill %d child process", SYS_child_process_count);
424    
425                                    for (i = 0; i < BBS_max_client; i++)
426                                    {
427                                            if (process_sockaddr_pool[i].pid != 0)
428                                            {
429                                                    log_error("Kill child process (pid=%d)\n", process_sockaddr_pool[i].pid);
430                                                    if (kill(process_sockaddr_pool[i].pid, SIGKILL) < 0)
431                                                    {
432                                                            log_error("Send SIGKILL signal failed (%d)\n", errno);
433                                                    }
434                                            }
435                                    }
436    
437                          sd_notifyf(0, "STATUS=Waiting for %d child process to exit", SYS_child_process_count);                                  notify_child_exit = 2;
438                                    tm_notify_child_exit = time(NULL);
439                            }
440                            else if (notify_child_exit == 2 && time(NULL) - tm_notify_child_exit >= WAIT_CHILD_PROCESS_KILL_TIMEOUT)
441                            {
442                                    log_error("Main process prepare to exit without waiting for %d child process any longer\n", SYS_child_process_count);
443                                    SYS_child_process_count = 0;
444                            }
445                  }                  }
446    
447                  if (SYS_conf_reload && !SYS_server_exit)                  if (SYS_conf_reload && !SYS_server_exit)
# Line 420  int net_server(const char *hostaddr, in_ Line 455  int net_server(const char *hostaddr, in_
455                                  log_error("Reload conf failed\n");                                  log_error("Reload conf failed\n");
456                          }                          }
457    
458                          // acquire rw lock of all sections to avoid conflict with menu reload in data loader process                          if (load_menu(&bbs_menu_new, CONF_MENU) < 0)
                         ret = section_list_rw_lock(NULL);  
                         if (ret < 0)  
459                          {                          {
460                                  log_error("section_list_rw_lock(NULL) error\n");                                  unload_menu(&bbs_menu_new);
461                                    log_error("Reload menu failed\n");
462                          }                          }
463                          else                          else
464                          {                          {
465                                  if (load_menu(&bbs_menu_new, CONF_MENU) < 0)                                  unload_menu(&bbs_menu);
466                                  {                                  memcpy(&bbs_menu, &bbs_menu_new, sizeof(bbs_menu_new));
467                                          unload_menu(&bbs_menu_new);                                  log_common("Reload menu successfully\n");
                                         log_error("Reload menu failed\n");  
                                 }  
                                 else  
                                 {  
                                         unload_menu(&bbs_menu);  
                                         memcpy(&bbs_menu, &bbs_menu_new, sizeof(bbs_menu_new));  
                                         log_common("Reload menu successfully\n");  
                                 }  
   
                                 // release rw lock of all sections  
                                 ret = section_list_rw_unlock(NULL);  
                                 if (ret < 0)  
                                 {  
                                         log_error("section_list_rw_unlock(NULL) error\n");  
                                 }  
468                          }                          }
469    
                         sd_notify(0, "READY=1");  
                 }  
   
                 if (SYS_data_file_reload && !SYS_server_exit)  
                 {  
                         SYS_data_file_reload = 0;  
                         sd_notify(0, "RELOADING=1");  
   
470                          for (int i = 0; i < data_files_load_startup_count; i++)                          for (int i = 0; i < data_files_load_startup_count; i++)
471                          {                          {
472                                  if (load_file(data_files_load_startup[i]) < 0)                                  if (load_file(data_files_load_startup[i]) < 0)
# Line 463  int net_server(const char *hostaddr, in_ Line 474  int net_server(const char *hostaddr, in_
474                                          log_error("load_file_mmap(%s) error\n", data_files_load_startup[i]);                                          log_error("load_file_mmap(%s) error\n", data_files_load_startup[i]);
475                                  }                                  }
476                          }                          }
   
477                          log_common("Reload data files successfully\n");                          log_common("Reload data files successfully\n");
                         sd_notify(0, "READY=1");  
                 }  
478    
479                  if (SYS_section_list_reload && !SYS_server_exit)                          // Load section config and gen_ex
480                  {                          if (load_section_config_from_db(1) < 0)
                         SYS_section_list_reload = 0;  
   
                         if (section_list_loader_reload() < 0)  
481                          {                          {
482                                  log_error("section_list_loader_reload() failed\n");                                  log_error("load_section_config_from_db(1) error\n");
483                          }                          }
484                            else
485                            {
486                                    log_common("Reload section config and gen_ex successfully\n");
487                            }
488    
489                            sd_notify(0, "READY=1");
490                  }                  }
491    
492                  nfds = epoll_wait(epollfd, events, MAX_EVENTS, 100); // 0.1 second                  nfds = epoll_wait(epollfd, events, MAX_EVENTS, 100); // 0.1 second


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

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