Hi,

Changelog of v2:
================
* New patch.

This patch separates the netlink method for the readability, because
the later patch [PATCH 6/8] adds "unix domain socket" handling method
around the netlink method.


Thanks
Ken'ichi Ohmichi

Signed-off-by: Ken'ichi Ohmichi <[email protected]>
---
 src/daemon/cgrulesengd.c |   75 ++++++++++++++++++++++++++-------------------
 1 files changed, 43 insertions(+), 32 deletions(-)

diff --git a/src/daemon/cgrulesengd.c b/src/daemon/cgrulesengd.c
index be91bbc..6000163 100644
--- a/src/daemon/cgrulesengd.c
+++ b/src/daemon/cgrulesengd.c
@@ -388,17 +388,55 @@ int cgre_handle_msg(struct cn_msg *cn_hdr)
        return ret;
 }
 
+int cgre_receive_netlink_msg(int sk_nl, struct cn_msg *cn_hdr,
+                                       struct sockaddr_nl *kern_nla)
+{
+       char buff[BUFF_SIZE];
+       size_t recv_len;
+       struct sockaddr_nl from_nla;
+       socklen_t from_nla_len;
+       struct nlmsghdr *nlh;
+
+       memset(buff, 0, sizeof(buff));
+       from_nla_len = sizeof(from_nla);
+       memcpy(&from_nla, kern_nla, sizeof(from_nla));
+       recv_len = recvfrom(sk_nl, buff, sizeof(buff), 0,
+               (struct sockaddr *)&from_nla, &from_nla_len);
+       if (recv_len == ENOBUFS) {
+               flog(LOG_ERR, "ERROR: NETLINK BUFFER FULL, MESSAGE DROPPED!");
+               return 0;
+       }
+       if (recv_len < 1)
+               return 0;
+
+       nlh = (struct nlmsghdr *)buff;
+       while (NLMSG_OK(nlh, recv_len)) {
+               cn_hdr = NLMSG_DATA(nlh);
+               if (nlh->nlmsg_type == NLMSG_NOOP) {
+                       nlh = NLMSG_NEXT(nlh, recv_len);
+                       continue;
+               }
+               if ((nlh->nlmsg_type == NLMSG_ERROR) ||
+                               (nlh->nlmsg_type == NLMSG_OVERRUN))
+                       break;
+               if (cgre_handle_msg(cn_hdr) < 0)
+                       return 1;
+               if (nlh->nlmsg_type == NLMSG_DONE)
+                       break;
+               nlh = NLMSG_NEXT(nlh, recv_len);
+       }
+       return 0;
+}
+
 int cgre_create_netlink_socket_process_msg()
 {
        int sk_nl;
-       struct sockaddr_nl my_nla, kern_nla, from_nla;
-       socklen_t from_nla_len;
+       struct sockaddr_nl my_nla, kern_nla;
        char buff[BUFF_SIZE];
        int rc = -1;
        struct nlmsghdr *nl_hdr;
        struct cn_msg *cn_hdr;
        enum proc_cn_mcast_op *mcop_msg;
-       size_t recv_len = 0;
 
        /*
         * Create an endpoint for communication. Use the kernel user
@@ -456,35 +494,8 @@ int cgre_create_netlink_socket_process_msg()
        cgroup_dbg("sent\n");
 
        for(;;) {
-               memset(buff, 0, sizeof(buff));
-               from_nla_len = sizeof(from_nla);
-               struct nlmsghdr *nlh = (struct nlmsghdr*)buff;
-               memcpy(&from_nla, &kern_nla, sizeof(from_nla));
-               recv_len = recvfrom(sk_nl, buff, BUFF_SIZE, 0,
-               (struct sockaddr*)&from_nla, &from_nla_len);
-               if (recv_len == ENOBUFS) {
-                       flog(LOG_ERR, "ERROR: NETLINK BUFFER FULL, MESSAGE "
-                                       "DROPPED!");
-                       continue;
-               }
-               if (recv_len < 1)
-                       continue;
-               while (NLMSG_OK(nlh, recv_len)) {
-                       cn_hdr = NLMSG_DATA(nlh);
-                       if (nlh->nlmsg_type == NLMSG_NOOP) {
-                               nlh = NLMSG_NEXT(nlh, recv_len);
-                               continue;
-                       }
-                       if ((nlh->nlmsg_type == NLMSG_ERROR) ||
-                                       (nlh->nlmsg_type == NLMSG_OVERRUN))
-                               break;
-                       if(cgre_handle_msg(cn_hdr) < 0) {
-                               goto close_and_exit;
-                       }
-                       if (nlh->nlmsg_type == NLMSG_DONE)
-                               break;
-                       nlh = NLMSG_NEXT(nlh, recv_len);
-               }
+               if (cgre_receive_netlink_msg(sk_nl, cn_hdr, &kern_nla))
+                       break;
        }
 
 close_and_exit:

------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises 
looking to deploy the next generation of Solaris that includes the latest 
innovations from Sun and the OpenSource community. Download a copy and 
enjoy capabilities such as Networking, Storage and Virtualization. 
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
Libcg-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to