From 047fd17f317591ac5c87c5362b50afe240d3354f Mon Sep 17 00:00:00 2001 From: Ken'ichi Ohmichi Date: Mon, 6 Apr 2009 17:04:08 +0900 Subject: Add some success/error messages to 'cgconfig' service. Hi, The existing 'cgconfig' service does not display any message even if it succeeds. So this patch adds some success/error messages to 'cgconfig' service like the following: # service cgconfig start Starting cgconfig service: [ OK ] # # service cgconfig stop Stopping cgconfig service: [ OK ] # # service cgconfig restart Stopping cgconfig service: [ OK ] Starting cgconfig service: [ OK ] # It makes test of 'cgconfig' service a little easy. Signed-off-by: Ken'ichi Ohmichi Signed-off-by: Dhaval Giani --- scripts/init.d/cgconfig | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/scripts/init.d/cgconfig b/scripts/init.d/cgconfig index 6e6bcd6..6b01d9c 100644 --- a/scripts/init.d/cgconfig +++ b/scripts/init.d/cgconfig @@ -69,6 +69,7 @@ umount_fs() { } start() { + echo -n "Starting cgconfig service: " if [ -f /var/lock/subsys/$servicename ] then log_warning_msg "lock file already exists" @@ -77,11 +78,11 @@ start() { if [ $? -eq 0 ] then - #log_progress_msg "Starting cgconfig service: " cgconfigparser -l $CONFIG_FILE retval=$? if [ $retval -ne 0 ] then + log_failure_msg "Failed to parse " $CONFIG_FILE return $retval fi fi @@ -136,7 +137,14 @@ start() { done touch /var/lock/subsys/$servicename - return $? + retval=$? + if [ $retval -ne 0 ] + then + log_failure_msg "Failed to touch " /var/lock/subsys/$servicename + return $retval + fi + log_success_msg + return 0 } move_all_to_init_class() { @@ -169,9 +177,11 @@ move_all_to_init_class() { stop() { + echo -n "Stopping cgconfig service: " move_all_to_init_class umount_fs rm -f /var/lock/subsys/$servicename + log_success_msg } trapped() { -- cgit From 52ee80ca0f26e4a7350504c56fb17decb562420b Mon Sep 17 00:00:00 2001 From: Ken'ichi Ohmichi Date: Tue, 7 Apr 2009 09:50:32 +0900 Subject: Add some success/error messages to 'cgred' service. Hi, The existing 'cgred' service displays a success message ([ OK ]) when the service is starting, but it does not display any messages when it is stopping/reloading. So this patch adds some success/error messages to 'cgred' service like the following: # service cgred start Starting CGroup Rules Engine Daemon... [ OK ] # # service cgred stop Stopping CGroup Rules Engine Daemon... [ OK ] # # service cgred restart Stopping CGroup Rules Engine Daemon... [ OK ] Starting CGroup Rules Engine Daemon... [ OK ] # # service cgred reload Reloading rules configuration... [ OK ] # This patch's purpose is almost same as the one of 'cgconfig' service: http://sourceforge.net/mailarchive/forum.php?thread_name=49D9B778.3000900%40mxs.nes.nec.co.jp&forum_name=libcg-devel Signed-off-by: Ken'ichi Ohmichi Signed-off-by: Dhaval Giani --- scripts/init.d/cgred | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/init.d/cgred b/scripts/init.d/cgred index 73ca480..fa824df 100644 --- a/scripts/init.d/cgred +++ b/scripts/init.d/cgred @@ -67,7 +67,7 @@ start() { echo $"Starting CGroup Rules Engine Daemon..." if [ -f "/var/lock/subsys/$servicename" ] ; then - echo "$servicename is already running with PID `cat ${pidfile}`" + log_failure_msg "$servicename is already running with PID `cat ${pidfile}`" return 1 fi daemon --check $servicename --pidfile $pidfile $processname $OPTIONS @@ -87,6 +87,7 @@ stop() rm -f /var/lock/subsys/$servicename rm -f $pidfile fi + log_success_msg } # See how we are called @@ -116,9 +117,13 @@ case "$1" in echo $"Reloading rules configuration..." kill -s 12 `cat ${pidfile}` RETVAL=$? - echo + if [ $RETVAL -eq 0 ] ; then + log_success_msg + else + log_failure_msg + fi else - echo $"$servicename is not running." + log_failure_msg "$servicename is not running." fi ;; *) -- cgit From e9b0b26d8bf46719b05e8ebf7bccb829ba1cec93 Mon Sep 17 00:00:00 2001 From: Ken'ichi Ohmichi Date: Tue, 7 Apr 2009 14:02:24 +0900 Subject: Fix infinite loop if receiving a NLMSG_NOOP packet. Hi, I tested 'cgred' service and I saw the problem that some processes are not moved to a right cgroup. This problem did not occur always, and it did sometimes. I reviewed cgrulesengd.c and found the bug cgrulesengd stays in an infinite loop if receiving a NLMSG_NOOP packet. This patch fixes this problem. Signed-off-by: Ken'ichi Ohmichi Acked-by: Balbir Singh Signed-off-by: Dhaval Giani --- src/daemon/cgrulesengd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/daemon/cgrulesengd.c b/src/daemon/cgrulesengd.c index 8efdce1..4e00e18 100644 --- a/src/daemon/cgrulesengd.c +++ b/src/daemon/cgrulesengd.c @@ -386,8 +386,10 @@ int cgre_create_netlink_socket_process_msg() continue; while (NLMSG_OK(nlh, recv_len)) { cn_hdr = NLMSG_DATA(nlh); - if (nlh->nlmsg_type == NLMSG_NOOP) + 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; -- cgit From 973dac482d4a46386ad14602df2cf37470258238 Mon Sep 17 00:00:00 2001 From: Ken'ichi Ohmichi Date: Mon, 13 Apr 2009 09:47:36 +0900 Subject: Fix the lacks of pthread_rwlock_unlock() calls. Two pthread_rwlock_unlock() calls are necessary if *cgroup is null and fprintf()/fflush() fails in cgroup_attach_task_pid(): src/api.c:785 785 pthread_rwlock_rdlock(&cg_mount_table_lock); 786 for(i = 0; i < CG_CONTROLLER_MAX && 787 cg_mount_table[i].name[0]!='\0'; i++) { [snip] 805 ret = fprintf(tasks, "%d", tid); 806 if (ret < 0) { <> 807 cgroup_dbg("Error writing tid %d to %s:%s\n", 808 tid, path, strerror(errno)); 809 fclose(tasks); 810 last_errno = errno; 811 return ECGOTHER; 812 } 813 814 ret = fflush(tasks); 815 if (ret) { <> 816 last_errno = errno; 817 cgroup_dbg("Error writing tid %d to %s:%s\n", 818 tid, path, strerror(errno)); 819 fclose(tasks); 820 return ECGOTHER; 821 } For the readability, this patch merges almost the same lines into one function(__cgroup_attach_task_pid()) and adds pthread_rwlock_unlock() call for the case the function fails. Signed-off-by: Ken'ichi Ohmichi Signed-off-by: Dhaval Giani --- src/api.c | 106 +++++++++++++++++++++++++------------------------------------- 1 file changed, 43 insertions(+), 63 deletions(-) diff --git a/src/api.c b/src/api.c index a45802e..99e71fe 100644 --- a/src/api.c +++ b/src/api.c @@ -762,6 +762,43 @@ char *cg_build_path(char *name, char *path, char *type) return path; } +static int __cgroup_attach_task_pid(char *path, pid_t tid) +{ + int ret = 0; + FILE *tasks = NULL; + + tasks = fopen(path, "w"); + if (!tasks) { + switch (errno) { + case EPERM: + return ECGROUPNOTOWNER; + case ENOENT: + return ECGROUPNOTEXIST; + default: + return ECGROUPNOTALLOWED; + } + } + ret = fprintf(tasks, "%d", tid); + if (ret < 0) { + last_errno = errno; + ret = ECGOTHER; + goto err; + } + ret = fflush(tasks); + if (ret) { + last_errno = errno; + ret = ECGOTHER; + goto err; + } + fclose(tasks); + return 0; +err: + cgroup_dbg("Error writing tid %d to %s:%s\n", + tid, path, strerror(errno)); + fclose(tasks); + return ret; +} + /** cgroup_attach_task_pid is used to assign tasks to a cgroup. * struct cgroup *cgroup: The cgroup to assign the thread to. * pid_t tid: The thread to be assigned to the cgroup. @@ -773,7 +810,6 @@ char *cg_build_path(char *name, char *path, char *type) int cgroup_attach_task_pid(struct cgroup *cgroup, pid_t tid) { char path[FILENAME_MAX]; - FILE *tasks = NULL; int i, ret = 0; if (!cgroup_initialized) { @@ -789,37 +825,11 @@ int cgroup_attach_task_pid(struct cgroup *cgroup, pid_t tid) cg_mount_table[i].name)) continue; strncat(path, "/tasks", sizeof(path) - strlen(path)); - - tasks = fopen(path, "w"); - if (!tasks) { - pthread_rwlock_unlock(&cg_mount_table_lock); - switch (errno) { - case EPERM: - return ECGROUPNOTOWNER; - case ENOENT: - return ECGROUPNOTEXIST; - default: - return ECGROUPNOTALLOWED; - } - } - ret = fprintf(tasks, "%d", tid); - if (ret < 0) { - cgroup_dbg("Error writing tid %d to %s:%s\n", - tid, path, strerror(errno)); - fclose(tasks); - last_errno = errno; - return ECGOTHER; - } - - ret = fflush(tasks); + ret = __cgroup_attach_task_pid(path, tid); if (ret) { - last_errno = errno; - cgroup_dbg("Error writing tid %d to %s:%s\n", - tid, path, strerror(errno)); - fclose(tasks); - return ECGOTHER; + pthread_rwlock_unlock(&cg_mount_table_lock); + return ret; } - fclose(tasks); } pthread_rwlock_unlock(&cg_mount_table_lock); } else { @@ -835,40 +845,10 @@ int cgroup_attach_task_pid(struct cgroup *cgroup, pid_t tid) if (!cg_build_path(cgroup->name, path, cgroup->controller[i]->name)) continue; - strncat(path, "/tasks", sizeof(path) - strlen(path)); - - tasks = fopen(path, "w"); - if (!tasks) { - cgroup_dbg("fopen failed for %s:%s", path, - strerror(errno)); - - switch (errno) { - case EPERM: - return ECGROUPNOTOWNER; - case ENOENT: - return ECGROUPNOTEXIST; - default: - return ECGROUPNOTALLOWED; - } - } - ret = fprintf(tasks, "%d", tid); - if (ret < 0) { - last_errno = errno; - cgroup_dbg("Error writing tid %d to %s:%s\n", - tid, path, strerror(errno)); - fclose(tasks); - return ECGOTHER; - } - ret = fflush(tasks); - if (ret) { - last_errno = errno; - cgroup_dbg("Error writing tid %d to %s:%s\n", - tid, path, strerror(errno)); - fclose(tasks); - return ECGOTHER; - } - fclose(tasks); + ret = __cgroup_attach_task_pid(path, tid); + if (ret) + return ret; } } return 0; -- cgit From a2e27126706502134a1ed228391dd7bbd78aeb1b Mon Sep 17 00:00:00 2001 From: Bharata B Rao Date: Mon, 6 Apr 2009 14:17:38 +0530 Subject: Remove the dependency of libcgroup on libcgroup build. libcgroup build checks for the availability of cgroup_creat_cgroup from libcgroup during its build. This causes a build failure if libcgroup is compiled in a system which already has libcgroup library installed. Remove this check from configure.in. Signed-off-by: Bharata B Rao Signed-off-by: Dhaval Giani --- configure.in | 3 --- 1 file changed, 3 deletions(-) diff --git a/configure.in b/configure.in index 0d82f96..cb54d15 100644 --- a/configure.in +++ b/configure.in @@ -48,9 +48,6 @@ fi AM_PROG_LEX AC_PROG_LIBTOOL -# Checks for libraries. -AC_CHECK_LIB([cgroup], [cgroup_create_cgroup]) - # Checks for header files. AC_HEADER_DIRENT AC_HEADER_STDC -- cgit From 8d8a747b161508ebfd48a6dac52f1438e2714a2b Mon Sep 17 00:00:00 2001 From: Bharata B Rao Date: Mon, 13 Apr 2009 15:49:06 +0530 Subject: Fix a few compilation warnings in api.c gcc -DHAVE_CONFIG_H -I. -I.. -I../include -g -O2 -Wall -MT api.lo -MD -MP -MF .deps/api.Tpo -c api.c -fPIC -DPIC -o .libs/api.o api.c:52:1: warning: "VERSION" redefined In file included from ./libcgroup-internal.h:21, from api.c:31: ../config.h:129:1: warning: this is the location of the previous definition api.c: In function 'cgroup_parse_rules': api.c:353: warning: implicit declaration of function 'isblank' api.c: In function 'cgroup_modify_cgroup': api.c:1073: warning: implicit declaration of function 'asprintf' This patch fixes the warning arising due to isblank, asprintf and getline. Signed-off-by: Bharata B Rao Signed-off-by: Dhaval Giani --- src/api.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/api.c b/src/api.c index 99e71fe..4d5b524 100644 --- a/src/api.c +++ b/src/api.c @@ -25,6 +25,10 @@ * for mistakes in APIs for reading statistics. */ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + #include #include #include -- cgit