Date: Mon, 24 Jul 2006 21:13:01 +0400 From: Yar Tikhiy <yar@comp.chem.msu.su> To: freebsd-rc@FreeBSD.org Subject: Order of _nice, _user, and _chdir Message-ID: <20060724171301.GA52664@comp.chem.msu.su>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060724171301.GA52664>
