// File: /workspace/github_c_makefile_star2_O3/buf1024[P]mysch/mysch.c
// Function: load_conf
int load_conf(sch_info_t* info, int flag)
{
    int ret = 0;
    ini_conf_t* ini = ini_create();
    ret = ini_load(ini, info->conf);
    if (ret != 0) {
        ini_destroy(ini);
        printf("ini_load failed.\n");
        return -1;
    }

    ini_sec_t* sec = ini_get_sec(ini, "COMMON");
    if(sec == NULL) {
        printf("ini_get_sec failed.\n");
        ini_destroy(ini);
        return -1;
    }

    READ_CONF_STR_OPT(sec, "RUN_USER", info->run_user);

    if(runas(info->run_user) != 0) {
        printf("runas %s failed.\n", info->run_user);
        return -1;
    }

    {
        char file_level[64] = { 0 };
        char log_path[256] = { 0 };
        char log_header[64] = { 0 };
        int log_buffer = 0;
        int log_sw_time = 0;

        READ_CONF_STR_MUST(sec, "LOG_LEVEL", file_level);
        READ_CONF_STR_MUST(sec, "LOG_PATH", log_path);
        READ_CONF_STR_MUST(sec, "LOG_HEADER", log_header);
        READ_CONF_INT_MUST(sec, "LOG_BUFFER", log_buffer);
        READ_CONF_INT_MUST(sec, "LOG_SWITCH_TIME", log_sw_time);

        if(log_buffer < 0 || log_sw_time < 0) {
            printf("log_buffer = %d or log_switch_time = %d invalid.\n",
                    log_buffer, log_sw_time);
            return -1;
        }
        if(log_sw_time > 86400) {
            log_sw_time %= 86400;
        }

        if (flag != LOAD_CONF_TEST) {
            if (flag == LOAD_CONF_RELOAD) {
                log_finish();
                log_clearup();
            }

            int lvl = log_get_level(file_level);

            if (log_initialize_console(lvl) != 0) {
                printf("log_initialize_console failed.\n");
                return -1;
            }

            if (log_initialize_file(lvl, log_path, log_header, log_buffer,
                        log_sw_time, -1) != 0) {
                printf("log_initialize_file failed.\n");
                return -1;
            }
            if (log_start() != 0) {
                printf("log_initilize failed.\n");
                return -1;
            }
            LOG_INFO("logger is ready.\n");
        }
    }

    READ_CONF_INT_MUST(sec, "SLEEP_TIME", info->sleep_time);
    READ_CONF_INT_MUST(sec, "KILL_CHILD_FLAG", info->kill_flag);
    READ_CONF_STR_OPT(sec, "PID_FILE", info->pid_file);

    {
        char prog_list[2048] = { 0 };
        char progs[128][64] = { { 0 } };
        int num = 0;
        READ_CONF_STR_MUST(sec, "PROG_LIST", prog_list);

        num = split(prog_list, '|', (char **)progs, 64, 128);
        if(num <= 0) {
            LOG_ERROR("split %s failed.\n", prog_list);
            ini_destroy(ini);
            log_finish();
            return -1;
        }

        if(flag == LOAD_CONF_RELOAD) {
            if(info->progq){
                list_iter* it = list_get_iterator(info->progq, AL_START_HEAD);
                list_node* n = NULL;
                while((n = list_next(it)) != NULL) {
                    prog_t* p = list_node_value(n);
                    if(p->cond) {
                        list_release(p->cond, AL_FREE);
                    }
                }

                list_release_iterator(it);
                list_release(info->progq, AL_FREE);
            }

            info->progq = list_create();
        }

        int i = 0;
        for(i=0; i<num; i++) {

            ini_sec_t* ssec = ini_get_sec(ini, progs[i]);
            if (ssec == NULL ) {
                LOG_ERROR("get section %s failed.\n", progs[i]);
                ini_destroy(ini);
                log_finish();
                return -1;
            }


            prog_t* prog = (prog_t*)malloc(sizeof(*prog));
            memset(prog, 0, sizeof(*prog));

            char run_cmd[1024] = {0};

            READ_CONF_STR_MUST(ssec, "RUN_COMMAND", run_cmd);
            READ_CONF_STR_MUST(ssec, "RUN_USER", prog->user);
            char run_flag[256] = {0};
            READ_CONF_STR_MUST(ssec, "RUN_FLAG", run_flag);
            if(strcasecmp(run_flag, "forkfirst") == 0){
                prog->flag = FORK_FIRST;
            }else if(strcasecmp(run_flag, "forkonce") == 0){
                prog->flag = FORK_ONCE;
            }else if(strcasecmp(run_flag, "forkwatch") == 0){
                prog->flag = FORK_WATCH;
            }else if(strcasecmp(run_flag, "forkperiod") == 0){
                prog->flag = FORK_PERIOD;
            }else{
                printf("syntax not right, available value: forkfirst forkonce forkwatch\n");
                return -1;
            } 
            int ncmd = 0;
            ncmd = split(run_cmd, ' ',  (char**)prog->argv, 128, 16);
            if(ncmd <= 0){
                LOG_ERROR("split cmd %s failed\n", run_cmd);
                free(prog);

                ini_destroy(ini);
                log_finish();
                return -1;
            }
            prog->argc = ncmd;
            strcpy(prog->cmd, prog->argv[0]);

            if(prog->flag) {
                char cond[1024] = {0};
                READ_CONF_STR_MUST(ssec, "RUN_TIME", cond);

                if(build_condition(prog, cond) != 0) {
                    LOG_ERROR("build_condition failed. condition=%s\n", cond);
                    free(prog);

                    ini_destroy(ini);
                    log_finish();
                    return -1;
                }
                char has_pid[1024] = {0};
                READ_CONF_STR_OPT(ssec, "RUN_HAS_PID_FILE", has_pid);
                if(strcmp(has_pid, "1") == 0) {
                    prog->has_pid_file = 1;
                } 
                if(prog->has_pid_file == 0) {
                    if(strcasecmp(has_pid, "yes") == 0) {
                        prog->has_pid_file = 1;
                    }
                }
                READ_CONF_STR_OPT(ssec, "RUN_PID_FILE", prog->pid_file);
            }


            list_iter* it = list_get_iterator(info->progq, AL_START_HEAD);
            list_node* node = NULL;
            while((node = list_next(it))) {
                prog_t* lp = list_node_value(node);
                if(lp->flag > prog->flag) {
                    break;
                }
            }
            if(node == NULL) {
                if(list_length(info->progq) == 0) {
                    list_add_node_head(info->progq, prog);
                }else{
                    list_add_node_tail(info->progq, prog);
                }
            }else{
                list_insert_node(info->progq, node, prog, 0);
            }
            list_release_iterator(it);
        }

        list_iter* it = list_get_iterator(info->progq, AL_START_HEAD);
        list_node* node = NULL;
        while((node = list_next(it))) {
            prog_t* lp = list_node_value(node);
            LOG_DEBUG("prog = %s\n", lp->cmd);
        }
        list_release_iterator(it);
    }


    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3518, %rsp           # imm = 0x3518
movl %esi, %r12d
movq %rdi, %r14
xorl %eax, %eax
callq 0x37f5
movq %rax, %rbx
leaq 0x148(%r14), %rsi
movq %rax, %rdi
callq 0x3801
testl %eax, %eax
je 0x5d8f
movq %rbx, %rdi
callq 0x3780
leaq 0x2a74(%rip), %rdi      # 0x87fc
callq 0x20b0
jmp 0x5e03
leaq 0x251a(%rip), %rsi      # 0x82b0
movq %rbx, %rdi
callq 0x4040
testq %rax, %rax
je 0x5def
movq %rax, %r13
leaq 0x250a(%rip), %rsi      # 0x82b7
movq %rax, %rdi
callq 0x40bd
testq %rax, %rax
je 0x5dc9
leaq 0x108(%r14), %rdi
movq %rax, %rsi
callq 0x2090
leaq 0x108(%r14), %r15
movq %r15, %rdi
callq 0x5246
testl %eax, %eax
je 0x5e1c
leaq 0x24dd(%rip), %rdi      # 0x82c0
movq %r15, %rsi
xorl %eax, %eax
callq 0x2160
jmp 0x5e03
leaq 0x29f2(%rip), %rdi      # 0x87e8
callq 0x20b0
movq %rbx, %rdi
callq 0x3780
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0x3518, %rsp           # imm = 0x3518
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorps %xmm0, %xmm0
movaps %xmm0, -0xc10(%rbp)
movaps %xmm0, -0xc20(%rbp)
movaps %xmm0, -0xc30(%rbp)
movaps %xmm0, -0xc40(%rbp)
leaq -0x3540(%rbp), %rdi
movl $0x100, %edx            # imm = 0x100
xorl %esi, %esi
callq 0x21a0
xorps %xmm0, %xmm0
movaps %xmm0, -0x410(%rbp)
movaps %xmm0, -0x420(%rbp)
movaps %xmm0, -0x430(%rbp)
movaps %xmm0, -0x440(%rbp)
leaq 0x245e(%rip), %rsi      # 0x82d2
movq %r13, %rdi
callq 0x40bd
testq %rax, %rax
je 0x5f3c
leaq -0xc40(%rbp), %rdi
movq %rax, %rsi
callq 0x2090
leaq 0x246e(%rip), %rsi      # 0x8309
movq %r13, %rdi
callq 0x40bd
testq %rax, %rax
je 0x5f4f
leaq -0x3540(%rbp), %rdi
movq %rax, %rsi
callq 0x2090
leaq 0x2450(%rip), %rsi      # 0x8312
movq %r13, %rdi
callq 0x40bd
testq %rax, %rax
je 0x5f62
leaq -0x440(%rbp), %rdi
movq %rax, %rsi
callq 0x2090
leaq 0x2434(%rip), %rsi      # 0x831d
movq %r13, %rdi
callq 0x40bd
testq %rax, %rax
je 0x5f75
movq %rax, %rdi
callq 0x2330
movl %eax, %r15d
leaq 0x2420(%rip), %rsi      # 0x8328
movq %r13, %rdi
callq 0x40bd
testq %rax, %rax
je 0x5f88
movq %rax, %rdi
callq 0x2330
movl %r15d, %ecx
orl %eax, %ecx
jns 0x5f9b
leaq 0x240d(%rip), %rdi      # 0x8338
movl %r15d, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x2160
jmp 0x5e03
leaq 0x2399(%rip), %rdi      # 0x82dc
leaq 0x2388(%rip), %rsi      # 0x82d2
jmp 0x5de6
leaq 0x2386(%rip), %rdi      # 0x82dc
leaq 0x23ac(%rip), %rsi      # 0x8309
jmp 0x5de6
leaq 0x2373(%rip), %rdi      # 0x82dc
leaq 0x23a2(%rip), %rsi      # 0x8312
jmp 0x5de6
leaq 0x2360(%rip), %rdi      # 0x82dc
leaq 0x239a(%rip), %rsi      # 0x831d
jmp 0x5de6
leaq 0x234d(%rip), %rdi      # 0x82dc
leaq 0x2392(%rip), %rsi      # 0x8328
jmp 0x5de6
movl %r15d, -0x38(%rbp)
movl %eax, %ecx
movl $0xc22e4507, %edx       # imm = 0xC22E4507
imulq %rcx, %rdx
shrq $0x30, %rdx
imull $0x15180, %edx, %ecx    # imm = 0x15180
movl %eax, %r15d
subl %ecx, %r15d
cmpl $0x15181, %eax          # imm = 0x15181
cmovbl %eax, %r15d
testl %r12d, %r12d
je 0x605d
cmpl $0x1, %r12d
jne 0x5fe0
xorl %eax, %eax
callq 0x4873
xorl %eax, %eax
callq 0x429e
leaq -0xc40(%rbp), %rdi
callq 0x40f8
movl %eax, -0x30(%rbp)
movl %eax, %edi
callq 0x4977
testl %eax, %eax
je 0x6006
leaq 0x2788(%rip), %rdi      # 0x8789
jmp 0x5d88
leaq -0x3540(%rbp), %rsi
leaq -0x440(%rbp), %rdx
movl -0x30(%rbp), %edi
movl -0x38(%rbp), %ecx
movl %r15d, %r8d
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
callq 0x4995
testl %eax, %eax
je 0x6038
leaq 0x273a(%rip), %rdi      # 0x876d
jmp 0x5d88
xorl %eax, %eax
callq 0x425e
testl %eax, %eax
je 0x604f
leaq 0x270d(%rip), %rdi      # 0x8757
jmp 0x5d88
leaq 0x2314(%rip), %rdi      # 0x836a
xorl %eax, %eax
callq 0x45cb
leaq 0x2318(%rip), %rsi      # 0x837c
movq %r13, %rdi
callq 0x40bd
testq %rax, %rax
je 0x618b
movq %rax, %rdi
callq 0x2330
movl %eax, (%r14)
leaq 0x2300(%rip), %rsi      # 0x8387
movq %r13, %rdi
callq 0x40bd
testq %rax, %rax
je 0x619e
movq %rax, %rdi
callq 0x2330
movl %eax, 0x4(%r14)
leaq 0x23b0(%rip), %rsi      # 0x845b
movq %r13, %rdi
callq 0x40bd
testq %rax, %rax
je 0x60c4
leaq 0x8(%r14), %rdi
movq %rax, %rsi
callq 0x2090
leaq -0xc40(%rbp), %rdi
movl $0x800, %edx            # imm = 0x800
xorl %esi, %esi
callq 0x21a0
leaq -0x3540(%rbp), %rdi
movl $0x2000, %edx           # imm = 0x2000
xorl %esi, %esi
callq 0x21a0
leaq 0x22a6(%rip), %rsi      # 0x8397
movq %r13, %rdi
callq 0x40bd
testq %rax, %rax
je 0x61b1
leaq -0xc40(%rbp), %r15
movq %r15, %rdi
movq %rax, %rsi
callq 0x2090
leaq -0x3540(%rbp), %rdx
movq %r15, %rdi
movl $0x7c, %esi
movl $0x40, %ecx
movl $0x80, %r8d
callq 0x582e
testl %eax, %eax
jle 0x61c4
movl %eax, %r13d
cmpl $0x1, %r12d
jne 0x6200
movq 0x248(%r14), %rdi
testq %rdi, %rdi
je 0x61f4
xorl %esi, %esi
callq 0x3626
movq %rax, %r15
movq %rax, %rdi
callq 0x3688
testq %rax, %rax
je 0x61de
movq 0x10(%rax), %rax
movq 0xa58(%rax), %rdi
testq %rdi, %rdi
je 0x6186
xorl %esi, %esi
callq 0x3434
movq %r15, %rdi
jmp 0x6165
leaq 0x214a(%rip), %rdi      # 0x82dc
leaq 0x21e3(%rip), %rsi      # 0x837c
jmp 0x5de6
leaq 0x2137(%rip), %rdi      # 0x82dc
leaq 0x21db(%rip), %rsi      # 0x8387
jmp 0x5de6
leaq 0x2124(%rip), %rdi      # 0x82dc
leaq 0x21d8(%rip), %rsi      # 0x8397
jmp 0x5de6
leaq 0x21d6(%rip), %rdi      # 0x83a1
leaq -0xc40(%rbp), %rsi
xorl %eax, %eax
callq 0x471f
jmp 0x65d8
movq %r15, %rdi
callq 0x3657
movq 0x248(%r14), %rdi
xorl %esi, %esi
callq 0x3434
callq 0x3420
movq %rax, 0x248(%r14)
movl %r13d, %eax
movq %rax, -0x30(%rbp)
xorl %ecx, %ecx
leaq 0x21bb(%rip), %rax      # 0x83cb
movq %rax, -0x40(%rbp)
movq %rcx, -0x38(%rbp)
movq %rcx, %rax
shlq $0x6, %rax
leaq (%rax,%rbp), %r15
addq $-0x3540, %r15          # imm = 0xCAC0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4040
testq %rax, %rax
je 0x655b
movq %rax, %r12
movl $0x1, %edi
movl $0xa70, %esi            # imm = 0xA70
callq 0x21f0
movq %rax, %r13
movl $0x400, %edx            # imm = 0x400
leaq -0x440(%rbp), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x21a0
movq %r12, %rdi
leaq 0x2158(%rip), %rsi      # 0x83cb
callq 0x40bd
testq %rax, %rax
je 0x6575
movq %r15, %rdi
movq %rax, %rsi
callq 0x2090
movq %r12, %rdi
leaq 0x2021(%rip), %rsi      # 0x82b7
callq 0x40bd
testq %rax, %rax
je 0x656a
leaq 0xa10(%r13), %rdi
movq %rax, %rsi
callq 0x2090
movl $0x100, %edx            # imm = 0x100
leaq -0xd40(%rbp), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x21a0
movq %r12, %rdi
leaq 0x2104(%rip), %rsi      # 0x83d7
callq 0x40bd
testq %rax, %rax
je 0x6585
movq %r15, %rdi
movq %rax, %rsi
callq 0x2090
movq %r15, %rdi
leaq 0x20ea(%rip), %rsi      # 0x83e0
callq 0x2040
testl %eax, %eax
je 0x6342
movq %r15, %rdi
leaq 0x20e1(%rip), %rsi      # 0x83ea
callq 0x2040
testl %eax, %eax
je 0x6349
movq %r15, %rdi
leaq 0x24c2(%rip), %rsi      # 0x87de
callq 0x2040
testl %eax, %eax
je 0x634d
movq %r15, %rdi
leaq 0x20c4(%rip), %rsi      # 0x83f3
callq 0x2040
movl $0x2, %ecx
testl %eax, %eax
je 0x6352
jmp 0x65ec
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
jmp 0x6352
xorl %ecx, %ecx
jmp 0x6352
movl $0x1, %ecx
movl %ecx, 0xa50(%r13)
leaq 0x210(%r13), %r15
leaq -0x440(%rbp), %rdi
movl $0x20, %esi
movq %r15, %rdx
movl $0x80, %ecx
movl $0x10, %r8d
callq 0x582e
testl %eax, %eax
jle 0x6598
movl %eax, 0x20c(%r13)
leaq 0x10c(%r13), %rdi
movq %r15, %rsi
callq 0x2090
cmpl $0x0, 0xa50(%r13)
leaq -0x1540(%rbp), %r15
je 0x6483
movl $0x400, %edx            # imm = 0x400
movq %r15, %rdi
xorl %esi, %esi
callq 0x21a0
movq %r12, %rdi
leaq 0x2048(%rip), %rsi      # 0x8413
callq 0x40bd
testq %rax, %rax
je 0x65a8
movq %r15, %rdi
movq %rax, %rsi
callq 0x2090
movq %r13, %rdi
movq %r15, %rsi
callq 0x65f8
testl %eax, %eax
jne 0x65bb
movl $0x400, %edx            # imm = 0x400
leaq -0x1140(%rbp), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x21a0
movq %r12, %rdi
leaq 0x202b(%rip), %rsi      # 0x8442
callq 0x40bd
testq %rax, %rax
je 0x642c
movq %r15, %rdi
movq %rax, %rsi
callq 0x2090
leaq 0x8(%r13), %r15
cmpw $0x31, -0x1140(%rbp)
jne 0x6443
movl $0x1, (%r15)
jmp 0x6460
cmpl $0x0, (%r15)
jne 0x6460
leaq -0x1140(%rbp), %rdi
leaq 0x1ffc(%rip), %rsi      # 0x8453
callq 0x2040
testl %eax, %eax
je 0x643a
movq %r12, %rdi
leaq 0x1fed(%rip), %rsi      # 0x8457
callq 0x40bd
testq %rax, %rax
je 0x6483
movq %r13, %rdi
addq $0xc, %rdi
movq %rax, %rsi
callq 0x2090
movq 0x248(%r14), %rdi
xorl %esi, %esi
callq 0x3626
movq %rax, %r12
movq %r12, %rdi
callq 0x3688
testq %rax, %rax
je 0x64ca
movq 0x10(%rax), %rcx
movl 0xa50(%rcx), %ecx
cmpl 0xa50(%r13), %ecx
jle 0x6494
movq 0x248(%r14), %rdi
movq %rax, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0x3554
jmp 0x64ea
movq 0x248(%r14), %rdi
cmpq $0x0, 0x10(%rdi)
je 0x64e2
movq %r13, %rsi
callq 0x34ee
jmp 0x64ea
movq %r13, %rsi
callq 0x348f
movq %r12, %rdi
callq 0x3657
movq -0x38(%rbp), %rcx
incq %rcx
cmpq -0x30(%rbp), %rcx
jne 0x6214
movq 0x248(%r14), %rdi
xorl %ebx, %ebx
xorl %esi, %esi
callq 0x3626
movq %rax, %r14
movq %rax, %rdi
callq 0x3688
testq %rax, %rax
je 0x654e
movl $0x10c, %r12d           # imm = 0x10C
leaq 0x1f34(%rip), %r15      # 0x8464
movq 0x10(%rax), %rsi
addq %r12, %rsi
movq %r15, %rdi
xorl %eax, %eax
callq 0x4316
movq %r14, %rdi
callq 0x3688
testq %rax, %rax
jne 0x6530
movq %r14, %rdi
callq 0x3657
jmp 0x5e08
leaq 0x1e51(%rip), %rdi      # 0x83b3
movq %r15, %rsi
jmp 0x61d2
leaq 0x1d46(%rip), %rax      # 0x82b7
movq %rax, -0x40(%rbp)
leaq 0x1d60(%rip), %rdi      # 0x82dc
movq -0x40(%rbp), %rsi
jmp 0x5de6
leaq 0x1d50(%rip), %rdi      # 0x82dc
leaq 0x1e44(%rip), %rsi      # 0x83d7
jmp 0x5de6
leaq 0x1e5f(%rip), %rdi      # 0x83fe
leaq -0x440(%rbp), %rsi
jmp 0x65c9
leaq 0x1d2d(%rip), %rdi      # 0x82dc
leaq 0x1e5d(%rip), %rsi      # 0x8413
jmp 0x5de6
leaq 0x1e5a(%rip), %rdi      # 0x841c
leaq -0x1540(%rbp), %rsi
xorl %eax, %eax
callq 0x471f
movq %r13, %rdi
callq 0x2030
movq %rbx, %rdi
callq 0x3780
xorl %eax, %eax
callq 0x4873
jmp 0x5e03
leaq 0x21b5(%rip), %rdi      # 0x87a8
jmp 0x5d88