/[LeafOK_CVS]/lbbs/src/common.c
ViewVC logotype

Diff of /lbbs/src/common.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.15 by sysadm, Tue May 6 05:31:26 2025 UTC Revision 1.17 by sysadm, Fri May 9 11:21:11 2025 UTC
# Line 20  Line 20 
20  #include <string.h>  #include <string.h>
21  #include <time.h>  #include <time.h>
22  #include <sys/types.h>  #include <sys/types.h>
 #include <sys/wait.h>  
23    
24  // Version information  // Version information
25  char app_version[256] = "LBBS-devel version 1.0";  char app_version[256] = "LBBS-devel version 1.0";
# Line 34  int port_server; Line 33  int port_server;
33  int port_client;  int port_client;
34    
35  // Global declaration for system  // Global declaration for system
36  int SYS_exit;  volatile int SYS_server_exit = 0;
37  int SYS_child_process_count;  volatile int SYS_child_process_count = 0;
38    volatile int SYS_child_exit_count = 0;
39    volatile int SYS_menu_reload = 0;
40    
41  // Common function  // Common function
42  const char *str_space(char *string, int length)  const char *str_space(char *string, int length)
# Line 90  const char *get_time_str(char *s, size_t Line 91  const char *get_time_str(char *s, size_t
91          return s;          return s;
92  }  }
93    
94  void reload_bbs_menu(int i)  void sig_hup_handler(int i)
95  {  {
96          if (reload_menu(&bbs_menu) < 0)          SYS_menu_reload = 1;
                 log_error("Reload menu failed\n");  
         else  
                 log_std("Reload menu successfully\n");  
97  }  }
98    
99  void system_exit(int i)  void sig_term_handler(int i)
100  {  {
101          SYS_exit = 1;          SYS_server_exit = 1;
102  }  }
103    
104  void child_exit(int i)  void sig_chld_handler(int i)
105  {  {
106          int pid;          SYS_child_exit_count++;
107    }
108    
109    const char * ip_mask(char * s, int level, char mask)
110    {
111            char * p = s;
112    
113            if (level <= 0)
114            {
115                    return s;
116            }
117            if (level > 4)
118            {
119                    level = 4;
120            }
121    
122          pid = wait(0);          for (int i = 0; i < 4 - level; i++)
123            {
124                    p = strchr(p, '.');
125                    if (p == NULL)
126                    {
127                            return s;
128                    }
129                    p++;
130            }
131    
132          if (pid > 0)          for (int i = 0; i < level; i++)
133          {          {
134                  SYS_child_process_count--;                  *p = mask;
135                  log_std("Child process (%d) exited\n", pid);                  p++;
136                    if (i < level - 1)
137                    {
138                            *p = '.';
139                            p++;
140                    }
141          }          }
142            *p = '\0';
143    
144            return s;
145  }  }


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

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