Bug 212493 - /etc/rc.subr's new limits + chdir will cause limits to run on chdir instead of prog
Summary: /etc/rc.subr's new limits + chdir will cause limits to run on chdir instead o...
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: misc (show other bugs)
Version: 11.0-STABLE
Hardware: Any Any
: --- Affects Many People
Assignee: FreeBSD Release Engineering
URL:
Keywords: needs-qa, patch-ready
Depends on:
Blocks:
 
Reported: 2016-09-08 18:02 UTC by Ultima
Modified: 2018-05-23 13:17 UTC (History)
14 users (show)

See Also:


Attachments
rc.subr.diff (483 bytes, patch)
2016-09-08 18:02 UTC, Ultima
no flags Details | Diff
PATCH fix problem with chdir and limits in rc.subr (856 bytes, patch)
2016-10-03 01:42 UTC, Palle Girgensohn
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ultima 2016-09-08 18:02:06 UTC
Created attachment 174540 [details]
rc.subr.diff

Recently I was having issues with a port after upgrading from 10.3 to 11. (This bug also exists on head) When the chdir var is used, the limits command will be prepended to chdir instead of the prog. This can, and in my case caused the cd command to fail and the program will fail to start.


i'm going to omit much of the debugging info and paste the useful points.

Current rc.subr:
+ _doit='limits -C daemon cd /var/db/teamspeak && /usr/sbin/daemon  -fp /var/db/teamspeak/teamspeak_server.pid -u teamspeak /usr/local/libexec/ts3server dbsqlpath=/usr/local/share/teamspeak/server/sql/ inifile=/usr/local/etc/teamspeak/ts3server.ini licensepath=/usr/local/etc/teamspeak/ logpath=/var/log/teamspeak'
+ _run_rc_doit 'limits -C daemon cd /var/db/teamspeak && /usr/sbin/daemon  -fp /var/db/teamspeak/teamspeak_server.pid -u teamspeak /usr/local/libexec/ts3server dbsqlpath=/usr/local/share/teamspeak/server/sql/ inifile=/usr/local/etc/teamspeak/ts3server.ini licensepath=/usr/local/etc/teamspeak/ logpath=/var/log/teamspeak'
+ debug 'run_rc_command: doit: limits -C daemon cd /var/db/teamspeak && /usr/sbin/daemon  -fp /var/db/teamspeak/teamspeak_server.pid -u teamspeak /usr/local/libexec/ts3server dbsqlpath=/usr/local/share/teamspeak/server/sql/ inifile=/usr/local/etc/teamspeak/ts3server.ini licensepath=/usr/local/etc/teamspeak/ logpath=/var/log/teamspeak'
+ eval 'limits -C daemon cd /var/db/teamspeak && /usr/sbin/daemon  -fp /var/db/teamspeak/teamspeak_server.pid -u teamspeak /usr/local/libexec/ts3server dbsqlpath=/usr/local/share/teamspeak/server/sql/ inifile=/usr/local/etc/teamspeak/ts3server.ini licensepath=/usr/local/etc/teamspeak/ logpath=/var/log/teamspeak'
+ limits -C daemon cd /var/db/teamspeak
+ /usr/sbin/daemon -fp /var/db/teamspeak/teamspeak_server.pid -u teamspeak /usr/local/libexec/ts3server 'dbsqlpath=/usr/local/share/teamspeak/server/sql/' 'inifile=/usr/local/etc/teamspeak/ts3server.ini' 'licensepath=/usr/local/etc/teamspeak/' 'logpath=/var/log/teamspeak'


Attached, I have created a small change to rc.subr that fixes this issue.
Comment 1 Palle Girgensohn freebsd_committer 2016-10-03 01:42:12 UTC
Created attachment 175378 [details]
PATCH fix problem with chdir and limits in rc.subr

Hi,

I was just bitten by the same bug.

The suggested fix here is not correct, though, since the limits clause is moved into the else clauee after "if chroot".

I've attached another suggestion to fix this, that works with chroot as well.

Palle
Comment 2 Palle Girgensohn freebsd_committer 2016-10-03 01:46:16 UTC
Hi, 

I'm taking the liberty to add adrian@ who committed the original work and dteske who reviewed it, just to draw your attention to this corner case, hope you don't mind.

Palle
Comment 3 Adrian Chadd freebsd_committer 2016-10-03 16:46:06 UTC
lgtm
Comment 4 Devin Teske freebsd_committer 2016-10-03 19:24:50 UTC
lgtm
Comment 5 Palle Girgensohn freebsd_committer 2016-10-03 21:30:27 UTC
So who can commit it. I'm only a porter, no commit bit in src. :)
Comment 6 Devin Teske freebsd_committer 2016-10-03 22:34:18 UTC
If still pending by this weekend, I'll jump on it. Pretty busy right now though.
Comment 7 Jakob Breivik Grimstveit 2016-10-12 17:44:08 UTC
(In reply to Devin Teske from comment #6)
Seems like this still isn't fixed? Since this bites me as well, can you please look into it?
Comment 8 Jakob Breivik Grimstveit 2016-10-12 18:31:08 UTC
Have manually applied the suggested fix, and can confirm that it works.
Comment 9 Devin Teske freebsd_committer 2016-10-12 21:17:49 UTC
I've filed a patch for review.

https://reviews.freebsd.org/D8232

Changed "_docd" from girgen's patch to "_cd" to prevent confusion (docd could be shorthand for "doc directory" instead of "do cd").

Changed the way NULL values are assigned (no quotes needed).
Comment 10 shark 2016-10-17 07:42:34 UTC
The same Teamspeak issue affected me as well.

I applied the patch from https://reviews.freebsd.org/D8232 and now my Teamspeak service runs again.

Thanks for the patch.
Comment 11 Jérôme Le Gal 2016-10-19 10:27:32 UTC
Since I patched my rc.subr Teamspeak works like a charm.

Thanks.
Comment 12 Ultima 2016-10-26 02:28:30 UTC
https://reviews.freebsd.org/D8232 was accepted, has this been committed yet?
Comment 13 Devin Teske freebsd_committer 2016-10-26 14:07:47 UTC
(In reply to Ultima from comment #12)

We're waiting on Adrian
Comment 14 nepotel 2016-11-08 17:49:26 UTC
The fix is working flawlessly for me too.
Comment 15 Devin Teske freebsd_committer 2016-11-08 17:59:25 UTC
Still waiting on Adrian
Comment 16 Matthias Fechner freebsd_committer 2016-12-03 17:12:50 UTC
any news here?
Comment 17 commit-hook freebsd_committer 2016-12-03 19:03:58 UTC
A commit references this bug:

Author: dteske
Date: Sat Dec  3 19:03:40 UTC 2016
New revision: 309504
URL: https://svnweb.freebsd.org/changeset/base/309504

Log:
  Fix bug preventing limits(1) from being applied

  PR:		misc/212493
  Differential Revision:	https://reviews.freebsd.org/D8232
  Submitted by:	girgen
  Reviewed by:	adrian
  MFC after:	3 days
  X-MFC-to:	stable/11

Changes:
  head/etc/rc.subr
Comment 18 Devin Teske freebsd_committer 2016-12-03 20:42:49 UTC
(In reply to Matthias Fechner from comment #16)

Adrian approved today.
It's committed.
Waiting 3 days for MFC to stable/11.
Comment 19 Matthias Fechner freebsd_committer 2016-12-11 15:36:33 UTC
(In reply to Devin Teske from comment #18)
Thanks a lot Devin!
Hopefully it goes quickly into the stable branch. After this is fixed I can rollout freebsd 11 to all servers.
Comment 20 commit-hook freebsd_committer 2016-12-13 04:51:51 UTC
A commit references this bug:

Author: dteske
Date: Tue Dec 13 04:50:45 UTC 2016
New revision: 310010
URL: https://svnweb.freebsd.org/changeset/base/310010

Log:
  MFC r309504: Fix bug preventing limits(1) from being applied

  PR:		misc/212493
  Differential Revision:	https://reviews.freebsd.org/D8232
  Submitted by:	girgen
  Reviewed by:	adrian

Changes:
_U  stable/11/
  stable/11/etc/rc.subr
Comment 21 Ultima 2016-12-17 15:32:04 UTC
 Will this be MFC'd to releng/11.0?
Comment 22 Devin Teske freebsd_committer 2017-01-08 18:21:04 UTC
(In reply to Ultima from comment #21)
When we merge into stable, it's from head (aka Current) and hence "MFC" is Merge from Current [into Stable].

When we merge into releng, it's from stable and hence "MFS" is the appropriate acronym here, for Merge from Stable [into Releng].

Merging into releng requires approval from secteam@ and/or releng@.

I will be pointing them at this bug and see if I can get approval for MFS.
Comment 23 Ultima 2017-01-08 19:44:56 UTC
(In reply to Devin Teske from comment #22)
Ah, Thanks for clearing this up.

I have been getting messages from users asking when the port will be fixed and I refer them to this bug and that its not the port, waiting for MFC (actually is MFS). I hope there is an __FreeBSD_version bump if this gets MFS.
Comment 24 Palle Girgensohn freebsd_committer 2017-01-15 01:29:58 UTC
Yeah, would it be possible to get this into an errata? For some ports this is a big problem.
Comment 25 fullermd 2017-04-09 09:18:21 UTC
Put me down as another vote for merge, or at least errata noting.  I just wasted well over an hour trying to figure out why a program with _chdir was failing to start.
Comment 26 Matthias Fechner freebsd_committer 2017-05-11 08:55:40 UTC
Is there a time planning available this will be fixed in FreeBSD 11 (available via freebsd-update)?
This is the last bug that prevents me to update all servers to FreeBSD 11.

Thanks a lot for your answers.
Comment 27 Eitan Adler freebsd_committer freebsd_triage 2018-05-23 10:27:16 UTC
batch change of PRs untouched in 2018 marked "in progress" back to open.
Comment 28 Palle Girgensohn freebsd_committer 2018-05-23 13:17:16 UTC
(In reply to commit-hook from comment #20)

This was comitted in 2016.