From 7c76f6c825e13d9e1930cff25a40e537de463ca4 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Wed, 13 Apr 2016 09:08:59 +0200 Subject: [PATCH] fix ignoring return value warn --- .../provisioner/MeasurementProvisioner.cpp | 31 ++++++++++--------- .../MeasurementProvisionerUtils.cpp | 12 +++++-- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/alib2measurepp/src/provisioner/MeasurementProvisioner.cpp b/alib2measurepp/src/provisioner/MeasurementProvisioner.cpp index d36df4424a..3c69b543b0 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 1f6a796afc..e4dee6e34f 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 ) { -- GitLab