// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl 0x4dc(%rdi), %ebp
cmpb $0x3, 0x2c(%rdi)
jne 0x20783
testb $0x1, 0x500(%rbx)
je 0x207c9
testb $0x2, 0x4f4(%rbx)
je 0x20728
leaq 0x3b0(%rbx), %rdi
leaq 0x25314(%rip), %rsi     # 0x45a30
callq 0x20f92
andb $-0x3, 0x4f4(%rbx)
cmpl $0x1, %ebp
jne 0x2087b
movl 0x4e0(%rbx), %eax
testl %eax, %eax
je 0x208b8
leaq 0x8(%rbx), %r14
leaq 0x4(%rsp), %r15
movl %eax, (%r15)
leaq 0xf2e5(%rip), %rsi      # 0x2fa37
pushq $0x1
popq %rdi
callq 0x28e0a
movq %r14, %rdi
callq 0x20e5b
leaq 0xf34c(%rip), %rdi      # 0x2fab5
callq 0x28f17
movq %r15, %rdi
callq 0x20e63
movq %rbx, %rdi
callq 0x1e30a
jmp 0x208c1
movl 0x4e0(%rbx), %eax
testl %eax, %eax
je 0x208ed
cmpl $0x1, %ebp
jne 0x2081c
leaq 0x8(%rbx), %r14
leaq 0x4(%rsp), %r15
movl %eax, (%r15)
leaq 0xf28a(%rip), %rsi      # 0x2fa37
pushq $0x3
popq %rdi
callq 0x28e0a
movq %r14, %rdi
callq 0x20e5b
leaq 0xf331(%rip), %rdi      # 0x2faf5
jmp 0x20855
movl 0x4e0(%rbx), %eax
testl %eax, %eax
je 0x208dc
leaq 0x8(%rbx), %r14
cmpl $0x1, %ebp
jne 0x208ca
leaq 0x4(%rsp), %r15
movl %eax, (%r15)
leaq 0xf244(%rip), %rsi      # 0x2fa37
pushq $0x2
popq %rdi
callq 0x28e0a
movq %r14, %rdi
callq 0x20e5b
leaq 0xf2e6(%rip), %rdi      # 0x2faf0
callq 0x28f17
movq %r15, %rdi
callq 0x20e63
jmp 0x208dc
cmpl $0x2, %eax
jne 0x2082b
testb $0x1, 0x2f(%rbx)
jne 0x208e6
leaq 0x8(%rbx), %r14
leaq 0x4(%rsp), %r15
movl %eax, (%r15)
leaq 0xf1f9(%rip), %rsi      # 0x2fa37
pushq $0x3
popq %rdi
callq 0x28e0a
movq %r14, %rdi
callq 0x20e5b
leaq 0xf2c5(%rip), %rdi      # 0x2fb1a
callq 0x28f17
movq %r15, %rdi
callq 0x20e63
movl $0x3, 0x1c4(%rbx)
pushq $0x1
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1ed2e
jmp 0x208f5
leaq 0x8(%rbx), %r14
movl 0x4e0(%rbx), %eax
leaq 0x4(%rsp), %r15
movl %eax, (%r15)
leaq 0xf1a3(%rip), %rsi      # 0x2fa37
pushq $0x1
popq %rdi
callq 0x28e0a
movq %r14, %rdi
callq 0x20e5b
leaq 0xf227(%rip), %rdi      # 0x2fad2
callq 0x28f17
movq %r15, %rdi
callq 0x20e63
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
andb $-0x2, 0x500(%rbx)
jmp 0x208f5
leaq 0x4(%rsp), %rdx
movl %eax, (%rdx)
pushq $0x2
popq %rdi
movq %r14, %rsi
callq 0x2090b
movq %rbx, %rdi
callq 0x1e30a
jmp 0x208f5
orb $0x1, 0x10e(%rbx)
movq %rbx, %rdi
callq 0x1f01a
movq 0x148(%rbx), %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xcdd2