| 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"; |
| 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 = 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) |
| 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 = 1; |
| 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 |
} |
} |