/[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.30 by sysadm, Tue May 13 07:30:53 2025 UTC Revision 1.39 by sysadm, Sun May 25 06:55:23 2025 UTC
# Line 24  Line 24 
24  #include "io.h"  #include "io.h"
25  #include "fork.h"  #include "fork.h"
26  #include "menu.h"  #include "menu.h"
27    #include "file_loader.h"
28  #include <errno.h>  #include <errno.h>
29  #include <fcntl.h>  #include <fcntl.h>
30  #include <string.h>  #include <string.h>
# Line 35  Line 36 
36  #include <sys/wait.h>  #include <sys/wait.h>
37  #include <sys/epoll.h>  #include <sys/epoll.h>
38  #include <arpa/inet.h>  #include <arpa/inet.h>
39    #include <systemd/sd-daemon.h>
40    
41  int net_server(const char *hostaddr, in_port_t port)  int net_server(const char *hostaddr, in_port_t port)
42  {  {
# Line 45  int net_server(const char *hostaddr, in_ Line 47  int net_server(const char *hostaddr, in_
47          struct epoll_event ev, events[MAX_EVENTS];          struct epoll_event ev, events[MAX_EVENTS];
48          int nfds, epollfd;          int nfds, epollfd;
49          siginfo_t siginfo;          siginfo_t siginfo;
50            int sd_notify_stopping = 0;
51            MENU_SET *p_bbs_menu_new;
52    
53          socket_server = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);          socket_server = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
54    
# Line 112  int net_server(const char *hostaddr, in_ Line 116  int net_server(const char *hostaddr, in_
116          flags = fcntl(socket_server, F_GETFL, 0);          flags = fcntl(socket_server, F_GETFL, 0);
117          fcntl(socket_server, F_SETFL, flags | O_NONBLOCK);          fcntl(socket_server, F_SETFL, flags | O_NONBLOCK);
118    
119            // Startup complete
120            sd_notifyf(0, "READY=1\n"
121                                      "STATUS=Listening at %s:%d\n"
122                                      "MAINPID=%d",
123                               hostaddr_server, port_server, getpid());
124    
125          while (!SYS_server_exit || SYS_child_process_count > 0)          while (!SYS_server_exit || SYS_child_process_count > 0)
126          {          {
127                    if (SYS_server_exit && !sd_notify_stopping)
128                    {
129                            sd_notify(0, "STOPPING=1");
130                            sd_notify_stopping = 1;
131                    }
132    
133                  while ((SYS_child_exit || SYS_server_exit) && SYS_child_process_count > 0)                  while ((SYS_child_exit || SYS_server_exit) && SYS_child_process_count > 0)
134                  {                  {
135                          SYS_child_exit = 0;                          SYS_child_exit = 0;
# Line 145  int net_server(const char *hostaddr, in_ Line 161  int net_server(const char *hostaddr, in_
161                          {                          {
162                                  log_error("Send SIGTERM signal failed (%d)\n", errno);                                  log_error("Send SIGTERM signal failed (%d)\n", errno);
163                          }                          }
164    
165                            sd_notifyf(0, "STATUS=Waiting for %d child process to exit", SYS_child_process_count);
166                  }                  }
167    
168                  if (SYS_menu_reload && !SYS_server_exit)                  if (SYS_menu_reload && !SYS_server_exit)
169                  {                  {
170                          SYS_menu_reload = 0;                          SYS_menu_reload = 0;
171                            sd_notify(0, "RELOADING=1");
172    
173                          if (reload_menu(&bbs_menu) < 0)                          p_bbs_menu_new = calloc(1, sizeof(MENU_SET));
174                            if (p_bbs_menu_new == NULL)
175                          {                          {
176                                    log_error("OOM: calloc(MENU_SET)\n");
177                            }
178                            else if (load_menu(p_bbs_menu_new, CONF_MENU) < 0)
179                            {
180                                    unload_menu(p_bbs_menu_new);
181                                    free(p_bbs_menu_new);
182                                    p_bbs_menu_new = NULL;
183    
184                                  log_error("Reload menu failed\n");                                  log_error("Reload menu failed\n");
185                          }                          }
186                          else                          else
187                          {                          {
188                                    unload_menu(p_bbs_menu);
189                                    free(p_bbs_menu);
190    
191                                    p_bbs_menu = p_bbs_menu_new;
192                                    p_bbs_menu_new = NULL;
193    
194                                  log_std("Reload menu successfully\n");                                  log_std("Reload menu successfully\n");
195                          }                          }
196    
197                            sd_notify(0, "READY=1");
198                    }
199    
200                    if (SYS_data_file_reload && !SYS_server_exit)
201                    {
202                            SYS_data_file_reload = 0;
203                            sd_notify(0, "RELOADING=1");
204    
205                            for (int i = 0; i < data_files_load_startup_count; i++)
206                            {
207                                    if (load_file(data_files_load_startup[i]) < 0)
208                                    {
209                                            log_error("load_file_mmap(%s) error\n", data_files_load_startup[i]);
210                                    }
211                            }
212    
213                            log_std("Reload data files successfully\n");
214                            sd_notify(0, "READY=1");
215                  }                  }
216    
217                  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