Hi,

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

This patch adds the library function cgroup_register_unchanged_process()
for notifying cgrulesengd daemon of the unchanged process.


Thanks
Ken'ichi Ohmichi

Signed-off-by: Ken'ichi Ohmichi <[email protected]>
---
 include/libcgroup.h |    9 +++++++++
 src/api.c           |   43 +++++++++++++++++++++++++++++++++++++++++++
 src/libcgroup.map   |    1 +
 3 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/include/libcgroup.h b/include/libcgroup.h
index 69d060b..9e08356 100644
--- a/include/libcgroup.h
+++ b/include/libcgroup.h
@@ -337,6 +337,15 @@ int cgroup_get_uid_gid_from_procfs(pid_t pid, uid_t *euid, 
gid_t *egid);
 char *cgroup_get_procname_from_procfs(pid_t pid);
 
 /**
+ * Register the unchanged process to a cgrulesengd daemon.
+ * If the daemon does not work, this function returns 0 as success.
+ * @param pid: The process id
+ * @param flags Bit flags to change the behavior, as defined above
+ * @return 0 on success, > 0 on error.
+ */
+int cgroup_register_unchanged_process(pid_t pid, int flags);
+
+/**
  * Read the next task value
  * @handle: The handle used for iterating
  * @pid: The variable where the value will be stored
diff --git a/src/api.c b/src/api.c
index 8b291f6..4207458 100644
--- a/src/api.c
+++ b/src/api.c
@@ -40,6 +40,7 @@
 #include <string.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/socket.h>
 #include <fcntl.h>
 #include <sys/syscall.h>
 #include <unistd.h>
@@ -48,6 +49,7 @@
 #include <pwd.h>
 #include <libgen.h>
 #include <assert.h>
+#include <linux/un.h>
 
 #ifndef PACKAGE_VERSION
 #define PACKAGE_VERSION 0.01
@@ -2715,3 +2717,44 @@ char *cgroup_get_procname_from_procfs(pid_t pid)
        return pname_status;
 }
 
+int cgroup_register_unchanged_process(pid_t pid, int flags)
+{
+       int sk;
+       int ret = 1;
+       char buff[sizeof(CGRULE_SUCCESS_STORE_PID)];
+       struct sockaddr_un addr;
+
+       sk = socket(PF_UNIX, SOCK_STREAM, 0);
+       if (sk < 0)
+               return 1;
+
+       bzero((char *)&addr, sizeof(addr));
+       addr.sun_family = AF_UNIX;
+       strcpy(addr.sun_path, CGRULE_CGRED_TEMP_FILE);
+
+       if (connect(sk, (struct sockaddr *)&addr,
+           sizeof(addr.sun_family) + strlen(CGRULE_CGRED_TEMP_FILE)) < 0) {
+               if (errno == ECONNREFUSED)
+                       /* If the daemon does not work, this function
+                        * returns 0 as success. */
+                       ret = 0;
+               goto close;
+       }
+       if (write(sk, &pid, sizeof(pid)) < 0)
+               goto close;
+
+       if (write(sk, &flags, sizeof(flags)) < 0)
+               goto close;
+
+       if (read(sk, buff, sizeof(buff)) < 0)
+               goto close;
+
+       if (strncmp(buff, CGRULE_SUCCESS_STORE_PID, sizeof(buff)))
+               goto close;
+
+       ret = 0;
+close:
+       close(sk);
+       return ret;
+}
+
diff --git a/src/libcgroup.map b/src/libcgroup.map
index bed1cbc..346ff7a 100644
--- a/src/libcgroup.map
+++ b/src/libcgroup.map
@@ -64,5 +64,6 @@ global:
        cgroup_read_stats_end;
        cgroup_get_uid_gid_from_procfs;
        cgroup_get_procname_from_procfs;
+       cgroup_register_unchanged_process;
        cgroup_change_cgroup_flags;
 } CGROUP_0.33;

------------------------------------------------------------------------------
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