diff --git a/alib2measurepp/src/provisioner/MeasurementProvisioner.cpp b/alib2measurepp/src/provisioner/MeasurementProvisioner.cpp index d36df4424aeccd0e217aa07da0196b08335b0b90..3c69b543b06bcff5c42f448b93b7864b5f2454bd 100644 --- a/alib2measurepp/src/provisioner/MeasurementProvisioner.cpp +++ b/alib2measurepp/src/provisioner/MeasurementProvisioner.cpp @@ -123,7 +123,7 @@ MPRPipelineResult MeasurementProvisioner::runPipeline ( const MPPipeline & pipel if ( WEXITSTATUS ( status ) != 0 ) { pipelineFinalResults.pipelineStatus.exitCode = WEXITSTATUS ( status ); pipelineFinalResults.pipelineStatus.errorOrigin = mppcIter->getRawCommand ( ); - pipelineFinalResults.pipelineStatus.errorValue = pre.retrievePipelineError ( ); + pipelineFinalResults.pipelineStatus.errorValue = pre.retrievePipelineError ( ); break; } @@ -181,15 +181,15 @@ MeasurementProvisioner::PipelineRunnerEnvironment::PipelineRunnerEnvironment ( ) throw::exception::CommonException ( "MeasurementProvisioner: Cannot open measurements file descriptor" ); try { - inputTmpfile = MPUtils::openShmFile ( ); + inputTmpfile = MPUtils::openShmFile ( ); outputTmpfile = MPUtils::openShmFile ( ); - errorTmpfile = MPUtils::openShmFile ( ); + errorTmpfile = MPUtils::openShmFile ( ); } catch ( ::exception::CommonException & ) { throw::exception::CommonException ( "MeasurementProvisioner: Cannot make io tmp files" ); } // store handles to stdin, stdout, stderr, we will need to restore them later - stdinFd = dup ( 0 ); + stdinFd = dup ( 0 ); stdoutFd = dup ( 1 ); stderrFd = dup ( 2 ); @@ -213,9 +213,8 @@ MeasurementProvisioner::PipelineRunnerEnvironment::~PipelineRunnerEnvironment ( close ( 1 ); close ( 2 ); - dup ( stdinFd ); - dup ( stdoutFd ); - dup ( stderrFd ); + if ( ( dup ( stdinFd ) == -1 ) || ( dup ( stdoutFd ) == -1 ) || ( dup ( stderrFd ) == -1 ) ) + throw::exception::CommonException ( "MeasurementProvisioner: dup failed" ); close ( stdinFd ); close ( stdoutFd ); @@ -224,27 +223,27 @@ MeasurementProvisioner::PipelineRunnerEnvironment::~PipelineRunnerEnvironment ( void MeasurementProvisioner::PipelineRunnerEnvironment::commandFdInit ( ) { // sets the right file descriptors for child processes - commands - dup ( inputTmpfile.fd ); - dup ( outputTmpfile.fd ); - dup ( errorTmpfile.fd ); + if ( ( dup ( inputTmpfile.fd ) == -1 ) || ( dup ( outputTmpfile.fd ) == -1 ) || ( dup ( errorTmpfile.fd ) == -1 ) ) + throw::exception::CommonException ( "MeasurementProvisioner: dup failed" ); } void MeasurementProvisioner::PipelineRunnerEnvironment::commandFdSwap ( ) { // swap stdin and stdout for next command close ( 0 ); close ( 1 ); - if ( dup ( outputTmpfile.fd ) == -1 || dup ( inputTmpfile.fd ) == -1) { + + if ( ( dup ( outputTmpfile.fd ) == -1 ) || ( dup ( inputTmpfile.fd ) == -1 ) ) throw::exception::CommonException ( "MeasurementProvisioner: dup failed" ); - } + // rewind previous stdout to the beginning, so the next command can read the whole file as input lseek ( 0, 0, SEEK_SET ); // destroy the contents of previous stdin and rewind to the beginning lseek ( 1, 0, SEEK_SET ); - if(ftruncate ( 1, 0 ) == -1) { + + if ( ftruncate ( 1, 0 ) == -1 ) throw::exception::CommonException ( "MeasurementProvisioner: ftruncate failed" ); - } } void MeasurementProvisioner::PipelineRunnerEnvironment::commandFdEnd ( ) { @@ -280,7 +279,9 @@ MeasurementResults MeasurementProvisioner::PipelineRunnerEnvironment::retrieveMe // destroy the contents and rewind for another commands measurements lseek ( measurementsFd, 0, SEEK_SET ); - ftruncate ( measurementsFd, 0 ); + + if ( ftruncate ( measurementsFd, 0 ) == -1 ) + throw::exception::CommonException ( "MeasurementProvisioner: ftruncate failed" ); return measurements::MeasurementResultsXml::parse ( tokens ); } diff --git a/alib2measurepp/src/provisioner/MeasurementProvisionerUtils.cpp b/alib2measurepp/src/provisioner/MeasurementProvisionerUtils.cpp index 1f6a796afcbee8c5d63d427e716a046a8343d191..e4dee6e34fda1870df9bbbd4bd345eff75d8148d 100644 --- a/alib2measurepp/src/provisioner/MeasurementProvisionerUtils.cpp +++ b/alib2measurepp/src/provisioner/MeasurementProvisionerUtils.cpp @@ -73,14 +73,22 @@ std::string MPUtils::generateTmpfileFromCommand ( const std::string & command ) int stdoutfd = dup ( 1 ); + if ( stdoutfd == -1 ) + throw::exception::CommonException ( "MeasurementProvisionerUtils: dup failed" ); + close ( 1 ); - dup ( tempShmFile.fd ); + + if ( dup ( tempShmFile.fd ) == -1 ) + throw::exception::CommonException ( "MeasurementProvisionerUtils: dup failed" ); int status = system ( command.c_str ( ) ); close ( 1 ); close ( tempShmFile.fd ); - dup ( stdoutfd ); + + if ( dup ( stdoutfd ) == -1 ) + throw::exception::CommonException ( "MeasurementProvisionerUtils: dup failed" ); + close ( stdoutfd ); if ( WEXITSTATUS ( status ) != 0 ) {