Sisyphus repository
Last update: 1 october 2023 | SRPMs: 18631 | Visits: 37569942
en ru br
ALT Linux repos
S:2.0.3-alt1

Group :: System/Libraries
RPM: libcgroup

 Main   Changelog   Spec   Patches   Sources   Download   Gear   Bugs and FR  Repocop 

Patch: libcgroup-2.0.3-alt1.patch
Download


 .gear/rules                                        |   3 +
 .../tags/49a9a197b5d129e0570321c75a9b3ddf579d5a1d  |  23 +++
 .gear/tags/list                                    |   2 +
 .gear/upstream/remotes                             |   3 +
 cgred.service                                      |  11 ++
 dist/cgconfig.service                              |   5 +-
 libcgroup.spec                                     | 195 +++++++++++++++++++++
 samples/cgconfig.conf                              |  46 ++---
 samples/cgconfig.sysconfig                         |   8 +-
 scripts/init.d/cgconfig.in                         | 183 +++++++++----------
 scripts/init.d/cgred.in                            | 153 +++++++---------
 src/Makefile.am                                    |   1 +
 src/tools/Makefile.am                              |   2 +-
 13 files changed, 405 insertions(+), 230 deletions(-)
diff --git a/.gear/rules b/.gear/rules
new file mode 100644
index 0000000..7cfbf87
--- /dev/null
+++ b/.gear/rules
@@ -0,0 +1,3 @@
+tar: v@version@:.
+diff: v@version@:. .
+tar: upstream-tests:. name=tests base=
\ No newline at end of file
diff --git a/.gear/tags/49a9a197b5d129e0570321c75a9b3ddf579d5a1d b/.gear/tags/49a9a197b5d129e0570321c75a9b3ddf579d5a1d
new file mode 100644
index 0000000..224a03d
--- /dev/null
+++ b/.gear/tags/49a9a197b5d129e0570321c75a9b3ddf579d5a1d
@@ -0,0 +1,23 @@
+object 0f1c55b5f2fc8a914ebb044f528f61847226159c
+type commit
+tag v2.0.3
+tagger Tom Hromatka <tom.hromatka@oracle.com> 1674238400 -0700
+
+version 2.0.3
+-----BEGIN PGP SIGNATURE-----
+
+iQJMBAABCAA2FiEER6aPzjfH1wJP1l4RNWzmLCtSQJkFAmPK2cAYHHRvbS5ocm9t
+YXRrYUBvcmFjbGUuY29tAAoJEDVs5iwrUkCZF44P/jd1PURa9P6JwBEdYy2DdZ0U
+h4BO+Xr3T8SRZ2NC3byUsxvKYJM+nBNj6ac/CL4MFw2ZUtYKZpyR2wgGBZIYe6iZ
+rFCIfLlZ/n0ErAS/QpNXpZu8opHiefbeE8qe35xhemABdHwJGYr+X8kt0dHKov7X
+jj/0Z78CM+iBcx+rMyczmsRX1mqGsSbZ+vpxbizmg8pDHZSf7JVt46LhXb1Siktl
+eMhUPYbmZVn3Oso67TjH+BoqDTMqP6NeZ36crsYNiSDoR3AhrN3pUCiKvVFYwQBD
+ej5dRFCOWBpv/YIXGjHWjajBSZrx7ls0/PZHELVpYzuDYjIM6EVFeNZrmXh0rhB+
+0HDqG+gDVbuEnSxsgWEHTZf0A/9RIReXrlRk4tIzdEHNtou37pTaT+x8xayR/7f/
+RGhu7rPxGShujXmaADAQuMPLOq3OJ6a+r1Y79Fl+k86lEVHODrsVYRr8R4pVVuMN
+D1tL5qFukT/1SV4CEaoypgmWo42S6XXtHb4K9t34/XMPatp7iGH9cVAZ9CEN7Q3e
+i23+b4ucV2BE6CVXZGeAShQgYtIt75R9lRvqp958SqDIWx3ySyefujAQaTdgYDdD
+0P5AfUAzQN1+XXIC0Td9ldXwDkbjFDL7UyZt05x7+EbB7J59tdZrxywxFfih7nKx
+byD9XJKE2p9uoZGQlYcx
+=mlji
+-----END PGP SIGNATURE-----
diff --git a/.gear/tags/list b/.gear/tags/list
new file mode 100644
index 0000000..cd53969
--- /dev/null
+++ b/.gear/tags/list
@@ -0,0 +1,2 @@
+127bc7ea59fd9f7d11dc9058d5ec6a4b8011927c upstream-tests
+49a9a197b5d129e0570321c75a9b3ddf579d5a1d v2.0.3
diff --git a/.gear/upstream/remotes b/.gear/upstream/remotes
new file mode 100644
index 0000000..802dcf7
--- /dev/null
+++ b/.gear/upstream/remotes
@@ -0,0 +1,3 @@
+[remote "upstream"]
+	url = https://github.com/libcgroup/libcgroup.git
+	fetch = +refs/heads/*:refs/remotes/upstream/*
diff --git a/cgred.service b/cgred.service
new file mode 100644
index 0000000..c1ecb51
--- /dev/null
+++ b/cgred.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=CGroups Rules Engine Daemon
+After=syslog.target
+
+[Service]
+Type=forking
+EnvironmentFile=-/etc/sysconfig/cgred
+ExecStart=/usr/sbin/cgrulesengd -s -g $SOCKET_GROUP
+
+[Install]
+WantedBy=multi-user.target
diff --git a/dist/cgconfig.service b/dist/cgconfig.service
index e63f26d..cc6a19f 100644
--- a/dist/cgconfig.service
+++ b/dist/cgconfig.service
@@ -10,8 +10,9 @@ Before=basic.target shutdown.target
 [Service]
 Type=oneshot
 RemainAfterExit=yes
-ExecStart=/sbin/cgconfigparser -l /etc/cgconfig.conf -s 1664
-ExecStop=/sbin/cgclear -l /etc/cgconfig.conf -e
+Delegate=yes
+ExecStart=/usr/sbin/cgconfigparser -l /etc/cgconfig.conf -L /etc/cgconfig.d -s 1664
+ExecStop=/usr/sbin/cgclear -l /etc/cgconfig.conf -L /etc/cgconfig.d -e
 
 [Install]
 WantedBy=sysinit.target
diff --git a/libcgroup.spec b/libcgroup.spec
new file mode 100644
index 0000000..3c6cdf4
--- /dev/null
+++ b/libcgroup.spec
@@ -0,0 +1,195 @@
+
+Name: libcgroup
+Summary: Libraries for allow to control and monitor control groups
+Group: System/Libraries
+Version: 2.0.3
+Release: alt1
+License: LGPLv2+
+Url: http://libcg.sourceforge.net/
+# VCS: https://github.com/libcgroup/libcgroup.git
+Source: %name-%version.tar
+Source2: tests.tar
+Patch: %name-%version-%release.patch
+
+BuildRequires: flex gcc-c++ libpam-devel
+
+%description
+Control groups infrastructure.
+
+This library allows applications to manipulate, control, administrate and
+monitor control groups and the associated controllers.
+
+%package -n pam_cgroup
+Summary: A Pluggable Authentication Module for libcgroup
+Group: System/Base
+Requires: libcgroup = %version-%release
+
+%description -n pam_cgroup
+Linux-PAM module, which allows administrators to classify the user's login
+processes to pre-configured control group.
+
+%package -n cgroup
+Summary: Tools to control and monitor control groups
+Group: System/Configuration/Other
+Requires: libcgroup = %version-%release
+
+%description -n cgroup
+Control groups infrastructure.
+
+These tools help manipulate, control, administrate and monitor control groups
+and the associated controllers.
+
+%package devel
+Summary: Development libraries to develop applications that utilize control groups
+Group: Development/C
+Requires: libcgroup = %version-%release
+
+%description devel
+It provides API to create/delete and modify cgroup nodes. It will also in the
+future allow creation of persistent configuration for control groups and
+provide scripts to manage that configuration.
+
+%prep
+%setup
+%patch -p1
+tar -xf %SOURCE2 -C tests
+
+%build
+%autoreconf
+%configure \
+	--disable-static \
+	--enable-initscript-install \
+	--enable-pam-module-dir=/%_lib/security \
+	--enable-opaque-hierarchy=name=systemd
+
+%make_build
+
+%install
+%make DESTDIR=%buildroot install
+
+# install config files
+mkdir -p %buildroot%_sysconfdir/sysconfig
+cp samples/cgred.conf %buildroot%_sysconfdir/sysconfig/cgred
+cp samples/cgconfig.sysconfig %buildroot%_sysconfdir/sysconfig/cgconfig
+cp samples/cgconfig.conf %buildroot%_sysconfdir/cgconfig.conf
+cp samples/cgrules.conf %buildroot%_sysconfdir/cgrules.conf
+cp samples/cgsnapshot_blacklist.conf %buildroot%_sysconfdir/cgsnapshot_blacklist.conf
+
+rm -f %buildroot/%_lib/security/pam_cgroup.la
+rm -f %buildroot%_libdir/*.la
+rm -f %buildroot%_libdir/libcgroupfortesting.*
+
+mkdir -p %buildroot%_sysconfdir/cgconfig.d
+# install unit and sysconfig files
+install -d %buildroot%_unitdir
+install -m 644 dist/cgconfig.service %buildroot%_unitdir/
+install -m 644 cgred.service %buildroot%_unitdir/
+
+%pre -n cgroup
+%_sbindir/groupadd -r -f cgred 2> /dev/null ||:
+
+%post -n cgroup
+%post_service cgred
+%post_service cgconfig
+
+%preun -n cgroup
+%preun_service cgred
+%preun_service cgconfig
+
+%files
+%_libdir/*.so.*
+
+%files -n cgroup
+%doc COPYING INSTALL README README_daemon README_systemd
+%config(noreplace) %_sysconfdir/sysconfig/cgred
+%config(noreplace) %_sysconfdir/sysconfig/cgconfig
+%config(noreplace) %_sysconfdir/cgconfig.conf
+%config(noreplace) %_sysconfdir/cgrules.conf
+%config(noreplace) %_sysconfdir/cgsnapshot_blacklist.conf
+%dir %_sysconfdir/cgconfig.d
+%attr(2711, root, cgred) %_bindir/cgexec
+%attr(2711, root, cgred) %_bindir/cgclassify
+%_bindir/*
+%_sbindir/*
+%_man1dir/*
+%_man5dir/*
+%_man8dir/*
+%config %_initdir/cgconfig
+%config %_initdir/cgred
+%_unitdir/cgconfig.service
+%_unitdir/cgred.service
+
+%files -n pam_cgroup
+%_pam_modules_dir/pam_cgroup.so
+
+%files devel
+%doc COPYING INSTALL
+%_includedir/libcgroup.h
+%_includedir/libcgroup
+%_libdir/*.so
+%_pkgconfigdir/libcgroup.pc
+
+%changelog
+* Sun Jan 22 2023 Alexey Shabalin <shaba@altlinux.org> 2.0.3-alt1
+- 2.0.3
+- Add cgconfig.d support to systemd unit (ALT #44890)
+
+* Fri Jun 03 2022 Alexey Shabalin <shaba@altlinux.org> 2.0.2-alt1
+- new version 2.0.2
+
+* Sat May 29 2021 Alexey Shabalin <shaba@altlinux.org> 2.0-alt1
+- new version 2.0
+
+* Tue Feb 25 2020 Alexey Shabalin <shaba@altlinux.org> 0.42.2-alt2
+- fixed start service (package %%_sysconfdir/cgconfig.d dir)
+
+* Thu Feb 20 2020 Alexey Shabalin <shaba@altlinux.org> 0.42.2-alt1
+- 0.42.2
+
+* Wed Aug 28 2019 Alexey Shabalin <shaba@altlinux.org> 0.41-alt3
+- backport several upstream fixes (Fixes: CVE-2018-14348)
+- set Delegate property for cgconfig service to make sure complete
+  cgroup hierarchy is always created by systemd
+
+* Sat Feb 10 2018 Mikhail Efremov <sem@altlinux.org> 0.41-alt2
+- Fix parallel build.
+
+* Fri Mar 21 2014 Alexey Shabalin <shaba@altlinux.ru> 0.41-alt1
+- 0.41
+
+* Mon Mar 12 2012 Alexey Shabalin <shaba@altlinux.ru> 0.38.0-alt1
+- 0.38 release
+
+* Mon Mar 12 2012 Alexey Shabalin <shaba@altlinux.ru> 0.38.0-alt0.rc1
+- 0.38.rc1
+- add systemd unit files
+
+* Thu Aug 18 2011 Alexey Shabalin <shaba@altlinux.ru> 0.37.1-alt3.7f564
+- upstream git snapshot 7f5641d9b2e8d073466f0511a17e669438dbaea7
+
+* Thu May 19 2011 Alexey Shabalin <shaba@altlinux.ru> 0.37.1-alt2
+- fix pid file of cgred service
+- ignore systemd hierarchy
+- use -avoid-version instead of messing with pam module renaming
+- backported from upstream snapshot:
+  + Fixed parsing of mount options
+  + Fix cgclear to continue unmounting on error
+
+* Thu Mar 03 2011 Alexey Shabalin <shaba@altlinux.ru> 0.37.1-alt1
+- 0.37.1
+- Fix buffer overflow when processing list of controllers from command line (CVE-2011-1006)
+
+* Thu Dec 16 2010 Alexey Shabalin <shaba@altlinux.ru> 0.37-alt1
+- 0.37
+- defined startup_failure in cgconfig init script (ALT #24596)
+
+* Sun Sep 19 2010 Alexey Shabalin <shaba@altlinux.ru> 0.36.2-alt3.git20100906
+- git snapshot af53a11e8e5f27593f31a34739756d41a08b5416
+- fix init scripts
+- mount tmpfs to /sys/fs/cgroup from init cgconfig (/sys/fs/cgroup exist in kernel 2.6.35-un-def-alt4.2)
+
+* Thu Aug 26 2010 Alexey Shabalin <shaba@altlinux.ru> 0.36.2-alt2
+- change default mount point from /var/run/cgroup/system to /sys/fs/cgroup/system
+
+* Wed Jul 07 2010 Alexey Shabalin <shaba@altlinux.ru> 0.36.2-alt1
+- initial build for ALTLinux
diff --git a/samples/cgconfig.conf b/samples/cgconfig.conf
index de77e4b..b7fdd75 100644
--- a/samples/cgconfig.conf
+++ b/samples/cgconfig.conf
@@ -10,39 +10,19 @@
 #  WITHOUT ANY WARRANTY; without even the implied warranty of
 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 #
-#group daemons/www {
-#	perm {
-#		task {
-#			uid = root;
-#			gid = webmaster;
-#		}
-#		admin {
-#			uid = root;
-#			gid = root;
-#		}
-#	}
-#	cpu {
-#		cpu.shares = 1000;
-#	}
-#}
-#
-#group daemons/ftp {
-#	perm {
-#		task {
-#			uid = root;
-#			gid = ftpmaster;
-#		}
-#		admin {
-#			uid = root;
-#			gid = root;
-#		}
-#	}
-#	cpu {
-#		cpu.shares = 500;
-#	}
-#}
 #
+# By default, mount all controllers to /sys/fs/cgroup/<controller>
 #mount {
-#	cpu = /mnt/cgroups/cpu;
-#	cpuacct = /mnt/cgroups/cpuacct;
+#	cpuset = /sys/fs/cgroup/cpuset;
+#	cpu = /sys/fs/cgroup/cpu;
+#	cpuacct = /sys/fs/cgroup/cpuacct;
+#	memory = /sys/fs/cgroup/memory;
+#	devices = /sys/fs/cgroup/devices;
+#	freezer = /sys/fs/cgroup/freezer;
+#	net_cls = /sys/fs/cgroup/net_cls;
 #}
+
+# By default, we expect systemd mounts everything on boot,
+# so there is not much to do.
+# See man cgconfig.conf for further details, how to create groups
+# on system boot using this file.
diff --git a/samples/cgconfig.sysconfig b/samples/cgconfig.sysconfig
index 5a61bf6..0f4f6d1 100644
--- a/samples/cgconfig.sysconfig
+++ b/samples/cgconfig.sysconfig
@@ -5,8 +5,6 @@
 # controller to limit cpu.shares of this default group and allowing some more
 # important group take most of the CPU.
 #
-# By default, create these groups:
-CREATE_DEFAULT=yes
-
-# Uncomment following line to disable creation of the default group on startup:
-# CREATE_DEFAULT=no
+# By default, do not create these groups:
+# CREATE_DEFAULT=yes
+CREATE_DEFAULT=no
diff --git a/scripts/init.d/cgconfig.in b/scripts/init.d/cgconfig.in
index f299d0f..ed56b22 100644
--- a/scripts/init.d/cgconfig.in
+++ b/scripts/init.d/cgconfig.in
@@ -18,6 +18,8 @@
 # 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.
+# config:	/etc/cgconfig.conf
+#
 
 ### BEGIN INIT INFO
 # Provides:             cgconfig
@@ -29,23 +31,22 @@
 # Description:          Create and setup control group filesystem(s)
 ### END INIT INFO
 
-# get correct location of binaries from configure
-prefix=@prefix@;exec_prefix=@exec_prefix@;sbindir=@sbindir@
-CGCONFIGPARSER_BIN=$sbindir/cgconfigparser
+WITHOUT_RC_COMPAT=1
+
+# Source function library.
+. /etc/init.d/functions
+
+
+CGCONFIGPARSER_BIN=cgconfigparser
+SERVICENAME=cgconfig
 CONFIG_FILE=/etc/cgconfig.conf
-servicename=cgconfig
-lockfile=/var/lock/subsys/$servicename
 
-#
-# Source LSB routines
-#
-. /lib/lsb/init-functions
+LOCKFILE=/var/lock/subsys/$SERVICENAME
+RETVAL=0
 
 # read the config
 CREATE_DEFAULT=yes
-if [ -e /etc/sysconfig/cgconfig ]; then
-        . /etc/sysconfig/cgconfig
-fi
+SourceIfNotEmpty /etc/sysconfig/$SERVICENAME
 
 create_default_groups() {
 	defaultcgroup=
@@ -54,8 +55,8 @@ create_default_groups() {
 	    read user ctrl defaultcgroup <<< \
 		    $(grep -m1 '^\*[[:space:]]\+' /etc/cgrules.conf)
             if [ -n "$defaultcgroup" -a "$defaultcgroup" = "*" ]; then
-                log_warning_msg "/etc/cgrules.conf incorrect"
-                log_warning_msg "Overriding it"
+                passed "/etc/cgrules.conf incorrect"
+                passed "Overriding it"
                 defaultcgroup=
             fi
         fi
@@ -95,112 +96,100 @@ create_default_groups() {
                  2>/dev/null || :
 }
 
-start() {
-        echo -n "Starting cgconfig service: "
-	if [ -f "$lockfile" ]; then
-            log_warning_msg "lock file already exists"
-            return 0
-        fi
-
-        if [ $? -eq 0 ]; then
-                if [ ! -s $CONFIG_FILE ]; then
-                    log_failure_msg $CONFIG_FILE "is not configured"
-                    return 6
-                fi
-
-                $CGCONFIGPARSER_BIN -l $CONFIG_FILE
-                retval=$?
-                if [ $retval -ne 0 ]; then
-                    log_failure_msg "Failed to parse " $CONFIG_FILE
-                    return 1
-                fi
-        fi
-
-        if [ $CREATE_DEFAULT = "yes" ]; then
-                create_default_groups
-        fi
-
-        touch "$lockfile"
-        retval=$?
-        if [ $retval -ne 0 ]; then
-            log_failure_msg "Failed to touch $lockfile"
-            return 1
-        fi
-        log_success_msg
-        return 0
+startup_failure()
+{
+        msg_starting "cgconfig"
+        printf "%s" "$1"
+        failure "cgconfig startup"
+        echo
 }
 
-stop() {
-    echo -n "Stopping cgconfig service: "
-    cgclear
-    rm -f "$lockfile"
-    log_success_msg
-    return 0
+check()
+{
+	# Check system before trying to start
+	[ -d /sys/fs/cgroup ] || {
+		startup_failure "kernel too old - no  /sys/fs/cgroup"
+		return 1
+	}
+	# Prepare tmpfs for /sys/fs/cgroup
+	if ! grep -q "[[:space:]]/sys/fs/cgroup[[:space:]]" /proc/mounts; then
+		mount -t tmpfs -o noexec,nodev,nosuid tmpfs /sys/fs/cgroup
+	fi
+	echo -n "Checking cgconfig configuration: "
+	if "$CGCONFIGPARSER_BIN" -l "$CONFIG_FILE"; then
+		success "cgconfig check"
+		RETVAL=0
+	else
+		failure "cgconfig check"
+		RETVAL=1
+	fi
+	echo
+	return $RETVAL
 }
 
-trapped() {
-    #
-    # Do nothing
-    #
-    true
-}
-
-usage() {
-    echo "$0 <start|stop|restart|condrestart|status>"
-    exit 2
+start() {
+	check || return
+	is_yes "$CREATE_DEFAULT" && create_default_groups
+	touch "$LOCKFILE"
+	return $RETVAL
 }
 
-common() {
-    #
-    # main script work done here
-    #
-    trap "trapped ABRT" ABRT
-    trap "trapped QUIT" QUIT
-    trap "trapped TERM" TERM
-    trap "trapped INT"   INT
+stop() {
+	action "Stopping cgconfig service: " cgclear
+	RETVAL=$?
+	[ $RETVAL -eq 0 ] && rm -f "$LOCKFILE"
+	return $RETVAL
 }
 
-restart() {
-	common
+restart()
+{
 	stop
 	start
 }
 
-RETVAL=0
 
-case $1 in
-    'stop')
-        common
-        stop
-        RETVAL=$?
+case "$1" in
+    stop)
+        stop;
+        ;;
+    start)
+        start;
         ;;
-    'start')
-        common
-        start
-        RETVAL=$?
+    restart)
+        restart
         ;;
-    'restart'|'reload')
-	restart
-        RETVAL=$?
+    reload)
+        restart
+        ;;
+    condstop)
+        if [ -e "$LOCKFILE" ]; then
+                stop
+        fi
         ;;
-    'condrestart')
-        if [ -f "$lockfile" ]; then
-            restart
-            RETVAL=$?
+    condreload)
+        if [ -e "$LOCKFILE" ]; then
+                restart
         fi
         ;;
-    'status')
-        if [ -f "$lockfile" ]; then
+    condrestart)
+        if [ -e "$LOCKFILE" ]; then
+                restart
+        fi
+        ;;
+    status)
+        if [ -f "$LOCKFILE" ]; then
             echo "Running"
-            exit 0
         else
             echo "Stopped"
-            exit 3
         fi
-	;;
-    *)
-        usage
         ;;
+    check)
+        check
+        ;;
+    *)
+	msg_usage "${0##*/} {start|stop|restart|reload|status|condrestart|check}"
+	RETVAL=1
+	;;
 esac
 
 exit $RETVAL
diff --git a/scripts/init.d/cgred.in b/scripts/init.d/cgred.in
index 247ec61..6572473 100644
--- a/scripts/init.d/cgred.in
+++ b/scripts/init.d/cgred.in
@@ -22,139 +22,108 @@
 # pidfile: /var/run/cgred.pid
 #
 ### BEGIN INIT INFO
-# Provides:		cgrulesengd
-# Required-Start:	$local_fs $syslog $cgconfig
+# Provides:		cgred
+# Required-Start:	$local_fs $syslog cgconfig
 # Required-Stop:	$local_fs $syslog
-# Should-Start:		
-# Should-Stop:		
+# Should-Start:		2 3 4 5
+# Should-Stop:		0 1 6
 # Short-Description:	start and stop the cgroups rules engine daemon
 # Description:		CGroup Rules Engine is a tool for automatically using \
 #			cgroups to classify processes
 ### END INIT INFO
 
-prefix=@prefix@;exec_prefix=@exec_prefix@;sbindir=@sbindir@
-CGRED_BIN=$sbindir/cgrulesengd
-CGRED_CONF=/etc/cgrules.conf
+WITHOUT_RC_COMPAT=1
 
-# Sanity checks
-[ -x $CGRED_BIN ] || exit 1
+# Source function library.
+. /etc/init.d/functions
 
-# Source function library & LSB routines
-. /etc/rc.d/init.d/functions
-. /lib/lsb/init-functions
+# For convenience
+PROCESSNAME=cgrulesengd
+SERVICENAME=cgred
+PIDFILE=/var/run/cgred.pid
+LOCKFILE=/var/lock/subsys/$SERVICENAME
+RETVAL=0
+
+SourceIfNotEmpty /etc/sysconfig/$SERVICENAME
 
-# Read in configuration options.
-if [ -f "/etc/sysconfig/cgred.conf" ] ; then
-	. /etc/sysconfig/cgred.conf
-	OPTIONS="$NODAEMON $LOG"
-	if [ -n "$LOG_FILE" ]; then
-		OPTIONS="$OPTIONS --logfile=$LOG_FILE"
-	fi
-	if [ -n "$SOCKET_USER" ]; then
+OPTIONS="$NODAEMON $LOG"
+if [ -n "$LOG_FILE" ]; then
+	OPTIONS="$OPTIONS --logfile=$LOG_FILE"
+fi
+if [ -n "$SOCKET_USER" ]; then
 		OPTIONS="$OPTIONS -u $SOCKET_USER"
-	fi
-	if [ -n "$SOCKET_GROUP" ]; then
+fi
+if [ -n "$SOCKET_GROUP" ]; then
 		OPTIONS="$OPTIONS -g $SOCKET_GROUP"
-	fi
-else
-	OPTIONS=""
 fi
 
-# For convenience
-processname=cgrulesengd
-servicename=cgred
-lockfile="/var/lock/subsys/$servicename"
-pidfile=/var/run/cgred.pid
-
 start()
 {
-	echo -n $"Starting CGroup Rules Engine Daemon: "
-	if [ -f "$lockfile" ]; then
-		log_failure_msg "$servicename is already running with PID `cat ${pidfile}`"
-		return 0
-	fi
-	num=`grep "cgroup" /proc/mounts | awk '$3=="cgroup"' | wc -l`
-	if [ $num -eq 0 ]; then
-		echo
-		log_failure_msg $"Cannot find cgroups, is cgconfig service running?"
-		return 1
-	fi
-	daemon --check $servicename --pidfile $pidfile $CGRED_BIN $OPTIONS
-	retval=$?
-	echo
-	if [ $retval -ne 0 ]; then
-		return 7
-	fi
-	touch "$lockfile"
-	if [ $? -ne 0 ]; then
-		return 1
-	fi
-	echo "`pidof $processname`" > $pidfile
-	return 0
+	start_daemon --make-pidfile --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --displayname "$SERVICENAME" --name "$SERVICENAME" --expect-user root -- $PROCESSNAME $OPTIONS
+	RETVAL=$?
+	# fix pid
+	pidof cgrulesengd > "$PIDFILE"
+	return $RETVAL
 }
 
 stop()
 {
-	echo -n $"Stopping CGroup Rules Engine Daemon..."
-	if [ ! -f $pidfile ]; then
-		log_success_msg
-		return 0
-	fi
-	killproc -p $pidfile -TERM "$processname"
-	retval=$?
-	echo
-	if [ $retval -ne 0 ]; then
-		return 1
-	fi
-	rm -f "$lockfile" "$pidfile"
-	return 0
+	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --displayname "$SERVICENAME" --expect-user root -- $PROCESSNAME
+	RETVAL=$?
+	return $RETVAL
+}
+
+reload()
+{
+	msg_reloading $SERVICENAME
+	stop_daemon --pidfile "$PIDFILE" --displayname "$SERVICENAME" --expect-user root -HUP -- $PROCESSNAME
+	RETVAL=$?
+	return $RETVAL
+}
+
+restart()
+{
+	stop
+	start
 }
 
-RETVAL=0
 
 # See how we are called
 case "$1" in
 	start)
 		start
-		RETVAL=$?
 		;;
 	stop)
 		stop
-		RETVAL=$?
 		;;
 	status)
-		status -p $pidfile $servicename
+		status --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --displayname "$SERVICENAME" --expect-user root -- $PROCESSNAME
 		RETVAL=$?
 		;;
 	restart)
-		stop
-		start
-		RETVAL=$?
+		restart
 		;;
-	condrestart)
-		if [ -f "$lockfile" ]; then
+	reload)
+		reload
+		;;
+	condstop)
+		if [ -e "$LOCKFILE" ]; then
 			stop
-			start
-			RETVAL=$?
 		fi
 		;;
-	reload|flash)
-		if [ -f "$lockfile" ]; then
-			echo $"Reloading rules configuration..."
-			kill -s 12 `cat ${pidfile}`
-			RETVAL=$?
-			if [ $RETVAL -eq 0 ] ; then
-				log_success_msg
-			else
-				log_failure_msg
-			fi
-		else
-			log_failure_msg "$servicename is not running."
+	condreload)
+		if [ -e "$LOCKFILE" ]; then
+			reload
+		fi
+		;;
+	condrestart)
+		if [ -e "$LOCKFILE" ]; then
+			restart
 		fi
 		;;
 	*)
-		echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
-		RETVAL=2
+		msg_usage "${0##*/} {start|stop|restart|reload|status|condrestart}"
+		RETVAL=1
 		;;
 esac
 
diff --git a/src/Makefile.am b/src/Makefile.am
index 26e3223..f35c9a3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -16,6 +16,7 @@ CLEANFILES = lex.c parse.c parse.h
 AM_CPPFLAGS = -I$(top_srcdir)/include
 
 lib_LTLIBRARIES = libcgroup.la
+lex.c: parse.h
 libcgroup_la_SOURCES = parse.h parse.y lex.l api.c config.c libcgroup-internal.h libcgroup.map wrapper.c log.c
 libcgroup_la_LIBADD = -lpthread $(CODE_COVERAGE_LIBS)
 libcgroup_la_CFLAGS = $(CODE_COVERAGE_CFLAGS) -DSTATIC=static
diff --git a/src/tools/Makefile.am b/src/tools/Makefile.am
index 4060887..23cac99 100644
--- a/src/tools/Makefile.am
+++ b/src/tools/Makefile.am
@@ -1,7 +1,7 @@
 @CODE_COVERAGE_RULES@
 
 AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/include
-LDADD = $(top_builddir)/src/libcgroup.la -lpthread
+LIBS = $(top_builddir)/src/libcgroup.la -lpthread
 
 if WITH_TOOLS
 
 
design & coding: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
current maintainer: Michael Shigorin