// File: davmac314[P]dinit/src/control.cc
// Function: control_conn_t::list_services()
bool control_conn_t::list_services()
{
    rbuf.consume(1); // clear request packet
    chklen = 0;
    
    try {
        auto slist = services->list_services();
        for (auto sptr : slist) {
            if (sptr->get_type() == service_type_t::PLACEHOLDER) continue;

            std::vector<char> pkt_buf;
            int hdrsize = 2 + STATUS_BUFFER_SIZE;

            const std::string &name = sptr->get_name();
            int nameLen = std::min((size_t)256, name.length());
            pkt_buf.resize(hdrsize + nameLen);
            
            pkt_buf[0] = (char)cp_rply::SVCINFO;
            pkt_buf[1] = nameLen;
            
            fill_status_buffer(&pkt_buf[2], sptr);

            for (int i = 0; i < nameLen; i++) {
                pkt_buf[hdrsize+i] = name[i];
            }
            
            if (!queue_packet(std::move(pkt_buf))) return false;
        }
        
        char ack_buf[] = { (char) cp_rply::LISTDONE };
        if (!queue_packet(ack_buf, 1)) return false;

        return true;
    }
    catch (std::bad_alloc &exc)
    {
        do_oom_close();
        return true;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
subq $-0x80, %rdi
movl $0x1, %esi
callq 0x5e1a0
movq -0xb8(%rbp), %rax
movl $0x0, 0x7c(%rax)
movq 0x70(%rax), %rdi
callq 0x5ef10
movq %rax, %rsi
leaq -0x28(%rbp), %rdi
callq 0x5ef30
jmp 0x5977d
leaq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x16aa0
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
callq 0x16ad0
movq %rax, -0x50(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x16b00
testb $0x1, %al
jne 0x597b5
jmp 0x599d7
leaq -0x48(%rbp), %rdi
callq 0x16b30
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
callq 0x2d5a0
cmpl $0x0, %eax
jne 0x597e9
jmp 0x599c9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x59940
leaq -0x70(%rbp), %rdi
callq 0x30d60
movl $0xc, -0x74(%rbp)
movq -0x58(%rbp), %rdi
callq 0x2d420
movq %rax, -0x80(%rbp)
movq $0x100, -0x90(%rbp) # imm = 0x100
movq -0x80(%rbp), %rdi
callq 0xab20
movq %rax, -0x98(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x12a60
movq %rax, -0xc0(%rbp)
jmp 0x5983d
movq -0xc0(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x84(%rbp)
movl -0x74(%rbp), %eax
movl -0x84(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rsi
leaq -0x70(%rbp), %rdi
callq 0x31490
jmp 0x59865
xorl %eax, %eax
movl %eax, %esi
leaq -0x70(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
callq 0x5e950
movq -0xc8(%rbp), %rdi
movb $0x3e, (%rax)
movb -0x84(%rbp), %al
movb %al, -0xc9(%rbp)
movl $0x1, %esi
callq 0x5e950
movb -0xc9(%rbp), %cl
movq -0xc8(%rbp), %rdi
movb %cl, (%rax)
movl $0x2, %esi
callq 0x5e950
movq %rax, %rdi
movq -0x58(%rbp), %rsi
callq 0x5c2b0
jmp 0x598c0
movl $0x0, -0x9c(%rbp)
movl -0x9c(%rbp), %eax
cmpl -0x84(%rbp), %eax
jge 0x59984
movq -0x80(%rbp), %rdi
movslq -0x9c(%rbp), %rsi
callq 0xa7b0
movb (%rax), %al
movb %al, -0xca(%rbp)
movl -0x74(%rbp), %eax
addl -0x9c(%rbp), %eax
movslq %eax, %rsi
leaq -0x70(%rbp), %rdi
callq 0x5e950
movb -0xca(%rbp), %cl
movb %cl, (%rax)
movl -0x9c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x9c(%rbp)
jmp 0x598ca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x13f20
leaq -0x28(%rbp), %rdi
callq 0x16b80
movl -0x34(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x59a34
movq -0x30(%rbp), %rdi
callq 0xa240
movq -0xb8(%rbp), %rdi
movq %rax, -0xb0(%rbp)
callq 0x5eff0
movb $0x1, -0x1(%rbp)
movl $0x1, -0xa0(%rbp)
callq 0xac30
jmp 0x59a26
movq -0xb8(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x5bc70
testb $0x1, %al
jne 0x599a8
movb $0x0, -0x1(%rbp)
movl $0x1, -0xa0(%rbp)
jmp 0x599b2
movl $0x0, -0xa0(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x13f20
movl -0xa0(%rbp), %eax
testl %eax, %eax
jne 0x59a1d
jmp 0x599c7
jmp 0x599c9
leaq -0x48(%rbp), %rdi
callq 0x16b60
jmp 0x5979f
movq -0xb8(%rbp), %rdi
movb 0x1fa66(%rip), %al      # 0x7944a
movb %al, -0xa1(%rbp)
leaq -0xa1(%rbp), %rsi
movl $0x1, %edx
callq 0x58340
testb $0x1, %al
jne 0x59a0f
movb $0x0, -0x1(%rbp)
movl $0x1, -0xa0(%rbp)
jmp 0x59a1d
movb $0x1, -0x1(%rbp)
movl $0x1, -0xa0(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x16b80
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xd0, %rsp
popq %rbp
retq
movq -0x30(%rbp), %rdi
callq 0xacc0
nopl (%rax)