From nobody@FreeBSD.org  Sun Dec 21 11:39:36 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id D070E106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 21 Dec 2008 11:39:36 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id BF8628FC08
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 21 Dec 2008 11:39:36 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id mBLBdaOi013253
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 21 Dec 2008 11:39:36 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id mBLBdadv013252;
	Sun, 21 Dec 2008 11:39:36 GMT
	(envelope-from nobody)
Message-Id: <200812211139.mBLBdadv013252@www.freebsd.org>
Date: Sun, 21 Dec 2008 11:39:36 GMT
From: Artem Naluzhnyy <tut@nhamon.com.ua>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] support of per script nice(1) value in periodic.conf(5)
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         129814
>Category:       bin
>Synopsis:       [patch] support of per script nice(1) value in periodic.conf(5)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Dec 21 11:40:03 UTC 2008
>Closed-Date:    
>Last-Modified:  Tue Dec 23 08:10:01 UTC 2008
>Originator:     Artem Naluzhnyy
>Release:        7.1-PRERELEASE
>Organization:
>Environment:
>Description:
The patch adds support of per periodic(8) script nice(1) value the script will be run at. There are two features:

  * default_nice variable - default nice level
  * <basename>_<script>_nice variables - nice level for the specific script


Default behavior after the patch application is still the same - no nice level changes.


periodic.conf(5) example:

  default_nice=10
  daily_status_mail_rejects_enable="YES"
  daily_status_mail_rejects_nice=8
>How-To-Repeat:

>Fix:
--- usr.sbin/periodic/periodic.sh.orig	2007-06-22 13:04:05.000000000 +0300
+++ usr.sbin/periodic/periodic.sh	2008-12-21 12:06:09.000000000 +0200
@@ -78,7 +78,23 @@
                 then
                     output=TRUE
                     processed=$(($processed + 1))
-                    $file </dev/null >$tmp_output 2>&1
+
+                    _script=$(basename "$file")
+                    # trim three leading digits and dot if present
+                    # replace '-' with '_'
+                    _script=$(echo "${_script##[0-9][0-9][0-9].}" | tr - _)
+                    eval _nice=\$${arg##*/}_${_script}_nice
+                    if [ -n "${_nice}" ]
+                    then
+                        nice_cmd="nice -n ${_nice}"
+                    elif [ -n "${default_nice}" ]
+                    then
+                        nice_cmd="nice -n ${default_nice}"
+                    else
+                        nice_cmd=''
+                    fi
+
+                    $nice_cmd $file </dev/null >$tmp_output 2>&1
                     rc=$?
                     if [ -s $tmp_output ]
                     then
--- usr.sbin/periodic/periodic.8.orig	2007-09-08 00:54:45.000000000 +0300
+++ usr.sbin/periodic/periodic.8	2008-12-21 13:19:24.000000000 +0200
@@ -144,6 +144,18 @@
 If
 .Ao Ar basedir Ac Ns Va _output
 is not set or is empty, output is sent to standard output.
+.Pp
+If
+.Ao Ar basedir Ac Ns Va _ Ns Ao Ar script Ac Ns Va _nice
+variable is set, the script will be run at specified nice level. Otherwise
+nice level from
+.Va default_nice
+variable is used. Script name should be specified without three leading digits
+and dot, dashes in the script name should be replaced with underscores (e.g.
+.Pa daily_status_mail_rejects_nice
+variable for
+.Pa /etc/periodic/daily/460.status-mail-rejects
+script).
 .Sh ENVIRONMENT
 The
 .Nm
--- etc/defaults/periodic.conf.orig	2008-01-27 10:07:14.000000000 +0200
+++ etc/defaults/periodic.conf	2008-12-21 13:26:24.000000000 +0200
@@ -22,6 +22,9 @@
 # periodic script dirs
 local_periodic="/usr/local/etc/periodic"
 
+# default nice level all periodic scripts will be run at
+default_nice=""
+
 
 # Daily options
 


>Release-Note:
>Audit-Trail:

From: "Garrett Cooper" <yanefbsd@gmail.com>
To: "Artem Naluzhnyy" <tut@nhamon.com.ua>
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: bin/129814: [patch] support of per script nice(1) value in periodic.conf(5)
Date: Mon, 22 Dec 2008 15:38:09 -0800

     Can you provide a concrete example of this so I don't have to go
 reading through ~50 lines of bourne shell and put it in perspective of
 periodic.conf(5)?
 Thanks :),
 -Garrett

From: "Garrett Cooper" <yanefbsd@gmail.com>
To: "Artem Naluzhnyy" <tut@nhamon.com.ua>
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: bin/129814: [patch] support of per script nice(1) value in periodic.conf(5)
Date: Mon, 22 Dec 2008 15:38:48 -0800

     Nevermind.. I need to read more closely before I submit ><.
 Sorry,
 -Garrett

From: "Garrett Cooper" <yanefbsd@gmail.com>
To: "Artem Naluzhnyy" <tut@nhamon.com.ua>
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: bin/129814: [patch] support of per script nice(1) value in periodic.conf(5)
Date: Mon, 22 Dec 2008 15:44:22 -0800

 The only issue with this is that:
 
 if [ -n "${_nice}" ]
 
 and:
 
 elif [ -n "${default_nice}" ]
 
 don't check for valid number values. I'm not sure if we'd want to
 throw in that logic or not (or if there's something else in our
 rc-scripts that automatically checks for numbers in range)...
 
 I'd ask (quickly) on hackers@ to see if the change makes sense for a
 more widespread review.
 
 Cheers,
 -Garrett

From: "Artem Naluzhnyy" <tut@nhamon.com.ua>
To: "Garrett Cooper" <yanefbsd@gmail.com>
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: bin/129814: [patch] support of per script nice(1) value in periodic.conf(5)
Date: Tue, 23 Dec 2008 09:28:01 +0200

 Hi,
 
 On Tue, Dec 23, 2008 at 01:44, Garrett Cooper <yanefbsd@gmail.com> wrote:
 > The only issue with this is that:
 >
 > if [ -n "${_nice}" ]
 >
 > and:
 >
 > elif [ -n "${default_nice}" ]
 >
 > don't check for valid number values. I'm not sure if we'd want to
 > throw in that logic or not (or if there's something else in our
 > rc-scripts that automatically checks for numbers in range)...
 >
 > I'd ask (quickly) on hackers@ to see if the change makes sense for a
 > more widespread review.
 
 Actually the same feature for rc.conf file has no integer value syntax
 check and produces the same error message from nice(1):
 
   nice: qwerty: invalid nice value
 
 -- 
 Artem Naluzhnyy
>Unformatted:
