On 02/28/2011 05:39 PM, Jiri Slaby wrote:
> * get rid of some unneeded bashisms
> * remove unused variables
> * define lockfile to be used all over the file
> * define restart, to not duplicate code
> 
> Signed-off-by: Jiri Slaby <jsl...@suse.cz>

Acked-By: Jan Safranek <jsafr...@redhat.com>

> ---
>  scripts/init.d/cgconfig.in |   53 +++++++++++++++++++------------------------
>  1 files changed, 23 insertions(+), 30 deletions(-)
> 
> diff --git a/scripts/init.d/cgconfig.in b/scripts/init.d/cgconfig.in
> index 00a1c9b..d9d67d7 100644
> --- a/scripts/init.d/cgconfig.in
> +++ b/scripts/init.d/cgconfig.in
> @@ -34,6 +34,7 @@ prefix=@prefix@;exec_prefix=@exec_prefix@;sbindir=@sbindir@
>  CGCONFIGPARSER_BIN=$sbindir/cgconfigparser
>  CONFIG_FILE=/etc/cgconfig.conf
>  servicename=cgconfig
> +lockfile=/var/lock/subsys/$servicename
>  
>  #
>  # Source LSB routines
> @@ -46,8 +47,6 @@ if [ -e /etc/sysconfig/cgconfig ]; then
>          . /etc/sysconfig/cgconfig
>  fi
>  
> -RETVAL=0
> -
>  create_default_groups() {
>       defaultcgroup=
>  
> @@ -98,24 +97,20 @@ create_default_groups() {
>  
>  start() {
>          echo -n "Starting cgconfig service: "
> -     if [ -f /var/lock/subsys/$servicename ]
> -        then
> +     if [ -f "$lockfile" ]; then
>              log_warning_msg "lock file already exists"
>              return 0
>          fi
>  
> -        if [ $? -eq 0 ]
> -        then
> -                if [ ! -s $CONFIG_FILE ]
> -                then
> +        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
> +                if [ $retval -ne 0 ]; then
>                      log_failure_msg "Failed to parse " $CONFIG_FILE
>                      return 1
>                  fi
> @@ -125,11 +120,10 @@ start() {
>                  create_default_groups
>          fi
>  
> -        touch /var/lock/subsys/$servicename
> +        touch "$lockfile"
>          retval=$?
> -        if [ $retval -ne 0 ]
> -        then
> -            log_failure_msg "Failed to touch " /var/lock/subsys/$servicename
> +        if [ $retval -ne 0 ]; then
> +            log_failure_msg "Failed to touch $lockfile"
>              return 1
>          fi
>          log_success_msg
> @@ -139,7 +133,7 @@ start() {
>  stop() {
>      echo -n "Stopping cgconfig service: "
>      cgclear
> -    rm -f /var/lock/subsys/$servicename
> +    rm -f "$lockfile"
>      log_success_msg
>      return 0
>  }
> @@ -166,38 +160,37 @@ common() {
>      trap "trapped INT"   INT
>  }
>  
> +restart() {
> +     common
> +     stop
> +     start
> +}
> +
> +RETVAL=0
> +
>  case $1 in
>      'stop')
>          common
> -        stop;
> +        stop
>          RETVAL=$?
>          ;;
>      'start')
>          common
> -        start;
> -        RETVAL=$?
> -        ;;
> -    'restart')
> -        common
> -     stop
>          start
>          RETVAL=$?
>          ;;
> -    'reload')
> -        common
> -     stop
> -        start
> +    'restart'|'reload')
> +     restart
>          RETVAL=$?
>          ;;
>      'condrestart')
> -        if [ -f /var/lock/subsys/$servicename ] ; then
> -            stop
> -            start
> +        if [ -f "$lockfile" ]; then
> +            restart
>              RETVAL=$?
>          fi
>          ;;
>      'status')
> -        if [ -f /var/lock/subsys/$servicename ] ; then
> +        if [ -f "$lockfile" ]; then
>              echo "Running"
>              exit 0
>          else


------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in 
Real-Time with Splunk. Collect, index and harness all the fast moving IT data 
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business 
insights. http://p.sf.net/sfu/splunk-dev2dev 
_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to