From: Ken'ichi Ohmichi Date: Fri, 26 Jun 2009 05:51:06 +0000 (+0900) Subject: Add the library function cgroup_register_unchanged_process(). X-Git-Tag: v0.34~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1c29610af69bf3bb0e088ed3eca770589849b0da;p=thirdparty%2Flibcgroup.git 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 Signed-off-by: Dhaval Giani --- diff --git a/include/libcgroup.h b/include/libcgroup.h index 87074129..953703b8 100644 --- a/include/libcgroup.h +++ b/include/libcgroup.h @@ -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 diff --git a/src/api.c b/src/api.c index 92bdebd5..353b6dce 100644 --- a/src/api.c +++ b/src/api.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -48,6 +49,7 @@ #include #include #include +#include #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 2935d48a..aa9d0d27 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;