/[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.31 by sysadm, Tue May 13 10:42:21 2025 UTC Revision 1.43 by sysadm, Sat May 31 14:05:53 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 "section_list_loader.h"
29  #include <errno.h>  #include <errno.h>
30  #include <fcntl.h>  #include <fcntl.h>
31  #include <string.h>  #include <string.h>
# Line 47  int net_server(const char *hostaddr, in_ Line 49  int net_server(const char *hostaddr, in_
49          int nfds, epollfd;          int nfds, epollfd;
50          siginfo_t siginfo;          siginfo_t siginfo;
51          int sd_notify_stopping = 0;          int sd_notify_stopping = 0;
52            MENU_SET *p_bbs_menu_new;
53    
54          socket_server = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);          socket_server = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
55    
# Line 116  int net_server(const char *hostaddr, in_ Line 119  int net_server(const char *hostaddr, in_
119    
120          // Startup complete          // Startup complete
121          sd_notifyf(0, "READY=1\n"          sd_notifyf(0, "READY=1\n"
122                                    "STATUS=Accepting incoming connections...\n"                                    "STATUS=Listening at %s:%d\n"
123                                    "MAINPID=%d",                                    "MAINPID=%d",
124                             getpid());                             hostaddr_server, port_server, getpid());
125    
126          while (!SYS_server_exit || SYS_child_process_count > 0)          while (!SYS_server_exit || SYS_child_process_count > 0)
127          {          {
# Line 127  int net_server(const char *hostaddr, in_ Line 130  int net_server(const char *hostaddr, in_
130                          sd_notify(0, "STOPPING=1");                          sd_notify(0, "STOPPING=1");
131                          sd_notify_stopping = 1;                          sd_notify_stopping = 1;
132                  }                  }
133    
134                  while ((SYS_child_exit || SYS_server_exit) && SYS_child_process_count > 0)                  while ((SYS_child_exit || SYS_server_exit) && SYS_child_process_count > 0)
135                  {                  {
136                          SYS_child_exit = 0;                          SYS_child_exit = 0;
# Line 165  int net_server(const char *hostaddr, in_ Line 169  int net_server(const char *hostaddr, in_
169                  if (SYS_menu_reload && !SYS_server_exit)                  if (SYS_menu_reload && !SYS_server_exit)
170                  {                  {
171                          SYS_menu_reload = 0;                          SYS_menu_reload = 0;
172                            sd_notify(0, "RELOADING=1");
173    
174                          if (reload_menu(&bbs_menu) < 0)                          p_bbs_menu_new = calloc(1, sizeof(MENU_SET));
175                            if (p_bbs_menu_new == NULL)
176                            {
177                                    log_error("OOM: calloc(MENU_SET)\n");
178                            }
179                            else if (load_menu(p_bbs_menu_new, CONF_MENU) < 0)
180                          {                          {
181                                    unload_menu(p_bbs_menu_new);
182                                    free(p_bbs_menu_new);
183                                    p_bbs_menu_new = NULL;
184    
185                                  log_error("Reload menu failed\n");                                  log_error("Reload menu failed\n");
186                          }                          }
187                          else                          else
188                          {                          {
189                                    unload_menu(p_bbs_menu);
190                                    free(p_bbs_menu);
191    
192                                    p_bbs_menu = p_bbs_menu_new;
193                                    p_bbs_menu_new = NULL;
194    
195                                  log_std("Reload menu successfully\n");                                  log_std("Reload menu successfully\n");
196                          }                          }
197    
198                            sd_notify(0, "READY=1");
199                    }
200    
201                    if (SYS_data_file_reload && !SYS_server_exit)
202                    {
203                            SYS_data_file_reload = 0;
204                            sd_notify(0, "RELOADING=1");
205    
206                            for (int i = 0; i < data_files_load_startup_count; i++)
207                            {
208                                    if (load_file(data_files_load_startup[i]) < 0)
209                                    {
210                                            log_error("load_file_mmap(%s) error\n", data_files_load_startup[i]);
211                                    }
212                            }
213    
214                            log_std("Reload data files successfully\n");
215                            sd_notify(0, "READY=1");
216                    }
217    
218                    if (SYS_section_list_reload && !SYS_server_exit)
219                    {
220                            SYS_section_list_reload = 0;
221    
222                            if (section_list_loader_reload() < 0)
223                            {
224                                    log_error("ksection_list_loader_reload() failed\n");
225                            }
226                  }                  }
227    
228                  nfds = epoll_wait(epollfd, events, MAX_EVENTS, 100); // 0.1 second                  nfds = epoll_wait(epollfd, events, MAX_EVENTS, 100); // 0.1 second
# Line 225  int net_server(const char *hostaddr, in_ Line 274  int net_server(const char *hostaddr, in_
274    
275                                          log_std("Accept connection from %s:%d\n", hostaddr_client, port_client);                                          log_std("Accept connection from %s:%d\n", hostaddr_client, port_client);
276    
277                                          if (fork_server() < 0)                                          if (SYS_child_process_count - 1 < BBS_max_client)
278                                            {
279                                                    if (fork_server() < 0)
280                                                    {
281                                                            log_error("fork_server() error\n");
282                                                    }
283                                            }
284                                            else
285                                          {                                          {
286                                                  log_error("fork_server() error\n");                                                  log_error("Rejected client connection over limit (%d)\n", SYS_child_process_count - 1);
287                                          }                                          }
288    
289                                          if (close(socket_client) == -1)                                          if (close(socket_client) == -1)


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

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