/[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.44 by sysadm, Sun Jun 1 03:07:42 2025 UTC Revision 1.50 by sysadm, Wed Jun 4 14:41:17 2025 UTC
# Line 38  Line 38 
38  #include <sys/wait.h>  #include <sys/wait.h>
39  #include <sys/epoll.h>  #include <sys/epoll.h>
40  #include <arpa/inet.h>  #include <arpa/inet.h>
41    #include <netinet/in.h>
42  #include <systemd/sd-daemon.h>  #include <systemd/sd-daemon.h>
43    
44  struct process_sockaddr_t  struct process_sockaddr_t
# Line 47  struct process_sockaddr_t Line 48  struct process_sockaddr_t
48  };  };
49  typedef struct process_sockaddr_t PROCESS_SOCKADDR;  typedef struct process_sockaddr_t PROCESS_SOCKADDR;
50    
51  static PROCESS_SOCKADDR process_sockaddr_pool[MAX_CLIENTS_LIMIT];  static PROCESS_SOCKADDR process_sockaddr_pool[MAX_CLIENT_LIMIT];
52    
53  int net_server(const char *hostaddr, in_port_t port)  int net_server(const char *hostaddr, in_port_t port)
54  {  {
# Line 105  int net_server(const char *hostaddr, in_ Line 106  int net_server(const char *hostaddr, in_
106          port_server = ntohs(sin.sin_port);          port_server = ntohs(sin.sin_port);
107          namelen = sizeof(sin);          namelen = sizeof(sin);
108    
109          log_std("Listening at %s:%d\n", hostaddr_server, port_server);          log_common("Listening at %s:%d\n", hostaddr_server, port_server);
110    
111          epollfd = epoll_create1(0);          epollfd = epoll_create1(0);
112          if (epollfd < 0)          if (epollfd < 0)
# Line 154  int net_server(const char *hostaddr, in_ Line 155  int net_server(const char *hostaddr, in_
155                                  SYS_child_exit = 1; // Retry waitid                                  SYS_child_exit = 1; // Retry waitid
156    
157                                  SYS_child_process_count--;                                  SYS_child_process_count--;
158                                  log_std("Child process (%d) exited\n", siginfo.si_pid);                                  log_common("Child process (%d) exited\n", siginfo.si_pid);
159    
160                                  i = 0;                                  if (siginfo.si_pid != section_list_loader_pid)
                                 for (; i < BBS_max_client; i++)  
161                                  {                                  {
162                                          if (process_sockaddr_pool[i].pid == siginfo.si_pid)                                          i = 0;
163                                            for (; i < BBS_max_client; i++)
164                                          {                                          {
165                                                  process_sockaddr_pool[i].pid = 0;                                                  if (process_sockaddr_pool[i].pid == siginfo.si_pid)
166                                                  break;                                                  {
167                                                            process_sockaddr_pool[i].pid = 0;
168                                                            break;
169                                                    }
170                                            }
171                                            if (i >= BBS_max_client)
172                                            {
173                                                    log_error("Child process (%d) not found in process sockaddr pool\n", siginfo.si_pid);
174                                          }                                          }
                                 }  
                                 if (i >= BBS_max_client)  
                                 {  
                                         log_error("Child process (%d) not found in process sockaddr pool\n", siginfo.si_pid);  
175                                  }                                  }
176                          }                          }
177                          else if (ret == 0)                          else if (ret == 0)
# Line 183  int net_server(const char *hostaddr, in_ Line 187  int net_server(const char *hostaddr, in_
187    
188                  if (SYS_server_exit && !SYS_child_exit && SYS_child_process_count > 0)                  if (SYS_server_exit && !SYS_child_exit && SYS_child_process_count > 0)
189                  {                  {
190                          log_std("Notify %d child process to exit\n", SYS_child_process_count);                          log_common("Notify %d child process to exit\n", SYS_child_process_count);
191                          if (kill(0, SIGTERM) < 0)                          if (kill(0, SIGTERM) < 0)
192                          {                          {
193                                  log_error("Send SIGTERM signal failed (%d)\n", errno);                                  log_error("Send SIGTERM signal failed (%d)\n", errno);
# Line 224  int net_server(const char *hostaddr, in_ Line 228  int net_server(const char *hostaddr, in_
228                                  p_bbs_menu = p_bbs_menu_new;                                  p_bbs_menu = p_bbs_menu_new;
229                                  p_bbs_menu_new = NULL;                                  p_bbs_menu_new = NULL;
230    
231                                  log_std("Reload menu successfully\n");                                  log_common("Reload menu successfully\n");
232                          }                          }
233    
234                          sd_notify(0, "READY=1");                          sd_notify(0, "READY=1");
# Line 243  int net_server(const char *hostaddr, in_ Line 247  int net_server(const char *hostaddr, in_
247                                  }                                  }
248                          }                          }
249    
250                          log_std("Reload data files successfully\n");                          log_common("Reload data files successfully\n");
251                          sd_notify(0, "READY=1");                          sd_notify(0, "READY=1");
252                  }                  }
253    
# Line 304  int net_server(const char *hostaddr, in_ Line 308  int net_server(const char *hostaddr, in_
308    
309                                          port_client = ntohs(sin.sin_port);                                          port_client = ntohs(sin.sin_port);
310    
311                                          log_std("Accept connection from %s:%d\n", hostaddr_client, port_client);                                          log_common("Accept connection from %s:%d\n", hostaddr_client, port_client);
312    
313                                          if (SYS_child_process_count - 1 < BBS_max_client)                                          if (SYS_child_process_count - 1 < BBS_max_client)
314                                          {                                          {
# Line 316  int net_server(const char *hostaddr, in_ Line 320  int net_server(const char *hostaddr, in_
320                                                                  j++;                                                                  j++;
321                                                                  if (j >= BBS_max_client_per_ip)                                                                  if (j >= BBS_max_client_per_ip)
322                                                                  {                                                                  {
323                                                                          log_error("Too many client connections (%d) from %s\n", j, hostaddr_client);                                                                          log_common("Too many client connections (%d) from %s\n", j, hostaddr_client);
324                                                                          break;                                                                          break;
325                                                                  }                                                                  }
326                                                          }                                                          }


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

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