| 38 |
#include <libssh/libssh.h> |
#include <libssh/libssh.h> |
| 39 |
#include <libssh/server.h> |
#include <libssh/server.h> |
| 40 |
#include <netinet/in.h> |
#include <netinet/in.h> |
| 41 |
|
#include <sys/ioctl.h> |
| 42 |
#include <sys/socket.h> |
#include <sys/socket.h> |
|
#include <sys/syscall.h> |
|
| 43 |
#include <sys/types.h> |
#include <sys/types.h> |
| 44 |
#include <sys/wait.h> |
#include <sys/wait.h> |
| 45 |
|
|
| 509 |
#endif |
#endif |
| 510 |
|
|
| 511 |
int nfds; |
int nfds; |
|
siginfo_t siginfo; |
|
| 512 |
int notify_child_exit = 0; |
int notify_child_exit = 0; |
| 513 |
time_t tm_notify_child_exit = time(NULL); |
time_t tm_notify_child_exit = time(NULL); |
| 514 |
MENU_SET bbs_menu_new; |
MENU_SET bbs_menu_new; |
| 566 |
{ |
{ |
| 567 |
log_error("setsockopt SO_REUSEADDR error (%d)\n", errno); |
log_error("setsockopt SO_REUSEADDR error (%d)\n", errno); |
| 568 |
} |
} |
| 569 |
|
#if defined(SO_REUSEPORT) |
| 570 |
if (setsockopt(socket_server[i], SOL_SOCKET, SO_REUSEPORT, &flags_server[i], sizeof(flags_server[i])) < 0) |
if (setsockopt(socket_server[i], SOL_SOCKET, SO_REUSEPORT, &flags_server[i], sizeof(flags_server[i])) < 0) |
| 571 |
{ |
{ |
| 572 |
log_error("setsockopt SO_REUSEPORT error (%d)\n", errno); |
log_error("setsockopt SO_REUSEPORT error (%d)\n", errno); |
| 573 |
} |
} |
| 574 |
|
#endif |
| 575 |
|
|
| 576 |
if (bind(socket_server[i], (struct sockaddr *)&sin, sizeof(sin)) < 0) |
if (bind(socket_server[i], (struct sockaddr *)&sin, sizeof(sin)) < 0) |
| 577 |
{ |
{ |
| 641 |
{ |
{ |
| 642 |
SYS_child_exit = 0; |
SYS_child_exit = 0; |
| 643 |
|
|
| 644 |
siginfo.si_pid = 0; |
pid = waitpid(-1, NULL, WNOHANG); |
| 645 |
ret = waitid(P_ALL, 0, &siginfo, WEXITED | WNOHANG); |
if (pid > 0) |
|
if (ret == 0 && siginfo.si_pid > 0) |
|
| 646 |
{ |
{ |
| 647 |
SYS_child_exit = 1; // Retry waitid |
SYS_child_exit = 1; // Retry waitid |
| 648 |
|
|
| 649 |
SYS_child_process_count--; |
SYS_child_process_count--; |
| 650 |
log_common("Child process (%d) exited\n", siginfo.si_pid); |
log_common("Child process (%d) exited\n", pid); |
| 651 |
|
|
| 652 |
if (siginfo.si_pid != section_list_loader_pid) |
if (pid != section_list_loader_pid) |
| 653 |
{ |
{ |
| 654 |
j = 0; |
j = 0; |
| 655 |
ret = hash_dict_get(hash_dict_pid_sockaddr, (uint64_t)siginfo.si_pid, (int64_t *)&j); |
ret = hash_dict_get(hash_dict_pid_sockaddr, (uint64_t)pid, (int64_t *)&j); |
| 656 |
if (ret < 0) |
if (ret < 0) |
| 657 |
{ |
{ |
| 658 |
log_error("hash_dict_get(hash_dict_pid_sockaddr, %d) error\n", siginfo.si_pid); |
log_error("hash_dict_get(hash_dict_pid_sockaddr, %d) error\n", pid); |
| 659 |
} |
} |
| 660 |
else |
else |
| 661 |
{ |
{ |
| 665 |
log_error("hash_dict_inc(hash_dict_sockaddr_count, %d, -1) error\n", j); |
log_error("hash_dict_inc(hash_dict_sockaddr_count, %d, -1) error\n", j); |
| 666 |
} |
} |
| 667 |
|
|
| 668 |
ret = hash_dict_del(hash_dict_pid_sockaddr, (uint64_t)siginfo.si_pid); |
ret = hash_dict_del(hash_dict_pid_sockaddr, (uint64_t)pid); |
| 669 |
if (ret < 0) |
if (ret < 0) |
| 670 |
{ |
{ |
| 671 |
log_error("hash_dict_del(hash_dict_pid_sockaddr, %d) error\n", siginfo.si_pid); |
log_error("hash_dict_del(hash_dict_pid_sockaddr, %d) error\n", pid); |
| 672 |
} |
} |
| 673 |
} |
} |
| 674 |
} |
} |
| 675 |
} |
} |
| 676 |
else if (ret == 0) |
else if (pid == 0) |
| 677 |
{ |
{ |
| 678 |
break; |
break; |
| 679 |
} |
} |
| 680 |
else if (ret < 0) |
else if (pid < 0) |
| 681 |
{ |
{ |
| 682 |
log_error("Error in waitid: %d\n", errno); |
log_error("Error in waitpid(): %d\n", errno); |
| 683 |
break; |
break; |
| 684 |
} |
} |
| 685 |
} |
} |