| 685 | } |
| 686 | |
| 687 | static void main_thread_loop() |
| 688 | { |
| 689 | #if !defined(_WIN32) && !defined(_WIN64) |
| 690 | if (__daemon_mode) { |
| 691 | ACL_VSTREAM *stat_stream = acl_vstream_fdopen( |
| 692 | ACL_MASTER_STATUS_FD, O_RDWR, 8192, -1, |
| 693 | ACL_VSTREAM_TYPE_SOCK); |
| 694 | |
| 695 | acl_fiber_create(main_fiber_monitor_master, |
| 696 | stat_stream, STACK_SIZE); |
| 697 | acl_close_on_exec(ACL_MASTER_STATUS_FD, ACL_CLOSE_ON_EXEC); |
| 698 | acl_close_on_exec(ACL_MASTER_FLOW_READ, ACL_CLOSE_ON_EXEC); |
| 699 | acl_close_on_exec(ACL_MASTER_FLOW_WRITE, ACL_CLOSE_ON_EXEC); |
| 700 | if (acl_var_fiber_dispatch_addr && *acl_var_fiber_dispatch_addr) { |
| 701 | acl_fiber_create(main_fiber_dispatch, NULL, STACK_SIZE); |
| 702 | } |
| 703 | } |
| 704 | #endif |
| 705 | |
| 706 | ACL_FIBER_ATTR attr; |
| 707 | |
| 708 | acl_fiber_attr_init(&attr); |
| 709 | acl_fiber_attr_setstacksize(&attr, acl_var_fiber_stack_size); |
| 710 | acl_fiber_attr_setsharestack(&attr, acl_var_fiber_share_stack ? 1 : 0); |
| 711 | |
| 712 | __sighup_fiber = acl_fiber_create2(&attr, main_fiber_sighup, NULL); |
| 713 | |
| 714 | if (acl_var_fiber_use_limit > 0) { |
| 715 | acl_fiber_create(main_fiber_monitor_used, NULL, STACK_SIZE); |
| 716 | } |
| 717 | |
| 718 | if (acl_var_fiber_idle_limit > 0) { |
| 719 | acl_fiber_create(main_fiber_monitor_idle, NULL, STACK_SIZE); |
| 720 | } |
| 721 | |
| 722 | acl_server_sighup_setup(); |
| 723 | acl_server_sigterm_setup(); |
| 724 | |
| 725 | acl_msg_info("daemon started, log=%s, ev=%d", acl_var_fiber_log_file, |
| 726 | __fiber_schedule_event); |
| 727 | acl_fiber_schedule_with(__fiber_schedule_event); |
| 728 | acl_msg_info("daemon stopped now, exit status=%d", __exit_status); |
| 729 | exit(__exit_status); |
| 730 | } |
| 731 | |
| 732 | static FIBER_SERVER *server_alloc(int socket_count, int fdtype) |
| 733 | { |
no test coverage detected
searching dependent graphs…