]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
Add the library function cgroup_register_unchanged_process().
authorKen'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp>
Fri, 26 Jun 2009 05:51:06 +0000 (14:51 +0900)
committerDhaval Giani <dhaval@linux.vnet.ibm.com>
Mon, 29 Jun 2009 11:21:10 +0000 (16:51 +0530)
Hi,

Changelog of v6:
================
 * No change.

Changelog of v5:
================
 * Rebase the patch to the latest code.

Changelog of v4:
================
 * No change.

Changelog of v3:
================
 * No change.

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

Description:
============
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 <oomichi@mxs.nes.nec.co.jp>
Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
include/libcgroup.h
src/api.c
src/libcgroup.map

index 8707412983d88ea6cc413a3a193dc16e2b708895..953703b8f62391b0b2cce528c20350c467934002 100644 (file)
@@ -323,6 +323,15 @@ int cgroup_read_stats_end(void **handle);
 int cgroup_get_task_begin(char *cgroup, char *controller, void **handle,
                                                                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
index 92bdebd589b1eca6c02c98b0e76a48bb5b5ce046..353b6dcebb92a3f3b13ead765a96b4546ce474f1 100644 (file)
--- 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
@@ -2933,6 +2935,46 @@ int cgroup_get_procname_from_procfs(pid_t pid, char **procname)
        return ret;
 }
 
+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 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;
+}
+
 int cgroup_get_subsys_mount_point(char *controller, char **mount_point)
 {
        int i;
index 2935d48a6fecf212ce36830fffe4aba180e54863..aa9d0d2706cd5fa5a729bfc0b5e87f0bd2a23295 100644 (file)
@@ -71,5 +71,6 @@ global:
        cgroup_get_uid_gid_from_procfs;
        cgroup_get_subsys_mount_point;
        cgroup_get_procname_from_procfs;
+       cgroup_register_unchanged_process;
        cgroup_change_cgroup_flags;
 } CGROUP_0.33;