From 3bb3b5f47e7a202157002d305ceac8fa101a4346 Mon Sep 17 00:00:00 2001 From: Master Date: Mon, 29 Jun 2020 22:00:01 -0400 Subject: [PATCH] reworked exceptions for message value --- src/loaders/abstract/Unit.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/loaders/abstract/Unit.cpp b/src/loaders/abstract/Unit.cpp index 1a7c61a..5ddd2d7 100644 --- a/src/loaders/abstract/Unit.cpp +++ b/src/loaders/abstract/Unit.cpp @@ -122,21 +122,23 @@ int Unit::load_root(Json::Value loader_root) throw UnitException("No rectify boolean attribute specified when loading a unit."); // TODO functionize this - char * lgn; + int uid = getuid(); + struct passwd * upw; + std::string errmsg_user; // if no user field is specified then default to the currently executing user - if ( ( lgn = getlogin() ) == NULL ) + if ( ( upw = getpwuid(uid) ) == NULL ) { throw UnitException( "Could not retrieve current user." ); } else { - errmsg_user = lgn; + errmsg_user = upw->pw_name; } // -TODO if ( loader_root.isMember( "user" ) ) - { this->user = loader_root.get( "user", errmsg_user ).asString(); } else this->user = lgn; + { this->user = loader_root.get( "user", errmsg_user ).asString(); } else this->user = errmsg_user; // TODO functionalize this