// File: /workspace/github_c_makefile_star2_O3/buf1024[P]mysch/mysch.c
// Function: mytask
int mytask()
{
    while(1) {
        sleep(g_info.sleep_time);

        if(g_usr1) {
            LOG_DEBUG("catch usr1\n");
            handle_sigusr1();
        }
        if(g_usr2) {
            LOG_DEBUG("catch usr2\n");
            log_flush();
            g_usr2 = 0;
        }
        if(g_chld) {
            LOG_DEBUG("catch child\n");
            handle_sigchild();
        }
        if(g_term) {
            LOG_DEBUG("catch term\n");
            break;
        }

        list_iter* it = list_get_iterator(g_info.progq, AL_START_HEAD);
        list_node* n = NULL;

        while((n = list_next(it)) != NULL) {
            prog_t* p = list_node_value(n);
            if(p->flag < 0) {
                if(p->pid == 0) {
                    // 启动程序
                    run_prog(p);
                    break;
                }
                if(!p->has_pid_file) {
                    if (kill(p->pid, 0) == 0) {
                        // 等待程序结束
                        break;
                    }
                }
                // 程序已经结束，继续
                list_del_node(g_info.progq, n, AL_FREE);

            }else if(p->flag == FORK_ONCE || p->flag == FORK_PERIOD) {
				if (p->flag == FORK_PERIOD) {
					if (p->pid && kill(p->pid, 0) == 0) {
						continue;
					}
	                if (judge_condition(p)) {
	                    run_prog(p);
	                    // 程序已经启动，不管它生死存亡
	                    list_del_node(g_info.progq, n, AL_FREE);
	                    continue;
	                }

				}
                run_prog(p);
                // 程序已经启动，不管它生死存亡
                list_del_node(g_info.progq, n, AL_FREE);
            }else {
                prog_t* f = (prog_t*)
                    list_node_value(list_first(g_info.progq));
                if(f->flag < 0) {
                    // 等待程序结束
                    continue;
                }

                if (judge_condition(p)) {
                    if (p->pid > 0) {
                        if(update_pid(p) != 0) {
                            LOG_ERROR("update_pid failed.\n");
                            continue;
                        }
                        if (kill(p->pid, 0) == 0) {
                            // 程序正运行
                            continue;
                        }
                    }
                    run_prog(p);
                }else{
                    if (p->pid > 0) {
                        if (update_pid(p) != 0) {
                            LOG_ERROR("update_pid failed.\n");
                            continue;
                        }
                        if (kill(p->pid, 0) == 0) {
                            // 程序正运行,干掉它
                            LOG_INFO("killing %d\n", p->pid);
                            kill(p->pid, SIGTERM);
                            waitpid(p->pid, NULL, 0);
                            LOG_INFO("%d killed\n", p->pid);

                            dict_delete(g_info.waitq, &p, sizeof(pid_t));
                        }
                    }
                }
            }
        }

        list_release_iterator(it);
    }

    clean_proccess(g_info.kill_flag);

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0x16ea(%rip), %r14      # 0x86eb
leaq 0x16ef(%rip), %r15      # 0x86f7
leaq 0x1701(%rip), %r13      # 0x8710
movl 0x5553(%rip), %edi      # 0xc568
callq 0x2380
cmpb $0x1, 0x57a3(%rip)      # 0xc7c4
jne 0x7036
leaq 0x16b5(%rip), %rdi      # 0x86df
xorl %eax, %eax
callq 0x4316
callq 0x6c03
cmpb $0x1, 0x578b(%rip)      # 0xc7c8
jne 0x7057
movq %r14, %rdi
xorl %eax, %eax
callq 0x4316
xorl %eax, %eax
callq 0x42c5
movb $0x0, 0x5771(%rip)      # 0xc7c8
cmpb $0x1, 0x5762(%rip)      # 0xc7c0
jne 0x706f
movq %r15, %rdi
xorl %eax, %eax
callq 0x4316
callq 0x6b42
cmpb $0x1, 0x5756(%rip)      # 0xc7cc
je 0x7221
movq 0x572d(%rip), %rdi      # 0xc7b0
xorl %esi, %esi
callq 0x3626
movq %rax, %r12
movq %rax, %rdi
callq 0x3688
testq %rax, %rax
je 0x7214
movq %rax, %rbx
movq 0x10(%rbx), %rdi
movq %rdi, -0x30(%rbp)
movl 0xa50(%rdi), %eax
testl %eax, %eax
js 0x70e3
je 0x70dc
cmpl $0x2, %eax
jne 0x712e
movl (%rdi), %eax
testl %eax, %eax
je 0x70d1
movl %eax, %edi
xorl %esi, %esi
callq 0x2260
testl %eax, %eax
je 0x7115
movq -0x30(%rbp), %rdi
callq 0x6a25
movq -0x30(%rbp), %rdi
testl %eax, %eax
callq 0x6d1f
jmp 0x7104
movl (%rdi), %eax
testl %eax, %eax
je 0x720f
cmpl $0x0, 0x8(%rdi)
jne 0x7104
movl %eax, %edi
xorl %esi, %esi
callq 0x2260
testl %eax, %eax
je 0x7214
movq 0x56a5(%rip), %rdi      # 0xc7b0
movq %rbx, %rsi
xorl %edx, %edx
callq 0x35d8
movq %r12, %rdi
callq 0x3688
movq %rax, %rbx
testq %rax, %rax
jne 0x70a1
jmp 0x7214
movq 0x567b(%rip), %rax      # 0xc7b0
movq (%rax), %rax
movq 0x10(%rax), %rax
cmpl $0x0, 0xa50(%rax)
js 0x7115
callq 0x6a25
movq -0x30(%rbp), %rdi
movl (%rdi), %ecx
testl %eax, %eax
je 0x717d
testl %ecx, %ecx
jle 0x7176
callq 0x6f07
testl %eax, %eax
jne 0x718a
movq -0x30(%rbp), %rax
movl (%rax), %edi
xorl %esi, %esi
callq 0x2260
testl %eax, %eax
je 0x7115
movq -0x30(%rbp), %rdi
callq 0x6d1f
jmp 0x7115
testl %ecx, %ecx
jle 0x7115
callq 0x6f07
testl %eax, %eax
je 0x7199
movq %r13, %rdi
xorl %eax, %eax
callq 0x471f
jmp 0x7115
movq -0x30(%rbp), %rax
movl (%rax), %edi
xorl %esi, %esi
callq 0x2260
testl %eax, %eax
jne 0x7115
movq -0x30(%rbp), %rax
movl (%rax), %esi
leaq 0x1423(%rip), %rdi      # 0x85de
xorl %eax, %eax
callq 0x45cb
movq -0x30(%rbp), %rax
movl (%rax), %edi
movl $0xf, %esi
callq 0x2260
movq -0x30(%rbp), %rax
movl (%rax), %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x22e0
movq -0x30(%rbp), %rax
movl (%rax), %esi
leaq 0x13fc(%rip), %rdi      # 0x85ea
xorl %eax, %eax
callq 0x45cb
movq 0x55bc(%rip), %rdi      # 0xc7b8
leaq -0x30(%rbp), %rsi
movl $0x4, %edx
callq 0x2d11
jmp 0x7115
callq 0x6d1f
movq %r12, %rdi
callq 0x3657
jmp 0x700f
leaq 0x14dc(%rip), %rdi      # 0x8704
xorl %eax, %eax
callq 0x4316
movl 0x5337(%rip), %edi      # 0xc56c
callq 0x6c4d
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq