// File: /workspace/github_cpp_makefile_star2_O3/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 0x125dc
movl 0x4(%rsp), %ecx
movl %ecx, %eax
andl $0x7f, %eax
je 0x12510
cmpl $0xd, %eax
je 0x12513
cmpl $0xa, %eax
jne 0x125e9
xorl %edi, %edi
callq 0x63c0
movzbl %ch, %ebx
movl %ebx, 0x80(%r15)
movq 0x10(%r15), %rax
cmpb $0x1, 0xe0(%rax)
jne 0x1259c
movq 0x9ac2(%rip), %r14      # 0x1bff0
leaq 0x1d3e(%rip), %rsi      # 0x14273
movl $0x6, %edx
movq %r14, %rdi
callq 0x63a0
movq %r14, %rdi
movl %ebp, %esi
callq 0x6560
movq %rax, %r14
leaq 0x2251(%rip), %rsi      # 0x147a7
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 0x125d1
movl 0x80(%r15), %eax
testl %eax, %eax
je 0x125d1
cmpb $0x0, 0x85(%r15)
je 0x125c2
cmpl $0x1, %eax
je 0x125d1
jmp 0x12622
cmpl $0x1, %eax
jne 0x12622
cmpb $0x0, 0x86(%r15)
je 0x12622
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x60(%r15), %rdi
leaq 0x1f61(%rip), %rsi      # 0x14548
jmp 0x125f4
leaq 0x60(%r15), %rdi
leaq 0x2195(%rip), %rsi      # 0x14789
callq 0x6410
movl $0x2, 0x80(%r15)
movl $0x8, %edi
callq 0x6190
movq %r15, (%rax)
leaq 0x95a8(%rip), %rsi      # 0x1bbc0
movq %rax, %rdi
xorl %edx, %edx
callq 0x6550
testl %eax, %eax
jle 0x1264d
cmpb $0x0, 0x88(%r15)
je 0x1264d
leaq 0x60(%r15), %rdi
leaq 0x2173(%rip), %rsi      # 0x147ae
callq 0x6410
movl $0x8, 0x80(%r15)
jmp 0x12604
movq 0x20(%r15), %rax
subq 0x18(%r15), %rax
cmpq $0x9, %rax
leaq 0x2161(%rip), %rax      # 0x147c1
leaq 0x1f56(%rip), %rsi      # 0x145bd
cmovaeq %rax, %rsi
leaq 0x60(%r15), %rdi
callq 0x6410
movb $0x1, 0x84(%r15)
jmp 0x12604
nop