From owner-freebsd-rc@FreeBSD.ORG Mon Jul 24 17:13:13 2006 Return-Path: X-Original-To: freebsd-rc@FreeBSD.org Delivered-To: freebsd-rc@FreeBSD.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 10EC916A4DE for ; Mon, 24 Jul 2006 17:13:13 +0000 (UTC) (envelope-from yar@comp.chem.msu.su) Received: from comp.chem.msu.su (comp.chem.msu.su [158.250.32.97]) by mx1.FreeBSD.org (Postfix) with ESMTP id B1BE943D6E for ; Mon, 24 Jul 2006 17:13:07 +0000 (GMT) (envelope-from yar@comp.chem.msu.su) Received: from comp.chem.msu.su (localhost [127.0.0.1]) by comp.chem.msu.su (8.13.4/8.13.3) with ESMTP id k6OHD1gx055732 for ; Mon, 24 Jul 2006 21:13:02 +0400 (MSD) (envelope-from yar@comp.chem.msu.su) Received: (from yar@localhost) by comp.chem.msu.su (8.13.4/8.13.3/Submit) id k6OHD12v055731 for freebsd-rc@FreeBSD.org; Mon, 24 Jul 2006 21:13:01 +0400 (MSD) (envelope-from yar) Date: Mon, 24 Jul 2006 21:13:01 +0400 From: Yar Tikhiy To: freebsd-rc@FreeBSD.org Message-ID: <20060724171301.GA52664@comp.chem.msu.su> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.9i Cc: Subject: Order of _nice, _user, and _chdir X-BeenThere: freebsd-rc@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Discussion related to /etc/rc.d design and implementation." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Jul 2006 17:13:13 -0000 Hi all, I saw a complaint in a Russian BSD newsgroup that it was impossible to assign a negative niceness to the $command process via $foo_nice whenever $foo_user was set to a non-root user. So I took a look at the part of rc.subr dealing with the start of $command. As of now, the order of processing foo_chdir, foo_nice, and foo_user is as follows: user ( chdir ; nice ( command ) ) E.g.: su -m $foo_user -c 'sh -c "cd $foo_chdir ; nice -n $foo_nice $command"' Therefore the command's process(es) may not be assigned a negative niceness because nice(1) is run as the unprivileged $foo_user. In addition, a failure to chdir() will be ignored. IMHO a better order would be: nice ( user ( chdir && command ) ) E.g.: nice -n $foo_nice su -m $foo_user -c 'sh -c "cd $foo_chdir && $command"' nice -n $foo_nice sh -c "cd $foo_chdir && $command" # w/o foo_user The respective patch is attached. Any comments? Thanks. -- Yar Index: rc.subr =================================================================== RCS file: /home/ncvs/src/etc/rc.subr,v retrieving revision 1.59 diff -u -p -r1.59 rc.subr --- rc.subr 21 Jun 2006 09:42:55 -0000 1.59 +++ rc.subr 24 Jul 2006 15:30:53 -0000 @@ -666,12 +666,17 @@ chroot ${_user:+-u $_user }${_group:+-g $_chroot $command $rc_flags $command_args" else _doit="\ -${_chdir:+cd $_chdir; }\ -${_nice:+nice -n $_nice }\ +${_chdir:+cd $_chdir && }\ $command $rc_flags $command_args" if [ -n "$_user" ]; then _doit="su -m $_user -c 'sh -c \"$_doit\"'" fi + if [ -n "$_nice" ]; then + if [ -z "$_user" ]; then + _doit="sh -c \"$_doit\"" + fi + _doit="nice -n $_nice $_doit" + fi fi # if the cmd failed and force