Fix coverity accepted/tizen_4.0_unified tizen_4.0 accepted/tizen/4.0/unified/20181226.234119 submit/tizen_4.0/20181221.021633
authoryeji01.kim <yeji01.kim@samsung.com>
Fri, 23 Mar 2018 05:42:05 +0000 (14:42 +0900)
committerSungbae Yoo <sungbae.yoo@samsung.com>
Fri, 21 Dec 2018 02:13:27 +0000 (11:13 +0900)
- Add check return
- Add exception handling

Change-Id: I7e2d58e7c5175846d6bf22837af6aba96737c3af
Signed-off-by: yeji01.kim <yeji01.kim@samsung.com>
src/auth/group.cpp
src/auth/user.cpp
src/mainloop.cpp

index 67dc2911dcc12d4c99b200f31a85eef3cc4d8281..e306f64bfb75b740c8570c841caaa131eb5a60b2 100644 (file)
@@ -23,6 +23,7 @@
 #include <regex>
 #include <memory>
 
+#include <klay/error.h>
 #include <klay/exception.h>
 #include <klay/auth/group.h>
 
@@ -36,7 +37,7 @@ Group::Group(const Group& group) :
 Group::Group(const std::string& group)
 {
        struct group grp, *result;
-       int bufsize;
+       int bufsize, ret;
 
        bufsize = sysconf(_SC_GETGR_R_SIZE_MAX);
        if (bufsize == -1)
@@ -44,9 +45,12 @@ Group::Group(const std::string& group)
 
        std::unique_ptr<char[]> buf(new char[bufsize]);
 
-       ::getgrnam_r(group.c_str(), &grp, buf.get(), bufsize, &result);
+       ret = ::getgrnam_r(group.c_str(), &grp, buf.get(), bufsize, &result);
        if (result == NULL) {
-               throw runtime::Exception("Group doesn't exist");
+               if (ret == 0)
+                       throw runtime::Exception("Group doesn't exist");
+               else
+                       throw runtime::Exception(runtime::GetSystemErrorMessage(ret));
        }
 
        name = result->gr_name;
@@ -56,7 +60,7 @@ Group::Group(const std::string& group)
 Group::Group(const gid_t group)
 {
        struct group grp, *result;
-       int bufsize;
+       int bufsize, ret;
 
        bufsize = sysconf(_SC_GETGR_R_SIZE_MAX);
        if (bufsize == -1)
@@ -64,9 +68,12 @@ Group::Group(const gid_t group)
 
        std::unique_ptr<char[]> buf(new char[bufsize]);
 
-       ::getgrgid_r(group, &grp, buf.get(), bufsize, &result);
+       ret = ::getgrgid_r(group, &grp, buf.get(), bufsize, &result);
        if (result == NULL) {
-               throw runtime::Exception("Group doesn't exist");
+               if (ret == 0)
+                       throw runtime::Exception("Group doesn't exist");
+               else
+                       throw runtime::Exception(runtime::GetSystemErrorMessage(ret));
        }
 
        name = result->gr_name;
index e501cd0072ec68eb7653904086819d7e191478be..3eba7d97f5cf4666ef5440f9ed867a0cac253d85 100644 (file)
@@ -23,6 +23,7 @@
 #include <regex>
 #include <memory>
 
+#include <klay/error.h>
 #include <klay/exception.h>
 #include <klay/auth/user.h>
 
@@ -36,7 +37,7 @@ User::User(const User& user) :
 User::User(const std::string& user)
 {
        struct passwd pwd, *result;
-       int bufsize;
+       int bufsize, ret;
 
        bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
        if (bufsize == -1)
@@ -44,9 +45,12 @@ User::User(const std::string& user)
 
        std::unique_ptr<char[]> buf(new char[bufsize]);
 
-       ::getpwnam_r(user.c_str(), &pwd, buf.get(), bufsize, &result);
+       ret = ::getpwnam_r(user.c_str(), &pwd, buf.get(), bufsize, &result);
        if (result == NULL) {
-               throw runtime::Exception("User " + user + " doesn't exist");
+               if (ret == 0)
+                       throw runtime::Exception("User " + user + " doesn't exist");
+               else
+                       throw runtime::Exception(runtime::GetSystemErrorMessage(ret));
        }
 
        name = result->pw_name;
@@ -57,16 +61,19 @@ User::User(const std::string& user)
 User::User(const uid_t user)
 {
        struct passwd pwd, *result;
-       int bufsize;
+       int bufsize, ret;
 
        bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
        if (bufsize == -1)
                bufsize = 16384;
 
        std::unique_ptr<char[]> buf(new char[bufsize]);
-       ::getpwuid_r(user, &pwd, buf.get(), bufsize, &result);
+       ret = ::getpwuid_r(user, &pwd, buf.get(), bufsize, &result);
        if (result == NULL) {
-               throw runtime::Exception("User " + std::to_string(user) + "doesn't exist");
+               if (ret == 0)
+                       throw runtime::Exception("User " + std::to_string(user) + "doesn't exist");
+               else
+                       throw runtime::Exception(runtime::GetSystemErrorMessage(ret));
        }
 
        name = result->pw_name;
index 92321ea54747ea9feeff29b53b1933b61332a01d..0188e128ab08a23a3fdca94ae382639c822fd437 100644 (file)
@@ -124,7 +124,11 @@ bool Mainloop::dispatch(int timeout)
 
 void Mainloop::stop()
 {
-       wakeupSignal.send();
+       try {
+               wakeupSignal.send();
+       } catch (std::exception &e) {
+               std::cout << "EXCEPTION ON EVENTFD IN MAINLOOP" << std::endl;
+       }
 }
 
 void Mainloop::prepare()