summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDhaval Giani <dhaval@linux.vnet.ibm.com>2008-06-10 19:17:26 +0000
committerDhaval Giani <dhaval@linux.vnet.ibm.com>2008-06-10 19:17:26 +0000
commitf1bce06975c0c4d6b1e348bbd1cbc26694e57f82 (patch)
tree1c08928a71070164304e94662137d79f3c86cf07
parentab944729e147ed15188905a9e196a82db88c7eff (diff)
downloadlibcg-f1bce06975c0c4d6b1e348bbd1cbc26694e57f82.tar.gz
libcg-f1bce06975c0c4d6b1e348bbd1cbc26694e57f82.tar.xz
libcg-f1bce06975c0c4d6b1e348bbd1cbc26694e57f82.zip
Some bugs were missed in v0.1b. Fixing those bugs and tagging
v0.1c. Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com> git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/tags/v0.1c@76 4f4bb910-9a46-0410-90c8-c897d4f1cd53
-rw-r--r--Makefile4
-rw-r--r--api.c66
-rwxr-xr-xconfigure52
-rw-r--r--configure.in2
-rw-r--r--libcgroup.h1
-rw-r--r--libcgroup.spec.in4
6 files changed, 76 insertions, 53 deletions
diff --git a/Makefile b/Makefile
index 269edf5..e37458f 100644
--- a/Makefile
+++ b/Makefile
@@ -20,11 +20,11 @@ LEX=flex
bindir=${exec_prefix}/bin
libdir=${exec_prefix}/lib
includedir=${prefix}/include
-prefix=/usr
+prefix=/usr/local
exec_prefix=${prefix}
INSTALL=install
INSTALL_DATA=install -m 644
-PACKAGE_VERSION=0.1b
+PACKAGE_VERSION=0.1c
CFLAGS=-g -O2 $(INC) -DPACKAGE_VERSION=$(PACKAGE_VERSION)
VERSION=1
diff --git a/api.c b/api.c
index a279631..6250ceb 100644
--- a/api.c
+++ b/api.c
@@ -48,6 +48,9 @@ const static char cg_version[] = VERSION(PACKAGE_VERSION);
struct cg_mount_table_s cg_mount_table[CG_CONTROLLER_MAX];
+/* Check if cgroup_init has been called or not. */
+static int cgroup_initialized;
+
static int cg_chown_file(FTS *fts, FTSENT *ent, uid_t owner, gid_t group)
{
int ret = 0;
@@ -93,6 +96,19 @@ static int cg_chown_recursive(char **path, uid_t owner, gid_t group)
return ret;
}
+static int cgroup_test_subsys_mounted(const char *name)
+{
+ int i;
+
+ for (i = 0; cg_mount_table[i].name[0] != '\0'; i++) {
+ if (strncmp(cg_mount_table[i].name, name,
+ sizeof(cg_mount_table[i].name)) == 0) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
/**
* cgroup_init(), initializes the MOUNT_POINT.
* This code is not currently thread safe (hint: getmntent is not thread safe).
@@ -152,6 +168,7 @@ int cgroup_init()
if (!strncmp(ent->mnt_type, "cgroup", strlen("cgroup"))) {
for (i = 0; controllers[i] != NULL; i++) {
mntopt = hasmntopt(ent, controllers[i]);
+ mntopt = strtok(mntopt, ",");
if (mntopt &&
strcmp(mntopt, controllers[i]) == 0) {
dbg("matched %s:%s\n", mntopt,
@@ -177,8 +194,8 @@ int cgroup_init()
found_mnt++;
cg_mount_table[found_mnt].name[0] = '\0';
-
fclose(proc_mount);
+ cgroup_initialized = 1;
return ret;
}
@@ -214,8 +231,10 @@ static char* cg_build_path(char *name, char *path, char *type)
if (strcmp(cg_mount_table[i].name, type) == 0) {
strcpy(path, cg_mount_table[i].path);
strcat(path, "/");
- strcat(path, name);
- strcat(path, "/");
+ if (name) {
+ strcat(path, name);
+ strcat(path, "/");
+ }
return path;
}
}
@@ -236,11 +255,14 @@ int cgroup_attach_task_pid(struct cgroup *cgroup, pid_t tid)
FILE *tasks;
int i;
+ if (!cgroup_initialized)
+ return ECGROUPNOTINITALIZED;
+
if(!cgroup)
{
for(i = 0; i < CG_CONTROLLER_MAX &&
cg_mount_table[i].name[0]!='\0'; i++) {
- if (!cg_build_path(cgroup->name, path, NULL))
+ if (!cg_build_path(NULL, path, cg_mount_table[i].name))
continue;
strcat(path, "/tasks");
@@ -257,7 +279,12 @@ int cgroup_attach_task_pid(struct cgroup *cgroup, pid_t tid)
fclose(tasks);
}
} else {
- for( i = 0; i <= CG_CONTROLLER_MAX &&
+ for (i = 0; i <= CG_CONTROLLER_MAX &&
+ cgroup->controller[i] != NULL; i++) {
+ if (!cgroup_test_subsys_mounted(cgroup->controller[i]->name))
+ return ECGROUPSUBSYSNOTMOUNTED;
+ }
+ for (i = 0; i <= CG_CONTROLLER_MAX &&
cgroup->controller[i] != NULL ; i++) {
if (!cg_build_path(cgroup->name, path,
cgroup->controller[i]->name))
@@ -382,6 +409,15 @@ int cgroup_modify_cgroup(struct cgroup *cgroup)
int i;
int error;
+ if (!cgroup_initialized)
+ return ECGROUPNOTINITALIZED;
+
+ for (i = 0; i <= CG_CONTROLLER_MAX && cgroup->controller[i] != NULL;
+ i++) {
+ if (!cgroup_test_subsys_mounted(cgroup->controller[i]->name))
+ return ECGROUPSUBSYSNOTMOUNTED;
+ }
+
for (i = 0; i < CG_CONTROLLER_MAX && cgroup->controller[i];
i++, strcpy(path, base)) {
int j;
@@ -413,9 +449,18 @@ err:
int cgroup_create_cgroup(struct cgroup *cgroup, int ignore_ownership)
{
char *fts_path[2], base[FILENAME_MAX], *path;
- int j, k;
+ int i, j, k;
int error = 0;
+ if (!cgroup_initialized)
+ return ECGROUPNOTINITALIZED;
+
+ for (i = 0; i <= CG_CONTROLLER_MAX && cgroup->controller[i] != NULL;
+ i++) {
+ if (!cgroup_test_subsys_mounted(cgroup->controller[i]->name))
+ return ECGROUPSUBSYSNOTMOUNTED;
+ }
+
fts_path[0] = (char *)malloc(FILENAME_MAX);
if (!fts_path[0])
return ENOMEM;
@@ -490,6 +535,15 @@ int cgroup_delete_cgroup(struct cgroup *cgroup, int ignore_migration)
int error = ECGROUPNOTALLOWED;
int i, ret;
+ if (!cgroup_initialized)
+ return ECGROUPNOTINITALIZED;
+
+ for (i = 0; i <= CG_CONTROLLER_MAX && cgroup->controller[i] != NULL;
+ i++) {
+ if (!cgroup_test_subsys_mounted(cgroup->controller[i]->name))
+ return ECGROUPSUBSYSNOTMOUNTED;
+ }
+
for (i = 0; i < CG_CONTROLLER_MAX && cgroup->controller; i++) {
if (!cg_build_path(cgroup->name, path,
cgroup->controller[i]->name))
diff --git a/configure b/configure
index 4504a65..9daa7a1 100755
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.61 for control groups library and utilities 0.1b.
+# Generated by GNU Autoconf 2.61 for control groups library and utilities 0.1c.
#
# Report bugs to <http://sourceforge.net/tracker/?group_id=218421&atid=1043649>.
#
@@ -574,8 +574,8 @@ SHELL=${CONFIG_SHELL-/bin/sh}
# Identity of this package.
PACKAGE_NAME='control groups library and utilities'
PACKAGE_TARNAME='control-groups-library-and-utilities'
-PACKAGE_VERSION='0.1b'
-PACKAGE_STRING='control groups library and utilities 0.1b'
+PACKAGE_VERSION='0.1c'
+PACKAGE_STRING='control groups library and utilities 0.1c'
PACKAGE_BUGREPORT='http://sourceforge.net/tracker/?group_id=218421&atid=1043649'
ac_unique_file="wrapper.c"
@@ -1189,7 +1189,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
-\`configure' configures control groups library and utilities 0.1b to adapt to many kinds of systems.
+\`configure' configures control groups library and utilities 0.1c to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@@ -1250,7 +1250,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
- short | recursive ) echo "Configuration of control groups library and utilities 0.1b:";;
+ short | recursive ) echo "Configuration of control groups library and utilities 0.1c:";;
esac
cat <<\_ACEOF
@@ -1335,7 +1335,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
-control groups library and utilities configure 0.1b
+control groups library and utilities configure 0.1c
generated by GNU Autoconf 2.61
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
@@ -1349,7 +1349,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
-It was created by control groups library and utilities $as_me 0.1b, which was
+It was created by control groups library and utilities $as_me 0.1c, which was
generated by GNU Autoconf 2.61. Invocation command line was
$ $0 $@
@@ -6383,7 +6383,7 @@ exec 6>&1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
-This file was extended by control groups library and utilities $as_me 0.1b, which was
+This file was extended by control groups library and utilities $as_me 0.1c, which was
generated by GNU Autoconf 2.61. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@@ -6432,7 +6432,7 @@ Report bugs to <bug-autoconf@gnu.org>."
_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF
ac_cs_version="\\
-control groups library and utilities config.status 0.1b
+control groups library and utilities config.status 0.1c
configured by $0, generated by GNU Autoconf 2.61,
with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
@@ -7052,40 +7052,6 @@ echo "$as_me: $ac_file is unchanged" >&6;}
cat "$ac_result"
fi
rm -f "$tmp/out12"
-# Compute $ac_file's index in $config_headers.
-_am_arg=$ac_file
-_am_stamp_count=1
-for _am_header in $config_headers :; do
- case $_am_header in
- $_am_arg | $_am_arg:* )
- break ;;
- * )
- _am_stamp_count=`expr $_am_stamp_count + 1` ;;
- esac
-done
-echo "timestamp for $_am_arg" >`$as_dirname -- "$_am_arg" ||
-$as_expr X"$_am_arg" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
- X"$_am_arg" : 'X\(//\)[^/]' \| \
- X"$_am_arg" : 'X\(//\)$' \| \
- X"$_am_arg" : 'X\(/\)' \| . 2>/dev/null ||
-echo X"$_am_arg" |
- sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
- s//\1/
- q
- }
- /^X\(\/\/\)[^/].*/{
- s//\1/
- q
- }
- /^X\(\/\/\)$/{
- s//\1/
- q
- }
- /^X\(\/\).*/{
- s//\1/
- q
- }
- s/.*/./; q'`/stamp-h$_am_stamp_count
;;
diff --git a/configure.in b/configure.in
index 4924da0..6943029 100644
--- a/configure.in
+++ b/configure.in
@@ -13,7 +13,7 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
AC_PREREQ(2.61)
-AC_INIT([control groups library and utilities], 0.1b,
+AC_INIT([control groups library and utilities], 0.1c,
[http://sourceforge.net/tracker/?group_id=218421&atid=1043649])
AC_CONFIG_SRCDIR([wrapper.c])
AC_CONFIG_HEADER([config.h])
diff --git a/libcgroup.h b/libcgroup.h
index ccd82ef..27c35e5 100644
--- a/libcgroup.h
+++ b/libcgroup.h
@@ -116,6 +116,7 @@ enum cgroup_errors {
ECGINVAL,
ECGCONTROLLERCREATEFAILED,
ECGFAIL,
+ ECGROUPNOTINITALIZED,
};
#define CG_MAX_MSG_SIZE 256
diff --git a/libcgroup.spec.in b/libcgroup.spec.in
index 8e1d43a..93ad868 100644
--- a/libcgroup.spec.in
+++ b/libcgroup.spec.in
@@ -2,7 +2,7 @@ Name: libcgroup
Summary: Tools and libraries to control and monitor control groups
Group: Development/Libraries
Version: @PACKAGE_VERSION@
-Release: 3%{?dist}
+Release: 1%{?dist}
License: LGPLv2+
URL: http://libcg.sourceforge.net/
Source0: http://downloads.sourceforge.net/libcg/%{name}-%{version}.tar.bz2
@@ -58,6 +58,8 @@ rm -rf $RPM_BUILD_ROOT
%changelog
+* Wed Jun 11 2008 Dhaval Giani <dhaval@linux.vnet.ibm.com> 0.1c-1
+- Update to latest upstream version
* Tue Jun 3 2008 Balbir Singh <balbir@linux.vnet.ibm.com> 0.1b-3
- Add post and postun. Also fix Requires for devel to depend on base n-v-r
* Sat May 31 2008 Balbir Singh <balbir@linux.vnet.ibm.com> 0.1b-2