// File: /workspace/github_cpp_makefile_star2_O1/davmac314[P]dinit/src/proc-service.cc
// Function: scripted_service::handle_exit_status()
void scripted_service::handle_exit_status() noexcept
{
    bool did_exit = exit_status.did_exit();
    bool was_signalled = exit_status.was_signalled();
    auto current_state = get_state();

    // For a scripted service, a termination occurs in one of three main cases:
    // - the start script completed (or failed), when service was STARTING
    // - the start script was interrupted to cancel startup; state is STOPPING
    // - the stop script complete (or failed), state is STOPPING

    if (current_state == service_state_t::STOPPING) {
        // We might be running the stop script, or we might be running the start script and have issued
        // a cancel order via SIGINT:
        if (interrupting_start) {
            if (waiting_stopstart_timer) {
                process_timer.stop_timer(event_loop);
                waiting_stopstart_timer = false;
            }
            // We issued a start interrupt, so we expected this failure:
            if (did_exit && exit_status.get_exit_status() != 0) {
                log(loglevel_t::NOTICE, "Service ", get_name(), " start cancelled; exit code ",
                        exit_status.get_exit_status());
                // Assume that a command terminating normally (with failure status) requires no cleanup:
                stopped();
            }
            else {
                if (was_signalled) {
                    log(loglevel_t::NOTICE, "Service ", get_name(), " start cancelled from signal ",
                            exit_status.get_signal());
                }
                // If the start script completed successfully, or was interrupted via our signal,
                // we want to run the stop script to clean up:
                bring_down();
            }
            interrupting_start = false;
        }
        else if (exit_status.did_exit_clean()) {
            // We were running the stop script and finished successfully
            stopped();
        }
        else {
            // ??? failed to stop! Let's log it as warning:
            if (did_exit) {
                log(loglevel_t::WARN, "Service ", get_name(), " stop command failed with exit code ",
                        exit_status.get_exit_status());
            }
            else if (was_signalled) {
                log(loglevel_t::WARN, "Service ", get_name(), " stop command terminated due to signal ",
                        exit_status.get_signal());
            }
            // Even if the stop script failed, assume that service is now stopped, so that any dependencies
            // can be stopped. There's not really any other useful course of action here.
            stopped();
        }
        services->process_queues();
    }
    else { // STARTING
        if (exit_status.did_exit_clean()) {
            started();
        }
        else if (was_signalled && exit_status.get_signal() == SIGINT && onstart_flags.skippable) {
            // A skippable service can be skipped by interrupting (eg by ^C if the service
            // starts on the console).
            start_skipped = true;
            started();
        }
        else {
            // failed to start
            if (did_exit) {
                log(loglevel_t::ERROR, "Service ", get_name(), " command failed with exit code ",
                        exit_status.get_exit_status());
            }
            else if (was_signalled) {
                log(loglevel_t::ERROR, "Service ", get_name(), " command terminated due to signal ",
                        exit_status.get_signal());
            }
            stop_reason = stopped_reason_t::FAILED;
            failed_to_start();
        }
        services->process_queues();
    }
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movl 0x4dc(%rdi), %r14d
cmpb $0x3, 0x2c(%rdi)
jne 0x24d3e
testb $0x1, 0x500(%rbx)
je 0x24d97
testb $0x2, 0x4f4(%rbx)
je 0x24cce
movl 0x3fc(%rbx), %edx
leaq 0x3d0(%rbx), %rsi
leaq 0x21d6e(%rip), %rdi     # 0x46a30
callq 0x25df4
andb $-0x3, 0x4f4(%rbx)
cmpl $0x1, %r14d
jne 0x24dd5
movl 0x4e0(%rbx), %ebp
testl %ebp, %ebp
je 0x24dd5
leaq 0x10dab(%rip), %rsi     # 0x35a98
movl $0x1, %edi
callq 0x2e63a
movq 0x8(%rbx), %rdi
callq 0x2e73d
leaq 0x10e0f(%rip), %rdi     # 0x35b16
callq 0x2e73d
leaq 0x11ac9(%rip), %rdx     # 0x367dc
leaq 0x4(%rsp), %r14
movl $0xc, %esi
movq %r14, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x89e0
movq %r14, %rdi
callq 0x2e759
movq %rbx, %rdi
callq 0x224b2
jmp 0x24e35
movl 0x4e0(%rbx), %ebp
testl %ebp, %ebp
je 0x24e94
cmpl $0x1, %r14d
sete %al
cmpl $0x2, %ebp
setne %cl
orb %al, %cl
jne 0x24d67
testb $0x1, 0x2f(%rbx)
jne 0x24e8d
leaq 0x10d2a(%rip), %rsi     # 0x35a98
movl $0x3, %edi
callq 0x2e63a
movq 0x8(%rbx), %rdi
callq 0x2e73d
cmpl $0x1, %r14d
jne 0x24e41
leaq 0x10dc4(%rip), %rdi     # 0x35b56
jmp 0x24e48
movl 0x4e0(%rbx), %ebp
testl %ebp, %ebp
je 0x24ecf
leaq 0x10cec(%rip), %rsi     # 0x35a98
movl $0x2, %edi
callq 0x2e63a
movq 0x8(%rbx), %rdi
callq 0x2e73d
cmpl $0x1, %r14d
jne 0x24e9e
leaq 0x10d81(%rip), %rdi     # 0x35b51
jmp 0x24ea5
cmpl $0x1, %r14d
je 0x24e2c
movl 0x4e0(%rbx), %ebp
leaq 0x10cb0(%rip), %rsi     # 0x35a98
movl $0x1, %edi
callq 0x2e63a
movq 0x8(%rbx), %rdi
callq 0x2e73d
leaq 0x10d31(%rip), %rdi     # 0x35b33
callq 0x2e73d
leaq 0x119ce(%rip), %rdx     # 0x367dc
leaq 0x4(%rsp), %r14
movl $0xc, %esi
movq %r14, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x89e0
movq %r14, %rdi
callq 0x2e759
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
andb $-0x2, 0x500(%rbx)
jmp 0x24ed7
leaq 0x10d33(%rip), %rdi     # 0x35b7b
callq 0x2e73d
leaq 0x11988(%rip), %rdx     # 0x367dc
leaq 0x4(%rsp), %r14
movl $0xc, %esi
movq %r14, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x89e0
movq %r14, %rdi
callq 0x2e759
movl $0x3, 0x1c4(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x23018
jmp 0x24ed7
orb $0x1, 0x10e(%rbx)
movq %rbx, %rdi
callq 0x233ac
jmp 0x24ed7
leaq 0x10cd1(%rip), %rdi     # 0x35b76
callq 0x2e73d
leaq 0x1192b(%rip), %rdx     # 0x367dc
leaq 0x4(%rsp), %r14
movl $0xc, %esi
movq %r14, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x89e0
movq %r14, %rdi
callq 0x2e759
movq %rbx, %rdi
callq 0x224b2
movq 0x148(%rbx), %rdi
callq 0xd8da
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq