diff options
author | Chase Douglas <chase.douglas@ubuntu.com> | 2011-12-07 12:15:08 -0800 |
---|---|---|
committer | Chase Douglas <chase.douglas@ubuntu.com> | 2011-12-07 12:15:08 -0800 |
commit | e97811a1be63c97706fe3ca87a0568eb5a585a08 (patch) | |
tree | 0c74f03f07794f7f7187d087845db8e1771ccd77 | |
parent | bd446fb14847d6ab4d6531fb39309eea58aac4df (diff) |
Let setenv() and getenv() do error handling, and throw exception if they
fail
-rw-r--r-- | include/xorg/gtest/process.h | 3 | ||||
-rw-r--r-- | src/process.cpp | 12 |
2 files changed, 6 insertions, 9 deletions
diff --git a/include/xorg/gtest/process.h b/include/xorg/gtest/process.h index 258e645..5aa288b 100644 --- a/include/xorg/gtest/process.h +++ b/include/xorg/gtest/process.h @@ -45,8 +45,7 @@ class Process { bool Terminate(); bool Kill(); - bool SetEnv(const char* name, const char* value, SetEnvBehaviour behaviour = - DONT_OVERWRITE_EXISTING_VALUE); + void SetEnv(const char* name, const char* value, bool overwrite); const char * GetEnv(const char* name); pid_t Pid() const; diff --git a/src/process.cpp b/src/process.cpp index aaabb4c..d0ab2d8 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -108,17 +108,15 @@ bool xorg::testing::Process::Kill() { return true; } -bool xorg::testing::Process::SetEnv(const char* name, const char* value, - Process::SetEnvBehaviour b) { - if (name == NULL || value == NULL) - return false; +void xorg::testing::Process::SetEnv(const char* name, const char* value, + bool overwrite) { + if (setenv(name, value, overwrite) != 0) + throw std::runtime_error("Failed to set environment variable in process"); - return setenv(name, value, static_cast<int>(b)) == 0; + return; } const char* xorg::testing::Process::GetEnv(const char* name) { - if (name == NULL) - return NULL; return getenv(name); } |