// File: /workspace/github_c_makefile_star2_O2/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 $0x3528, %rsp           # imm = 0x3528
movl %esi, %r13d
movq %rdi, %r15
xorl %eax, %eax
callq 0x3496
movq %rax, %r14
leaq 0x148(%r15), %rsi
movq %rax, %rdi
callq 0x34a2
pushq $-0x1
popq %rbx
testl %eax, %eax
je 0x596a
movq %r14, %rdi
callq 0x3430
leaq 0x1e9c(%rip), %rdi      # 0x77fc
callq 0x20b0
jmp 0x5b62
leaq 0x193f(%rip), %rsi      # 0x72b0
movq %r14, %rdi
callq 0x3c81
testq %rax, %rax
je 0x59d0
movq %rax, %r12
leaq 0x192f(%rip), %rsi      # 0x72b7
movq %rax, %rdi
callq 0x3cfd
testq %rax, %rax
je 0x59a4
leaq 0x108(%r15), %rdi
movq %rax, %rsi
callq 0x2090
leaq 0x108(%r15), %rbx
movq %rbx, %rdi
callq 0x4eff
testl %eax, %eax
je 0x59e9
leaq 0x1902(%rip), %rdi      # 0x72c0
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2160
pushq $-0x1
popq %rbx
jmp 0x5b62
leaq 0x1e11(%rip), %rdi      # 0x77e8
callq 0x20b0
movq %r14, %rdi
callq 0x3430
jmp 0x5b62
xorps %xmm0, %xmm0
movaps %xmm0, -0xc20(%rbp)
movaps %xmm0, -0xc30(%rbp)
movaps %xmm0, -0xc40(%rbp)
movaps %xmm0, -0xc50(%rbp)
leaq -0x3550(%rbp), %rdi
movl $0x100, %edx            # imm = 0x100
xorl %esi, %esi
callq 0x21a0
xorps %xmm0, %xmm0
movaps %xmm0, -0x420(%rbp)
movaps %xmm0, -0x430(%rbp)
movaps %xmm0, -0x440(%rbp)
movaps %xmm0, -0x450(%rbp)
leaq 0x1891(%rip), %rsi      # 0x72d2
movq %r12, %rdi
callq 0x3cfd
testq %rax, %rax
je 0x5b0a
leaq -0xc50(%rbp), %rdi
movq %rax, %rsi
callq 0x2090
leaq 0x18a1(%rip), %rsi      # 0x7309
movq %r12, %rdi
callq 0x3cfd
testq %rax, %rax
pushq $-0x1
popq %rbx
je 0x5b1d
leaq -0x3550(%rbp), %rdi
movq %rax, %rsi
callq 0x2090
leaq 0x1880(%rip), %rsi      # 0x7312
movq %r12, %rdi
callq 0x3cfd
testq %rax, %rax
je 0x5b2d
leaq -0x450(%rbp), %rdi
movq %rax, %rsi
callq 0x2090
leaq 0x1864(%rip), %rsi      # 0x731d
movq %r12, %rdi
callq 0x3cfd
testq %rax, %rax
je 0x5b3d
movq %rax, %rdi
callq 0x2330
movl %eax, -0x30(%rbp)
leaq 0x1850(%rip), %rsi      # 0x7328
movq %r12, %rdi
callq 0x3cfd
testq %rax, %rax
je 0x5b4d
movq %rax, %rdi
callq 0x2330
movl %eax, %ecx
movl -0x30(%rbp), %esi
movl %esi, %eax
orl %ecx, %eax
jns 0x5b76
leaq 0x1839(%rip), %rdi      # 0x7338
movl %ecx, %edx
xorl %eax, %eax
callq 0x2160
jmp 0x5b62
leaq 0x17cb(%rip), %rdi      # 0x72dc
leaq 0x17ba(%rip), %rsi      # 0x72d2
jmp 0x59c1
leaq 0x17b8(%rip), %rdi      # 0x72dc
leaq 0x17de(%rip), %rsi      # 0x7309
jmp 0x5b5b
leaq 0x17a8(%rip), %rdi      # 0x72dc
leaq 0x17d7(%rip), %rsi      # 0x7312
jmp 0x5b5b
leaq 0x1798(%rip), %rdi      # 0x72dc
leaq 0x17d2(%rip), %rsi      # 0x731d
jmp 0x5b5b
leaq 0x1788(%rip), %rdi      # 0x72dc
leaq 0x17cd(%rip), %rsi      # 0x7328
xorl %eax, %eax
callq 0x2160
movl %ebx, %eax
addq $0x3528, %rsp           # imm = 0x3528
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x15180, %edi          # imm = 0x15180
movl %ecx, %eax
xorl %edx, %edx
divl %edi
cmpl $0x15181, %ecx          # imm = 0x15181
cmovbl %ecx, %edx
testl %r13d, %r13d
je 0x5c29
movl %edx, -0x38(%rbp)
cmpl $0x1, %r13d
jne 0x5baa
xorl %eax, %eax
callq 0x450e
xorl %eax, %eax
callq 0x3ef1
leaq -0xc50(%rbp), %rdi
callq 0x3d38
movl %eax, %ebx
movl %eax, %edi
callq 0x462c
testl %eax, %eax
je 0x5bcc
leaq 0x1bbf(%rip), %rdi      # 0x7789
jmp 0x5bf7
leaq -0x3550(%rbp), %rsi
leaq -0x450(%rbp), %rdx
pushq $-0x1
popq %r9
movl %ebx, %edi
movl -0x30(%rbp), %ecx
movl -0x38(%rbp), %r8d
callq 0x464a
testl %eax, %eax
je 0x5c01
leaq 0x1b76(%rip), %rdi      # 0x776d
callq 0x20b0
jmp 0x59c8
xorl %eax, %eax
callq 0x3e98
testl %eax, %eax
pushq $-0x1
popq %rbx
je 0x5c1b
leaq 0x1b41(%rip), %rdi      # 0x7757
jmp 0x5960
leaq 0x1748(%rip), %rdi      # 0x736a
xorl %eax, %eax
callq 0x4266
leaq 0x174c(%rip), %rsi      # 0x737c
movq %r12, %rdi
callq 0x3cfd
testq %rax, %rax
je 0x5d50
movq %rax, %rdi
callq 0x2330
movl %eax, (%r15)
leaq 0x1734(%rip), %rsi      # 0x7387
movq %r12, %rdi
callq 0x3cfd
testq %rax, %rax
je 0x5d63
movq %rax, %rdi
callq 0x2330
movl %eax, 0x4(%r15)
leaq 0x17e4(%rip), %rsi      # 0x745b
movq %r12, %rdi
callq 0x3cfd
testq %rax, %rax
je 0x5c90
leaq 0x8(%r15), %rdi
movq %rax, %rsi
callq 0x2090
leaq -0xc50(%rbp), %rdi
movl $0x800, %edx            # imm = 0x800
xorl %esi, %esi
callq 0x21a0
leaq -0x3550(%rbp), %rdi
movl $0x2000, %edx           # imm = 0x2000
xorl %esi, %esi
callq 0x21a0
leaq 0x16da(%rip), %rsi      # 0x7397
movq %r12, %rdi
callq 0x3cfd
testq %rax, %rax
je 0x5d76
leaq -0xc50(%rbp), %rbx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2090
pushq $0x7c
popq %rsi
leaq -0x3550(%rbp), %rdx
pushq $0x40
popq %rcx
movq %rbx, %rdi
movl $0x80, %r8d
callq 0x5473
testl %eax, %eax
jle 0x5d89
movl %eax, %r12d
cmpl $0x1, %r13d
jne 0x5dc5
movq 0x248(%r15), %rdi
testq %rdi, %rdi
je 0x5db9
xorl %esi, %esi
callq 0x32e5
movq %rax, %r13
movq %r13, %rdi
callq 0x3342
testq %rax, %rax
je 0x5da3
movq 0x10(%rax), %rax
movq 0xa58(%rax), %rdi
testq %rdi, %rdi
je 0x5d2a
xorl %esi, %esi
callq 0x310a
jmp 0x5d2a
leaq 0x1585(%rip), %rdi      # 0x72dc
leaq 0x161e(%rip), %rsi      # 0x737c
jmp 0x5b5b
leaq 0x1572(%rip), %rdi      # 0x72dc
leaq 0x1616(%rip), %rsi      # 0x7387
jmp 0x5b5b
leaq 0x155f(%rip), %rdi      # 0x72dc
leaq 0x1613(%rip), %rsi      # 0x7397
jmp 0x5b5b
leaq 0x1611(%rip), %rdi      # 0x73a1
leaq -0xc50(%rbp), %rsi
xorl %eax, %eax
callq 0x43ba
jmp 0x6198
movq %r13, %rdi
callq 0x3314
movq 0x248(%r15), %rdi
xorl %esi, %esi
callq 0x310a
callq 0x30ec
movq %rax, 0x248(%r15)
movl %r12d, %eax
movq %rax, -0x48(%rbp)
xorl %ecx, %ecx
leaq 0x15f6(%rip), %rax      # 0x73cb
movq %rax, -0x40(%rbp)
cmpq -0x48(%rbp), %rcx
je 0x60ce
movq %rcx, -0x38(%rbp)
movq %rcx, %rax
shlq $0x6, %rax
leaq (%rax,%rbp), %r12
addq $-0x3550, %r12          # imm = 0xCAB0
movq %r14, %rdi
movq %r12, %rsi
callq 0x3c81
testq %rax, %rax
je 0x611b
movq %rax, %rbx
movl $0xa70, %esi            # imm = 0xA70
pushq $0x1
popq %rdi
callq 0x21f0
movq %rax, %r13
movl $0x400, %edx            # imm = 0x400
leaq -0x450(%rbp), %r12
movq %r12, %rdi
xorl %esi, %esi
callq 0x21a0
movq %rbx, %rdi
leaq 0x158b(%rip), %rsi      # 0x73cb
callq 0x3cfd
testq %rax, %rax
je 0x6135
movq %r12, %rdi
movq %rax, %rsi
callq 0x2090
movq %rbx, %rdi
leaq 0x1454(%rip), %rsi      # 0x72b7
callq 0x3cfd
testq %rax, %rax
je 0x612a
leaq 0xa10(%r13), %rdi
movq %rax, %rsi
callq 0x2090
movl $0x100, %edx            # imm = 0x100
leaq -0xd50(%rbp), %r12
movq %r12, %rdi
xorl %esi, %esi
callq 0x21a0
movq %rbx, -0x30(%rbp)
movq %rbx, %rdi
leaq 0x1533(%rip), %rsi      # 0x73d7
callq 0x3cfd
testq %rax, %rax
je 0x6145
movq %r12, %rdi
movq %rax, %rsi
callq 0x2090
movq %r12, %rdi
leaq 0x1519(%rip), %rsi      # 0x73e0
callq 0x2040
pushq $-0x1
popq %rcx
testl %eax, %eax
je 0x5f19
movq %r12, %rdi
leaq 0x150d(%rip), %rsi      # 0x73ea
callq 0x2040
testl %eax, %eax
je 0x5f17
movq %r12, %rdi
leaq 0x18ee(%rip), %rsi      # 0x77de
callq 0x2040
pushq $0x1
popq %rcx
testl %eax, %eax
je 0x5f19
movq %r12, %rdi
leaq 0x14ed(%rip), %rsi      # 0x73f3
callq 0x2040
pushq $0x2
popq %rcx
testl %eax, %eax
je 0x5f19
jmp 0x61ac
xorl %ecx, %ecx
movl %ecx, 0xa50(%r13)
leaq 0x210(%r13), %r12
leaq -0x450(%rbp), %rdi
pushq $0x20
popq %rsi
movq %r12, %rdx
movl $0x80, %ecx
pushq $0x10
popq %r8
callq 0x5473
testl %eax, %eax
jle 0x6158
movl %eax, 0x20c(%r13)
leaq 0x10c(%r13), %rdi
movq %r12, %rsi
callq 0x2090
cmpl $0x0, 0xa50(%r13)
je 0x6053
movl $0x400, %edx            # imm = 0x400
leaq -0x1550(%rbp), %r12
movq %r12, %rdi
xorl %esi, %esi
callq 0x21a0
movq -0x30(%rbp), %rdi
leaq 0x1484(%rip), %rsi      # 0x7413
callq 0x3cfd
testq %rax, %rax
je 0x6168
movq %r12, %rdi
movq %rax, %rsi
callq 0x2090
movq %r13, %rdi
movq %r12, %rsi
callq 0x61b8
testl %eax, %eax
jne 0x617b
movl $0x400, %edx            # imm = 0x400
leaq -0x1150(%rbp), %r12
movq %r12, %rdi
xorl %esi, %esi
callq 0x21a0
movq -0x30(%rbp), %rdi
leaq 0x1466(%rip), %rsi      # 0x7442
callq 0x3cfd
testq %rax, %rax
je 0x5ff1
movq %r12, %rdi
movq %rax, %rsi
callq 0x2090
leaq 0x8(%r13), %r12
cmpw $0x31, -0x1150(%rbp)
jne 0x600d
movq -0x30(%rbp), %rdi
movl $0x1, (%r12)
jmp 0x6033
cmpl $0x0, (%r12)
movq -0x30(%rbp), %rdi
jne 0x6033
leaq -0x1150(%rbp), %rdi
leaq 0x142d(%rip), %rsi      # 0x7453
callq 0x2040
movq -0x30(%rbp), %rdi
testl %eax, %eax
je 0x6003
leaq 0x141d(%rip), %rsi      # 0x7457
callq 0x3cfd
testq %rax, %rax
je 0x6053
movq %r13, %rdi
addq $0xc, %rdi
movq %rax, %rsi
callq 0x2090
movq 0x248(%r15), %rdi
xorl %esi, %esi
callq 0x32e5
movq %rax, %r12
movq %r12, %rdi
callq 0x3342
testq %rax, %rax
je 0x609a
movq 0x10(%rax), %rcx
movl 0xa50(%rcx), %ecx
cmpl 0xa50(%r13), %ecx
jle 0x6064
movq 0x248(%r15), %rdi
movq %rax, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0x3215
jmp 0x60ba
movq 0x248(%r15), %rdi
cmpq $0x0, 0x10(%rdi)
je 0x60b2
movq %r13, %rsi
callq 0x31b7
jmp 0x60ba
movq %r13, %rsi
callq 0x3160
movq %r12, %rdi
callq 0x3314
movq -0x38(%rbp), %rcx
incq %rcx
jmp 0x5dd9
movq 0x248(%r15), %rdi
xorl %esi, %esi
callq 0x32e5
movq %rax, %rbx
movl $0x10c, %r15d           # imm = 0x10C
leaq 0x1378(%rip), %r14      # 0x7464
movq %rbx, %rdi
callq 0x3342
testq %rax, %rax
je 0x610c
movq 0x10(%rax), %rsi
addq %r15, %rsi
movq %r14, %rdi
xorl %eax, %eax
callq 0x3fa2
jmp 0x60ec
movq %rbx, %rdi
callq 0x3314
xorl %ebx, %ebx
jmp 0x5b62
leaq 0x1291(%rip), %rdi      # 0x73b3
movq %r12, %rsi
jmp 0x5d97
leaq 0x1186(%rip), %rax      # 0x72b7
movq %rax, -0x40(%rbp)
leaq 0x11a0(%rip), %rdi      # 0x72dc
movq -0x40(%rbp), %rsi
jmp 0x59c1
leaq 0x1190(%rip), %rdi      # 0x72dc
leaq 0x1284(%rip), %rsi      # 0x73d7
jmp 0x59c1
leaq 0x129f(%rip), %rdi      # 0x73fe
leaq -0x450(%rbp), %rsi
jmp 0x6189
leaq 0x116d(%rip), %rdi      # 0x72dc
leaq 0x129d(%rip), %rsi      # 0x7413
jmp 0x59c1
leaq 0x129a(%rip), %rdi      # 0x741c
leaq -0x1550(%rbp), %rsi
xorl %eax, %eax
callq 0x43ba
movq %r13, %rdi
callq 0x2030
movq %r14, %rdi
callq 0x3430
xorl %eax, %eax
callq 0x450e
jmp 0x59c8
leaq 0x15f5(%rip), %rdi      # 0x77a8
jmp 0x5bf7