]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
Merge several bug-fixes and cleanups. No version bump yet, since this is
authorBalbir Singh <balbir@linux.vnet.ibm.com>
Wed, 15 Oct 2008 04:20:29 +0000 (04:20 +0000)
committerBalbir Singh <balbir@linux.vnet.ibm.com>
Wed, 15 Oct 2008 04:20:29 +0000 (04:20 +0000)
an ongoing exercise (after more testing, I'll recommend one).

Signed-off-by: Balbir Singh <balbir@linux.vnet.ibm.com>
git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@216 4f4bb910-9a46-0410-90c8-c897d4f1cd53

Makefile
Makefile.in
api.c
cgconfig.c
config.c
libcgroup.spec.in
samples/wlm.conf.3
scripts/init.d/cgconfig
scripts/init.d/cgred

index fcc59273fc38b22580746da50f05a42ced338001..3a20fa9ed93ddafacd7bc8975e76d38f11432b92 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -21,7 +21,7 @@ bindir=${exec_prefix}/bin
 sbindir=${exec_prefix}/sbin
 libdir=${exec_prefix}/lib
 includedir=${prefix}/include
-prefix=/usr/local
+prefix=/usr
 exec_prefix=${prefix}
 INSTALL=install
 INSTALL_DATA=install -m 644
@@ -29,7 +29,9 @@ PACKAGE_VERSION=0.32
 CFLAGS=-g -O2 $(INC) -DPACKAGE_VERSION=$(PACKAGE_VERSION)
 VERSION=1
 
-all: libcgroup.so cgconfigparser cgexec cgclassify cgrulesengd
+TARGETS = libcgroup.so cgconfigparser cgexec cgclassify cgrulesengd
+
+all: $(TARGETS)
 
 cgconfigparser: libcgroup.so cgconfig.c libcgroup.h
        $(CC) $(CFLAGS) $(INC) -Wall -o $@ cgconfig.c $(LDFLAGS) $(LIBS)
@@ -63,12 +65,12 @@ pam_cgroup.so: pam_cgroup.c
        $(CC) $(CFLAGS) -shared -fPIC -Wall -o $@ pam_cgroup.c $(LDFLAGS) \
        $(LIBS) -lpam
 
-install: libcgroup.so cgexec cgclassify cgconfigparser
+install: $(TARGETS)
        $(INSTALL_DATA) -D libcgroup.h $(DESTDIR)$(includedir)/libcgroup.h
        $(INSTALL) -D libcgroup.so $(DESTDIR)$(libdir)/libcgroup-$(PACKAGE_VERSION).so
        ln -sf libcgroup-$(PACKAGE_VERSION).so $(DESTDIR)$(libdir)/libcgroup.so.$(VERSION)
        ln -sf libcgroup.so.$(VERSION) $(DESTDIR)$(libdir)/libcgroup.so
-       $(INSTALL) -D cgconfigparser $(DESTDIR)$(sbindir)
+       $(INSTALL) -D cgconfigparser $(DESTDIR)$(sbindir)/cgconfigparser
        $(INSTALL) -D cgexec $(DESTDIR)$(bindir)/cgexec
        $(INSTALL) -D cgclassify $(DESTDIR)$(bindir)/cgclassify
        $(INSTALL) -D cgrulesengd $(DESTDIR)$(bindir)/cgrulesengd
@@ -85,5 +87,4 @@ uninstall: libcgroup.so
 
 clean:
        \rm -f y.tab.c y.tab.h lex.yy.c y.output libcgroup.so cgclassify \
-       libcgroup.so.$(VERSION) cgconfigparser config.log config.status cgexec \
-       pam_cgroup.so cgrulesengd
+       libcgroup.so.$(VERSION) $(TARGETS)
index f98552a0070a5aaf5fd6f2db9a7255ebd529d473..feb750ee0e763407d2f6f8126ae7e65cec2ffdaa 100644 (file)
@@ -29,7 +29,9 @@ PACKAGE_VERSION=@PACKAGE_VERSION@
 CFLAGS=@CFLAGS@ $(INC) -DPACKAGE_VERSION=$(PACKAGE_VERSION)
 VERSION=1
 
-all: libcgroup.so cgconfigparser cgexec cgclassify cgrulesengd
+TARGETS = libcgroup.so cgconfigparser cgexec cgclassify cgrulesengd
+
+all: $(TARGETS)
 
 cgconfigparser: libcgroup.so cgconfig.c libcgroup.h
        $(CC) $(CFLAGS) $(INC) -Wall -o $@ cgconfig.c $(LDFLAGS) $(LIBS)
@@ -63,7 +65,7 @@ pam_cgroup.so: pam_cgroup.c
        $(CC) $(CFLAGS) -shared -fPIC -Wall -o $@ pam_cgroup.c $(LDFLAGS) \
        $(LIBS) -lpam
 
-install: libcgroup.so cgexec cgclassify cgconfigparser
+install: $(TARGETS)
        $(INSTALL_DATA) -D libcgroup.h $(DESTDIR)$(includedir)/libcgroup.h
        $(INSTALL) -D libcgroup.so $(DESTDIR)$(libdir)/libcgroup-$(PACKAGE_VERSION).so
        ln -sf libcgroup-$(PACKAGE_VERSION).so $(DESTDIR)$(libdir)/libcgroup.so.$(VERSION)
@@ -85,5 +87,4 @@ uninstall: libcgroup.so
 
 clean:
        \rm -f y.tab.c y.tab.h lex.yy.c y.output libcgroup.so cgclassify \
-       libcgroup.so.$(VERSION) cgconfigparser config.log config.status cgexec \
-       pam_cgroup.so cgrulesengd
+       libcgroup.so.$(VERSION) $(TARGETS)
diff --git a/api.c b/api.c
index c11d83d684c58a83337f5eb87a2e3c26adfd15cc..4efb3909508d030aed4ad50799f7174784820bf8 100644 (file)
--- a/api.c
+++ b/api.c
@@ -536,7 +536,7 @@ int cgroup_init()
                                &hierarchy, &num_cgroups, &enabled);
                if (err < 0)
                        break;
-               controllers[i] = (char *)malloc(strlen(subsys_name));
+               controllers[i] = (char *)malloc(strlen(subsys_name) + 1);
                strcpy(controllers[i], subsys_name);
                i++;
        }
@@ -584,6 +584,8 @@ int cgroup_init()
                }
        }
 
+       free(temp_ent);
+
        if (!found_mnt) {
                cg_mount_table[0].name[0] = '\0';
                ret = ECGROUPNOTMOUNTED;
@@ -606,6 +608,7 @@ static int cg_test_mounted_fs()
        FILE *proc_mount;
        struct mntent *ent, *temp_ent;
        char mntent_buff[4 * FILENAME_MAX];
+       int ret = 1;
 
        proc_mount = fopen("/proc/mounts", "r");
        if (proc_mount == NULL) {
@@ -627,11 +630,15 @@ static int cg_test_mounted_fs()
        while (strcmp(ent->mnt_type, "cgroup") !=0) {
                ent = getmntent_r(proc_mount, temp_ent, mntent_buff,
                                                sizeof(mntent_buff));
-               if (ent == NULL)
-                       return 0;
+               if (ent == NULL) {
+                       ret = 0;
+                       goto done;
+               }
        }
+done:
        fclose(proc_mount);
-       return 1;
+       free(temp_ent);
+       return ret;
 }
 
 static inline pid_t cg_gettid()
@@ -1058,6 +1065,7 @@ int cgroup_create_cgroup(struct cgroup *cgroup, int ignore_ownership)
        char *fts_path[2], base[FILENAME_MAX], *path;
        int i, j, k;
        int error = 0;
+       int retval = 0;
 
        if (!cgroup_initialized)
                return ECGROUPNOTINITIALIZED;
@@ -1108,12 +1116,17 @@ int cgroup_create_cgroup(struct cgroup *cgroup, int ignore_ownership)
                                cgroup->controller[k]->values[j]->value);
                        /*
                         * Should we undo, what we've done in the loops above?
-                        * An error should not be treated as fatal, since we have
-                        * several read-only files and several files that
+                        * An error should not be treated as fatal, since we
+                        * have several read-only files and several files that
                         * are only conditionally created in the child.
+                        *
+                        * A middle ground would be to track that there
+                        * was an error and return that value.
                         */
-                       if (error)
+                       if (error) {
+                               retval = error;
                                continue;
+                       }
                }
 
                if (!ignore_ownership) {
@@ -1130,6 +1143,8 @@ int cgroup_create_cgroup(struct cgroup *cgroup, int ignore_ownership)
 
 err:
        free(path);
+       if (retval && !error)
+               error = retval;
        return error;
 }
 
@@ -1266,38 +1281,38 @@ int cgroup_delete_cgroup(struct cgroup *cgroup, int ignore_migration)
 
                base_tasks = fopen(path, "w");
                if (!base_tasks)
-                       goto base_open_err;
+                       goto open_err;
 
                if (!cg_build_path(cgroup->name, path,
-                                       cgroup->controller[i]->name))
+                                       cgroup->controller[i]->name)) {
+                       fclose(base_tasks);
                        continue;
+               }
 
                strcat(path, "tasks");
 
                delete_tasks = fopen(path, "r");
-               if (!delete_tasks)
-                       goto del_open_err;
+               if (!delete_tasks) {
+                       fclose(base_tasks);
+                       goto open_err;
+               }
 
                while (!feof(delete_tasks)) {
                        ret = fscanf(delete_tasks, "%d", &tids);
-                       /*
-                        * Don't know how to handle EOF yet, so
-                        * ignore it
-                        */
+                       if (ret == EOF || ret < 1)
+                               break;
                        fprintf(base_tasks, "%d", tids);
                }
 
+               fclose(delete_tasks);
+               fclose(base_tasks);
+
                if (!cg_build_path(cgroup->name, path,
                                        cgroup->controller[i]->name))
                        continue;
                error = rmdir(path);
-
-               fclose(delete_tasks);
        }
-del_open_err:
-       if (base_tasks)
-               fclose(base_tasks);
-base_open_err:
+open_err:
        if (ignore_migration) {
                for (i = 0; i < cgroup->index; i++) {
                        if (!cg_build_path(cgroup->name, path,
index b98769f0ca538354dccdc39eeb727462ba4f4cf7..6b59001f2c95f8f5548eecd7c688554c30ad4bf0 100644 (file)
@@ -22,6 +22,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <errno.h>
 
 int main(int argc, char *argv[])
 {
@@ -42,7 +43,9 @@ int main(int argc, char *argv[])
                        ret = cgroup_config_load_config(filename);
                        if (ret) {
                                printf("Loading configuration file %s "
-                                       "failed, ret = %d\n", filename, ret);
+                                       "failed, error: %s\n", filename,
+                                       strerror(errno));
+                               printf("return code = %d\n", ret);
                                exit(3);
                        }
                        break;
index baaf7d80b7a8f8846df2cb66ef2452abf07dc914..6897442514680ca353dcdd0cfb48e231b109d730 100644 (file)
--- a/config.c
+++ b/config.c
@@ -203,6 +203,8 @@ int cgroup_config_group_task_perm(char *perm_type, char *value)
                config_cgroup->tasks_gid = val;
        }
 
+       free(perm_type);
+       free(value);
        return 1;
 
 group_task_error:
@@ -267,6 +269,8 @@ int cgroup_config_group_admin_perm(char *perm_type, char *value)
                config_cgroup->control_gid = val;
        }
 
+       free(perm_type);
+       free(value);
        return 1;
 
 admin_error:
index 93ad86815ff81c6e3803c895d1432c7a5779386f..177c7c0893caa9ea12f46ed02d261c3b313e3e9f 100644 (file)
@@ -10,6 +10,7 @@ BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 BuildRequires: byacc
 BuildRequires: flex
 BuildRequires: coreutils
+Requires(post): chkconfig, /sbin/service
 
 %description
 Control groups infrastructure. The tools and library help manipulate, control,
@@ -36,11 +37,27 @@ make %{?_smp_mflags}
 %install
 rm -rf $RPM_BUILD_ROOT
 make DESTDIR=$RPM_BUILD_ROOT install
+mkdir -p $RPM_BUILD_ROOT/%{_initrddir}
+cp scripts/init.d/cgconfig $RPM_BUILD_ROOT/%{_initrddir}/cgconfig
+cp scripts/init.d/cgred $RPM_BUILD_ROOT/%{_initrddir}/cgred
+
 
 %clean
 rm -rf $RPM_BUILD_ROOT
 
-%post -p /sbin/ldconfig
+%post 
+/sbin/ldconfig
+#
+# Do this later if required
+#
+#/sbin/chkconfig --add cgred
+#/sbin/chkconfig --add cgconfig
+
+%preun
+/sbin/service cgred stop > /dev/null 2>&1 || :
+/sbin/service cgconfig stop > /dev/null 2>&1 || :
+/sbin/chkconfig --del cgconfig
+/sbin/chkconfig --del cgred
 
 %postun -p /sbin/ldconfig
 
@@ -48,16 +65,29 @@ rm -rf $RPM_BUILD_ROOT
 %defattr(-,root,root,-)
 %{_libdir}/libcgroup-%{version}.so
 %{_libdir}/libcgroup.so.*
-%doc COPYING INSTALL
+%{_bindir}/cgexec
+%{_bindir}/cgclassify
+%{_sbindir}/cgconfigparser
+%{_bindir}/cgrulesengd
+%attr(0755,root,root) %{_initrddir}/cgconfig
+%attr(0755,root,root) %{_initrddir}/cgred
+
+%doc COPYING INSTALL README_daemon
 
 %files devel
 %defattr(-,root,root,-)
 %{_includedir}/libcgroup.h
 %{_libdir}/libcgroup.so
-%doc COPYING INSTALL
+%doc COPYING INSTALL 
 
 
 %changelog
+* Fri Oct 10 2008 Dhaval Giani <dhaval@linux.vnet.ibm.com> 0.32-1
+- Update to latest upstream
+* Thu Sep 11 2008 Dhaval Giani <dhaval@linux-vnet.ibm.com> 0.31-1
+- Update to latest upstream
+* Sat Aug 2 2008 Dhaval Giani <dhaval@linux.vnet.ibm.com> 0.1c-3
+- Change release to fix broken upgrade path
 * 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
index a0e9a1bb3b8101111ebd40fb946dce72f7af0022..8700854d5034b17703161c9c6bad014ca5836670 100644 (file)
@@ -17,11 +17,11 @@ group ca1 {
        perm {
                task {
                        uid = root;
-                       gid = kvm;
+                       gid = root;
                }
                admin {
-                       uid = root;
-                       gid = root;
+                       uid = balbir;
+                       gid = balbir;
                }
        }
 
index 1a8ca42907e6783773487eae11dc866bec91e597..4e04fb98fc669a5537308d002a9aed4bec0ba09b 100644 (file)
@@ -1,3 +1,4 @@
+#!/bin/bash
 #
 # Start/Stop the workload manager
 #
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 #
+# cgconfig Control Groups Configuration Startup
+# chkconfig: 2345 80 20
+# description: This script runs the cgconfigparser utility to parse and setup
+#              the control group filesystem. It uses /etc/cgconfig.conf
+#              and parses the configuration specified in there.
 
-#### BEGIN INIT INFO
+### BEGIN INIT INFO
 # Provides:             cgconfig
 # Required-Start:       $local_fs $syslog $time
 # Required-Stop:        $local_fs $syslog
@@ -23,7 +29,7 @@
 # Default-Stop:         0 1 6
 # Short-Description:    start and stop the WLM configuration
 # Description:          This script allows us to create a default configuration
-#### END INIT INFO
+### END INIT INFO
 
 PATH=/bin:/usr/bin:/sbin:/usr/sbin:.
 MOUNTS_FILE=/proc/mounts
@@ -35,6 +41,7 @@ CONFIG_FILE=/etc/cgconfig.conf
 declare -a MOUNTPOINT
 declare -a MOUNTOPTS
 maxindex=0
+servicename=cgconfig
 
 #
 # Source LSB routines
@@ -64,7 +71,7 @@ umount_fs() {
 }
 
 start() {
-       if [ -f /var/lock/cgconfig ]
+       if [ -f /var/lock/subsys/$servicename ]
         then
             log_warning_msg "lock file already exists"
             return
@@ -72,10 +79,10 @@ start() {
 
         if [ $? -eq 0 ]
         then
-                log_progress_msg "Starting cgconfig service: "
+                #log_progress_msg "Starting cgconfig service: "
                 cgconfigparser -l $CONFIG_FILE
         fi
-        [ $? == 0 ] && touch /var/lock/cgconfig
+        [ $? == 0 ] && touch /var/lock/subsys/$servicename
         return $?
 }
 
@@ -97,7 +104,7 @@ move_all_to_init_class() {
                 ;;
             *)
                 class=${i#./*}
-                log_progress_msg "Removing class $class"
+                #log_progress_msg "Removing class $class"
                 sed -nu p < ./$i/tasks > tasks
                 rmdir $i
                 ;;
@@ -111,7 +118,7 @@ move_all_to_init_class() {
 stop() {
     move_all_to_init_class
     umount_fs
-    rm -f /var/lock/cgconfig
+    rm -f /var/lock/subsys/$servicename
 }
 
 trapped() {
@@ -122,7 +129,7 @@ trapped() {
 }
 
 usage() {
-    echo "$0 <start|stop>"
+    echo "$0 <start|stop|restart|condrestart|status>"
     exit 1
 }
 
@@ -157,6 +164,19 @@ case $1 in
        stop
         start
         ;;
+    'condrestart')
+        if [ -f /var/lock/subsys/$servicename ] ; then
+            stop
+            start
+        fi
+        ;;
+    'status')
+        if [ -f /var/lock/subsys/$servicename ] ; then
+            echo "Running"
+        else
+            echo "Stopped"
+        fi
+       ;;
     *)
         usage
         ;;
index b99e769268005a79e1c2cff1003872fe14ce1864..3d9fe2aa80fe1869aecdc34d767ff59548241c5f 100644 (file)
@@ -23,7 +23,7 @@
 #
 ### BEGIN INIT INFO
 # Provides:            cgrulesengd
-# Required-Start:      $local_fs $syslog $wlm
+# Required-Start:      $local_fs $syslog $cgconfig
 # Required-Stop:       $local_fs $syslog
 # Should-Start:                
 # Should-Stop: