// File: metopa[P]HTTP_Server/src/content/CExternalContent.cpp
// Function: CExternalContent::exec()
void CExternalContent::exec() {
	int dataPipe[2];
	pipe( dataPipe );

	int chPID;
	if ( ( chPID = fork() ) == -1 ) {
		int errNo = errno;
		Log.ger<>( CRITICAL, "fork() failed, errno", errNo );
		close( dataPipe[0] );
		close( dataPipe[1] );
		throw InternalErrorException( realPath_m ); //TODO add args
	}

	if ( chPID == 0 ) {
		close( dataPipe[0] );
		dup2( dataPipe[1], STDOUT_FILENO );

		if ( isScript_m )
			exit( system( realPath_m.c_str() ) );
		else {
			execl( realPath_m.c_str(), realPath_m.c_str(), (char *) nullptr );
			exit( 127 );
		}
	}
	else {
		close( dataPipe[1] );
		readPipe( dataPipe[0] );
		close( dataPipe[0] );
		int rc;
		waitpid( chPID, &rc, 0 );
		if ( rc == 127 )
			throw PermissionDeniedException( realPath_m );
		if ( rc != 0 )
			throw ServiceUnavailableException( realPath_m );
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x6710
callq 0x6180
movl %eax, -0x14(%rbp)
cmpl $-0x1, %eax
jne 0x1c388
callq 0x6080
movl (%rax), %eax
movl %eax, -0x18(%rbp)
leaq 0x233d1(%rip), %rdi     # 0x3f6e0
leaq 0x101d7(%rip), %rdx     # 0x2c4ed
movl $0x1, %esi
leaq -0x18(%rbp), %rcx
callq 0x1c670
movl -0x10(%rbp), %edi
callq 0x69e0
movl -0xc(%rbp), %edi
callq 0x69e0
movl $0x48, %edi
callq 0x6280
movq -0x30(%rbp), %rsi
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x38(%rbp)
addq $0x40, %rsi
callq 0x1c730
jmp 0x1c357
movq -0x38(%rbp), %rdi
leaq 0x223b6(%rip), %rsi     # 0x3e718
leaq 0x407(%rip), %rdx       # 0x1c770
callq 0x68e0
movq -0x38(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
callq 0x63b0
jmp 0x1c4e6
cmpl $0x0, -0x14(%rbp)
jne 0x1c406
movl -0x10(%rbp), %edi
callq 0x69e0
movl -0xc(%rbp), %edi
movl $0x1, %esi
callq 0x64a0
movq -0x30(%rbp), %rax
testb $0x1, 0xc9(%rax)
je 0x1c3cc
movq -0x30(%rbp), %rdi
addq $0x40, %rdi
callq 0x6240
movq %rax, %rdi
callq 0x6420
movl %eax, %edi
callq 0x65e0
movq -0x30(%rbp), %rdi
addq $0x40, %rdi
callq 0x6240
movq -0x30(%rbp), %rdi
movq %rax, -0x40(%rbp)
addq $0x40, %rdi
callq 0x6240
movq -0x40(%rbp), %rdi
movq %rax, %rsi
xorl %eax, %eax
movl %eax, %edx
movb $0x0, %al
callq 0x6620
movl $0x7f, %edi
callq 0x65e0
movl -0xc(%rbp), %edi
callq 0x69e0
movq -0x30(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0x1c510
movl -0x10(%rbp), %edi
callq 0x69e0
movl -0x14(%rbp), %edi
leaq -0x28(%rbp), %rsi
xorl %edx, %edx
callq 0x63f0
cmpl $0x7f, -0x28(%rbp)
jne 0x1c487
movl $0x48, %edi
callq 0x6280
movq -0x30(%rbp), %rsi
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x48(%rbp)
addq $0x40, %rsi
callq 0x168f0
jmp 0x1c459
movq -0x48(%rbp), %rdi
leaq 0x22194(%rip), %rsi     # 0x3e5f8
leaq -0x5b3b(%rip), %rdx     # 0x16930
callq 0x68e0
movq -0x48(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
callq 0x63b0
jmp 0x1c4e6
cmpl $0x0, -0x28(%rbp)
je 0x1c4de
movl $0x28, %edi
callq 0x6280
movq -0x30(%rbp), %rsi
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x50(%rbp)
addq $0x40, %rsi
callq 0x1c790
jmp 0x1c4b0
movq -0x50(%rbp), %rdi
leaq 0x22275(%rip), %rsi     # 0x3e730
leaq 0x32e(%rip), %rdx       # 0x1c7f0
callq 0x68e0
movq -0x50(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
callq 0x63b0
jmp 0x1c4e6
jmp 0x1c4e0
addq $0x50, %rsp
popq %rbp
retq
movq -0x20(%rbp), %rdi
callq 0x6920
nop