// File: /workspace/github_cpp_makefile_star2_O1/ryuichiueda[P]GlueLang/src/Pipeline.cc
// Function: Pipeline::waitCommands(int)
void Pipeline::waitCommands(int pid)
{
	int options = 0;
	int status;
	int wpid = waitpid(pid,&status,options);
	if(wpid < 1){
		m_error_msg = "Command wait error";
		m_exit_status = 2;
		throw this;
	}
		
	if(!WIFEXITED(status)){
		if(WIFSIGNALED(status) && WTERMSIG(status) == 13){//ignore sigpipe
			// The exit status of the command that is suffered a sigpipe
			// should be zero because the command itself does not anything bad. 
			m_exit_status = 0;
		}else if(WIFSIGNALED(status) && WTERMSIG(status) == SIGUSR1){
			exit(0);
		}else{
			m_error_msg = "Irregular command termination";
			m_exit_status = 2;
			throw this;
		}
	}else{
		m_exit_status = WEXITSTATUS(status);
	}

	if(m_env->m_v_opt)
		cerr << "+ pid " << pid << " exit " << m_exit_status << endl;

	// judged at the upper level if !> is used
	if(m_has_or || m_exit_status == 0)
		return;

	if((m_has_and or m_has_then) and m_exit_status == 1)
		return;

	if(m_is_then and m_exit_status > 0){
		m_error_msg = "Error at then part";
		m_exit_status = 8;
		throw this;
	}

	m_error_msg = m_nodes.size() > 1 ? "Pipeline error" : "Command error";
	m_command_error = true;
	throw this;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebp
movq %rdi, %r15
leaq 0x4(%rsp), %rsi
xorl %ebx, %ebx
movl %ebp, %edi
xorl %edx, %edx
callq 0x6250
testl %eax, %eax
jle 0x12808
movl 0x4(%rsp), %ecx
movl %ecx, %eax
andl $0x7f, %eax
je 0x1273c
cmpl $0xd, %eax
je 0x1273f
cmpl $0xa, %eax
jne 0x12815
xorl %edi, %edi
callq 0x63c0
movzbl %ch, %ebx
movl %ebx, 0x80(%r15)
movq 0x10(%r15), %rax
cmpb $0x1, 0xe0(%rax)
jne 0x127c8
movq 0x9896(%rip), %r14      # 0x1bff0
leaq 0x1b12(%rip), %rsi      # 0x14273
movl $0x6, %edx
movq %r14, %rdi
callq 0x63a0
movq %r14, %rdi
movl %ebp, %esi
callq 0x6560
movq %rax, %r14
leaq 0x200b(%rip), %rsi      # 0x1478d
movl $0x6, %edx
movq %rax, %rdi
callq 0x63a0
movl 0x80(%r15), %esi
movq %r14, %rdi
callq 0x6560
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x6300
movsbl %al, %esi
movq %r14, %rdi
callq 0x6040
movq %rax, %rdi
callq 0x61e0
cmpb $0x0, 0x87(%r15)
jne 0x127fd
movl 0x80(%r15), %eax
testl %eax, %eax
je 0x127fd
cmpb $0x0, 0x85(%r15)
je 0x127ee
cmpl $0x1, %eax
je 0x127fd
jmp 0x1284e
cmpl $0x1, %eax
jne 0x1284e
cmpb $0x0, 0x86(%r15)
je 0x1284e
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x60(%r15), %rdi
leaq 0x1d15(%rip), %rsi      # 0x14528
jmp 0x12820
leaq 0x60(%r15), %rdi
leaq 0x1f4f(%rip), %rsi      # 0x1476f
callq 0x6410
movl $0x2, 0x80(%r15)
movl $0x8, %edi
callq 0x6190
movq %r15, (%rax)
leaq 0x937c(%rip), %rsi      # 0x1bbc0
movq %rax, %rdi
xorl %edx, %edx
callq 0x6550
testl %eax, %eax
jle 0x12879
cmpb $0x0, 0x88(%r15)
je 0x12879
leaq 0x60(%r15), %rdi
leaq 0x1f2d(%rip), %rsi      # 0x14794
callq 0x6410
movl $0x8, 0x80(%r15)
jmp 0x12830
movq 0x20(%r15), %rax
subq 0x18(%r15), %rax
cmpq $0x9, %rax
leaq 0x1f1b(%rip), %rax      # 0x147a7
leaq 0x1d0a(%rip), %rsi      # 0x1459d
cmovaeq %rax, %rsi
leaq 0x60(%r15), %rdi
callq 0x6410
movb $0x1, 0x84(%r15)
jmp 0x12830
nop