@@ -487,8 +487,9 @@ static int execAppInternal(const char *appPath, const char *const *args, std::st
487487#elif defined(PLATFORM_UNIX)
488488 // create pipes
489489 int coutPipes[2 ], cerrPipes[2 ];
490- pipe (coutPipes);
491- pipe (cerrPipes);
490+ if (pipe (coutPipes) != 0 || pipe (cerrPipes) != 0 ) {
491+ throw std::runtime_error (argsToString (" Unable to create pipe: " , std::strerror (errno)));
492+ }
492493 const auto readCoutPipe = coutPipes[0 ], writeCoutPipe = coutPipes[1 ];
493494 const auto readCerrPipe = cerrPipes[0 ], writeCerrPipe = cerrPipes[1 ];
494495
@@ -500,7 +501,7 @@ static int execAppInternal(const char *appPath, const char *const *args, std::st
500501
501502 try {
502503 if (child == -1 ) {
503- throw runtime_error (" Unable to create fork" );
504+ throw std:: runtime_error (argsToString ( " Unable to create fork: " , std::strerror (errno)) );
504505 }
505506
506507 // init file descriptor set for poll
@@ -518,10 +519,10 @@ static int execAppInternal(const char *appPath, const char *const *args, std::st
518519 do {
519520 const auto retpoll = poll (fileDescriptorSet, 2 , timeout);
520521 if (retpoll == 0 ) {
521- throw runtime_error (" Poll time- out" );
522+ throw std:: runtime_error (" Poll timed out" );
522523 }
523524 if (retpoll < 0 ) {
524- throw runtime_error (" Poll failed" );
525+ throw std:: runtime_error (argsToString ( " Poll failed: " , std::strerror (errno)) );
525526 }
526527 if (fileDescriptorSet[0 ].revents & POLLIN) {
527528 const auto count = read (readCoutPipe, buffer, sizeof (buffer));
@@ -557,8 +558,10 @@ static int execAppInternal(const char *appPath, const char *const *args, std::st
557558 } else {
558559 // child process
559560 // -> set pipes to be used for stdout/stderr
560- dup2 (writeCoutPipe, STDOUT_FILENO);
561- dup2 (writeCerrPipe, STDERR_FILENO);
561+ if (dup2 (writeCoutPipe, STDOUT_FILENO) == -1 || dup2 (writeCerrPipe, STDERR_FILENO) == -1 ) {
562+ std::cerr << Phrases::Error << " Unable to duplicate file descriptor: " << std::strerror (errno) << Phrases::EndFlush;
563+ std::exit (EXIT_FAILURE);
564+ }
562565 close (readCoutPipe);
563566 close (writeCoutPipe);
564567 close (readCerrPipe);
0 commit comments