// File: /workspace/github_cpp_makefile_star2_O2/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 %r12
pushq %rbx
subq $0xf0, %rsp
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x78(%rsp), %rdi
movl $0x80000, %esi          # imm = 0x80000
callq 0x83e0
testl %eax, %eax
je 0x20b61
addq $0x8, %rbx
callq 0x8040
movl (%rax), %edi
callq 0x81c0
movq %rax, %r14
pushq $0x3
popq %rdi
movq %rbx, %rsi
callq 0x20e91
leaq 0xf0b3(%rip), %rdi      # 0x2fc00
callq 0x28f17
movq %r14, %rdi
callq 0x28f31
xorl %eax, %eax
jmp 0x20be2
movq 0x2a0(%rbx), %rax
cmpb $0x0, (%rax)
leaq 0xf0c4(%rip), %r12      # 0x2fc36
cmovneq %rax, %r12
leaq 0x588(%rbx), %r14
xorl %ebp, %ebp
movl 0x78(%rsp), %edx
leaq 0x24ea6(%rip), %rsi     # 0x45a30
pushq $0x1
popq %rcx
pushq $0x32
popq %r9
movq %r14, %rdi
movl %ecx, %r8d
callq 0xad4e
leaq 0x540(%rbx), %rdi
movb $0x1, %bpl
movzbl 0x500(%rbx), %edx
andl $0x1, %edx
leaq 0x24e79(%rip), %rsi     # 0x45a30
pushq $0x28
popq %rcx
callq 0x2115c
orb $0x1, 0x500(%rbx)
testl %eax, %eax
je 0x20bf2
movl %eax, 0x504(%rbx)
movl 0x7c(%rsp), %edi
callq 0x8b50
orb $-0x80, 0x10c(%rbx)
movb $0x1, %al
addq $0xf0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl 0x78(%rsp), %edi
callq 0x8b50
leaq 0x258(%rbx), %rax
leaq 0x100(%rbx), %rcx
cmpq $0x0, 0x260(%rbx)
cmoveq %rcx, %rax
movq (%rax), %rax
movq (%r15), %rcx
movl 0x7c(%rsp), %edx
movl 0x4e4(%rbx), %edi
movq 0x278(%rbx), %r8
movb 0x2f0(%rbx), %r9b
movl 0x2f4(%rbx), %r10d
movq 0x318(%rbx), %r11
movb 0x2f8(%rbx), %bpl
movzwl 0x2fa(%rbx), %r15d
leaq 0x80(%rsp), %rsi
movq %rcx, (%rsi)
movq %rax, 0x8(%rsi)
movq %r12, 0x10(%rsi)
movq %r8, 0x18(%rsi)
movq %r11, 0x20(%rsi)
xorl %eax, %eax
movb %al, 0x28(%rsi)
movb %al, 0x29(%rsi)
movb %al, 0x2a(%rsi)
movb %r9b, 0x2b(%rsi)
movl %r10d, 0x2c(%rsi)
movb %bpl, 0x30(%rsi)
movw %r15w, 0x32(%rsi)
movl %edx, 0x34(%rsi)
orl $-0x1, 0x38(%rsi)
movl %edi, 0x3c(%rsi)
orl $-0x1, 0x40(%rsi)
orl $-0x1, 0x44(%rsi)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x48(%rsi)
andq $0x0, 0x50(%rsi)
leaq 0x300(%rbx), %rax
movq 0x4a8(%rbx), %rcx
movq %rcx, 0x58(%rsi)
movq %rax, 0x60(%rsi)
orl $-0x1, 0x68(%rsi)
pushq $0xe
popq %rcx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq %rbx, %rdi
callq 0x297ec
leaq 0x24d57(%rip), %rsi     # 0x45a30
movq %r14, %rdi
callq 0xd002
movl 0x78(%rsp), %edi
callq 0x8b50
movl 0x7c(%rsp), %edi
callq 0x8b50
jmp 0x20b5a
cmpl $0x2, %edx
jne 0x20d40
movq %rax, %rdi
callq 0x8200
addq $0x8, %rbx
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
movq %rax, %r15
pushq $0x3
popq %rdi
movq %rbx, %rsi
callq 0x20e91
leaq 0xef19(%rip), %rdi      # 0x2fc40
callq 0x28f17
movq %r15, %rdi
callq 0x28f31
callq 0x8a40
testb %bpl, %bpl
jne 0x20cd2
jmp 0x20ce1
movq %rax, %rdi
callq 0xaebb