DSUtil: define LCOV_EXCL blocks for error handling code 45/243545/1
authorSung-Jin Park <sj76.park@samsung.com>
Tue, 8 Sep 2020 02:35:21 +0000 (11:35 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Tue, 8 Sep 2020 03:32:54 +0000 (12:32 +0900)
Change-Id: I4f2eedf8056e040c5698c0ec31984d982640c423
Signed-off-by: Sung-Jin Park <sj76.park@samsung.com>
src/DSUtil/DSUtilSocket.cpp

index 9c0e0ff..0e25111 100644 (file)
@@ -112,8 +112,10 @@ void DSUtilSocket::initSocket(std::string socketName)
        int nameLength = socketName.length();
        if ((dirLength + nameLength + 2) > STRERR_BUFSIZE)
      {
+       /*LCOV_EXCL_START*/
         DSLOG_WRN("DSUtilSocket", "Size of buffer is not enough. dir:%s name:%s", xdgDir, socketName);
         return;
+       /*LCOV_EXCL_STOP*/
      }
 
        //snprintf(socket_path, sizeof(socket_path), "%s/%s", dir, name);
@@ -125,17 +127,21 @@ void DSUtilSocket::initSocket(std::string socketName)
        res = chmod(socketPath.c_str(), 509);
        if (res < 0)
        {
+               /*LCOV_EXCL_START*/
                DSLOG_WRN("DSUtilSocket", "Could not change modes of socket file:%s (%s)", socketPath.c_str(), strerror_r(errno, buf, STRERR_BUFSIZE));
                //PRCTL("[Winsys] Could not chane modes of socket file: %s", socketPath.c_str());
                return;
+               /*LCOV_EXCL_STOP*/
        }
 
        res = chown(socketPath.c_str(), uid, gid);
        if (res < 0)
        {
+               /*LCOV_EXCL_START*/
                DSLOG_WRN("DSUtilSocket", "Could not change owner of socket file:%s (%s)", socketPath.c_str(), strerror_r(errno, buf, STRERR_BUFSIZE));
                //PRCTL("[Winsys] Could not change owner of socket file: %s", socketPath.c_str());
                return;
+               /*LCOV_EXCL_STOP*/
        }
 }
 
@@ -156,26 +162,32 @@ int DSUtilSocket::__getpwnam(std::string name)
        buf = (char *)malloc(bufLen);
        if (buf == NULL)
        {
+               /*LCOV_EXCL_START*/
                DSLOG_WRN("DSUtilSocket", "failed to create buffer");
                return 0;
+               /*LCOV_EXCL_STOP*/
        }
 
        u = (struct ::passwd *)malloc(sizeof(struct passwd));
        if (!u)
        {
+               /*LCOV_EXCL_START*/
                DSLOG_WRN("DSUtilSocket", "failed to create password struct");
                free(buf);
                return 0;
+               /*LCOV_EXCL_STOP*/
        }
 
        ret = getpwnam_r(name.c_str(), u, buf, bufLen, &uRes);
        if (uRes == nullptr)
        {
+               /*LCOV_EXCL_START*/
                if (ret == 0) DSLOG_WRN("DSUtilSocket", "password not found");
                else DSLOG_WRN("DSUtilSocket", "errno returned by getpwnam_r is %d", ret);
                free(buf);
                free(u);
                return 0;
+               /*LCOV_EXCL_STOP*/
        }
        ret = u->pw_uid;
        free(buf);
@@ -201,26 +213,32 @@ int DSUtilSocket::__getgrnam(std::string name)
        buf = (char *)malloc(bufLen);
        if (buf == nullptr)
        {
+               /*LCOV_EXCL_START*/
                DSLOG_WRN("DSUtilSocket", "failed to create buffer");
                return 0;
+               /*LCOV_EXCL_STOP*/
        }
 
        g = (struct ::group *)malloc(sizeof(struct group));
        if (!g)
        {
+               /*LCOV_EXCL_START*/
                DSLOG_WRN("DSUtilSocket", "failed to create group struct");
                free(buf);
                return 0;
+               /*LCOV_EXCL_STOP*/
        }
 
        ret = getgrnam_r(name.c_str(), g, buf, bufLen, &grpRes);
        if (grpRes == NULL)
        {
+               /*LCOV_EXCL_START*/
                if (ret == 0) DSLOG_WRN("DSUtilSocket", "Group not found");
                else DSLOG_WRN("DSUtilSocket", "errno returned by getpwnam_r is %d", ret);
                free(buf);
                free(g);
                return 0;
+               /*LCOV_EXCL_STOP*/
        }
 
        ret = g->gr_gid;