Possible problem with the ${name}_chdir variable behaviour in /etc/c.subr

From: Tim Preston <graywolfe_at_mac.com>
Date: Sun, 20 Mar 2016 17:51:30 +0000
I was having a problem making the audio/teamspeak3-server port start fro the rc.d scripts on a  -current box that I’ve just built. I eventually traced this down to it not starting in the correct directory.

Looking at the rc.d script I could see that it was attempting to chdir to  the correct directory by setting the teamspeak_chdir variable. So it looked like this feature was misbehaving in some way.

To test this I put together an rc.d script for pwd that used ${name}_chdir based on how the teamspeak rc.d script was setup. Running this on a 10.3 box showed that it was changing to the specified directory as expected, but on -current it was not.

I’ve taken a quick look at rc.subr on both boxes but I can’t immediately see what’s breaking this, and I can’t see anything in the setup or behaviour of the -current box that would point to it being something that I’ve broken somehow there.

I was wondering if anyone else could reproduce this?


Simple rc.d script for pwd
-----
#!/bin/sh

# PROVIDE: pwd
# REQUIRE: LOGIN
# KEYWORD: shutdown

. /etc/rc.subr

name="pwd"
rcvar=pwd_enable

db_dir=/var/db/teamspeak

command=/bin/pwd
pwd_chdir=$db_dir
required_dirs="$db_dir"

load_rc_config $name

: ${pwd_enable="NO"}

run_rc_command "$1"
-----

Running on 10.3 shows the expected result
-----
root_at_amy:~# uname -a
FreeBSD amy.flibble.org 10.3-BETA3 FreeBSD 10.3-BETA3 #3 r296346: Thu Mar  3 15:09:55 GMT 2016     root_at_amy:/usr/obj/usr/src/sys/GENERIC  amd64
root_at_amy:~# grep FreeBSD /etc/rc.subr  
# $FreeBSD: stable/10/etc/rc.subr 292450 2015-12-18 19:58:34Z rilles $
root_at_amy:~# ls -ld /var/db/teamspeak 
drwxr-xr-x  3 teamspeak  teamspeak  512 Mar 20 00:23 /var/db/teamspeak
root_at_amy:~# sum /usr/local/etc/rc.d/pwd 
33073 1 /usr/local/etc/rc.d/pwd

root_at_amy:~# service pwd onestart
Starting pwd.
/var/db/teamspeak
-----

On -current we see that were still in /
-----
root_at_emily:~# uname -a
FreeBSD emily.flibble.org 11.0-CURRENT FreeBSD 11.0-CURRENT #0 r297022: Fri Mar 18 15:18:44 UTC 2016     root_at_emily.flibble.org:/usr/obj/usr/src/sys/GENERIC  amd64
root_at_emily:~# grep FreeBSD /etc/rc.subr
# $FreeBSD: head/etc/rc.subr 295949 2016-02-24 01:32:12Z araujo $
root_at_amy:~# ls -ld /var/db/teamspeak 
drwxr-xr-x  3 teamspeak  teamspeak  512 Mar 20 00:23 /var/db/teamspeak
root_at_emily:~# sum /usr/local/etc/rc.d/pwd
33073 1 /usr/local/etc/rc.d/pwd

root_at_emily:~# service pwd onestart
Starting pwd.
/
-----


-- 
Tim Preston
graywolfe_at_mac.com
Received on Sun Mar 20 2016 - 17:51:40 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:41:03 UTC