summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKen'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp>2009-06-26 14:51:06 +0900
committerDhaval Giani <dhaval@linux.vnet.ibm.com>2009-06-29 16:51:10 +0530
commit1c29610af69bf3bb0e088ed3eca770589849b0da (patch)
treea6ed2493eff33c99d37f9368082ae294840fba17
parentafbbee67863b4debf4ec849ff3d6a3f1f21b73ef (diff)
downloadlibcg-1c29610af69bf3bb0e088ed3eca770589849b0da.tar.gz
libcg-1c29610af69bf3bb0e088ed3eca770589849b0da.tar.xz
libcg-1c29610af69bf3bb0e088ed3eca770589849b0da.zip
Add the library function cgroup_register_unchanged_process().
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>
-rw-r--r--include/libcgroup.h9
-rw-r--r--src/api.c42
-rw-r--r--src/libcgroup.map1
3 files changed, 52 insertions, 0 deletions
diff --git a/include/libcgroup.h b/include/libcgroup.h
index 8707412..953703b 100644
--- a/include/libcgroup.h
+++ b/include/libcgroup.h
@@ -324,6 +324,15 @@ 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
* @pid: The variable where the value will be stored
diff --git a/src/api.c b/src/api.c
index 92bdebd..353b6dc 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
@@ -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;
diff --git a/src/libcgroup.map b/src/libcgroup.map
index 2935d48..aa9d0d2 100644
--- a/src/libcgroup.map
+++ b/src/libcgroup.map
@@ -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;