| 43 |
#include <sys/syscall.h> |
#include <sys/syscall.h> |
| 44 |
#include <sys/types.h> |
#include <sys/types.h> |
| 45 |
#include <sys/wait.h> |
#include <sys/wait.h> |
| 46 |
|
|
| 47 |
|
#ifdef HAVE_SYSTEMD_SD_DAEMON_H |
| 48 |
#include <systemd/sd-daemon.h> |
#include <systemd/sd-daemon.h> |
| 49 |
|
#endif |
| 50 |
|
|
| 51 |
enum _net_server_constant_t |
enum _net_server_constant_t |
| 52 |
{ |
{ |
| 461 |
siginfo_t siginfo; |
siginfo_t siginfo; |
| 462 |
int notify_child_exit = 0; |
int notify_child_exit = 0; |
| 463 |
time_t tm_notify_child_exit = time(NULL); |
time_t tm_notify_child_exit = time(NULL); |
|
int sd_notify_stopping = 0; |
|
| 464 |
MENU_SET bbs_menu_new; |
MENU_SET bbs_menu_new; |
| 465 |
MENU_SET top10_menu_new; |
MENU_SET top10_menu_new; |
| 466 |
int i, j; |
int i, j; |
| 467 |
pid_t pid; |
pid_t pid; |
| 468 |
int ssh_log_level = SSH_LOG_NOLOG; |
int ssh_log_level = SSH_LOG_NOLOG; |
| 469 |
|
#ifdef HAVE_SYSTEMD_SD_DAEMON_H |
| 470 |
|
int sd_notify_stopping = 0; |
| 471 |
|
#endif |
| 472 |
|
|
| 473 |
ssh_init(); |
ssh_init(); |
| 474 |
|
|
| 563 |
} |
} |
| 564 |
|
|
| 565 |
// Startup complete |
// Startup complete |
| 566 |
|
#ifdef HAVE_SYSTEMD_SD_DAEMON_H |
| 567 |
sd_notifyf(0, "READY=1\n" |
sd_notifyf(0, "READY=1\n" |
| 568 |
"STATUS=Listening at %s:%d (Telnet) and %s:%d (SSH2)\n" |
"STATUS=Listening at %s:%d (Telnet) and %s:%d (SSH2)\n" |
| 569 |
"MAINPID=%d", |
"MAINPID=%d", |
| 570 |
hostaddr, port[0], hostaddr, port[1], getpid()); |
hostaddr, port[0], hostaddr, port[1], getpid()); |
| 571 |
|
#endif |
| 572 |
|
|
| 573 |
while (!SYS_server_exit || SYS_child_process_count > 0) |
while (!SYS_server_exit || SYS_child_process_count > 0) |
| 574 |
{ |
{ |
| 575 |
|
#ifdef HAVE_SYSTEMD_SD_DAEMON_H |
| 576 |
if (SYS_server_exit && !sd_notify_stopping) |
if (SYS_server_exit && !sd_notify_stopping) |
| 577 |
{ |
{ |
| 578 |
sd_notify(0, "STOPPING=1"); |
sd_notify(0, "STOPPING=1"); |
| 579 |
sd_notify_stopping = 1; |
sd_notify_stopping = 1; |
| 580 |
} |
} |
| 581 |
|
#endif |
| 582 |
|
|
| 583 |
while ((SYS_child_exit || SYS_server_exit) && SYS_child_process_count > 0) |
while ((SYS_child_exit || SYS_server_exit) && SYS_child_process_count > 0) |
| 584 |
{ |
{ |
| 632 |
{ |
{ |
| 633 |
if (notify_child_exit == 0) |
if (notify_child_exit == 0) |
| 634 |
{ |
{ |
| 635 |
|
#ifdef HAVE_SYSTEMD_SD_DAEMON_H |
| 636 |
sd_notifyf(0, "STATUS=Notify %d child process to exit", SYS_child_process_count); |
sd_notifyf(0, "STATUS=Notify %d child process to exit", SYS_child_process_count); |
| 637 |
log_common("Notify %d child process to exit\n", SYS_child_process_count); |
log_common("Notify %d child process to exit\n", SYS_child_process_count); |
| 638 |
|
#endif |
| 639 |
|
|
| 640 |
if (kill(-getpid(), SIGTERM) < 0) |
if (kill(-getpid(), SIGTERM) < 0) |
| 641 |
{ |
{ |
| 647 |
} |
} |
| 648 |
else if (notify_child_exit == 1 && time(NULL) - tm_notify_child_exit >= WAIT_CHILD_PROCESS_EXIT_TIMEOUT) |
else if (notify_child_exit == 1 && time(NULL) - tm_notify_child_exit >= WAIT_CHILD_PROCESS_EXIT_TIMEOUT) |
| 649 |
{ |
{ |
| 650 |
|
#ifdef HAVE_SYSTEMD_SD_DAEMON_H |
| 651 |
sd_notifyf(0, "STATUS=Kill %d child process", SYS_child_process_count); |
sd_notifyf(0, "STATUS=Kill %d child process", SYS_child_process_count); |
| 652 |
|
#endif |
| 653 |
|
|
| 654 |
if (kill(-getpid(), SIGKILL) < 0) |
if (kill(-getpid(), SIGKILL) < 0) |
| 655 |
{ |
{ |
| 669 |
if (SYS_conf_reload && !SYS_server_exit) |
if (SYS_conf_reload && !SYS_server_exit) |
| 670 |
{ |
{ |
| 671 |
SYS_conf_reload = 0; |
SYS_conf_reload = 0; |
| 672 |
|
|
| 673 |
|
#ifdef HAVE_SYSTEMD_SD_DAEMON_H |
| 674 |
sd_notify(0, "RELOADING=1"); |
sd_notify(0, "RELOADING=1"); |
| 675 |
|
#endif |
| 676 |
|
|
| 677 |
// Restart log |
// Restart log |
| 678 |
if (log_restart() < 0) |
if (log_restart() < 0) |
| 742 |
log_error("Send SIGUSR1 signal failed (%d)\n", errno); |
log_error("Send SIGUSR1 signal failed (%d)\n", errno); |
| 743 |
} |
} |
| 744 |
|
|
| 745 |
|
#ifdef HAVE_SYSTEMD_SD_DAEMON_H |
| 746 |
sd_notify(0, "READY=1"); |
sd_notify(0, "READY=1"); |
| 747 |
|
#endif |
| 748 |
} |
} |
| 749 |
|
|
| 750 |
nfds = epoll_wait(epollfd, events, MAX_EVENTS, 100); // 0.1 second |
nfds = epoll_wait(epollfd, events, MAX_EVENTS, 100); // 0.1 second |