// File: /workspace/github_cpp_makefile_star2_O1/davmac314[P]dinit/src/proc-service.cc
// Function: process_service::start_stop_process(std::vector<char const*, std::allocator<char const*>> const&)
bool process_service::start_stop_process(const std::vector<const char *> &cmd) noexcept
{
    // In general, you can't tell whether fork/exec is successful. We use a pipe to communicate
    // success/failure from the child to the parent. The pipe is set CLOEXEC so a successful
    // exec closes the pipe, and the parent sees EOF. If the exec is unsuccessful, the errno
    // is written to the pipe, and the parent can read it.

    int pipefd[2];
    if (bp_sys::pipe2(pipefd, O_CLOEXEC)) {
        log(loglevel_t::ERROR, get_name(), ": can't create status check pipe (for stop command): ",
                strerror(errno));
        return false;
    }

    const char * logfile = this->logfile.c_str();
    if (*logfile == 0) {
        logfile = "/dev/null";
    }

    bool child_status_registered = false;

    // Set up complete, now fork and exec:

    pid_t forkpid;

    try {
        stop_pipe_watcher.add_watch(event_loop, pipefd[0], dasynq::IN_EVENTS);
        child_status_registered = true;

        // We specify a high priority (i.e. low priority value) so that process termination is
        // handled early. This means we have always recorded that the process is terminated by the
        // time that we handle events that might otherwise cause us to signal the process, so we
        // avoid sending a signal to an invalid (and possibly recycled) process ID.
        forkpid = stop_watcher.fork(event_loop, reserved_stop_watch, dasynq::DEFAULT_PRIORITY - 10);
        reserved_stop_watch = true;
    }
    catch (std::exception &e) {
        log(loglevel_t::ERROR, get_name(), ": could not fork (for stop command): ", e.what());
        goto out_cs_h;
    }

    if (forkpid == 0) {
        close(pipefd[0]);
        const char * working_dir_c = service_dsc_dir;
        if (! working_dir.empty()) working_dir_c = working_dir.c_str();
        run_proc_params run_params{cmd.data(), working_dir_c, logfile, pipefd[1], run_as_uid, run_as_gid, rlimits};
        run_params.on_console = false;
        run_params.in_foreground = false;
        run_params.csfd = -1;
        run_params.socket_fd = socket_fd;
        run_params.notify_fd = -1;
        run_params.force_notify_fd = -1;
        run_params.notify_var = nullptr;
        run_params.env_file = env_file.c_str();
        run_params.nice_is_set = nice_is_set;
        run_params.nice = nice;
        #if SUPPORT_CGROUPS
        run_params.run_in_cgroup = run_in_cgroup.c_str();
        #endif
        #if SUPPORT_CAPABILITIES
        run_params.cap_iab = cap_iab.get();
        run_params.secbits = secbits;
        run_params.no_new_privs = onstart_flags.no_new_privs;
        #endif
        #if SUPPORT_IOPRIO
        run_params.ioprio = ioprio;
        #endif
        #if SUPPORT_OOM_ADJ
        run_params.oom_adj_is_set = oom_adj_is_set;
        run_params.oom_adj = oom_adj;
        #endif
        run_child_proc(run_params);
    }
    else {
        // Parent process
        stop_pid = forkpid;

        bp_sys::close(pipefd[1]); // close the 'other end' fd
        waiting_for_execstat = true;
        return true;
    }

    // Failure exit:

    out_cs_h:
    if (child_status_registered) {
        stop_pipe_watcher.deregister(event_loop);
    }

    bp_sys::close(pipefd[0]);
    bp_sys::close(pipefd[1]);

    return false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x70(%rsp), %rdi
movl $0x80000, %esi          # imm = 0x80000
callq 0x83e0
testl %eax, %eax
je 0x251c8
callq 0x8050
movl (%rax), %edi
callq 0x81d0
movq %rax, %r14
movq 0x8(%rbx), %rsi
movl $0x3, %edi
callq 0x2e63a
leaq 0x10aad(%rip), %rdi     # 0x35c61
callq 0x2e73d
movq %r14, %rdi
callq 0x2e759
xorl %eax, %eax
jmp 0x25273
movq 0x2a0(%rbx), %rax
cmpb $0x0, (%rax)
leaq 0x10abe(%rip), %r12     # 0x35c97
cmovneq %rax, %r12
leaq 0x588(%rbx), %r14
movl 0x70(%rsp), %edx
andb $-0x20, 0x594(%rbx)
movl $0x32, 0x5a0(%rbx)
movl %edx, 0x5a4(%rbx)
movl $0x1, 0x5a8(%rbx)
xorl %ebp, %ebp
leaq 0x2181e(%rip), %rdi     # 0x46a30
movq %r14, %rsi
movl $0x1, %ecx
movl $0x1, %r8d
movl $0x1, %r9d
callq 0xe744
leaq 0x540(%rbx), %rdi
movb $0x1, %bpl
movzbl 0x500(%rbx), %edx
andl $0x1, %edx
leaq 0x217ea(%rip), %rsi     # 0x46a30
movl $0x28, %ecx
callq 0x2575c
orb $0x1, 0x500(%rbx)
testl %eax, %eax
je 0x25285
movl %eax, 0x504(%rbx)
movl 0x74(%rsp), %edi
callq 0x8b60
orb $-0x80, 0x10c(%rbx)
movb $0x1, %al
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x70(%rsp), %edi
callq 0x8b60
leaq 0x258(%rbx), %rax
leaq 0x100(%rbx), %rcx
cmpq $0x0, 0x260(%rbx)
cmoveq %rcx, %rax
movq (%rax), %rdi
movq (%r15), %r8
movl 0x74(%rsp), %r9d
movl 0x4a8(%rbx), %eax
movl %eax, 0x7c(%rsp)
movl 0x4ac(%rbx), %eax
movl %eax, 0x78(%rsp)
leaq 0x300(%rbx), %rdx
movl 0x4e4(%rbx), %r10d
movq 0x278(%rbx), %r11
movb 0x2f0(%rbx), %bpl
movl 0x2f4(%rbx), %r15d
movq 0x318(%rbx), %r13
movb 0x2f8(%rbx), %al
movzwl 0x2fa(%rbx), %ecx
leaq 0x88(%rsp), %rsi
movq %r8, (%rsi)
movq %rdi, 0x8(%rsi)
movq %r12, 0x10(%rsi)
movq %r11, 0x18(%rsi)
movq %r13, 0x20(%rsi)
xorl %edi, %edi
movb %dil, 0x28(%rsi)
movb %dil, 0x29(%rsi)
movb %dil, 0x2a(%rsi)
movb %bpl, 0x2b(%rsi)
movl %r15d, 0x2c(%rsi)
movb %al, 0x30(%rsi)
movw %cx, 0x32(%rsi)
movl %r9d, 0x34(%rsi)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, 0x38(%rsi)
movl %r10d, 0x3c(%rsi)
movq $-0x1, 0x40(%rsi)
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %rcx, 0x48(%rsi)
movq $0x0, 0x50(%rsi)
movl 0x7c(%rsp), %ecx
movl %ecx, 0x58(%rsi)
movl 0x78(%rsp), %ecx
movl %ecx, 0x5c(%rsi)
movq %rdx, 0x60(%rsi)
movl %eax, 0x68(%rsi)
movl $0xe, %ecx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq %rbx, %rdi
callq 0x2f0c8
movl 0x5a4(%rbx), %edx
leaq 0x2169c(%rip), %rdi     # 0x46a30
movq %r14, %rsi
callq 0xda6a
movl 0x70(%rsp), %edi
callq 0x8b60
movl 0x74(%rsp), %edi
callq 0x8b60
jmp 0x251c1
cmpl $0x2, %edx
jne 0x253ec
movq %rax, %rdi
callq 0x8210
leaq 0x8(%rbx), %r15
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
leaq 0x80(%rsp), %rsi
movq %rax, (%rsi)
movq %r15, %rdi
callq 0x2553d
callq 0x8a50
testb %bpl, %bpl
jne 0x25387
jmp 0x2539c
movq %rax, %rdi
callq 0xb8be