// File: davmac314[P]dinit/src/proc-service.cc
// Function: exec_status_pipe_watcher::fd_event(dasynq::v2::event_loop<dasynq::null_mutex, dasynq::v2::default_traits<dasynq::null_mutex>>&, int, int)
rearm exec_status_pipe_watcher::fd_event(eventloop_t &loop, int fd, int flags) noexcept
{
    base_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->pid != -1) {
            sr->child_listener.deregister(event_loop, sr->pid);
            sr->reserved_child_watch = false;
            if (sr->waiting_stopstart_timer) {
                sr->process_timer.stop_timer(loop);
                sr->waiting_stopstart_timer = false;
            }
        }
        sr->pid = -1;
        sr->exec_err_info = exec_status;
        sr->exec_failed(exec_status);
    }
    else {
        sr->exec_succeeded();

        if (sr->pid == -1) {
            // Somehow the process managed to complete before we even saw the exec() status.
            sr->handle_exit_status();
        }
    }

    sr->services->process_queues();

    return rearm::REMOVED;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x40(%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, -0x38(%rbp)
jmp 0x4f5b6
movl -0x38(%rbp), %edi
leaq -0x28(%rbp), %rsi
movl $0x8, %edx
callq 0xaac0
movq %rax, -0x48(%rbp)
jmp 0x4f5cd
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rsi
callq 0x17d20
movq -0x40(%rbp), %rdi
callq 0x17d50
movl %eax, -0x4c(%rbp)
jmp 0x4f5ef
movl -0x4c(%rbp), %edi
callq 0xad80
jmp 0x4f5f9
cmpl $0x0, -0x2c(%rbp)
jle 0x4f6ba
movq -0x20(%rbp), %rax
cmpl $-0x1, 0x4d8(%rax)
je 0x4f685
movq -0x20(%rbp), %rdi
addq $0x338, %rdi            # imm = 0x338
movq -0x20(%rbp), %rax
movl 0x4d8(%rax), %edx
leaq 0x59534(%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
movb 0x4f4(%rax), %al
shrb %al
andb $0x1, %al
testb $0x1, %al
je 0x4f683
movq -0x20(%rbp), %rdi
addq $0x3b0, %rdi            # imm = 0x3B0
movq -0x10(%rbp), %rsi
callq 0x529f0
movq -0x20(%rbp), %rax
movb 0x4f4(%rax), %cl
andb $-0x3, %cl
orb $0x0, %cl
movb %cl, 0x4f4(%rax)
jmp 0x4f685
movq -0x20(%rbp), %rax
movl $0xffffffff, 0x4d8(%rax) # imm = 0xFFFFFFFF
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
movq %rcx, 0x4f8(%rax)
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rax
movq %rax, -0x34(%rbp)
movq -0x34(%rbp), %rsi
movq (%rdi), %rax
callq *0x70(%rax)
jmp 0x4f6dd
movq -0x20(%rbp), %rdi
movq (%rdi), %rax
callq *0x78(%rax)
movq -0x20(%rbp), %rax
cmpl $-0x1, 0x4d8(%rax)
jne 0x4f6db
movq -0x20(%rbp), %rdi
movq (%rdi), %rax
callq *0x68(%rax)
jmp 0x4f6dd
movq -0x20(%rbp), %rax
movq 0x148(%rax), %rdi
callq 0x173c0
movl $0x4, %eax
addq $0x50, %rsp
popq %rbp
retq
movq %rax, %rdi
callq 0xfa30