// File: davmac314[P]dinit/src/proc-service.cc
// Function: stop_status_pipe_watcher::fd_event(dasynq::v2::event_loop<dasynq::null_mutex, dasynq::v2::default_traits<dasynq::null_mutex>>&, int, int)
rearm stop_status_pipe_watcher::fd_event(eventloop_t &loop, int fd, int flags) noexcept
{
    process_service *sr = service;
    sr->waiting_for_execstat = false;

    run_proc_err exec_status;
    int r = read(get_watched_fd(), &exec_status, sizeof(exec_status));
    deregister(loop);
    close(get_watched_fd());

    if (r > 0) {
        // We read an errno code; exec() failed, and the service startup failed.
        if (sr->stop_pid != -1) {
            log(loglevel_t::ERROR, "Service ", sr->get_name(), ": could not fork for stop command: ",
                    exec_stage_descriptions[static_cast<int>(exec_status.stage)], ": ",
                    strerror(exec_status.st_errno));

            sr->stop_watcher.deregister(event_loop, sr->stop_pid);
            sr->reserved_child_watch = false;
            sr->stop_pid = -1;
            if (sr->pid != -1) {
                if (sr->term_signal != 0) {
                    sr->kill_pg(sr->term_signal);
                }
                if (!sr->tracking_child) {
                    sr->stop_issued = false;
                    sr->stopped();
                }
            }
        }
    }
    else {
        // Nothing to do really but wait for termination - unless it's already happened, so let's
        // check that now:
        if (sr->stop_pid == -1) {
            sr->handle_stop_exit();
        }
    }

    sr->services->process_queues();

    return rearm::REMOVED;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x48(%rbp)
movq 0x28(%rdi), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movl 0x10c(%rax), %ecx
andl $0xffffff7f, %ecx       # imm = 0xFFFFFF7F
movl %ecx, 0x10c(%rax)
callq 0x17d50
movl %eax, -0x3c(%rbp)
jmp 0x4f746
movl -0x3c(%rbp), %edi
leaq -0x28(%rbp), %rsi
movl $0x8, %edx
callq 0xaac0
movq %rax, -0x50(%rbp)
jmp 0x4f75d
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rsi
callq 0x17d20
movq -0x48(%rbp), %rdi
callq 0x17d50
movl %eax, -0x54(%rbp)
jmp 0x4f77f
movl -0x54(%rbp), %edi
callq 0xad80
jmp 0x4f789
cmpl $0x0, -0x2c(%rbp)
jle 0x4f8ac
movq -0x20(%rbp), %rax
cmpl $-0x1, 0x504(%rax)
je 0x4f8aa
movq -0x20(%rbp), %rdi
callq 0x2d420
movq %rax, -0x68(%rbp)
movslq -0x28(%rbp), %rcx
leaq 0x57de4(%rip), %rax     # 0xa75a0
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movl -0x24(%rbp), %edi
callq 0xa1f0
movq -0x68(%rbp), %rdx
movq -0x60(%rbp), %r8
movq %rax, -0x38(%rbp)
movl $0x3, %edi
leaq 0x29228(%rip), %rsi     # 0x78a0f
leaq 0x2922a(%rip), %rcx     # 0x78a18
leaq 0x27411(%rip), %r9      # 0x76c06
leaq -0x38(%rbp), %rax
movq %rax, (%rsp)
callq 0x4f8f0
movq -0x20(%rbp), %rdi
addq $0x540, %rdi            # imm = 0x540
movq -0x20(%rbp), %rax
movl 0x504(%rax), %edx
leaq 0x59342(%rip), %rsi     # 0xa8b60
callq 0x52a20
movq -0x20(%rbp), %rax
movb 0x4f4(%rax), %cl
andb $-0x5, %cl
orb $0x0, %cl
movb %cl, 0x4f4(%rax)
movq -0x20(%rbp), %rax
movl $0xffffffff, 0x504(%rax) # imm = 0xFFFFFFFF
movq -0x20(%rbp), %rax
cmpl $-0x1, 0x4d8(%rax)
je 0x4f8a8
movq -0x20(%rbp), %rax
cmpl $0x0, 0x194(%rax)
je 0x4f874
movq -0x20(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x194(%rax), %esi
callq 0x56c90
movq -0x20(%rbp), %rax
movb 0x4f4(%rax), %al
shrb $0x3, %al
andb $0x1, %al
testb $0x1, %al
jne 0x4f8a6
movq -0x20(%rbp), %rax
movb 0x500(%rax), %cl
andb $-0x3, %cl
orb $0x0, %cl
movb %cl, 0x500(%rax)
movq -0x20(%rbp), %rdi
callq 0x4bb20
jmp 0x4f8a8
jmp 0x4f8aa
jmp 0x4f8c4
movq -0x20(%rbp), %rax
cmpl $-0x1, 0x504(%rax)
jne 0x4f8c2
movq -0x20(%rbp), %rdi
callq 0x52a50
jmp 0x4f8c4
movq -0x20(%rbp), %rax
movq 0x148(%rax), %rdi
callq 0x173c0
movl $0x4, %eax
addq $0x70, %rsp
popq %rbp
retq
movq %rax, %rdi
callq 0xfa30
nopw (%rax,%rax)