/[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.48 by sysadm, Wed Jun 4 13:27:09 2025 UTC Revision 1.51 by sysadm, Thu Jun 5 05:24:56 2025 UTC
# Line 40  Line 40 
40  #include <arpa/inet.h>  #include <arpa/inet.h>
41  #include <netinet/in.h>  #include <netinet/in.h>
42  #include <systemd/sd-daemon.h>  #include <systemd/sd-daemon.h>
43    #include <libssh/server.h>
44    
45  struct process_sockaddr_t  struct process_sockaddr_t
46  {  {
# Line 52  static PROCESS_SOCKADDR process_sockaddr Line 53  static PROCESS_SOCKADDR process_sockaddr
53    
54  int net_server(const char *hostaddr, in_port_t port)  int net_server(const char *hostaddr, in_port_t port)
55  {  {
56            ssh_bind sshbind;
57          unsigned int namelen;          unsigned int namelen;
58          int ret;          int ret;
59          int flags;          int flags;
# Line 63  int net_server(const char *hostaddr, in_ Line 65  int net_server(const char *hostaddr, in_
65          MENU_SET *p_bbs_menu_new;          MENU_SET *p_bbs_menu_new;
66          int i, j;          int i, j;
67          pid_t pid;          pid_t pid;
68            int ssh_log_level = SSH_LOG_NOLOG;
69    
70            ssh_init();
71    
72            sshbind = ssh_bind_new();
73    
74            if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDADDR, hostaddr) < 0 ||
75                    ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDPORT, &port) < 0 ||
76                    ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, SSH_HOST_KEYFILE) < 0 ||
77                    ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_LOG_VERBOSITY, &ssh_log_level) < 0)
78            {
79                    log_error("Error setting SSH bind options: %s\n", ssh_get_error(sshbind));
80                    ssh_bind_free(sshbind);
81                    return -1;
82            }
83            
84          socket_server = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);          socket_server = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
85    
86          if (socket_server < 0)          if (socket_server < 0)
# Line 106  int net_server(const char *hostaddr, in_ Line 123  int net_server(const char *hostaddr, in_
123          port_server = ntohs(sin.sin_port);          port_server = ntohs(sin.sin_port);
124          namelen = sizeof(sin);          namelen = sizeof(sin);
125    
126          log_std("Listening at %s:%d\n", hostaddr_server, port_server);          log_common("Listening at %s:%d\n", hostaddr_server, port_server);
127    
128          epollfd = epoll_create1(0);          epollfd = epoll_create1(0);
129          if (epollfd < 0)          if (epollfd < 0)
# Line 155  int net_server(const char *hostaddr, in_ Line 172  int net_server(const char *hostaddr, in_
172                                  SYS_child_exit = 1; // Retry waitid                                  SYS_child_exit = 1; // Retry waitid
173    
174                                  SYS_child_process_count--;                                  SYS_child_process_count--;
175                                  log_std("Child process (%d) exited\n", siginfo.si_pid);                                  log_common("Child process (%d) exited\n", siginfo.si_pid);
176    
177                                  if (siginfo.si_pid != section_list_loader_pid)                                  if (siginfo.si_pid != section_list_loader_pid)
178                                  {                                  {
# Line 187  int net_server(const char *hostaddr, in_ Line 204  int net_server(const char *hostaddr, in_
204    
205                  if (SYS_server_exit && !SYS_child_exit && SYS_child_process_count > 0)                  if (SYS_server_exit && !SYS_child_exit && SYS_child_process_count > 0)
206                  {                  {
207                          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);
208                          if (kill(0, SIGTERM) < 0)                          if (kill(0, SIGTERM) < 0)
209                          {                          {
210                                  log_error("Send SIGTERM signal failed (%d)\n", errno);                                  log_error("Send SIGTERM signal failed (%d)\n", errno);
# Line 228  int net_server(const char *hostaddr, in_ Line 245  int net_server(const char *hostaddr, in_
245                                  p_bbs_menu = p_bbs_menu_new;                                  p_bbs_menu = p_bbs_menu_new;
246                                  p_bbs_menu_new = NULL;                                  p_bbs_menu_new = NULL;
247    
248                                  log_std("Reload menu successfully\n");                                  log_common("Reload menu successfully\n");
249                          }                          }
250    
251                          sd_notify(0, "READY=1");                          sd_notify(0, "READY=1");
# Line 247  int net_server(const char *hostaddr, in_ Line 264  int net_server(const char *hostaddr, in_
264                                  }                                  }
265                          }                          }
266    
267                          log_std("Reload data files successfully\n");                          log_common("Reload data files successfully\n");
268                          sd_notify(0, "READY=1");                          sd_notify(0, "READY=1");
269                  }                  }
270    
# Line 308  int net_server(const char *hostaddr, in_ Line 325  int net_server(const char *hostaddr, in_
325    
326                                          port_client = ntohs(sin.sin_port);                                          port_client = ntohs(sin.sin_port);
327    
328                                          log_std("Accept connection from %s:%d\n", hostaddr_client, port_client);                                          log_common("Accept connection from %s:%d\n", hostaddr_client, port_client);
329    
330                                          if (SYS_child_process_count - 1 < BBS_max_client)                                          if (SYS_child_process_count - 1 < BBS_max_client)
331                                          {                                          {
# Line 320  int net_server(const char *hostaddr, in_ Line 337  int net_server(const char *hostaddr, in_
337                                                                  j++;                                                                  j++;
338                                                                  if (j >= BBS_max_client_per_ip)                                                                  if (j >= BBS_max_client_per_ip)
339                                                                  {                                                                  {
340                                                                          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);
341                                                                          break;                                                                          break;
342                                                                  }                                                                  }
343                                                          }                                                          }
# Line 328  int net_server(const char *hostaddr, in_ Line 345  int net_server(const char *hostaddr, in_
345    
346                                                  if (j < BBS_max_client_per_ip)                                                  if (j < BBS_max_client_per_ip)
347                                                  {                                                  {
348                                                          if ((pid = fork_server()) < 0)                                                          if ((pid = fork_server(sshbind)) < 0)
349                                                          {                                                          {
350                                                                  log_error("fork_server() error\n");                                                                  log_error("fork_server() error\n");
351                                                          }                                                          }
# Line 381  int net_server(const char *hostaddr, in_ Line 398  int net_server(const char *hostaddr, in_
398                  log_error("Close server socket failed\n");                  log_error("Close server socket failed\n");
399          }          }
400    
401            ssh_bind_free(sshbind);
402            ssh_finalize();
403    
404          return 0;          return 0;
405  }  }


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

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