From c4aca8efba368032f7a68f57b0535a64c3d2ee07 Mon Sep 17 00:00:00 2001 From: Sonika Garg Date: Thu, 12 Oct 2017 08:24:21 -0500 Subject: [PATCH] Add error codes --- code/harness/c_harness.cpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/code/harness/c_harness.cpp b/code/harness/c_harness.cpp index f6ae1e0d..a7d7cd98 100644 --- a/code/harness/c_harness.cpp +++ b/code/harness/c_harness.cpp @@ -139,14 +139,28 @@ int main(int argc, char** argv) { ****************************************************************************/ const unsigned int test_case_idx = optind; const string path = argv[test_case_idx]; - setenv("MOUNT_FS", test_dev.c_str(), 1); - int i = system(("df --output=source,size | grep "+flags_dev + "> filesize.txt").c_str()); - std::ifstream infile("filesize.txt"); - string line; - std::getline(infile,line); - cout << line << endl; - setenv("FILESYS_SIZE", line.c_str(), 1); - remove("filesize.txt"); + int errno = setenv("MOUNT_FS", test_dev.c_str(), 1); + if (errno < 0){ + cerr << "Error Setting environment variable MOUNT_FS" << errno << endl; + } + int errno = system(("df --output=source,size | grep "+flags_dev + "> filesize.txt").c_str()); + if ( errno < 0){ + cerr << "Error finding the filesize of mounted filesystem" << errno << endl; + } + else{ + std::ifstream infile("filesize.txt"); + string line; + std::getline(infile,line); + cout << line << endl; + int errno = setenv("FILESYS_SIZE", line.c_str(), 1); + if (errno < 0){ + cerr << "Error setting environment variable FILESYS_SIZE" << errno << endl; + } + int errno = remove("filesize.txt"); + if (errno < 0){ + cerr << "Error removing residual file--filesize.txt" << erro << endl; + } + } cout << "========== PHASE 0: Setting up CrashMonkey basics ==========" << endl; if (test_case_idx == argc) {