Put the pid and flags into iovec structure for processing via 
writev/readv according to manual. Vector read/write syscall process 
multiple iovec buffers in array order (man 2 writev). It's reduce the 
number of syscalls and make code more clear (less read/write if pairs)

Signed-off-by: Alex Nikiforov <a.nikifo...@samsung.com>
---
   src/api.c                |   11 ++++++++---
   src/daemon/cgrulesengd.c |   14 +++++++++-----
   2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/src/api.c b/src/api.c
index d5022c2..8c6dd1e 100644
--- a/src/api.c
+++ b/src/api.c
@@ -43,6 +43,7 @@
   #include <sys/socket.h>
   #include <fcntl.h>
   #include <sys/syscall.h>
+#include <sys/uio.h>
   #include <unistd.h>
   #include <fts.h>
   #include <ctype.h>
@@ -3704,6 +3705,7 @@ int cgroup_register_unchanged_process(pid_t pid,
int flags)
        int ret = 1;
        char buff[sizeof(CGRULE_SUCCESS_STORE_PID)];
        struct sockaddr_un addr;
+       struct iovec    iov[2] = {};

        sk = socket(PF_UNIX, SOCK_STREAM, 0);
        if (sk < 0)
@@ -3720,10 +3722,13 @@ int cgroup_register_unchanged_process(pid_t pid,
int flags)
                ret = 0;
                goto close;
        }
-       if (write(sk, &pid, sizeof(pid)) < 0)
-               goto close;

-       if (write(sk, &flags, sizeof(flags)) < 0)
+       iov[0].iov_base =  &pid;
+       iov[0].iov_len =  sizeof(pid);
+       iov[1].iov_base =  &flags;
+       iov[1].iov_len =  sizeof(flags);
+
+       if (writev(sk, iov, 2) < 0)
                goto close;

        if (read(sk, buff, sizeof(buff)) < 0)
diff --git a/src/daemon/cgrulesengd.c b/src/daemon/cgrulesengd.c
index eb6893a..d3390f7 100644
--- a/src/daemon/cgrulesengd.c
+++ b/src/daemon/cgrulesengd.c
@@ -40,6 +40,7 @@
   #include <stdio.h>
   #include <stdlib.h>
   #include <sys/socket.h>
+#include <sys/uio.h>
   #include <sys/syslog.h>
   #include <string.h>
   #include <linux/netlink.h>
@@ -550,6 +551,7 @@ static void cgre_receive_unix_domain_msg(int sk_unix)
        pid_t pid;
        struct sockaddr_un caddr;
        socklen_t caddr_len;
+       struct iovec    iov[2] = {};

        caddr_len = sizeof(caddr);
        fd_client = accept(sk_unix, (struct sockaddr *)&caddr, &caddr_len);
@@ -557,11 +559,13 @@ static void cgre_receive_unix_domain_msg(int sk_unix)
                cgroup_dbg("accept error: %s\n", strerror(errno));
                return;
        }
-       if (read(fd_client, &pid, sizeof(pid)) < 0) {
-               cgroup_dbg("read error: %s\n", strerror(errno));
-               goto close;
-       }
-       if (read(fd_client, &flags, sizeof(flags)) < 0) {
+
+       iov[0].iov_base =  &pid;
+       iov[0].iov_len =  sizeof(pid);
+       iov[1].iov_base =  &flags;
+       iov[1].iov_len =  sizeof(flags);
+
+       if (readv(fd_client, iov, 2) < 0) {
                cgroup_dbg("read error: %s\n", strerror(errno));
                goto close;
        }
-- 1.7.4.1


------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security 
threats, fraudulent activity, and more. Splunk takes this data and makes 
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to