// File: /workspace/github_cpp_makefile_star2_O3/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 0x24ed2
testb $0x1, 0x500(%rbx)
je 0x24f09
testb $0x2, 0x4f4(%rbx)
je 0x24e62
movl 0x3fc(%rbx), %edx
leaq 0x3d0(%rbx), %rsi
leaq 0x21bda(%rip), %rdi     # 0x46a30
callq 0x25f62
andb $-0x3, 0x4f4(%rbx)
cmpl $0x1, %r14d
jne 0x24fbf
movl 0x4e0(%rbx), %ebp
testl %ebp, %ebp
je 0x25010
leaq 0x10bce(%rip), %rsi     # 0x35a4f
movl $0x1, %edi
callq 0x2e412
movq 0x8(%rbx), %rdi
callq 0x2e520
leaq 0x10c32(%rip), %rdi     # 0x35acd
callq 0x2e520
leaq 0x11905(%rip), %rdx     # 0x367ac
leaq 0x4(%rsp), %r14
movl $0xc, %esi
movq %r14, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x89e0
movq %r14, %rdi
callq 0x2e53c
movq %rbx, %rdi
callq 0x22792
jmp 0x25019
movl 0x4e0(%rbx), %ebp
testl %ebp, %ebp
je 0x25064
cmpl $0x1, %r14d
jne 0x24f47
leaq 0x10b62(%rip), %rsi     # 0x35a4f
movl $0x3, %edi
callq 0x2e412
movq 0x8(%rbx), %rdi
callq 0x2e520
leaq 0x10c06(%rip), %rdi     # 0x35b0d
jmp 0x24f77
movl 0x4e0(%rbx), %ebp
testl %ebp, %ebp
je 0x25053
leaq 0x10b31(%rip), %rsi     # 0x35a4f
movl $0x2, %edi
callq 0x2e412
movq 0x8(%rbx), %rdi
callq 0x2e520
cmpl $0x1, %r14d
jne 0x25022
leaq 0x10bc6(%rip), %rdi     # 0x35b08
jmp 0x25029
cmpl $0x2, %ebp
jne 0x24f56
testb $0x1, 0x2f(%rbx)
jne 0x2505d
leaq 0x10af2(%rip), %rsi     # 0x35a4f
movl $0x3, %edi
callq 0x2e412
movq 0x8(%rbx), %rdi
callq 0x2e520
leaq 0x10bbb(%rip), %rdi     # 0x35b32
callq 0x2e520
leaq 0x11829(%rip), %rdx     # 0x367ac
leaq 0x4(%rsp), %r14
movl $0xc, %esi
movq %r14, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x89e0
movq %r14, %rdi
callq 0x2e53c
movl $0x3, 0x1c4(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x23316
jmp 0x2506c
movl 0x4e0(%rbx), %ebp
leaq 0x10a83(%rip), %rsi     # 0x35a4f
movl $0x1, %edi
callq 0x2e412
movq 0x8(%rbx), %rdi
callq 0x2e520
leaq 0x10b04(%rip), %rdi     # 0x35aea
callq 0x2e520
leaq 0x117ba(%rip), %rdx     # 0x367ac
leaq 0x4(%rsp), %r14
movl $0xc, %esi
movq %r14, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x89e0
movq %r14, %rdi
callq 0x2e53c
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
andb $-0x2, 0x500(%rbx)
jmp 0x2506c
leaq 0x10b04(%rip), %rdi     # 0x35b2d
callq 0x2e520
leaq 0x11777(%rip), %rdx     # 0x367ac
leaq 0x4(%rsp), %r14
movl $0xc, %esi
movq %r14, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x89e0
movq %r14, %rdi
callq 0x2e53c
movq %rbx, %rdi
callq 0x22792
jmp 0x2506c
orb $0x1, 0x10e(%rbx)
movq %rbx, %rdi
callq 0x23690
movq 0x148(%rbx), %rdi
callq 0xd37e
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nop