Skip to content
Snippets Groups Projects
Commit 1231e0f6 authored by Steven Murray's avatar Steven Murray
Browse files

Added extra error handling code around getlogin_r()

parent c07cde10
Branches
Tags
No related merge requests found
......@@ -18,6 +18,7 @@
#include "common/exception/Exception.hpp"
#include "common/make_unique.hpp"
#include "common/utils/utils.hpp"
#include "xroot_plugins/WriteNotificationMsgCmd.hpp"
#include "xroot_plugins/WriteNotificationMsgCmdLineArgs.hpp"
......@@ -149,9 +150,11 @@ int WriteNotificationMsgCmd::exceptionThrowingMain(const int argc, char *const *
//------------------------------------------------------------------------------
std::string WriteNotificationMsgCmd::getUsername() {
char buf[128];
const int getLoginRet = getlogin_r(buf, sizeof(buf));
if(0 != getlogin_r(buf, sizeof(buf))) {
throw cta::exception::Exception(std::string(__FUNCTION__) + " failed: getlogin_r() failed");
if(0 != getLoginRet) {
const std::string errorMsg = utils::errnoToString(getLoginRet);
throw cta::exception::Exception(std::string(__FUNCTION__) + " failed: getlogin_r() failed: " + errorMsg);
}
buf[sizeof(buf) - 1] = '\0';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment